From 5b91e221148f2ec4a426cca89f7f8cd836b7eb13 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Thu, 28 Jul 2022 16:45:51 -0700 Subject: [PATCH] fix(wm): maximize monocle + floating windows This commit ensures that monocle containers and floating windows are considered validate candidates for the 'toggle-maximize' command and are handled accordingly if the command is called when they are in the foreground. fix #194 --- komorebi/src/workspace.rs | 47 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index b1ddb7db..9240e919 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -771,6 +771,53 @@ impl Workspace { pub fn new_maximized_window(&mut self) -> Result<()> { let focused_idx = self.focused_container_idx(); + let foreground_hwnd = WindowsApi::foreground_window()?; + let mut floating_window = None; + + if !self.floating_windows().is_empty() { + let mut focused_floating_window_idx = None; + for (i, w) in self.floating_windows().iter().enumerate() { + if w.hwnd == foreground_hwnd { + focused_floating_window_idx = Option::from(i); + } + } + + if let Some(idx) = focused_floating_window_idx { + floating_window = Option::from(self.floating_windows_mut().remove(idx)); + } + } + + if let Some(floating_window) = floating_window { + self.set_maximized_window(Option::from(floating_window)); + self.set_maximized_window_restore_idx(Option::from(focused_idx)); + if let Some(window) = self.maximized_window() { + window.maximize(); + } + + return Ok(()); + } + + let monocle_restore_idx = self.monocle_container_restore_idx(); + if let Some(monocle_container) = self.monocle_container_mut() { + let window = monocle_container + .remove_focused_window() + .ok_or_else(|| anyhow!("there is no window"))?; + + if monocle_container.windows().is_empty() { + self.set_monocle_container(None); + self.set_monocle_container_restore_idx(None); + } else { + monocle_container.load_focused_window(); + } + + self.set_maximized_window(Option::from(window)); + self.set_maximized_window_restore_idx(monocle_restore_idx); + if let Some(window) = self.maximized_window() { + window.maximize(); + } + + return Ok(()); + } let container = self .focused_container_mut()