-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[win32] Refresh thread dpi awareness on hooks #1813
base: master
Are you sure you want to change the base?
[win32] Refresh thread dpi awareness on hooks #1813
Conversation
4e3ac99
to
c9dc6e1
Compare
long previousDPIAwareness = refreshDPIAwareness(); | ||
if (runAsyncMessages (false)) wakeThread (); | ||
if (previousDPIAwareness > 0) { | ||
OS.SetThreadDpiAwarenessContext(previousDPIAwareness); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about extracting the whole set/reset logic into a separate method, so that this call looks something like this:
long previousDPIAwareness = refreshDPIAwareness(); | |
if (runAsyncMessages (false)) wakeThread (); | |
if (previousDPIAwareness > 0) { | |
OS.SetThreadDpiAwarenessContext(previousDPIAwareness); | |
} | |
runWithProperDPIAwareness(() -> { | |
if (runAsyncMessages(false)) wakeThread(); | |
}); |
and refreshDPIAwareness()
is extended to runWithProperDPIAwareness(Runnable operation)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adapted it accordingly
c9dc6e1
to
e36c58e
Compare
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.
e36c58e
to
918acf9
Compare
@@ -5382,4 +5398,18 @@ private boolean setDPIAwareness(int desiredDpiAwareness) { | |||
return true; | |||
} | |||
|
|||
private void runWithProperDPIAwareness(Runnable operation) { | |||
if (isRescalingAtRuntime()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be nice to still execute the passed operation if isRescalingAtRuntime() == false
, but just without correcting DPI awareness 😉
int flags = OS.PM_NOREMOVE | OS.PM_NOYIELD | OS.PM_QS_INPUT; | ||
if (!OS.PeekMessage (msg, 0, 0, 0, flags)) wakeThread (); | ||
sendPreExternalEventDispatchEvent (); | ||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that preserving formatting should not be the primary goal when processing changes, but if so much code like here is affected where the history might be interesting for different reasons (e.g., to find the commit when this handling of the "bug in Windows" was introduced, I was wondering whether we could still achieve that here without reducing comprehensibility. For example, wrapping the whole block inside the if (!synchronizer.isMessagesEmpty()) {
into a processMessages
runnable or the like, which is then executed with proper DPI awareness inside that if block, i.e.:
if (code >= 0) {
Runnable processMessages = () -> {
// all the existing code
}
if (!synchronizer.isMessagesEmpty()) {
runWithProperDPIAwareness(processMessages);
}
}
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.
How to reproduce
Have monitor specific scaling active and at least two monitors.
Bildschirmaufnahme.2025-02-10.121127.mp4