Repository navigation
Windows: per-monitor DPI thread context for monitors() and grab() (#219) - #612
Open
jeanluyac-sketch wants to merge 1 commit into
Open
jeanluyac-sketch wants to merge 1 commit into
jeanluyac-sketch wants to merge 1 commit into
Conversation
…() (BoboTiG#219) SetProcessDpiAwareness() fails with E_ACCESSDENIED when the process DPI mode was already set, leaving the process system-DPI aware so monitors with a different scaling than the primary one report scaled sizes. Wrap monitors() and grab() in SetThreadDpiAwarenessContext(PER_MONITOR_AWARE_V2), falling back to V1, and restore the caller's context afterwards. AI-assisted (Claude): implementation and tests drafted with AI, reviewed by the author.
4 tasks done
BoboTiG
requested
a balanced review from Copilot
and removed request for
Copilot
December 1, 2026 08:53
Owner
|
@halldorfannar I would like your input here, if possible. |
Copilot stopped reviewing on behalf of
BoboTiG due to an error
December 1, 2026 08:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #219
_set_dpi_awareness()callsSetProcessDpiAwareness(2)and ignores the result. It fails withE_ACCESSDENIEDwhen the process DPI mode was already set (host executable manifest, GUI toolkit, earlier call), so the process stays system-DPI aware and monitors with a different scaling than the primary one report scaled sizes (2926 = 2560 × 200%/175% in the issue).monitors()andgrab()now run insideSetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2)(falling back to V1 before Windows 10 1703) and restore the caller's previous thread context afterwards, so the host application's DPI behaviour is untouched. On Windows without the API it is a no-op and the existing process-level call still applies.monitors()leaves the thread context unchanged./check.ps1passedTested on Windows 11 / Python 3.14 with four monitors:
test_windows.py15/15 pass. The full suite has 5 failures that also happen onmainon this machine (a monitor at a negative x origin); I'll send a separate tests-only PR for those. Caveat: all my monitors are at 100% scaling, so I could not reproduce the original mixed-DPI sizes; a check from someone with mixed scaling would be welcome.AI assistance disclosure