Skip to content

Commit 4e3ac99

Browse files
committed
[win32] Refresh thread dpi awareness on hooks
This commit resets the DPI awareness for the WH_MSGFILTER hook, if called. For performance reasons that is only done, when runAsyncMessages will be triggered, as this can cause UI updates, which would be executed with the wrong DPI awareness context and cause UI glitches.
1 parent b4fabe5 commit 4e3ac99

File tree

1 file changed

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

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,7 +3425,17 @@ long msgFilterProc (long code, long wParam, long lParam) {
34253425
MSG msg = new MSG ();
34263426
int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT | OS.PM_QS_POSTMESSAGE;
34273427
if (!OS.PeekMessage (msg, 0, 0, 0, flags)) {
3428+
// Windows hooks will inherit the thread DPI awareness from
3429+
// the process. Whatever DPI awareness was set before on
3430+
// the thread will be overwritten before the hook is called.
3431+
// This requires to reset the thread DPi awareness to make
3432+
// sure, all UI updates caused by this will be executed
3433+
// with the correct DPI awareness
3434+
long previousDPIAwareness = refreshDPIAwareness();
34283435
if (runAsyncMessages (false)) wakeThread ();
3436+
if (previousDPIAwareness > 0) {
3437+
OS.SetThreadDpiAwarenessContext(previousDPIAwareness);
3438+
}
34293439
}
34303440
}
34313441
break;
@@ -5382,4 +5392,12 @@ private boolean setDPIAwareness(int desiredDpiAwareness) {
53825392
return true;
53835393
}
53845394

5395+
private long refreshDPIAwareness() {
5396+
int desiredApiAwareness = isRescalingAtRuntime() ? OS.DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2 : OS.DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;
5397+
long currentDPIAwareness = OS.GetThreadDpiAwarenessContext();
5398+
if (setDPIAwareness(desiredApiAwareness)) {
5399+
return currentDPIAwareness;
5400+
}
5401+
return 0;
5402+
}
53855403
}

0 commit comments

Comments
 (0)