From 259dbb66468571417923e17eaa3f1543fefe1e97 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 12:22:40 -0700 Subject: [PATCH] refactor(kde): Window::path is a String and resolve_placement_index uses should_act_window Groundwork for moving Workspace into komorebi-core. Window::path returns Option, as the Windows one does (the backend already holds a String; the PathBuf and the to_string_lossy calls at its seven uses go). window.rs gets should_act_window and should_act_window_individual, the one-class forms of should_act and should_act_individual (KDE wraps the class in a slice), and resolve_placement_index calls those, which is the text the Windows side gets in the next revision. No behaviour change. Verified: KDE cargo test -p komorebi --lib --tests (native, lite env): 630 passed, 0 failed. Not run: VM suites. --- .../komorebi/src/process_command.rs | 2 +- .../komorebi/src/process_event.rs | 2 +- .../komorebi/src/transparency_manager.rs | 2 +- komorebi-for-kde/komorebi/src/window.rs | 50 ++++++++++++++++--- .../komorebi/src/window_manager.rs | 4 +- komorebi-for-kde/komorebi/src/workspace.rs | 13 +++-- 6 files changed, 53 insertions(+), 20 deletions(-) diff --git a/komorebi-for-kde/komorebi/src/process_command.rs b/komorebi-for-kde/komorebi/src/process_command.rs index 54028784..a0923372 100644 --- a/komorebi-for-kde/komorebi/src/process_command.rs +++ b/komorebi-for-kde/komorebi/src/process_command.rs @@ -557,7 +557,7 @@ impl WindowManager { for window in container.windows() { match identifier { ApplicationIdentifier::Path => { - if window.path().unwrap_or_default().to_string_lossy() == *id { + if window.path().unwrap_or_default() == *id { window_ids_to_purge.push((i, window.id)); } } diff --git a/komorebi-for-kde/komorebi/src/process_event.rs b/komorebi-for-kde/komorebi/src/process_event.rs index 7ef82de1..8c784afe 100644 --- a/komorebi-for-kde/komorebi/src/process_event.rs +++ b/komorebi-for-kde/komorebi/src/process_event.rs @@ -394,7 +394,7 @@ impl WindowManager { &title, &exe_name, &[&class], - &path.to_string_lossy(), + &path, &floating_applications, ®ex_identifiers, ) diff --git a/komorebi-for-kde/komorebi/src/transparency_manager.rs b/komorebi-for-kde/komorebi/src/transparency_manager.rs index 40a20898..00d26d02 100644 --- a/komorebi-for-kde/komorebi/src/transparency_manager.rs +++ b/komorebi-for-kde/komorebi/src/transparency_manager.rs @@ -48,7 +48,7 @@ fn ignored(window: Window) -> bool { &title, &exe, &[class.as_str()], - &path.to_string_lossy(), + &path, &blacklist, ®ex_identifiers, ) diff --git a/komorebi-for-kde/komorebi/src/window.rs b/komorebi-for-kde/komorebi/src/window.rs index edf71ae0..c38aa2d8 100644 --- a/komorebi-for-kde/komorebi/src/window.rs +++ b/komorebi-for-kde/komorebi/src/window.rs @@ -45,7 +45,6 @@ use std::collections::HashMap; use std::fmt::Display; use std::fmt::Formatter; use std::fmt::Write; -use std::path::PathBuf; /// The windows the user is resizing by dragging an edge of: komorebi does not move them while they /// are (the other tiles follow the drag, and the window is put in its tile when they let go) @@ -136,10 +135,7 @@ impl From for WindowDetails { title: value.title().unwrap_or_default(), exe: value.exe().unwrap_or_default(), class: value.class().unwrap_or_default(), - path: value - .path() - .map(|p| p.to_string_lossy().to_string()) - .unwrap_or_default(), + path: value.path().map(|p| p.to_string()).unwrap_or_default(), } } } @@ -234,8 +230,8 @@ impl Window { self.info().map(|i| i.class) } - pub fn path(self) -> Option { - self.info().map(|i| PathBuf::from(i.path)) + pub fn path(self) -> Option { + self.info().map(|i| i.path) } pub fn process_id(self) -> i32 { @@ -572,6 +568,44 @@ fn window_is_eligible( /// and path, if one does: a simple rule matches when its one condition does /// ([`should_act_individual`]), and a composite rule when all of its conditions do #[allow(clippy::cognitive_complexity, clippy::too_many_lines)] +/// [`should_act`] for a window that has one class +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 that has one class +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, @@ -921,7 +955,7 @@ mod tests { assert_eq!(window.title().as_deref(), Some("a terminal")); assert_eq!(window.exe().as_deref(), Some("foot")); assert_eq!(window.class().as_deref(), Some("foot")); - assert_eq!(window.path(), Some(PathBuf::from("/usr/bin/foot"))); + assert_eq!(window.path(), Some("/usr/bin/foot".to_string())); assert_eq!(window.process_id(), 1201); assert_eq!( window.rect()?, diff --git a/komorebi-for-kde/komorebi/src/window_manager.rs b/komorebi-for-kde/komorebi/src/window_manager.rs index 1b6fd86c..90b865de 100644 --- a/komorebi-for-kde/komorebi/src/window_manager.rs +++ b/komorebi-for-kde/komorebi/src/window_manager.rs @@ -3030,7 +3030,7 @@ impl WindowManager { &title, &exe_name, &[&class], - &path.to_string_lossy(), + &path, r, ®ex_identifiers, ), @@ -3041,7 +3041,7 @@ impl WindowManager { &title, &exe_name, &[&class], - &path.to_string_lossy(), + &path, identifier, ®ex_identifiers, )); diff --git a/komorebi-for-kde/komorebi/src/workspace.rs b/komorebi-for-kde/komorebi/src/workspace.rs index 043d8c85..bd6bc8b7 100644 --- a/komorebi-for-kde/komorebi/src/workspace.rs +++ b/komorebi-for-kde/komorebi/src/workspace.rs @@ -39,8 +39,8 @@ use crate::window::Window; use crate::window::WindowDetails; use crate::window::cursor_position; use crate::window::foreground_window_id; -use crate::window::should_act; -use crate::window::should_act_individual; +use crate::window::should_act_window; +use crate::window::should_act_window_individual; use color_eyre::eyre; use color_eyre::eyre::OptionExt; use komorebi_backend::MonitorId; @@ -589,17 +589,16 @@ impl Workspace { else { return fallback_idx; }; - let path = path.to_string_lossy(); let regex_identifiers = REGEX_IDENTIFIERS.lock().clone(); // 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.as_str()], + &class, &path, id, ®ex_identifiers, @@ -608,10 +607,10 @@ 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( + should_act_window( &title, &exe_name, - &[class.as_str()], + &class, &path, rules, ®ex_identifiers,