feat: persist workspace-to-monitor assignments across disconnections#1284
Open
durdn wants to merge 1 commit intoglzr-io:mainfrom
Open
feat: persist workspace-to-monitor assignments across disconnections#1284durdn wants to merge 1 commit intoglzr-io:mainfrom
durdn wants to merge 1 commit intoglzr-io:mainfrom
Conversation
When monitors temporarily disconnect (sleep, dock/undock), record their identity and workspace names in a registry so workspaces are restored to the correct monitor on reconnection instead of being scattered. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
I will add some corollary after using this patch myself for the whole of today. I am so happy finally my PC goes in hibernation or sleep, the monitors switch off (I have 4) and when the system reactivates all my windows and workspaces are in the exact same place. I really really really am so happy. |
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.
Summary
When monitors temporarily disconnect (PC sleep, monitor standby, dock/undock), GlazeWM loses track of which workspaces were on which monitors. The current code treats every disconnection as permanent — it removes the monitor from the container tree and scatters its workspaces to remaining monitors. On reconnection, the monitor is treated as brand new and gets whatever workspace the config dictates, not what was actually there. This causes disruptive workspace shuffling that forces users to manually rearrange their layout after every sleep/wake cycle.
This PR introduces a Disconnected Monitor Registry — a lightweight record kept alongside the container tree that remembers which workspaces belonged to which monitor. When a monitor disconnects, we capture its identity (
device_path,hardware_id,device_name) and its workspace names ordered by focus. When the same physical monitor reconnects, we restore its workspaces automatically.Key design decisions
Vec<DisconnectedMonitor>onWmState. This avoids breakingsort_monitors,monitor.index(),to_rect(), and all other code that assumes every monitor in the tree is live.bind_to_monitorworkspace configs are processed first; ghost restoration fills in the remaining workspaces after. This means user config is always respected.device_pathfirst (most reliable), then fall back tohardware_idonly when it's unique across all connected + disconnected monitors.device_pathon each disconnect and pruned after 1 hour to prevent unbounded growth.remove_monitoris untouched. The newdisconnect_monitorwraps it — captures the record, then delegates to the existing removal logic.Edge cases handled
All monitors disconnect (sleep) — Last monitor preserved (existing logic). Others get ghost records. On wake, ghosts restore workspaces.
User moves windows while monitor is off — Ghost stores workspace names, not windows. Workspaces return with whatever windows they now contain.
Empty workspace was garbage-collected — Ghost has the name but workspace no longer exists — silently skipped.
Same monitor disconnects repeatedly — Ghost record is replaced (deduped by device_path).
Duplicate hardware IDs (e.g. identical monitors) — device_path match is preferred. hardware_id only used when unique.
Fixes #1130, #907, #318.
Test plan
cargo buildpassescargo clippypasses with no new warnings