From 4ca6879e037d6f316e8cb2dac51a7f1245c5fb7f Mon Sep 17 00:00:00 2001 From: Simeon Andreev Date: Sat, 24 Jan 2026 12:29:36 +0200 Subject: [PATCH] [GTK] Scale Program.getImageData() to 16x16 pixels This change ensures Program icons are scaled to 16x16 pixels, to avoid huge icons in platform UI. Fixes: #3003 --- .../Eclipse SWT PI/gtk/library/gtk3.c | 14 +++++++++++++- .../Eclipse SWT PI/gtk/library/gtk3_stats.h | 3 ++- .../gtk/org/eclipse/swt/internal/gtk3/GTK3.java | 9 +++++++++ .../gtk/org/eclipse/swt/program/Program.java | 6 +++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c index 49e4ba6a30b..fdd3f389e7f 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2025 IBM Corporation and others. + * Copyright (c) 2000, 2026 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -1097,6 +1097,18 @@ JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1icon_1theme_1lookup_1by_1gicon) } #endif +#ifndef NO_gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale +JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale) + (JNIEnv *env, jclass that, jlong arg0, jlong arg1, jint arg2, jint arg3, jint arg4) +{ + jlong rc = 0; + GTK3_NATIVE_ENTER(env, that, gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC); + rc = (jlong)gtk_icon_theme_lookup_by_gicon_for_scale((GtkIconTheme *)arg0, (GIcon *)arg1, (gint)arg2, (gint)arg3, (GtkIconLookupFlags)arg4); + GTK3_NATIVE_EXIT(env, that, gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC); + return rc; +} +#endif + #ifndef NO_gtk_1im_1context_1filter_1keypress JNIEXPORT jboolean JNICALL GTK3_NATIVE(gtk_1im_1context_1filter_1keypress) (JNIEnv *env, jclass that, jlong arg0, jlong arg1) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h index 1309731b018..581ca2bfb2c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2025 IBM Corporation and others. + * Copyright (c) 2000, 2026 IBM Corporation and others. * * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 @@ -111,6 +111,7 @@ typedef enum { gtk_1icon_1theme_1get_1default_FUNC, gtk_1icon_1theme_1load_1icon_FUNC, gtk_1icon_1theme_1lookup_1by_1gicon_FUNC, + gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC, gtk_1im_1context_1filter_1keypress_FUNC, gtk_1image_1new_1from_1icon_1name_FUNC, gtk_1image_1new_1from_1surface_FUNC, diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java index 7efbd329111..fb4bd8127cb 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java @@ -795,6 +795,15 @@ public class GTK3 { * @param flags cast=(GtkIconLookupFlags) */ public static final native long gtk_icon_theme_lookup_by_gicon(long icon_theme, long icon, int size, int flags); + /* GtkIconTheme */ + /** + * @param icon_theme cast=(GtkIconTheme *) + * @param icon cast=(GIcon *) + * @param size cast=(gint) + * @param scale cast=(gint) + * @param flags cast=(GtkIconLookupFlags) + */ + public static final native long gtk_icon_theme_lookup_by_gicon_for_scale(long icon_theme, long icon, int size, int scale, int flags); /** * @param icon_theme cast=(GtkIconTheme *) * @param icon_name cast=(const gchar *) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java index f5e11ef8031..694ee5e9ad4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java @@ -168,7 +168,7 @@ public ImageData getImageData(int zoom) { OS.g_object_unref(paintable); } else { long icon_theme = GTK3.gtk_icon_theme_get_default(); - long gicon_info = GTK3.gtk_icon_theme_lookup_by_gicon(icon_theme, gicon, 16/*size*/, 0); + long gicon_info = GTK3.gtk_icon_theme_lookup_by_gicon_for_scale(icon_theme, gicon, 16/*size*/, 1/*scale*/, 0); if (gicon_info != 0) { pixbuf = GTK3.gtk_icon_info_load_icon(gicon_info, null); OS.g_object_unref(gicon_info); @@ -204,6 +204,10 @@ public ImageData getImageData(int zoom) { } } data.alphaData = alphaData; + if (height > 16 && width > 16) { + ImageData scaled = data.scaledTo(16, 16); + data = scaled; + } } else { PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF); data = new ImageData(width, height, 24, palette, 4, srcData);