Skip to content

Commit 11c1f19

Browse files
committed
[Win32] Deactivate monitor-specific scaling if PerMonitorV2 unsupported
For monitor-specific scaling, PerMonitorV2 is set (and required) as DPI awareness do work properly. By now, even if the DPI awareness was not successfully set to PerMonitorV2 (which can actually only happen on Windows Server 2016), monitor-specific scaling will still be enabled. With this change, if the required DPI awareness for monitor-specific scaling could not be set, monitor-specific scaling will automatically be disabled.
1 parent 584132f commit 11c1f19

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void monitorSpecificScaling_withCustomDpiAwareness() {
4242
try {
4343
setMonitorSpecificScaling(true);
4444
Display display = Display.getDefault();
45-
assertTrue(display.isRescalingAtRuntime());
45+
assertFalse(display.isRescalingAtRuntime());
4646
assertExpectedDpiAwareness(OS.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE);
4747
} finally {
4848
System.clearProperty(Win32DPIUtils.CUSTOM_DPI_AWARENESS_PROPERTY);

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/internal/Win32DPIUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ public static boolean setDPIAwareness(long desiredDpiAwareness) {
8585
return true;
8686
}
8787

88+
public static boolean hasProperDpiAwarenessForMonitorSpecificScaling() {
89+
return OS.AreDpiAwarenessContextsEqual(OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2, OS.GetThreadDpiAwarenessContext());
90+
}
91+
8892
public static <T> T runWithProperDPIAwareness(Display display, Supplier<T> operation) {
8993
if (customDpiAwareness == -1) {
9094
return operation.get();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5408,9 +5408,9 @@ private boolean initializeAutoscaling(boolean useMonitorSpecificScaling) {
54085408
if (!Win32DPIUtils.initializeCustomDpiAwareness() && !DPIUtil.isCustomAutoScale()) {
54095409
successfullySetDpiAwareness = setDpiAwareness(useMonitorSpecificScaling);
54105410
}
5411-
DPIUtil.setMonitorSpecificScaling(useMonitorSpecificScaling);
5412-
rescalingAtRuntime = useMonitorSpecificScaling;
5413-
coordinateSystemMapper = useMonitorSpecificScaling ? new MultiZoomCoordinateSystemMapper(this, this::getMonitors) : new SingleZoomCoordinateSystemMapper(this);
5411+
rescalingAtRuntime = useMonitorSpecificScaling && Win32DPIUtils.hasProperDpiAwarenessForMonitorSpecificScaling();
5412+
DPIUtil.setMonitorSpecificScaling(rescalingAtRuntime);
5413+
coordinateSystemMapper = rescalingAtRuntime ? new MultiZoomCoordinateSystemMapper(this, this::getMonitors) : new SingleZoomCoordinateSystemMapper(this);
54145414
// dispose an existing font registry for the default display
54155415
SWTFontProvider.disposeFontRegistry(this);
54165416
return successfullySetDpiAwareness;

0 commit comments

Comments
 (0)