From 091e9c3e56a92be0e0d9976ccc552f787b8ea195 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 28 Jul 2022 16:22:11 -0700 Subject: [PATCH] fix(wm): float monocle + max windows This commit ensures that monocle containers and maximized windows are considered valid candidates for the 'toggle-float' command and are handled accordingly if the command is called when they are in the foreground. fix #193 --- komorebi/src/workspace.rs | 48 ++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 42366636..b1ddb7db 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -648,22 +648,44 @@ impl Workspace { } pub fn new_floating_window(&mut self) -> Result<()> { - let focused_idx = self.focused_container_idx(); + let window = if let Some(maximized_window) = self.maximized_window() { + let window = *maximized_window; + self.set_maximized_window(None); + self.set_maximized_window_restore_idx(None); + window + } else if let Some(monocle_container) = self.monocle_container_mut() { + let window = monocle_container + .remove_focused_window() + .ok_or_else(|| anyhow!("there is no window"))?; - let container = self - .focused_container_mut() - .ok_or_else(|| anyhow!("there is no container"))?; + if monocle_container.windows().is_empty() { + self.set_monocle_container(None); + self.set_monocle_container_restore_idx(None); + } else { + monocle_container.load_focused_window(); + } - let window = container - .remove_focused_window() - .ok_or_else(|| anyhow!("there is no window"))?; - - if container.windows().is_empty() { - self.containers_mut().remove(focused_idx); - self.resize_dimensions_mut().remove(focused_idx); + window } else { - container.load_focused_window(); - } + let focused_idx = self.focused_container_idx(); + + let container = self + .focused_container_mut() + .ok_or_else(|| anyhow!("there is no container"))?; + + let window = container + .remove_focused_window() + .ok_or_else(|| anyhow!("there is no window"))?; + + if container.windows().is_empty() { + self.containers_mut().remove(focused_idx); + self.resize_dimensions_mut().remove(focused_idx); + } else { + container.load_focused_window(); + } + + window + }; self.floating_windows_mut().push(window);