Skip to content

Commit 47af98e

Browse files
committed
[win32] Adjust wrong size after DPI fix in Shell
This commit addresses an issue with the logic fixing a missing DPI change event from windows in the Shell#WM_WINDOWPOSCHANGED callback. It adapts the calculation to properly calculate the new size taking previous and new zoom into account and executes the logic asynchronously.
1 parent 9eb34bf commit 47af98e

File tree

2 files changed

+21
-6
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT

2 files changed

+21
-6
lines changed

bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/internal/DPIUtil.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@ public static Point scaleDown(Point point, int zoom) {
235235
return scaledPoint;
236236
}
237237

238+
public static Point scalePoint(Point point, int targetZoom, int currentZoom) {
239+
if (point == null || targetZoom == currentZoom) return point;
240+
float scaleFactor = (float) targetZoom / (float) currentZoom;
241+
Point scaledPoint = new Point (0,0);
242+
scaledPoint.x = Math.round (point.x / scaleFactor);
243+
scaledPoint.y = Math.round (point.y / scaleFactor);
244+
return scaledPoint;
245+
}
246+
238247
/**
239248
* Returns a new scaled down Point if enabled for Drawable class.
240249
*/

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,12 +2738,18 @@ LRESULT WM_WINDOWPOSCHANGED (long wParam, long lParam) {
27382738
// this check is added to trigger a dpi change event if an unexpected DPI value is
27392739
// detected.
27402740
if (display.isRescalingAtRuntime()) {
2741-
int dpiForWindow = DPIUtil.mapDPIToZoom(OS.GetDpiForWindow(getShell().handle));
2742-
if (dpiForWindow != nativeZoom) {
2743-
WINDOWPOS lpwp = new WINDOWPOS ();
2744-
OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
2745-
handleMonitorSpecificDpiChange(dpiForWindow, new Rectangle(lpwp.x, lpwp.y, lpwp.cx, lpwp.cy));
2746-
}
2741+
display.asyncExec(() -> {
2742+
int dpiForWindow = DPIUtil.mapDPIToZoom(OS.GetDpiForWindow(getShell().handle));
2743+
if (dpiForWindow != nativeZoom) {
2744+
int dpiForWindowAutoscale = DPIUtil.getZoomForAutoscaleProperty(dpiForWindow);
2745+
int nativeZoomAutoscale = DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
2746+
WINDOWPOS lpwp = new WINDOWPOS ();
2747+
OS.MoveMemory (lpwp, lParam, WINDOWPOS.sizeof);
2748+
Point sizeInNativeZoom = new Point(lpwp.cx, lpwp.cy);
2749+
Point sizeInDpiForWindow = DPIUtil.scalePoint(sizeInNativeZoom, dpiForWindowAutoscale, nativeZoomAutoscale);
2750+
handleMonitorSpecificDpiChange(dpiForWindow, new Rectangle(lpwp.x, lpwp.y, sizeInDpiForWindow.x, sizeInDpiForWindow.y));
2751+
}
2752+
});
27472753
}
27482754
return result;
27492755
}

0 commit comments

Comments
 (0)