Skip to content

Commit

Permalink
Consider that program icons have scaling of primary monitor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
HeikoKlare committed Jan 26, 2024
1 parent c4922c6 commit 28ac0b1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ public ImageData getImageData () {
* The zoom level in % of the standard resolution
*
* @return the image data for the program, may be null
* @since 3.125
*/
public ImageData getImageData (int zoom) {
NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ public ImageData getImageData() {
* The zoom level in % of the standard resolution
*
* @return the image data for the program, may be null
* @since 3.125
*/
public ImageData getImageData(int zoom) {
if (iconPath == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.win32.*;
import org.eclipse.swt.widgets.*;

/**
* Instances of this class represent programs and
Expand Down Expand Up @@ -372,6 +374,7 @@ public ImageData getImageData () {
* The zoom level in % of the standard resolution
*
* @return the image data for the program, may be null
* @since 3.125
*/
public ImageData getImageData (int zoom) {
int nIconIndex = 0;
Expand All @@ -395,7 +398,10 @@ public ImageData getImageData (int zoom) {
OS.ExtractIconEx (lpszFile, nIconIndex, phiconLarge, phiconSmall, 1);
if (phiconSmall [0] == 0) return null;
Image image = Image.win32_new (null, SWT.ICON, phiconSmall [0]);
ImageData imageData = image.getImageData (zoom);
// Windows API returns image data according to primary monitor zoom factor
// rather than at original scaling
int nativeZoomFactor = 100 * Display.getCurrent().getPrimaryMonitor().getZoom() / DPIUtil.getDeviceZoom();
ImageData imageData = image.getImageData (100 * zoom / nativeZoomFactor);
image.dispose ();
return imageData;
}
Expand Down

0 comments on commit 28ac0b1

Please sign in to comment.