Skip to content

Commit 80daf2c

Browse files
ShahzaibIbrahimHeikoKlare
authored andcommitted
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 136b375 commit 80daf2c

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

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

Lines changed: 16 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.WithMonitor 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

@@ -59,6 +59,19 @@ private SingleZoomCoordinateSystemMapper getSingleZoomCoordinateSystemMapper() {
5959
return new SingleZoomCoordinateSystemMapper(null);
6060
}
6161

62+
@Test
63+
void mapMonitorBoundsShouldBeSameForAllMonitorsWithSingleZoomCoordinateMapper() {
64+
CoordinateSystemMapper mapper = getSingleZoomCoordinateSystemMapper();
65+
setupMonitors(mapper);
66+
Rectangle.WithMonitor rectInPixelsAt100Zoom = new Rectangle.WithMonitor(2100, 100, 500, 500, monitors[1]);
67+
Rectangle rectAfterMappingAt100 = mapper.mapMonitorBounds(rectInPixelsAt100Zoom);
68+
69+
Rectangle.WithMonitor rectInPixelsAt200Zoom = new Rectangle.WithMonitor(2100, 100, 500, 500, monitors[0]);
70+
Rectangle rectAfterMappingAt200 = mapper.mapMonitorBounds(rectInPixelsAt200Zoom);
71+
72+
assertEquals(rectAfterMappingAt100,rectAfterMappingAt200);
73+
}
74+
6275
@ParameterizedTest
6376
@MethodSource("provideCoordinateSystemMappers")
6477
void translatePointInNoMonitorBackAndForthShouldBeTheSame(CoordinateSystemMapper mapper) {

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.WithMonitor rectangle);
2929

3030
Point translateFromDisplayCoordinates(Point point);
3131

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,16 +2225,10 @@ 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;
@@ -2244,6 +2238,12 @@ Monitor getMonitor (long hmonitor) {
22442238
* to scaling issue on OS Win8.1 and above, for more details refer bug 537614.
22452239
*/
22462240
monitor.zoom = result;
2241+
Rectangle.WithMonitor boundsInPixels = new Rectangle.WithMonitor(lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top, monitor);
2242+
Rectangle.WithMonitor clientAreaInPixels = new Rectangle.WithMonitor(lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top, monitor);
2243+
2244+
monitor.setBounds(coordinateSystemMapper.mapMonitorBounds(boundsInPixels));
2245+
monitor.setClientArea(coordinateSystemMapper.mapMonitorBounds(clientAreaInPixels));
2246+
22472247
return monitor;
22482248
}
22492249

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ 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) {
87+
public Rectangle mapMonitorBounds(Rectangle.WithMonitor rect) {
88+
Monitor monitor = rect.getMonitor();
89+
int zoom = getApplicableMonitorZoom(monitor);
8890
Rectangle bounds = Win32DPIUtils.pixelToPoint(rect, zoom);
8991
bounds.x = rect.x;
9092
bounds.y = rect.y;

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.WithMonitor rect) {
75+
return Win32DPIUtils.pixelToPoint(rect, DPIUtil.getDeviceZoom());
7676
}
7777

7878
@Override

0 commit comments

Comments
 (0)