Skip to content

Commit 9fae876

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. The scaling is done only if DPI scaling is 1. Fixes: #3003
1 parent 22c3714 commit 9fae876

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

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

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
import java.nio.file.*;
1818
import java.nio.file.Path;
1919
import java.util.*;
20+
import java.util.List;
2021

2122
import org.eclipse.swt.*;
2223
import org.eclipse.swt.graphics.*;
2324
import org.eclipse.swt.internal.*;
2425
import org.eclipse.swt.internal.gtk.*;
2526
import org.eclipse.swt.internal.gtk3.*;
2627
import org.eclipse.swt.internal.gtk4.*;
28+
import org.eclipse.swt.widgets.*;
2729

2830
/**
2931
* Instances of this class represent programs and
@@ -146,6 +148,7 @@ public ImageData getImageData() {
146148
public ImageData getImageData(int zoom) {
147149
if (iconPath == null) return null;
148150
ImageData data = null;
151+
int scale = 1;
149152

150153
long gicon = OS.g_icon_new_for_string(Converter.javaStringToCString(iconPath), null);
151154
if (gicon != 0) {
@@ -168,7 +171,15 @@ public ImageData getImageData(int zoom) {
168171
OS.g_object_unref(paintable);
169172
} else {
170173
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);
174+
Shell shell = Display.getCurrent().getActiveShell();
175+
if (shell != null) {
176+
long shellHandle = shell.handle;
177+
long window = GTK3.gtk_widget_get_window(shellHandle);
178+
if (window != 0) {
179+
scale = GDK.gdk_window_get_scale_factor(window);
180+
}
181+
}
182+
long gicon_info = GTK3.gtk_icon_theme_lookup_by_gicon_for_scale(icon_theme, gicon, 16/*size*/, scale, 0);
172183
if (gicon_info != 0) {
173184
pixbuf = GTK3.gtk_icon_info_load_icon(gicon_info, null);
174185
OS.g_object_unref(gicon_info);
@@ -204,6 +215,10 @@ public ImageData getImageData(int zoom) {
204215
}
205216
}
206217
data.alphaData = alphaData;
218+
if (scale == 1 && height > 16 && width > 16) {
219+
ImageData scaled = data.scaledTo(16, 16);
220+
data = scaled;
221+
}
207222
} else {
208223
PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF);
209224
data = new ImageData(width, height, 24, palette, 4, srcData);

0 commit comments

Comments
 (0)