Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikita Nemkin2018-04-25 03:20:15 -0400
committerNikita Nemkin2018-04-26 07:55:03 -0400
commitcdc67cbff3fb701108f19e6dbec01306872e31dc (patch)
tree8c182399913e9b521b75276a173b191ee82ba516 /bundles/org.eclipse.swt/Eclipse SWT/win32
parent7283c66382291ec1d3eff3a3d435a713c1dd23e3 (diff)
downloadeclipse.platform.swt-cdc67cbff3fb701108f19e6dbec01306872e31dc.tar.gz
eclipse.platform.swt-cdc67cbff3fb701108f19e6dbec01306872e31dc.tar.xz
eclipse.platform.swt-cdc67cbff3fb701108f19e6dbec01306872e31dc.zip
Bug 480639 - Provide monitor-specific DPI scaling / zoom level
* Use flags=dynamic for GetDpiForMonitor * Set Monitor.zoom at Monitor creation time. Change-Id: I2756292bc673aa661b5cb0b97450a7677a730ae4 Signed-off-by: Nikita Nemkin <nikita@nemkin.ru>
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/win32')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java13
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java54
2 files changed, 24 insertions, 43 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
index e20ac85c44..e4e50d9bc5 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
@@ -1473,18 +1473,7 @@ public Menu getMenu () {
public Monitor getMonitor () {
checkWidget ();
long /*int*/ hmonitor = OS.MonitorFromWindow (handle, OS.MONITOR_DEFAULTTONEAREST);
- MONITORINFO lpmi = new MONITORINFO ();
- lpmi.cbSize = MONITORINFO.sizeof;
- OS.GetMonitorInfo (hmonitor, lpmi);
- Monitor monitor = new Monitor ();
- monitor.handle = hmonitor;
- Rectangle bounds = new Rectangle (lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left, lpmi.rcMonitor_bottom - lpmi.rcMonitor_top);
- bounds = DPIUtil.autoScaleDown (bounds);
- monitor.setBounds (bounds);
- Rectangle clientArea = new Rectangle (lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top);
- clientArea = DPIUtil.autoScaleDown (clientArea);
- monitor.setClientArea (clientArea);
- return monitor;
+ return display.getMonitor (hmonitor);
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 20792102fb..d3de3e489c 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -2025,6 +2025,28 @@ Dialog getModalDialog () {
return modalDialog;
}
+Monitor getMonitor (long /*int*/ hmonitor) {
+ MONITORINFO lpmi = new MONITORINFO ();
+ lpmi.cbSize = MONITORINFO.sizeof;
+ OS.GetMonitorInfo (hmonitor, lpmi);
+ Monitor monitor = new Monitor ();
+ monitor.handle = hmonitor;
+ Rectangle boundsInPixels = new Rectangle (lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top);
+ monitor.setBounds (DPIUtil.autoScaleDown (boundsInPixels));
+ Rectangle clientAreaInPixels = new Rectangle (lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top);
+ monitor.setClientArea (DPIUtil.autoScaleDown (clientAreaInPixels));
+ if (OS.WIN32_VERSION >= OS.VERSION (6, 3)) {
+ int [] dpiX = new int[1];
+ int [] dpiY = new int[1];
+ int result = OS.GetDpiForMonitor (monitor.handle, OS.MDT_EFFECTIVE_DPI, dpiX, dpiY);
+ result = (result == OS.S_OK) ? DPIUtil.mapDPIToZoom (dpiX[0]) : 100;
+ monitor.zoom = DPIUtil.getZoomForAutoscaleProperty (result);
+ } else {
+ monitor.zoom = getDeviceZoom ();
+ }
+ return monitor;
+}
+
/**
* Returns an array of monitors attached to the device.
*
@@ -3223,16 +3245,7 @@ long /*int*/ monitorEnumProc (long /*int*/ hmonitor, long /*int*/ hdc, long /*in
System.arraycopy (monitors, 0, newMonitors, 0, monitors.length);
monitors = newMonitors;
}
- MONITORINFO lpmi = new MONITORINFO ();
- lpmi.cbSize = MONITORINFO.sizeof;
- OS.GetMonitorInfo (hmonitor, lpmi);
- Monitor monitor = new Monitor ();
- monitor.handle = hmonitor;
- Rectangle boundsInPixels = new Rectangle (lpmi.rcMonitor_left, lpmi.rcMonitor_top, lpmi.rcMonitor_right - lpmi.rcMonitor_left,lpmi.rcMonitor_bottom - lpmi.rcMonitor_top);
- monitor.setBounds (DPIUtil.autoScaleDown (boundsInPixels));
- Rectangle clientAreaInPixels = new Rectangle (lpmi.rcWork_left, lpmi.rcWork_top, lpmi.rcWork_right - lpmi.rcWork_left, lpmi.rcWork_bottom - lpmi.rcWork_top);
- monitor.setClientArea (DPIUtil.autoScaleDown (clientAreaInPixels));
- monitors [monitorCount++] = monitor;
+ monitors [monitorCount++] = getMonitor (hmonitor);
return 1;
}
@@ -4938,24 +4951,3 @@ static char [] withCrLf (char [] string) {
}
}
-
-class MonitorUtil {
- static int getZoom (Monitor monitor) {
- if (OS.WIN32_VERSION >= OS.VERSION (6, 3)) {
- int[] dpiX = new int[1];
- int[] dpiY = new int[1];
- int result = OS.GetDpiForMonitor (monitor.handle, OS.MDT_EFFECTIVE_DPI, dpiX, dpiY);
- result = (result == OS.S_OK) ? DPIUtil.mapDPIToZoom (dpiX[0]) : 100;
- return DPIUtil.getZoomForAutoscaleProperty (result);
- }
- int dpi = getSystemDPI ();
- return DPIUtil.mapDPIToZoom (dpi);
- }
-
- static int getSystemDPI () {
- long /*int*/ hDC = OS.GetDC (0);
- int dpi = OS.GetDeviceCaps (hDC, OS.LOGPIXELSX);
- OS.ReleaseDC (0, hDC);
- return dpi;
- }
-}

Back to the top