Skip to content

Commit 2756354

Browse files
committed
Program icon scaling using DPI
This commit contributes to proper scaling of Program icon. Since, these icons are retrieved by OS.SHGetFileInfo which is System DPI-Aware, it returns the icon with zoom level of the primary monitor at application startup. Hence, for initialNativeZoom of the Image object to be created for the icon, the zoom retrieved from the DPI is considered. contributes to #62 and #127 fixes #1759
1 parent 009532c commit 2756354

File tree

1 file changed

+11
-4
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT Program/win32/org/eclipse/swt/program

1 file changed

+11
-4
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
import org.eclipse.swt.*;
2121
import org.eclipse.swt.graphics.*;
22+
import org.eclipse.swt.internal.*;
2223
import org.eclipse.swt.internal.win32.*;
23-
import org.eclipse.swt.widgets.*;
2424

2525
/**
2626
* Instances of this class represent programs and
@@ -379,9 +379,9 @@ public ImageData getImageData () {
379379
* @since 3.125
380380
*/
381381
public ImageData getImageData (int zoom) {
382-
// Windows API returns image data according to primary monitor zoom factor
383-
// rather than at original scaling
384-
int initialNativeZoom = Display.getCurrent().getPrimaryMonitor().getZoom();
382+
// OS.SHGetFileInfo is System DPI-aware, hence it retrieves the icon with zoom
383+
// of primary monitor at the application startup
384+
int initialNativeZoom = getPrimaryMonitorZoomAtStartup();
385385
if (extension != null) {
386386
SHFILEINFO shfi = new SHFILEINFO ();
387387
int flags = OS.SHGFI_ICON | OS.SHGFI_USEFILEATTRIBUTES;
@@ -427,6 +427,13 @@ public ImageData getImageData (int zoom) {
427427
return imageData;
428428
}
429429

430+
private int getPrimaryMonitorZoomAtStartup() {
431+
long hDC = OS.GetDC(0);
432+
int dpi = OS.GetDeviceCaps(hDC, OS.LOGPIXELSX);
433+
OS.ReleaseDC(0, hDC);
434+
return DPIUtil.mapDPIToZoom(dpi);
435+
}
436+
430437
/**
431438
* Returns the receiver's name. This is as short and
432439
* descriptive a name as possible for the program. If

0 commit comments

Comments
 (0)