Skip to content

Commit 28ac0b1

Browse files
committed
Consider that program icons have scaling of primary monitor
When loading icons for programs, their image data will be scaled according to the primary monitor scaling. This is different from other images, which when loaded have their original size. This change reflects that behavior when creating the image data for a target zoom factor by considering the icon's pre-scaling. It also add a @SInCE tag for the previously introduced zoom-aware getImageData() method for the Program class.
1 parent c4922c6 commit 28ac0b1

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ public ImageData getImageData () {
354354
* The zoom level in % of the standard resolution
355355
*
356356
* @return the image data for the program, may be null
357+
* @since 3.125
357358
*/
358359
public ImageData getImageData (int zoom) {
359360
NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public ImageData getImageData() {
141141
* The zoom level in % of the standard resolution
142142
*
143143
* @return the image data for the program, may be null
144+
* @since 3.125
144145
*/
145146
public ImageData getImageData(int zoom) {
146147
if (iconPath == null) return null;

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
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.*;
24+
import org.eclipse.swt.widgets.*;
2325

2426
/**
2527
* Instances of this class represent programs and
@@ -372,6 +374,7 @@ public ImageData getImageData () {
372374
* The zoom level in % of the standard resolution
373375
*
374376
* @return the image data for the program, may be null
377+
* @since 3.125
375378
*/
376379
public ImageData getImageData (int zoom) {
377380
int nIconIndex = 0;
@@ -395,7 +398,10 @@ public ImageData getImageData (int zoom) {
395398
OS.ExtractIconEx (lpszFile, nIconIndex, phiconLarge, phiconSmall, 1);
396399
if (phiconSmall [0] == 0) return null;
397400
Image image = Image.win32_new (null, SWT.ICON, phiconSmall [0]);
398-
ImageData imageData = image.getImageData (zoom);
401+
// Windows API returns image data according to primary monitor zoom factor
402+
// rather than at original scaling
403+
int nativeZoomFactor = 100 * Display.getCurrent().getPrimaryMonitor().getZoom() / DPIUtil.getDeviceZoom();
404+
ImageData imageData = image.getImageData (100 * zoom / nativeZoomFactor);
399405
image.dispose ();
400406
return imageData;
401407
}

0 commit comments

Comments
 (0)