Skip to content

Commit 7a04f7a

Browse files
amartya4256HeikoKlare
authored andcommitted
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 eclipse-platform#62 and eclipse-platform#127
1 parent 8fe0fb0 commit 7a04f7a

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

31583158
private Rectangle translateRectangleInPixelsInDisplayCoordinateSystem(int x, int y, int width, int height, Monitor monitorOfLocation, Monitor monitorOfArea) {
31593159
Point topLeft = getPixelsFromPoint(monitorOfLocation, x, y);
3160-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom);
3160+
int zoom = getApplicableMonitorZoom(monitorOfArea);
31613161
int widthInPixels = DPIUtil.scaleUp(width, zoom);
31623162
int heightInPixels = DPIUtil.scaleUp(height, zoom);
31633163
return new Rectangle(topLeft.x, topLeft.y, widthInPixels, heightInPixels);
@@ -3176,12 +3176,16 @@ private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int
31763176

31773177
private Rectangle translateRectangleInPointsInDisplayCoordinateSystem(int x, int y, int widthInPixels, int heightInPixels, Monitor monitorOfLocation, Monitor monitorOfArea) {
31783178
Point topLeft = getPointFromPixels(monitorOfLocation, x, y);
3179-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitorOfArea.zoom);
3179+
int zoom = getApplicableMonitorZoom(monitorOfArea);
31803180
int width = DPIUtil.scaleDown(widthInPixels, zoom);
31813181
int height = DPIUtil.scaleDown(heightInPixels, zoom);
31823182
return new Rectangle(topLeft.x, topLeft.y, width, height);
31833183
}
31843184

3185+
private int getApplicableMonitorZoom(Monitor monitor) {
3186+
return DPIUtil.getZoomForAutoscaleProperty(isRescalingAtRuntime() ? monitor.zoom : getDeviceZoom());
3187+
}
3188+
31853189
long messageProc (long hwnd, long msg, long wParam, long lParam) {
31863190
switch ((int)msg) {
31873191
case SWT_RUNASYNC: {
@@ -5480,21 +5484,21 @@ private Monitor getContainingMonitorInPixelsCoordinate(int xInPixels, int yInPix
54805484
}
54815485

54825486
private Rectangle getMonitorClientAreaInPixels(Monitor monitor) {
5483-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
5487+
int zoom = getApplicableMonitorZoom(monitor);
54845488
int widthInPixels = DPIUtil.scaleUp(monitor.clientWidth, zoom);
54855489
int heightInPixels = DPIUtil.scaleUp(monitor.clientHeight, zoom);
54865490
return new Rectangle(monitor.clientX, monitor.clientY, widthInPixels, heightInPixels);
54875491
}
54885492

54895493
private Point getPixelsFromPoint(Monitor monitor, int x, int y) {
5490-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
5494+
int zoom = getApplicableMonitorZoom(monitor);
54915495
int mappedX = DPIUtil.scaleUp(x - monitor.clientX, zoom) + monitor.clientX;
54925496
int mappedY = DPIUtil.scaleUp(y - monitor.clientY, zoom) + monitor.clientY;
54935497
return new Point(mappedX, mappedY);
54945498
}
54955499

54965500
private Point getPointFromPixels(Monitor monitor, int x, int y) {
5497-
int zoom = DPIUtil.getZoomForAutoscaleProperty(monitor.zoom);
5501+
int zoom = getApplicableMonitorZoom(monitor);
54985502
int mappedX = DPIUtil.scaleDown(x - monitor.clientX, zoom) + monitor.clientX;
54995503
int mappedY = DPIUtil.scaleDown(y - monitor.clientY, zoom) + monitor.clientY;
55005504
return new Point(mappedX, mappedY);

0 commit comments

Comments
 (0)