From 3cd1f36e022c1300e4130c8da7b454b096ae2896 Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Tue, 21 Jan 2025 09:51:45 +0100 Subject: [PATCH] Improve Shell::setBounds scaling on monitor change This commit contributes to the correct scaling of the Shell using its own zoom on Shell::setBounds call as the scaling of the shell in case of a monitor change is also handled by the DPI_CHANGED event. Contributes to #62 and #127 --- .../Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java index 26a0a2d995..f9e47a1fc9 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Shell.java @@ -1596,7 +1596,12 @@ public void setBounds(Rectangle rect) { if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); checkWidget (); Rectangle boundsInPixels = getDisplay().translateToDisplayCoordinates(rect, getZoom()); - setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height); + // The scaling of the width and height in case of a monitor change is handled by + // the WM_DPICHANGED event processing. So to avoid duplicate scaling, we always + // have to scale width and height with the zoom of the original monitor (still + // returned by getZoom()) here. + setBoundsInPixels(boundsInPixels.x, boundsInPixels.y, DPIUtil.scaleUp(rect.width, getZoom()), + DPIUtil.scaleUp(rect.height, getZoom())); } @Override