Skip to content

Commit 7746231

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 0324a13 commit 7746231

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
@@ -3193,7 +3193,7 @@ private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int
31933193

31943194
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitorOfLocation, Monitor monitorOfArea) {
31953195
Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y);
3196-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom);
3196+
int zoom = getApplicableMonitorZoom(monitorOfArea);
31973197
int widthInPixels = DPIUtil.scaleUp(width, zoom);
31983198
int heightInPixels = DPIUtil.scaleUp(height, zoom);
31993199
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
@@ -3212,12 +3212,16 @@ private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int
32123212

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

3221+
private int getApplicableMonitorZoom(Monitor monitor) {
3222+
return DPIUtil.getZoomForAutoscaleProperty(isRescalingAtRuntime() ? monitor.zoom : getDeviceZoom());
3223+
}
3224+
32213225
long messageProc (long hwnd, long msg, long wParam, long lParam) {
32223226
switch ((int)msg) {
32233227
case SWT_RUNASYNC: {
@@ -5414,21 +5418,21 @@ private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPix
54145418
}
54155419

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

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

54305434
private Point getPointFromPixels(Monitor monitor, int x, int y) {
5431-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
5435+
int zoom = getApplicableMonitorZoom(monitor);
54325436
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
54335437
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
54345438
return new Point(mappedX, mappedY);

0 commit comments

Comments
 (0)