Skip to content

Commit 4ca6879

Browse files
committed
[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
1 parent c20fea4 commit 4ca6879

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* 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)
10971097
}
10981098
#endif
10991099

1100+
#ifndef NO_gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale
1101+
JNIEXPORT jlong JNICALL GTK3_NATIVE(gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale)
1102+
(JNIEnv *env, jclass that, jlong arg0, jlong arg1, jint arg2, jint arg3, jint arg4)
1103+
{
1104+
jlong rc = 0;
1105+
GTK3_NATIVE_ENTER(env, that, gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC);
1106+
rc = (jlong)gtk_icon_theme_lookup_by_gicon_for_scale((GtkIconTheme *)arg0, (GIcon *)arg1, (gint)arg2, (gint)arg3, (GtkIconLookupFlags)arg4);
1107+
GTK3_NATIVE_EXIT(env, that, gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC);
1108+
return rc;
1109+
}
1110+
#endif
1111+
11001112
#ifndef NO_gtk_1im_1context_1filter_1keypress
11011113
JNIEXPORT jboolean JNICALL GTK3_NATIVE(gtk_1im_1context_1filter_1keypress)
11021114
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/gtk3_stats.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2025 IBM Corporation and others.
2+
* Copyright (c) 2000, 2026 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -111,6 +111,7 @@ typedef enum {
111111
gtk_1icon_1theme_1get_1default_FUNC,
112112
gtk_1icon_1theme_1load_1icon_FUNC,
113113
gtk_1icon_1theme_1lookup_1by_1gicon_FUNC,
114+
gtk_1icon_1theme_1lookup_1by_1gicon_1for_1scale_FUNC,
114115
gtk_1im_1context_1filter_1keypress_FUNC,
115116
gtk_1image_1new_1from_1icon_1name_FUNC,
116117
gtk_1image_1new_1from_1surface_FUNC,

bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk3/GTK3.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,15 @@ public class GTK3 {
795795
* @param flags cast=(GtkIconLookupFlags)
796796
*/
797797
public static final native long gtk_icon_theme_lookup_by_gicon(long icon_theme, long icon, int size, int flags);
798+
/* GtkIconTheme */
799+
/**
800+
* @param icon_theme cast=(GtkIconTheme *)
801+
* @param icon cast=(GIcon *)
802+
* @param size cast=(gint)
803+
* @param scale cast=(gint)
804+
* @param flags cast=(GtkIconLookupFlags)
805+
*/
806+
public static final native long gtk_icon_theme_lookup_by_gicon_for_scale(long icon_theme, long icon, int size, int scale, int flags);
798807
/**
799808
* @param icon_theme cast=(GtkIconTheme *)
800809
* @param icon_name cast=(const gchar *)

bundles/org.eclipse.swt/Eclipse SWT Program/gtk/org/eclipse/swt/program/Program.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public ImageData getImageData(int zoom) {
168168
OS.g_object_unref(paintable);
169169
} else {
170170
long icon_theme = GTK3.gtk_icon_theme_get_default();
171-
long gicon_info = GTK3.gtk_icon_theme_lookup_by_gicon(icon_theme, gicon, 16/*size*/, 0);
171+
long gicon_info = GTK3.gtk_icon_theme_lookup_by_gicon_for_scale(icon_theme, gicon, 16/*size*/, 1/*scale*/, 0);
172172
if (gicon_info != 0) {
173173
pixbuf = GTK3.gtk_icon_info_load_icon(gicon_info, null);
174174
OS.g_object_unref(gicon_info);
@@ -204,6 +204,10 @@ public ImageData getImageData(int zoom) {
204204
}
205205
}
206206
data.alphaData = alphaData;
207+
if (height > 16 && width > 16) {
208+
ImageData scaled = data.scaledTo(16, 16);
209+
data = scaled;
210+
}
207211
} else {
208212
PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
209213
data = new ImageData(width, height, 24, palette, 4, srcData);

0 commit comments

Comments
 (0)