From 5626775b8fd92383e05d48550be4481dd366d3fe Mon Sep 17 00:00:00 2001 From: Sebastian Ratz Date: Thu, 20 Aug 2026 13:58:24 +0200 Subject: [PATCH] [Win32] Use primary monitor zoom in Display.getBounds() scaling Display.getBounds() must not be affected by "zoom-of-the-last-moved-shell", which currently DPIUtil.getDeviceZoom() represents on Windows. Instead, Display.getBounds() should be consistent with the way a GC for the display is created: via Display.getDeviceZoom(), which in turn uses the zoom of the primary monitor. The same applies to Display.getClientArea() as well. Fixes #3530. --- .../eclipse/swt/widgets/DisplayWin32Test.java | 23 +++++++++++++++++-- .../org/eclipse/swt/widgets/Display.java | 4 ++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DisplayWin32Test.java b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DisplayWin32Test.java index 3d380ef1469..96dcd965168 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DisplayWin32Test.java +++ b/bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/DisplayWin32Test.java @@ -1,9 +1,9 @@ package org.eclipse.swt.widgets; import static org.eclipse.swt.internal.DPIUtil.setMonitorSpecificScaling; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.*; +import org.eclipse.swt.graphics.*; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.win32.*; import org.junit.jupiter.api.*; @@ -104,4 +104,23 @@ public void setRescaleAtRuntime_toggling() { assertExpectedDpiAwareness(OS.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE); } + // https://github.com/eclipse-platform/eclipse.platform.swt/issues/3530 + @Test + public void getBoundsAndGetClientAreaUseZoomOfPrimaryMonitor_MatchingGCZoom() throws Exception { + Display display = Display.getDefault(); + + DPIUtil.setDeviceZoom(200); // must not be considered + Rectangle bounds1 = display.getBounds(); + Rectangle clientArea1 = display.getClientArea(); + DPIUtil.setDeviceZoom(100); // must not be considered + Rectangle bounds2 = display.getBounds(); + Rectangle clientArea2 = display.getClientArea(); + + assertEquals(bounds2.width, bounds1.width); + assertEquals(clientArea2.width, clientArea1.width); + + GC gc = new GC(display); + assertEquals(display.getPrimaryMonitor().getZoom(), gc.getGCData().nativeZoom); + } + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java index bf07037f1fc..25a8366ca1c 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java @@ -1592,7 +1592,7 @@ public Menu getMenuBar () { @Override public Rectangle getBounds() { checkDevice (); - return Win32DPIUtils.pixelToPoint(getBoundsInPixels(), DPIUtil.getDeviceZoom()); + return Win32DPIUtils.pixelToPoint(getBoundsInPixels(), getDeviceZoom()); } Rectangle getBoundsInPixels () { @@ -1665,7 +1665,7 @@ int getClickCount (int type, int button, long hwnd, long lParam) { @Override public Rectangle getClientArea () { checkDevice (); - return Win32DPIUtils.pixelToPoint(getClientAreaInPixels(), DPIUtil.getDeviceZoom()); + return Win32DPIUtils.pixelToPoint(getClientAreaInPixels(), getDeviceZoom()); } Rectangle getClientAreaInPixels () {