Skip to content

fix(wm): reconcile monitor state across RDP transitions - #1761

Open
MattKotsenas wants to merge 6 commits into
LGUG2Z:masterfrom
MattKotsenas:fix/stale-rdp-monitors
Open

MattKotsenas wants to merge 6 commits into
LGUG2Z:masterfrom
MattKotsenas:fix/stale-rdp-monitors

Conversation

@MattKotsenas

@MattKotsenas MattKotsenas commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With this change, Komorebi reconciles display replacements across RDP transitions even when the monitor count stays unchanged. Previously, equal counts could leave windows associated with a detached monitor: retile operated on that stale state, while reacquisition skipped windows already considered managed.

Changes

  • Compare monitor identities during initial detection and stabilization, then use the verified display snapshot for removal and addition.
  • Preserve the surviving displays' focus, workspace routing, and known-window locations when removal or preference-based insertion changes monitor indices.
  • Use upstream's display-identity rules for session caching, distinguishing empty serials and separate displays with an UNKNOWN device ID. Prefer an exact nonempty serial when multiple cached displays could match, preserve explicit device/serial cache bindings, and consume only the entry restored.
  • Finish restoration, layout, bookkeeping, and subscriber notification before best-effort foreground activation. Normal explicit focus operations still propagate errors.

Validation

  • Bounded notification-handler tests cover same-count replacement, independent restoration and one-time consumption of multiple UNKNOWN displays, serial/device changes, competing serial and port matches, configured bindings, and configuration cached before a display connects.
  • Reference-preservation tests cover monitor removal and preference-based insertion.
  • A native-window test demonstrates that cached restoration completes when valid windows on a non-input test desktop cannot take the foreground.
  • Mutation testing confirmed that test_cached_unknown_displays_restore_independently fails when either cache insertion or new-monitor detection uses raw device IDs. The test passed again after each mutation was reverted.

Require present serial ids when matching attached monitors. Let the manager repair surviving monitor focus, user indices, workspace rules and known HWNDs after removal.
Compare monitor identities as well as counts. Apply the verified enumeration snapshot once and repair references after preference-based insertion.
Use ordinary tests with scoped fixtures for shared configuration and temporary storage. Replace the leaked-listener test with bounded handler processing; keep production listener supervision unchanged.
Finish cached restoration, layout, bookkeeping and subscriber notification before best-effort explicit activation. Preserve normal focus error propagation and report foreground refusal without stale last-error diagnostics.
Empty serials and shared UNKNOWN device IDs could overwrite or restore another display's cached
workspaces. Match session entries using upstream display identity, preferring an exact nonempty
serial over a competing port match. Keep configured device and serial cache bindings distinct,
including configuration for displays not yet connected.

Consume the selected entry only after its restoration and layout succeed, and recognize newly
attached UNKNOWN displays independently. Preserve UNKNOWN display names when insertion remaps focus,
workspace rules and known-window locations. Reuse upstream disconnection detection and update
rebased test fixtures.

Cover cache isolation, one-time consumption, serial/port conflicts and configured bindings through
bounded handler tests. Verify the regressions reject raw-device-ID mutations; retain upstream
live-topology matching policy.
Restore monitor focus through the same old-to-new index map used by workspace rules, avoiding a
separate identity snapshot and lookup. Explain why session cache matching needs explicit configured
bindings and cannot use Hash/Eq keys.

Consolidate same-count topology checks into the handler regression and remove the overlapping
handler smoke test. Keep cache-identity matrices, serial-priority regressions and isolation
guarantees. Verify the consolidated regression rejects count-only matching.
@MattKotsenas
MattKotsenas force-pushed the fix/stale-rdp-monitors branch from f98ddf9 to 1033c2a Compare November 19, 2026 01:01

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant