Skip to content

Commit

Permalink
Initialize Win32 Display thread with correct OS DPI awareness
Browse files Browse the repository at this point in the history
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
  • Loading branch information
HeikoKlare committed Jul 23, 2024
1 parent 3b3a2d0 commit 7a8fda3
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,29 @@ public Display () {
*/
public Display (DeviceData data) {
super (data);
initializeProperDPIAwareness();
}

private void initializeProperDPIAwareness() {
if (!DPIUtil.isAutoScaleOnRuntimeActive()) {
return;
}
// Auto scaling on runtime requires DPI awareness mode "Per Monitor V2"
boolean perMonitorV2Available = OS.WIN32_BUILD > OS.WIN32_BUILD_WIN10_1809;
if (!perMonitorV2Available) {
System.err.println(
"***WARNING: rescaling at runtime is activated but the OS version does not support required DPI awareness mode PerMonitorV2.");
return;
}

boolean alreadyUsesPerMonitorV2 = OS.GetThreadDpiAwarenessContext() == OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2;
if (alreadyUsesPerMonitorV2) {
return;
}
long setDpiAwarenessResult = OS.SetThreadDpiAwarenessContext(OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2);
if (setDpiAwarenessResult == 0L) {
System.err.println("***WARNING: setting DPI awareness to PerMonitorV2 failed.");
}
}

Control _getFocusControl () {
Expand Down

0 comments on commit 7a8fda3

Please sign in to comment.