Skip to content

Commit b492f42

Browse files
committed
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
1 parent b0413a8 commit b492f42

File tree

1 file changed

+9
-5
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3195,7 +3195,7 @@ private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int
31953195

31963196
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitorOfLocation, Monitor monitorOfArea) {
31973197
Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y);
3198-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom);
3198+
int zoom = getApplicableMonitorZoom(monitorOfArea);
31993199
int widthInPixels = DPIUtil.scaleUp(width, zoom);
32003200
int heightInPixels = DPIUtil.scaleUp(height, zoom);
32013201
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
@@ -3214,12 +3214,16 @@ private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int
32143214

32153215
private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitorOfLocation, Monitor monitorOfArea) {
32163216
Point topLeft = getPointFromPixels(monitorOfLocation, x, y);
3217-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom);
3217+
int zoom = getApplicableMonitorZoom(monitorOfArea);
32183218
int width = DPIUtil.scaleDown(widthInPixels, zoom);
32193219
int height = DPIUtil.scaleDown(heightInPixels, zoom);
32203220
return new Rectangle(topLeft.x, topLeft.y, width, height);
32213221
}
32223222

3223+
private int getApplicableMonitorZoom(Monitor monitor) {
3224+
return DPIUtil.getZoomForAutoscaleProperty(isRescalingAtRuntime() ? monitor.zoom : getDeviceZoom());
3225+
}
3226+
32233227
long messageProc (long hwnd, long msg, long wParam, long lParam) {
32243228
switch ((int)msg) {
32253229
case SWT_RUNASYNC: {
@@ -5416,21 +5420,21 @@ private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPix
54165420
}
54175421

54185422
private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {
5419-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
5423+
int zoom = getApplicableMonitorZoom(monitor);
54205424
int widthInPixels = DPIUtil.scaleUp(monitor.clientWidth, zoom);
54215425
int heightInPixels = DPIUtil.scaleUp(monitor.clientHeight, zoom);
54225426
return new Rectangle(monitor.clientX, monitor.clientY, widthInPixels, heightInPixels);
54235427
}
54245428

54255429
private Point getPixelsFromPoint(Monitor monitor, int x, int y) {
5426-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
5430+
int zoom = getApplicableMonitorZoom(monitor);
54275431
int mappedX = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX;
54285432
int mappedY = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY;
54295433
return new Point(mappedX, mappedY);
54305434
}
54315435

54325436
private Point getPointFromPixels(Monitor monitor, int x, int y) {
5433-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
5437+
int zoom = getApplicableMonitorZoom(monitor);
54345438
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
54355439
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
54365440
return new Point(mappedX, mappedY);

0 commit comments

Comments
 (0)