Skip to content

Commit 7a8fda3

Browse files
committed
Initialize Win32 Display thread with correct OS DPI awareness
The runtime auto-scaling for multi-monitor HiDPI support on Windows requires the system's DPI awareness to be set to PerMonitorV2. This change makes the Display class initialize its UI thread with the according DPI awareness. Contributes to #62 Contributes to #131
1 parent 3b3a2d0 commit 7a8fda3

File tree

1 file changed

+23
-0
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+23
-0
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,29 @@ public Display () {
582582
*/
583583
public Display (DeviceData data) {
584584
super (data);
585+
initializeProperDPIAwareness();
586+
}
587+
588+
private void initializeProperDPIAwareness() {
589+
if (!DPIUtil.isAutoScaleOnRuntimeActive()) {
590+
return;
591+
}
592+
// Auto scaling on runtime requires DPI awareness mode "Per Monitor V2"
593+
boolean perMonitorV2Available = OS.WIN32_BUILD > OS.WIN32_BUILD_WIN10_1809;
594+
if (!perMonitorV2Available) {
595+
System.err.println(
596+
"***WARNING: rescaling at runtime is activated but the OS version does not support required DPI awareness mode PerMonitorV2.");
597+
return;
598+
}
599+
600+
boolean alreadyUsesPerMonitorV2 = OS.GetThreadDpiAwarenessContext() == OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
601+
if (alreadyUsesPerMonitorV2) {
602+
return;
603+
}
604+
long setDpiAwarenessResult = OS.SetThreadDpiAwarenessContext(OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
605+
if (setDpiAwarenessResult == 0L) {
606+
System.err.println("***WARNING: setting DPI awareness to PerMonitorV2 failed.");
607+
}
585608
}
586609

587610
Control _getFocusControl () {

0 commit comments

Comments
 (0)