Skip to content

Commit e9cf5b5

Browse files
Remove zoom parameter from CoordinateSystemMapper#mapMonitorBounds()
The CoordinateSystemMapper#mapMonitorBounds() method currently accepts a zoom value and that is wrong for SingleZoomCoordinateMapper since it should always use the global zoom (DPIUtil#getDeviceZoom()) instead of monitor zoom. This commit changes how zoom is passed through Rectangle with monitor for MultiZoomCoordinateMapper while that monitor will be ignored for SingleZoomCoordinateMapper.
1 parent 32b6cd0 commit e9cf5b5

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

bundles/org.eclipse.swt/Eclipse SWT Tests/win32/org/eclipse/swt/widgets/CoordinateSystemMapperTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.util.stream.*;
2121

2222
import org.eclipse.swt.graphics.*;
23-
import org.eclipse.swt.internal.*;
2423
import org.junit.jupiter.api.*;
2524
import org.junit.jupiter.params.*;
2625
import org.junit.jupiter.params.provider.*;
@@ -33,10 +32,11 @@ class CoordinateSystemMapperTests {
3332

3433
private Monitor createMonitor(CoordinateSystemMapper mapper, Rectangle boundsInPixels, int nativeZoom) {
3534
Monitor monitor = new Monitor();
36-
Rectangle bounds = mapper.mapMonitorBounds(boundsInPixels, DPIUtil.getZoomForAutoscaleProperty(nativeZoom));
35+
monitor.zoom = nativeZoom;
36+
Rectangle boundsInPixelWithMonitor = new Rectangle.WithMonitor(boundsInPixels.x, boundsInPixels.y, boundsInPixels.width, boundsInPixels.height, monitor);
37+
Rectangle bounds = mapper.mapMonitorBounds(boundsInPixelWithMonitor);
3738
monitor.setBounds(bounds);
3839
monitor.setClientArea(bounds);
39-
monitor.zoom = nativeZoom;
4040
return monitor;
4141
}
4242

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ interface CoordinateSystemMapper {
2525

2626
Point map(Control from, Control to, int x, int y);
2727

28-
Rectangle mapMonitorBounds(Rectangle rectangle, int zoom);
28+
Rectangle mapMonitorBounds(Rectangle rectangle);
2929

3030
Point translateFromDisplayCoordinates(Point point);
3131

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,25 +2225,25 @@ Monitor getMonitor (long hmonitor) {
22252225
OS.GetMonitorInfo (hmonitor, lpmi);
22262226
Monitor monitor = new Monitor ();
22272227
monitor.handle = hmonitor;
2228-
Rectangle boundsInPixels = new Rectangle(lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top);
2229-
Rectangle clientAreaInPixels = new Rectangle(lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top);
22302228
int [] dpiX = new int[1];
22312229
int [] dpiY = new int[1];
22322230
int result = OS.GetDpiForMonitor (monitor.handle, OS.MDT_EFFECTIVE_DPI, dpiX, dpiY);
22332231
result = (result == OS.S_OK) ? DPIUtil.mapDPIToZoom (dpiX[0]) : 100;
2234-
2235-
int autoscaleZoom = DPIUtil.getZoomForAutoscaleProperty(result);
2236-
monitor.setBounds(coordinateSystemMapper.mapMonitorBounds(boundsInPixels, autoscaleZoom));
2237-
monitor.setClientArea(coordinateSystemMapper.mapMonitorBounds(clientAreaInPixels, autoscaleZoom));
22382232
if (result == 0) {
22392233
System.err.println("***WARNING: GetDpiForMonitor: SWT could not get valid monitor scaling factor.");
22402234
result = 100;
22412235
}
2236+
monitor.zoom = result;
2237+
Rectangle boundsInPixels = new Rectangle.WithMonitor(lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top, monitor);
2238+
Rectangle clientAreaInPixels = new Rectangle.WithMonitor(lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top, monitor);
2239+
2240+
monitor.setBounds(coordinateSystemMapper.mapMonitorBounds(boundsInPixels));
2241+
monitor.setClientArea(coordinateSystemMapper.mapMonitorBounds(clientAreaInPixels));
2242+
22422243
/*
22432244
* Always return true monitor zoom value as fetched from native, else will lead
22442245
* to scaling issue on OS Win8.1 and above, for more details refer bug 537614.
22452246
*/
2246-
monitor.zoom = result;
22472247
return monitor;
22482248
}
22492249

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,17 @@ public Rectangle map(Control from, Control to, int x, int y, int width, int heig
8484
}
8585

8686
@Override
87-
public Rectangle mapMonitorBounds(Rectangle rect, int zoom) {
88-
Rectangle bounds = Win32DPIUtils.pixelToPoint(rect, zoom);
89-
bounds.x = rect.x;
90-
bounds.y = rect.y;
91-
return bounds;
87+
public Rectangle mapMonitorBounds(Rectangle rect) {
88+
if (rect instanceof Rectangle.WithMonitor rectWithMonitor) {
89+
Monitor monitor = rectWithMonitor.getMonitor();
90+
int zoom = getApplicableMonitorZoom(monitor);
91+
Rectangle bounds = Win32DPIUtils.pixelToPoint(rect, zoom);
92+
bounds.x = rect.x;
93+
bounds.y = rect.y;
94+
return bounds;
95+
} else {
96+
return rect;
97+
}
9298
}
9399

94100
@Override

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public Rectangle map(Control from, Control to, int x, int y, int width, int heig
7171
}
7272

7373
@Override
74-
public Rectangle mapMonitorBounds(Rectangle rect, int zoom) {
75-
return Win32DPIUtils.pixelToPoint(rect, zoom);
74+
public Rectangle mapMonitorBounds(Rectangle rect) {
75+
return Win32DPIUtils.pixelToPoint(rect, DPIUtil.getDeviceZoom());
7676
}
7777

7878
@Override

0 commit comments

Comments
 (0)