diff --git a/komorebi/src/border_manager/mod.rs b/komorebi/src/border_manager/mod.rs index 227c31c00..ff0d5b19f 100644 --- a/komorebi/src/border_manager/mod.rs +++ b/komorebi/src/border_manager/mod.rs @@ -159,7 +159,7 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result let focused_monitor_idx = state.focused_monitor_idx(); - for (monitor_idx, m) in state.monitors.elements().iter().enumerate() { + 'monitors: for (monitor_idx, m) in state.monitors.elements().iter().enumerate() { // Only operate on the focused workspace of each monitor if let Some(ws) = m.focused_workspace() { // Workspaces with tiling disabled don't have borders @@ -208,7 +208,14 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result { let mut focus_state = FOCUS_STATE.lock(); - focus_state.insert(border.hwnd, WindowKind::Monocle); + focus_state.insert( + border.hwnd, + if monitor_idx != focused_monitor_idx { + WindowKind::Unfocused + } else { + WindowKind::Monocle + }, + ); } let rect = WindowsApi::window_rect( @@ -216,7 +223,7 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result )?; border.update(&rect)?; - continue 'receiver; + continue 'monitors; } let is_maximized = WindowsApi::is_zoomed(HWND( @@ -236,7 +243,7 @@ pub fn handle_notifications(wm: Arc>) -> color_eyre::Result borders.remove(id); } - continue 'receiver; + continue 'monitors; } // Destroy any borders not associated with the focused workspace diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 04238ca8e..5f4b7e892 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1290,6 +1290,16 @@ impl WindowManager { .ok_or_else(|| anyhow!("there is no container or monitor in this direction"))?; self.focus_monitor(monitor_idx)?; + + if let Ok(focused_workspace) = self.focused_workspace() { + if let Some(monocle) = focused_workspace.monocle_container() { + if let Some(window) = monocle.focused_window() { + WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect( + window.hwnd(), + )?)?; + } + } + } } Some(idx) => { let workspace = self.focused_workspace_mut()?; @@ -1304,13 +1314,14 @@ impl WindowManager { // With this piece of code, we check if we have changed focus to a container stack with // a stackbar, and if we have, we run a quick update to make sure the focused text colour // has been applied - let focused_window = self.focused_window_mut()?; - let focused_window_hwnd = focused_window.hwnd; - focused_window.focus(self.mouse_follows_focus)?; + if let Ok(focused_window) = self.focused_window_mut() { + let focused_window_hwnd = focused_window.hwnd; + focused_window.focus(self.mouse_follows_focus)?; - let focused_container = self.focused_container()?; - if let Some(stackbar) = focused_container.stackbar() { - stackbar.update(focused_container.windows(), focused_window_hwnd)?; + let focused_container = self.focused_container()?; + if let Some(stackbar) = focused_container.stackbar() { + stackbar.update(focused_container.windows(), focused_window_hwnd)?; + } } Ok(()) @@ -1361,7 +1372,19 @@ impl WindowManager { // focus the target monitor self.focus_monitor(target_monitor_idx)?; - // get the focused workspace on the target monitor + // unset monocle container on target workspace if there is one + let mut target_workspace_has_monocle = false; + if let Ok(target_workspace) = self.focused_workspace() { + if target_workspace.monocle_container().is_some() { + target_workspace_has_monocle = true; + } + } + + if target_workspace_has_monocle { + self.toggle_monocle()?; + } + + // get a mutable ref to the focused workspace on the target monitor let target_workspace = self.focused_workspace_mut()?; // insert the origin container into the focused workspace on the target monitor