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<String>, 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.
This commit is contained in:
LGUG2Z committed 2026-10-31 12:31:36 -07:00
1 parent 2b7deddca7
commit 259dbb6646
6 files changed
+53 -20

No files matched your search

@@ -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));
}
}
@@ -394,7 +394,7 @@ impl WindowManager {
&title,
&exe_name,
&[&class],
&path.to_string_lossy(),
&path,
&floating_applications,
&regex_identifiers,
)
@@ -48,7 +48,7 @@ fn ignored(window: Window) -> bool {
&title,
&exe,
&[class.as_str()],
&path.to_string_lossy(),
&path,
&blacklist,
&regex_identifiers,
)
+42 -8
View File
@@ -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<Window> 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<PathBuf> {
self.info().map(|i| PathBuf::from(i.path))
pub fn path(self) -> Option<String> {
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<String, Regex>,
) -> Option<MatchingRule> {
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<String, Regex>,
) -> 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()?,
@@ -3030,7 +3030,7 @@ impl WindowManager {
&title,
&exe_name,
&[&class],
&path.to_string_lossy(),
&path,
r,
&regex_identifiers,
),
@@ -3041,7 +3041,7 @@ impl WindowManager {
&title,
&exe_name,
&[&class],
&path.to_string_lossy(),
&path,
identifier,
&regex_identifiers,
));
+6 -7
View File
@@ -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,
&regex_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,
&regex_identifiers,