From 7a04f7a6cf7eccda8681f6c59d8f5d4064004e24 Mon Sep 17 00:00:00 2001 From: Amartya Parijat Date: Mon, 7 Oct 2024 14:59:34 +0200 Subject: [PATCH] Guard monitor.zoom with isRescalingAtRuntime flag This contribution protects the unintended usage of different zoom levels of different monitors in trasnlating the points and rectangles from control to display coordinate system when the isRescalingAtRuntime flag is disabled. contributes to #62 and #127 --- .../win32/org/eclipse/swt/widgets/Display.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 5a96bc17c8..8ef94c8ea5 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 @@ -3157,7 +3157,7 @@ private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitorOfLocation, Monitor monitorOfArea) { Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y); - int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom); + int zoom = getApplicableMonitorZoom(monitorOfArea); int widthInPixels = DPIUtil.scaleUp(width, zoom); int heightInPixels = DPIUtil.scaleUp(height, zoom); return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels); @@ -3176,12 +3176,16 @@ private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitorOfLocation, Monitor monitorOfArea) { Point topLeft = getPointFromPixels(monitorOfLocation, x, y); - int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom); + int zoom = getApplicableMonitorZoom(monitorOfArea); int width = DPIUtil.scaleDown(widthInPixels, zoom); int height = DPIUtil.scaleDown(heightInPixels, zoom); return new Rectangle(topLeft.x, topLeft.y, width, height); } +private int getApplicableMonitorZoom(Monitor monitor) { + return DPIUtil.getZoomForAutoscaleProperty(isRescalingAtRuntime() ? monitor.zoom : getDeviceZoom()); +} + long messageProc (long hwnd, long msg, long wParam, long lParam) { switch ((int)msg) { case SWT_RUNASYNC: { @@ -5480,21 +5484,21 @@ private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPix } private Rectangle getMonitorClientAreaInPixels(Monitor monitor) { - int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom); + int zoom = getApplicableMonitorZoom(monitor); int widthInPixels = DPIUtil.scaleUp(monitor.clientWidth, zoom); int heightInPixels = DPIUtil.scaleUp(monitor.clientHeight, zoom); return new Rectangle(monitor.clientX, monitor.clientY, widthInPixels, heightInPixels); } private Point getPixelsFromPoint(Monitor monitor, int x, int y) { - int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom); + int zoom = getApplicableMonitorZoom(monitor); int mappedX = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX; int mappedY = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY; return new Point(mappedX, mappedY); } private Point getPointFromPixels(Monitor monitor, int x, int y) { - int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom); + int zoom = getApplicableMonitorZoom(monitor); int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX; int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY; return new Point(mappedX, mappedY);