Skip to content

Conversation

@trancexpress
Copy link
Contributor

GTK3 API gtk_icon_theme_lookup_by_gicon() returns 48x48 icons, despite specifying size 16x16 in the arguments.

This change scales the retrieved icon to 16x16,
to avoid unexpected program icon sizes.

Fixes: #3003

@trancexpress
Copy link
Contributor Author

@akurtakov any better ideas here?

I'll try to get a 16x16 icon with GTK3 APIs, somehow. I do have such sizes available... I'm not sure why 48x48 is always returned.

}
}
data.alphaData = alphaData;
ImageData scaled = data.scaledTo(16, 16);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can check if the height or width are higher than 16 and only then scale...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense.

Did you found the commit that changed this icons size?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably its this commit in platform UI:

eclipse-platform/eclipse.platform.ui@f0b1071

For too large icons, we used to show a default. After this commit we don't.

@github-actions
Copy link
Contributor

github-actions bot commented Jan 23, 2026

Test Results (linux)

   59 files   - 29     59 suites   - 29   8m 23s ⏱️ - 6m 4s
4 562 tests ± 0  4 342 ✅ ± 0  220 💤 ±0  0 ❌ ±0 
  141 runs   - 70    139 ✅  - 69    2 💤  - 1  0 ❌ ±0 

Results for commit 4ca6879. ± Comparison against base commit 8c1409a.

♻️ This comment has been updated with latest results.

@akurtakov
Copy link
Member

Is there 16x16 icon available at all (/usr/share/icons/themename/... or smth similar)? If not what are the available sizes? I believe Gtk returns the closest bigger size if the requested size is not available. If this is on HiDPI system it becomes even more complicated as 16x16 with scale=2 will try to return 32x32 which in case of not available might give you the next one 48x48.
On a HiDPI screen I see too small icon - both with and without the patch
image

@akurtakov
Copy link
Member

I don't believe there would be such a "simple" fix.

@trancexpress
Copy link
Contributor Author

trancexpress commented Jan 23, 2026

Is there 16x16 icon available at all (/usr/share/icons/themename/... or smth similar)? If not what are the available sizes? I believe Gtk returns the closest bigger size if the requested size is not available.

I think there is:

#include <gtk/gtk.h>

// gcc -g icon.c  `pkg-config --cflags --libs gtk+-3.0`  -o IconExample && ./IconExample


int
main (int argc, char **argv)
{
	GtkWidget *window, *scrolled_window;
	GtkListStore *liststore;
	GtkTreeIter iter;

	gtk_init(&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	g_signal_connect(window, "delete_event", gtk_main_quit, NULL);
	gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);

	scrolled_window = gtk_scrolled_window_new(NULL, NULL);

	GIcon *gicon = g_icon_new_for_string("kate", NULL);
	GtkIconTheme *icon_theme = gtk_icon_theme_get_default();
	GtkIconInfo *gicon_info = gtk_icon_theme_lookup_by_gicon(icon_theme, gicon, 16/*size*/, 0);
	GdkPixbuf *pixbuf = gtk_icon_info_load_icon(gicon_info, NULL);

	int height = gdk_pixbuf_get_height(pixbuf);
	int width = gdk_pixbuf_get_width(pixbuf);
	g_print("height=%d, width=%d\n", height, width);

	gtk_container_add (GTK_CONTAINER (window), scrolled_window);

	gtk_widget_show_all(window);

	gtk_main();

	return 0;
}
$ gcc -g icon.c  `pkg-config --cflags --libs gtk+-3.0`  -o IconExample && ./IconExample
height=48, width=48
$ find /usr/share/icons/ -name "kate.png"  | sort -V
/usr/share/icons/hicolor/16x16/apps/kate.png
/usr/share/icons/hicolor/22x22/apps/kate.png
/usr/share/icons/hicolor/32x32/apps/kate.png
/usr/share/icons/hicolor/44x44/apps/kate.png
/usr/share/icons/hicolor/48x48/apps/kate.png
/usr/share/icons/hicolor/64x64/apps/kate.png
/usr/share/icons/hicolor/128x128/apps/kate.png
/usr/share/icons/hicolor/150x150/apps/kate.png
/usr/share/icons/hicolor/256x256/apps/kate.png
/usr/share/icons/hicolor/310x310/apps/kate.png
/usr/share/icons/hicolor/512x512/apps/kate.png

If this is on HiDPI system it becomes even more complicated as 16x16 with scale=2 will try to return 32x32 which in case of not available might give you the next one 48x48. On a HiDPI screen I see too small icon - both with and without the patch

What is the difference for HiDPI? Will the zoom level argument be different?

The GTK3 documentation does say this: https://docs.gtk.org/gtk3/method.IconTheme.lookup_by_gicon.html

When rendering on displays with high pixel densities you should not use a size multiplied by the scaling factor returned by functions like gdk_window_get_scale_factor(). Instead, you should use gtk_icon_theme_lookup_by_gicon_for_scale(), as the assets loaded for a given scaling factor may be different.

@trancexpress trancexpress marked this pull request as draft January 23, 2026 16:53
@akurtakov
Copy link
Member

akurtakov commented Jan 23, 2026

Yes, looks like gtk_icon_theme_lookup_by_gicon_for_scale https://docs.gtk.org/gtk3/method.IconTheme.lookup_by_gicon_for_scale.html has to be used.

@trancexpress
Copy link
Contributor Author

trancexpress commented Jan 23, 2026

Slightly modifying the prints:

g_print("height=%d, width=%d, %s\n", height, width, gtk_icon_info_get_filename(gicon_info));

Then I see:

$ gcc -g icon.c  `pkg-config --cflags --libs gtk+-3.0`  -o IconExample && ./IconExample
height=48, width=48, /usr/share/icons/breeze-dark/apps/48/kate.svg
$ find  /usr/share/icons/breeze-dark/apps/ -name "*kate*"
/usr/share/icons/breeze-dark/apps/22/kate-symbolic.svg
/usr/share/icons/breeze-dark/apps/16/kate-symbolic.svg
/usr/share/icons/breeze-dark/apps/48/kate.svg
/usr/share/icons/breeze-dark/apps/24/kate-symbolic.svg
/usr/share/icons/breeze-dark/apps/32/kate-symbolic.svg

In the Advantest environment, emacs is used to open the external file... There I see:

$ find  /usr/share/icons/breeze/apps/ -name "*emacs*"
/usr/share/icons/breeze/apps/48/emacs.svg

So we must be missing icons... at least for breeze...

@trancexpress
Copy link
Contributor Author

Yes, looks like gtk_icon_theme_lookup_by_gicon_for_scale https://docs.gtk.org/gtk3/method.IconTheme.lookup_by_gicon_for_scale.html has to be used.

OK, I'll try to in the next few days.

I assume for the scale parameter we use DPIUtil.getScalingFactor(int)?

And the scaling down we can do for scale 1, when hopefully we are not in the HiDPI case. Considering that breeze supplies a 48x48 SVG icon, that should be scalable however we want... I don't think we want to request more icon sizes for the theme.

Though SWT won't be scaling the SVG in a sensible way... Unless we try to open the SVG by using the path to the icon. Which will make things even more complicated, so I won't be trying that.

long shellHandle = shell.handle;
long window = GTK3.gtk_widget_get_window(shellHandle);
if (window != 0) {
scale = GDK.gdk_window_get_scale_factor(window);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like to get the scaling argument we need a window.

Any better way to get the window @akurtakov ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this, we are requesting icon data that is likely cached by platform UI.

Depending on the screen scaling doesn't seem like a good idea. E.g. if two screens have different scaling, we would be caching the icon for one of them...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HeikoKlare maybe you have insights here? Where do we handle different DPI for icons in platform UI? Maybe doing the fix in SWT is not the best place...

@trancexpress trancexpress changed the title Scale external program icons to 16x16 [GTK] Scale external program icons to 16x16 Jan 25, 2026
This change ensures Program icons are scaled to 16x16 pixels, to avoid
huge icons in platform UI.

Fixes: eclipse-platform#3003
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Huge icons in Open Resources dialog

3 participants