From b5a40a7ad870c3d365a68357ca243eab76ed0201 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 4 Jan 2025 17:32:05 -0800 Subject: [PATCH] fix(wm): skip destroyed windows on rule enforcement This commit introduces an if let binding to only process windows which still exist when attempting to enforce workspace rules. Previously, calls to functions such as Window::exe might have returned an error if a window which had been destroyed but not yet removed from the state was examined by the enforce_workspace_rules fn. Now, such windows will fail the if let binding and be skipped entirely, eventually being removed by the core event processing loop. --- komorebi/src/window_manager.rs | 98 +++++++++++++++++----------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 0123b495..1332716f 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -732,45 +732,56 @@ impl WindowManager { for window in workspace.visible_windows().into_iter().flatten() { let mut already_moved_window_handles = self.already_moved_window_handles.lock(); - let exe_name = window.exe()?; - let title = window.title()?; - let class = window.class()?; - let path = window.path()?; - - for rule in &*workspace_matching_rules { - let matched = match &rule.matching_rule { - MatchingRule::Simple(r) => should_act_individual( - &title, - &exe_name, - &class, - &path, - r, - ®ex_identifiers, - ), - MatchingRule::Composite(r) => { - let mut composite_results = vec![]; - for identifier in r { - composite_results.push(should_act_individual( - &title, - &exe_name, - &class, - &path, - identifier, - ®ex_identifiers, - )); - } - - composite_results.iter().all(|&x| x) - } - }; - - if matched { - let floating = workspace.floating_windows().contains(window); - - if rule.initial_only { - if !already_moved_window_handles.contains(&window.hwnd) { - already_moved_window_handles.insert(window.hwnd); + if let (Ok(exe_name), Ok(title), Ok(class), Ok(path)) = + (window.exe(), window.title(), window.class(), window.path()) + { + for rule in &*workspace_matching_rules { + let matched = match &rule.matching_rule { + MatchingRule::Simple(r) => should_act_individual( + &title, + &exe_name, + &class, + &path, + r, + ®ex_identifiers, + ), + MatchingRule::Composite(r) => { + let mut composite_results = vec![]; + for identifier in r { + composite_results.push(should_act_individual( + &title, + &exe_name, + &class, + &path, + identifier, + ®ex_identifiers, + )); + } + + composite_results.iter().all(|&x| x) + } + }; + + if matched { + let floating = workspace.floating_windows().contains(window); + + if rule.initial_only { + if !already_moved_window_handles.contains(&window.hwnd) { + already_moved_window_handles.insert(window.hwnd); + + self.add_window_handle_to_move_based_on_workspace_rule( + &window.title()?, + window.hwnd, + i, + j, + rule.monitor_index, + rule.workspace_index, + floating, + &mut to_move, + ); + } + } else { self.add_window_handle_to_move_based_on_workspace_rule( &window.title()?, window.hwnd, @@ -782,17 +793,6 @@ impl WindowManager { &mut to_move, ); } - } else { - self.add_window_handle_to_move_based_on_workspace_rule( - &window.title()?, - window.hwnd, - i, - j, - rule.monitor_index, - rule.workspace_index, - floating, - &mut to_move, - ); } } }