From 05777c34b9fcf5c5543f4af97aabedf141aae982 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 24 Aug 2021 07:20:16 -0700 Subject: [PATCH] fix(wm): ensure removal of max + monocle windows Previously, the implementation of maximized and monocle windows assumed that the only valid state for them to transition to would be to restore them to the index that they were maximized/monocle-d from in their host workspace. This is not exclusively the case as it is also possible for them to be closed when they are in a maximized or monocle state. This commit updates the Workspace.remove_window() fn to also look for the hwnd to be removed in the monocle container and maximized window, if they exist. fix #19 --- komorebi/src/workspace.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index a88ab2fb..32d07172 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -329,6 +329,33 @@ impl Workspace { return Ok(()); } + if let Some(container) = self.monocle_container_mut() { + if let Some(window_idx) = container + .windows() + .iter() + .position(|window| window.hwnd == hwnd) + { + container + .remove_window_by_idx(window_idx) + .ok_or_else(|| anyhow!("there is no window"))?; + + if container.windows().is_empty() { + self.set_monocle_container(None); + self.set_monocle_container_restore_idx(None); + } + + return Ok(()); + } + } + + if let Some(window) = self.maximized_window() { + if window.hwnd == hwnd { + self.set_maximized_window(None); + self.set_maximized_window_restore_idx(None); + return Ok(()); + } + } + let container_idx = self .container_idx_for_window(hwnd) .ok_or_else(|| anyhow!("there is no window"))?;