fix(wm): improve display enum error handling and added verification step #1634
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.
This change enhances the stability of monitor detection, particularly when monitors are being connected or disconnected, by adding a verification step against the windows system metrics.
Instead of silently flattening errors during display enumeration, we now partition the results to log any errors that occur when querying display devices. This helps in diagnosing issues with specific hardware/driver constellations.
Race condition mitigation: I discovered that when a monitor connection event fires, the win32-display-data crate might not immediately see the new monitor, even though the OS event has triggered; we now verify the count of enumerated monitors against GetSystemMetrics(SM_CMONITORS). If the count mismatches, we enter a retry loop.
Reason for creating this PR: I've noticed an issue with display enumeration after wakeup from display sleep (the sort that you configure in the power plan that only affects the display, not the entire system).
What I found out is that the displays may not immediately be available for enumeration after the event fires. Usually one or two retries via the added loop are necessary, for the displays to be correctly identified.
For now I'm testing this a bit, to see if I can notice any issues, but it's looking pretty good on my system. I'm no longer having any issues with "unknown" displays after wakeup; containers/windows are where they should be etc.
It would be nice if someone else could try this out as well (especially if you noticed an unmanaged/unknown display after wakeup before), as not everyones setup or system behavior may be the same.
Marking this as a draft for now, as I would like to hear some feedback since I'm very unfamiliar with Rust - is there anything that'd be considered "ugly" in Rust or a big "no-no"? Feedback is welcome.
I had created a support thread on the discord for this, which includes additional logging snippets and my findings here: https://discord.com/channels/898554690126630914/1459645640362426572