From e4d97c87edde6bae6a9f89b762607103e693234d Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 12:22:40 -0700 Subject: [PATCH] refactor(windows): resolve_placement_index uses should_act_window BEHAVIOUR (Windows runtime, none expected): window.rs gets should_act_window and should_act_window_individual, thin forms of should_act and should_act_individual that take one class, and resolve_placement_index has KDE's text (one let-else over the four lookups, then those two calls). Same checks in the same order. Windows e2e scenarios: initial_window_placement rules (target and rules map, single and many matching rules). Verified: Windows clippy --workspace --locked --all-targets -D warnings: PASS. Not run: Windows tests, e2e. --- komorebi/src/window.rs | 24 ++++++++++++++++++++++++ komorebi/src/workspace.rs | 29 +++++++++++++++-------------- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index b8b15e56..c89ed7dd 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -1107,6 +1107,30 @@ fn window_is_eligible( } #[allow(clippy::cognitive_complexity, clippy::too_many_lines)] +/// [`should_act`] for a window, which has one class here +pub fn should_act_window( + title: &str, + exe_name: &str, + class: &str, + path: &str, + identifiers: &[MatchingRule], + regex_identifiers: &HashMap, +) -> Option { + should_act(title, exe_name, class, path, identifiers, regex_identifiers) +} + +/// [`should_act_individual`] for a window, which has one class here +pub fn should_act_window_individual( + title: &str, + exe_name: &str, + class: &str, + path: &str, + identifier: &IdWithIdentifier, + regex_identifiers: &HashMap, +) -> bool { + should_act_individual(title, exe_name, class, path, identifier, regex_identifiers) +} + pub fn should_act( title: &str, exe_name: &str, diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 669dd6ee..cbaba58e 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -40,7 +40,8 @@ use crate::core::WindowPlacement; use crate::lockable_sequence::LockableSequence; use crate::ring::Ring; use crate::should_act; -use crate::should_act_individual; +use crate::should_act_window; +use crate::should_act_window_individual; use crate::stackbar_manager; use crate::stackbar_manager::STACKBAR_TAB_HEIGHT; use crate::static_config::WorkspaceConfig; @@ -1392,16 +1393,9 @@ impl Workspace { self.resolve_placement_target(target, fallback_idx) } InitialWindowPlacementRules::Rules(rules_map) => { - let Some(title) = window.title() else { - return fallback_idx; - }; - let Some(exe_name) = window.exe() else { - return fallback_idx; - }; - let Some(class) = window.class() else { - return fallback_idx; - }; - let Some(path) = window.path() else { + let (Some(title), Some(exe_name), Some(class), Some(path)) = + (window.title(), window.exe(), window.class(), window.path()) + else { return fallback_idx; }; @@ -1410,7 +1404,7 @@ impl Workspace { // BTreeMap iterates in key order for (target, placement_rules) in rules_map { let matched = match placement_rules { - PlacementMatchingRules::Single(id) => should_act_individual( + PlacementMatchingRules::Single(id) => should_act_window_individual( &title, &exe_name, &class, @@ -1422,8 +1416,15 @@ impl Workspace { // OR logic: any matching rule triggers placement at this target. // Each MatchingRule handles its own Simple/Composite (AND) logic // internally via should_act. - should_act(&title, &exe_name, &class, &path, rules, ®ex_identifiers) - .is_some() + should_act_window( + &title, + &exe_name, + &class, + &path, + rules, + ®ex_identifiers, + ) + .is_some() } };