mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-01-11 14:40:25 +01:00
[PR #1255] [MERGED] Fix/monitor disconnect #1278
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/LGUG2Z/komorebi/pull/1255
Author: @alex-ds13
Created: 1/31/2025
Status: ✅ Merged
Merged: 2/21/2025
Merged by: @LGUG2Z
Base:
master← Head:fix/monitor-disconnect📝 Commits (10+)
3d7843echore(release): v0.1.34b189b0bfix(wm): properly store tile state when caching ws699f830fix(wm): store config on workspaced211d84fix(wm): correctly use the display_index_preferencesd69ff5bfix(wm): cache monitor configs for unloaded monitors78930fbfix(wm): don't store empty layout_rules on monitor cache638a43ffix(wm): restore orphaned containers66ce028fix(wm): skip workspace_config on workspace serdeab163dcfix(wm): use serial numbers along device ids69d8d84fix(wm): handle serial id onload_monitor_information📊 Changes
22 files changed (+1069 additions, -366 deletions)
View changed files
📝
Cargo.lock(+52 -59)📝
Cargo.toml(+3 -1)📝
README.md(+1 -1)📝
docs/cli/flip-layout.md(+1 -1)➕
docs/cli/focus-monitor-at-cursor.md(+12 -0)📝
docs/cli/query.md(+1 -1)📝
docs/komorebi.bar.example.json(+1 -1)📝
docs/komorebi.example.json(+1 -1)📝
komorebi-bar/src/bar.rs(+232 -145)📝
komorebi-bar/src/komorebi.rs(+14 -1)📝
komorebi-bar/src/main.rs(+6 -4)📝
komorebi-client/src/lib.rs(+1 -0)📝
komorebi/src/main.rs(+8 -2)📝
komorebi/src/monitor.rs(+13 -13)📝
komorebi/src/monitor_reconciliator/hidden.rs(+98 -3)📝
komorebi/src/monitor_reconciliator/mod.rs(+279 -82)📝
komorebi/src/process_event.rs(+2 -0)📝
komorebi/src/static_config.rs(+262 -48)📝
komorebi/src/window_manager.rs(+7 -1)📝
komorebi/src/windows_api.rs(+68 -2)...and 2 more files
📄 Description
This PR tries to properly handle monitors disconnecting and reconnecting
This PR reworks the way the
postloadand thereloadfunctions apply the monitor configs to the monitors. Previously it was looping through the monitor configs and applying them to the monitor with the index corresponding to the config's index.However this isn't correct, since the user might set the preferred indices for 3 monitors (like monitor A, B and C), with the preferred index set to 0 for A, 1 for B and 2 for C, but if only monitors A and C are connected then komorebi would apply config 0 to A and config 1 to C, which is wrong it should be 2 for C.
This PR changes the way the configs are applied on those functions.
Now it loops through the existing monitors (already in order), then checks if the monitor has a preferred config index, if it does it uses that one, if it doesn't then it uses the first monitor config that isn't a preferred index for some other monitor and that hasn't been used yet.
For the situation above it means that it would still apply config 2 to monitor C. And in case there aren't any display_index_preferences set it will still apply the configs in order.
It also changes the way the layout is stored from the current monitor, by making sure to set it to
Noneif the workspace is not tiling. Previously any floating workspace would be restored from cache with a tiling BSP layout.Related to this discussion on Discord
However this entire code is based on the premise that the
device_idis always the same for the same devices. However there have been comments on discord stating that this isn't true, however I've not been able to confirm this and the users have not given any proof of this happening (they might simply be confusing it since it's a weird string similar between monitors...)I think the changes from this PR should fix most issues that people have been having with multiple monitors (specially with 3 or more monitors). But it's probably better to not merge this until we can get some users to test it.
This PR changes the monitor cache from caching a config to caching the actual state of the monitor itself.
With this PR when a monitor disconnects instead of "throwing" all windows to the main monitor, right now it does nothing and keeps your other monitors as is and simply stores the disconnected monitor state.
If then you reconnect (or wake up) the monitor again, then you'll get back to the same monitor with all the windows like you had before!
If while the monitor is disconnected you need to access some window that was on the disconnected monitor, you can simply
alt + tabto it or press the taskbar icon and the window will show on the focused workspace of the focused monitor and it becomes handled by this monitor/workspace. When the previously disconnected monitor reconnects it will see that this specific window is already handled by another workspace so it ignores it.This PR also introduces a few changes to the bar so that it can handle the monitor disconnect/reconnect properly and so that it can map the bar config to the correct monitor.
Previously if you had 3 monitor configs setup on
komorebi.jsonwith thedisplay_index_preferencesset like this:But if you only had connected monitors A and C you would have to manually change the bar configurations monitor index because now monitor A would have index 0, but monitor C would have index 1 instead of 2.
Now with this PR this is no longer needed. Now the monitor index setup on the bar configuration NEEDS TO BE the index you've used on
display_index_preferencesfor that monitor. So in the case above you would setup the bar configurations using the indices 0, 1 and 2 for monitors A, B and C respectively.If the monitor B is disconnected, komorebi will know that now the monitor with index 1 is monitor C so the bar will also be aware of this and automatically change it's internal index to 1 (the user doesn't have to do anything!). Meaning that the bar will still show on the correct monitor with the correct coordinates. After the monitor reconnects the bar will update it's internal index again automatically and continue to show on the correct monitor. This means that even if you connect other monitors that are not mentioned on the
display_index_preferencesthe bar should still point to the correct monitor.It would be great if some users could test this PR since it introduces quite a few changes to make sure there are no regressions!
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.