Skip to content

Commit 28cd4a8

Browse files
committed
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.
1 parent 3aa92a1 commit 28cd4a8

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

komorebi/src/window_manager.rs

+49-49
Original file line numberDiff line numberDiff line change
@@ -732,45 +732,56 @@ impl WindowManager {
732732
for window in workspace.visible_windows().into_iter().flatten() {
733733
let mut already_moved_window_handles =
734734
self.already_moved_window_handles.lock();
735-
let exe_name = window.exe()?;
736-
let title = window.title()?;
737-
let class = window.class()?;
738-
let path = window.path()?;
739-
740-
for rule in &*workspace_matching_rules {
741-
let matched = match &rule.matching_rule {
742-
MatchingRule::Simple(r) => should_act_individual(
743-
&title,
744-
&exe_name,
745-
&class,
746-
&path,
747-
r,
748-
&regex_identifiers,
749-
),
750-
MatchingRule::Composite(r) => {
751-
let mut composite_results = vec![];
752-
for identifier in r {
753-
composite_results.push(should_act_individual(
754-
&title,
755-
&exe_name,
756-
&class,
757-
&path,
758-
identifier,
759-
&regex_identifiers,
760-
));
761-
}
762-
763-
composite_results.iter().all(|&x| x)
764-
}
765-
};
766-
767-
if matched {
768-
let floating = workspace.floating_windows().contains(window);
769-
770-
if rule.initial_only {
771-
if !already_moved_window_handles.contains(&window.hwnd) {
772-
already_moved_window_handles.insert(window.hwnd);
773735

736+
if let (Ok(exe_name), Ok(title), Ok(class), Ok(path)) =
737+
(window.exe(), window.title(), window.class(), window.path())
738+
{
739+
for rule in &*workspace_matching_rules {
740+
let matched = match &rule.matching_rule {
741+
MatchingRule::Simple(r) => should_act_individual(
742+
&title,
743+
&exe_name,
744+
&class,
745+
&path,
746+
r,
747+
&regex_identifiers,
748+
),
749+
MatchingRule::Composite(r) => {
750+
let mut composite_results = vec![];
751+
for identifier in r {
752+
composite_results.push(should_act_individual(
753+
&title,
754+
&exe_name,
755+
&class,
756+
&path,
757+
identifier,
758+
&regex_identifiers,
759+
));
760+
}
761+
762+
composite_results.iter().all(|&x| x)
763+
}
764+
};
765+
766+
if matched {
767+
let floating = workspace.floating_windows().contains(window);
768+
769+
if rule.initial_only {
770+
if !already_moved_window_handles.contains(&window.hwnd) {
771+
already_moved_window_handles.insert(window.hwnd);
772+
773+
self.add_window_handle_to_move_based_on_workspace_rule(
774+
&window.title()?,
775+
window.hwnd,
776+
i,
777+
j,
778+
rule.monitor_index,
779+
rule.workspace_index,
780+
floating,
781+
&mut to_move,
782+
);
783+
}
784+
} else {
774785
self.add_window_handle_to_move_based_on_workspace_rule(
775786
&window.title()?,
776787
window.hwnd,
@@ -782,17 +793,6 @@ impl WindowManager {
782793
&mut to_move,
783794
);
784795
}
785-
} else {
786-
self.add_window_handle_to_move_based_on_workspace_rule(
787-
&window.title()?,
788-
window.hwnd,
789-
i,
790-
j,
791-
rule.monitor_index,
792-
rule.workspace_index,
793-
floating,
794-
&mut to_move,
795-
);
796796
}
797797
}
798798
}

0 commit comments

Comments
 (0)