GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.
fix: incorrect monitor-bound workspaces after disconnecting + reconnecting a monitor (#1185)
Van Tranb8de85c7e493
diff --git a/packages/wm/src/commands/monitor/add_monitor.rs b/packages/wm/src/commands/monitor/add_monitor.rsindex 804bdb91..fea2b357 100644--- a/packages/wm/src/commands/monitor/add_monitor.rs+++ b/packages/wm/src/commands/monitor/add_monitor.rs@@ -17,8 +17,7 @@ use crate::{pub fn add_monitor(native_monitor: NativeMonitor,state: &mut WmState,- config: &UserConfig,-) -> anyhow::Result<()> {+) -> anyhow::Result<Monitor> {// Create `Monitor` instance. This uses the working area of the monitor// instead of the bounds of the display. The working area excludes// taskbars and other reserved display space.@@ -36,6 +35,14 @@ pub fn add_monitor(added_monitor: monitor.to_dto()?,});+ Ok(monitor)+}++pub fn move_bounded_workspaces_to_new_monitor(+ monitor: &Monitor,+ state: &mut WmState,+ config: &UserConfig,+) -> anyhow::Result<()> {let bound_workspace_configs = config.value.workspaces@@ -55,7 +62,7 @@ pub fn add_monitor(// Move workspaces that should be bound to the newly added monitor.move_workspace_to_monitor(&existing_workspace,- &monitor,+ monitor,state,config,)?;@@ -74,7 +81,7 @@ pub fn add_monitor(// automatically prioritize bound workspace configs and fall back to the// first available one if needed.if monitor.child_count() == 0 {- activate_workspace(None, Some(monitor), state, config)?;+ activate_workspace(None, Some(monitor.clone()), state, config)?;}Ok(())diff --git a/packages/wm/src/events/handle_display_settings_changed.rs b/packages/wm/src/events/handle_display_settings_changed.rsindex c4822aca..fc1945f8 100644--- a/packages/wm/src/events/handle_display_settings_changed.rs+++ b/packages/wm/src/events/handle_display_settings_changed.rs@@ -4,8 +4,10 @@ use wm_platform::Platform;use crate::{commands::monitor::{- add_monitor, remove_monitor, sort_monitors, update_monitor,+ add_monitor, move_bounded_workspaces_to_new_monitor, remove_monitor,+ sort_monitors, update_monitor,},+ models::Monitor,traits::{CommonGetters, PositionGetters, WindowGetters},user_config::UserConfig,wm_state::WmState,@@ -84,14 +86,16 @@ pub fn handle_display_settings_changed(}}+ let mut new_monitors: Vec<Monitor> = Vec::new();+for native_monitor in new_native_monitors {- match pending_monitors.first() {- Some(_) => {- let monitor = pending_monitors.remove(0);- update_monitor(&monitor, native_monitor, state)- }- // Add monitor if it doesn't exist in state.- None => add_monitor(native_monitor, state, config),+ if pending_monitors.is_empty() {+ let monitor = add_monitor(native_monitor, state)?;+ new_monitors.push(monitor);+ Ok(())+ } else {+ let monitor = pending_monitors.remove(0);+ update_monitor(&monitor, native_monitor, state)}?;}@@ -111,6 +115,10 @@ pub fn handle_display_settings_changed(// Sort monitors by position.sort_monitors(&state.root_container)?;+ for new_monitor in new_monitors {+ move_bounded_workspaces_to_new_monitor(&new_monitor, state, config)?;+ }+for window in state.windows() {// Display setting changes can spread windows out sporadically, so mark// all windows as needing a DPI adjustment (just in case).diff --git a/packages/wm/src/wm_state.rs b/packages/wm/src/wm_state.rsindex 78816d25..89c064b8 100644--- a/packages/wm/src/wm_state.rs+++ b/packages/wm/src/wm_state.rs@@ -11,8 +11,10 @@ use wm_platform::{NativeMonitor, NativeWindow, Platform};use crate::{commands::{- container::set_focused_descendant, general::platform_sync,- monitor::add_monitor, window::manage_window,+ container::set_focused_descendant,+ general::platform_sync,+ monitor::{add_monitor, move_bounded_workspaces_to_new_monitor},+ window::manage_window,},models::{Container, Monitor, RootContainer, WindowContainer, Workspace,@@ -104,7 +106,8 @@ impl WmState {// Create a monitor, and consequently a workspace, for each detected// native monitor.for native_monitor in Platform::sorted_monitors()? {- add_monitor(native_monitor, self, config)?;+ let monitor = add_monitor(native_monitor, self)?;+ move_bounded_workspaces_to_new_monitor(&monitor, self, config)?;}// Manage windows in reverse z-order (bottom to top). This helps to