From 85f9c381e5bdbcbb735a1f204cbe1959f4449b22 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 21 Jun 2022 07:54:27 -0700 Subject: [PATCH] feat(wm): focus to last container across monitors This commit ensures that when focusing across a monitor boundary, the focus will go to the last focused window container on the focused workspace on the other side of a given window boundary. re #145 --- komorebi/src/window_manager.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 62d52fe8..3e5b757c 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -940,19 +940,19 @@ impl WindowManager { let new_idx = workspace.new_idx_for_direction(direction); // if there is no container in that direction for this workspace - if new_idx.is_none() { - // check if there is a monitor in that direction - let monitor_idx = self - .monitor_index_in_direction(direction) - .ok_or_else(|| anyhow!("there is no container or monitor in this direction"))?; - self.focus_monitor(monitor_idx)?; - } + match new_idx { + None => { + let monitor_idx = self + .monitor_index_in_direction(direction) + .ok_or_else(|| anyhow!("there is no container or monitor in this direction"))?; - let workspace = self.focused_workspace_mut()?; - workspace.focus_container(new_idx.unwrap_or_else(|| match direction { - OperationDirection::Right | OperationDirection::Down => 0, - OperationDirection::Left | OperationDirection::Up => workspace.containers().len() - 1, - })); + self.focus_monitor(monitor_idx)?; + } + Some(idx) => { + let workspace = self.focused_workspace_mut()?; + workspace.focus_container(idx); + } + } self.focused_window_mut()?.focus(self.mouse_follows_focus)?;