From 2ff76f0881cccf6699d1da2ccc13e3f36d1c9d40 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 29 Nov 2025 14:41:23 -0800 Subject: [PATCH] fix(wm): disable monocle mode if window is closed This commit ensures that monocle mode will be automatically disabled if the last window in a monocle container is closed. --- justfile | 3 +++ komorebi/src/reaper.rs | 24 +++++++++++++++++++++--- komorebi/src/workspace.rs | 16 ++++++++++++++++ 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/justfile b/justfile index eb7a2315..ab299ca1 100644 --- a/justfile +++ b/justfile @@ -27,6 +27,9 @@ build target: run target: cargo +stable run --bin {{ target }} --locked +error target $RUST_LOG="komorebi=error": + just run {{ target }} + warn target $RUST_LOG="komorebi=warn": just run {{ target }} diff --git a/komorebi/src/reaper.rs b/komorebi/src/reaper.rs index 642f4fe9..d7fa74e3 100644 --- a/komorebi/src/reaper.rs +++ b/komorebi/src/reaper.rs @@ -80,6 +80,22 @@ fn handle_notifications(wm: Arc>) -> color_eyre::Result<()> }); } + if let Some(container) = &mut workspace.monocle_container { + container.windows_mut().retain(|w| { + if w.id == window_id { + should_update = true; + tracing::info!("reaping window: {window_id}"); + } + + w.id != window_id + }); + + if container.windows().is_empty() { + workspace.monocle_container = None; + workspace.monocle_container_restore_idx = None; + } + } + workspace.floating_windows_mut().retain(|w| { if w.id == window_id { should_update = true; @@ -91,9 +107,11 @@ fn handle_notifications(wm: Arc>) -> color_eyre::Result<()> } } - // If an invalid window was cleaned up, we update the workspace - wm.update_focused_workspace(false, false)?; - border_manager::send_notification(None, Some(window_id)); + if should_update { + // If an invalid window was cleaned up, we update the workspace + wm.update_focused_workspace(false, false)?; + border_manager::send_notification(None, Some(window_id)); + } } ReaperNotification::MouseUpKeyUp => { // this first one will do a "nothing" update to check if any windows failed diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 37a8ecf3..cfd4d59c 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -415,6 +415,22 @@ impl Workspace { } } + if let Some(container) = &self.monocle_container + && let Some(focused_window) = container.focused_window() + { + if focused_window.application.process_id == process_id + && !valid_window_ids.contains(&focused_window.id) + { + invalid_window_ids.push(focused_window.id); + } + + // if accessibility API calls fail on AXError::InvalidUIElement + // let's try and nuke these early + if !focused_window.is_valid() { + invalid_window_ids.push(focused_window.id); + } + } + for window in self.floating_windows() { if window.application.process_id == process_id { if !valid_window_ids.contains(&window.id) {