fix(windows): take the rule-list locks in one documented order

window_is_eligible (window.rs) took regex, ignore, manage, floating, then
layered, no-titlebar and slow; apply_globals (static_config.rs) took
ignore, regex, manage and the rest in yet another order: a rule check and
a config load could wait for each other for ever (the KDE tree hit this,
see ef1d3ef0 there).

One order is now documented at the statics in lib.rs: floating, session
floating, transparency, ignore, manage, layered, tray, object-name-change
(two), slow, no-titlebar, workspace rules, regex (a leaf: every rule check
takes its list and then the regexes). window_is_eligible takes the lists it
reads up front in that order and, once it has matched them all, drops every
guard BEFORE the slow-application sleep (before this, the sleep ran with
the regex, ignore, manage, floating, layered and no-titlebar guards held, so
a config load or rule command waited out the compensation time); apply_globals
is reordered. Every other site that nests two of these (state.rs,
process_command.rs session float rules, process_event.rs,
window_manager_event.rs, transparency_manager.rs, window_manager.rs,
workspace.rs) already followed the order.

BEHAVIOUR: lock acquisition order and hold time only; no rule semantics
change. Gate needed: Windows e2e commands and config_reload. Verified: not
yet re-run after the guard-drop change.
This commit is contained in:
LGUG2Z committed 2026-10-31 10:14:06 -07:00
1 parent 633e7453cd
commit 8f37b9aea6
3 files changed
+53 -25

No files matched your search

+17
View File
@@ -86,6 +86,23 @@ use which::which;
use winreg::RegKey;
use winreg::enums::HKEY_CURRENT_USER;
// LOCK ORDER of the rule lists. A thread that holds one of these and takes another must take them
// in this order (a thread that takes two in another order can wait for one that holds what it
// needs, and both wait for ever):
//
// FLOATING_APPLICATIONS, SESSION_FLOATING_APPLICATIONS, TRANSPARENCY_BLACKLIST,
// IGNORE_IDENTIFIERS, MANAGE_IDENTIFIERS, LAYERED_WHITELIST, TRAY_AND_MULTI_WINDOW_IDENTIFIERS,
// OBJECT_NAME_CHANGE_ON_LAUNCH, OBJECT_NAME_CHANGE_TITLE_IGNORE_LIST,
// SLOW_APPLICATION_IDENTIFIERS, NO_TITLEBAR, WORKSPACE_MATCHING_RULES, REGEX_IDENTIFIERS
//
// REGEX_IDENTIFIERS is last: every rule check holds the list it matches against and then the
// compiled regexes. PERMAIGNORE_CLASSES and WSL2_UI_PROCESSES are leaves (nothing is taken while
// they are held). Places that nest the others: window.rs (window_is_eligible), static_config.rs
// (apply_globals),
// state.rs (the State snapshot), process_command.rs (session float rules), process_event.rs,
// window_manager_event.rs, transparency_manager.rs, window_manager.rs. The same rule applies to
// any new place: lock in this order, or lock one at a time.
lazy_static! {
static ref HIDDEN_HWNDS: Arc<Mutex<Vec<isize>>> = Arc::new(Mutex::new(vec![]));
static ref LAYERED_WHITELIST: Arc<Mutex<Vec<MatchingRule>>> = Arc::new(Mutex::new(vec![
+5 -4
View File
@@ -559,17 +559,18 @@ impl ApplyGlobals for StaticConfig {
transparency_manager::TRANSPARENCY_ALPHA.store(transparency_alpha, Ordering::SeqCst);
}
// the order documented at the statics in lib.rs
let mut floating_applications = FLOATING_APPLICATIONS.lock();
let mut transparency_blacklist = TRANSPARENCY_BLACKLIST.lock();
let mut ignore_identifiers = IGNORE_IDENTIFIERS.lock();
let mut regex_identifiers = REGEX_IDENTIFIERS.lock();
let mut manage_identifiers = MANAGE_IDENTIFIERS.lock();
let mut layered_identifiers = LAYERED_WHITELIST.lock();
let mut tray_and_multi_window_identifiers = TRAY_AND_MULTI_WINDOW_IDENTIFIERS.lock();
let mut object_name_change_identifiers = OBJECT_NAME_CHANGE_ON_LAUNCH.lock();
let mut object_name_change_title_ignore_list = OBJECT_NAME_CHANGE_TITLE_IGNORE_LIST.lock();
let mut layered_identifiers = LAYERED_WHITELIST.lock();
let mut transparency_blacklist = TRANSPARENCY_BLACKLIST.lock();
let mut slow_application_identifiers = SLOW_APPLICATION_IDENTIFIERS.lock();
let mut floating_applications = FLOATING_APPLICATIONS.lock();
let mut no_titlebar_applications = NO_TITLEBAR.lock();
let mut regex_identifiers = REGEX_IDENTIFIERS.lock();
if let Some(rules) = &mut self.ignore_rules {
populate_rules(rules, &mut ignore_identifiers, &mut regex_identifiers)?;
+31 -21
View File
@@ -886,9 +886,16 @@ fn window_is_eligible(
}
}
// Every place that holds two of the rule lists takes them in the order documented at the
// statics in lib.rs, so all the lists this check reads are taken up front, in that order.
let floating_identifiers = FLOATING_APPLICATIONS.lock();
let ignore_identifiers = IGNORE_IDENTIFIERS.lock();
let manage_identifiers = MANAGE_IDENTIFIERS.lock();
let layered_whitelist = LAYERED_WHITELIST.lock();
let slow_application_identifiers = SLOW_APPLICATION_IDENTIFIERS.lock();
let titlebars_removed = NO_TITLEBAR.lock();
let regex_identifiers = REGEX_IDENTIFIERS.lock();
let ignore_identifiers = IGNORE_IDENTIFIERS.lock();
let should_ignore = if let Some(rule) = should_act(
title,
exe_name,
@@ -903,7 +910,6 @@ fn window_is_eligible(
false
};
let manage_identifiers = MANAGE_IDENTIFIERS.lock();
let managed_override = if let Some(rule) = should_act(
title,
exe_name,
@@ -918,7 +924,6 @@ fn window_is_eligible(
false
};
let floating_identifiers = FLOATING_APPLICATIONS.lock();
if let Some(rule) = should_act(
title,
exe_name,
@@ -934,7 +939,6 @@ fn window_is_eligible(
return false;
}
let layered_whitelist = LAYERED_WHITELIST.lock();
let mut allow_layered = if let Some(rule) = should_act(
title,
exe_name,
@@ -972,7 +976,6 @@ fn window_is_eligible(
allow
};
let titlebars_removed = NO_TITLEBAR.lock();
let allow_titlebar_removed = if let Some(rule) = should_act(
title,
exe_name,
@@ -987,23 +990,30 @@ fn window_is_eligible(
false
};
{
let slow_application_identifiers = SLOW_APPLICATION_IDENTIFIERS.lock();
let should_sleep = should_act(
title,
exe_name,
class,
path,
&slow_application_identifiers,
&regex_identifiers,
)
.is_some();
let should_sleep = should_act(
title,
exe_name,
class,
path,
&slow_application_identifiers,
&regex_identifiers,
)
.is_some();
if should_sleep {
std::thread::sleep(Duration::from_millis(
SLOW_APPLICATION_COMPENSATION_TIME.load(Ordering::SeqCst),
));
}
// Nothing below reads a rule list: release them all before sleeping, so a config load or a
// rule command is never kept waiting for the slow-application compensation time.
drop(floating_identifiers);
drop(ignore_identifiers);
drop(manage_identifiers);
drop(layered_whitelist);
drop(slow_application_identifiers);
drop(titlebars_removed);
drop(regex_identifiers);
if should_sleep {
std::thread::sleep(Duration::from_millis(
SLOW_APPLICATION_COMPENSATION_TIME.load(Ordering::SeqCst),
));
}
if (allow_wsl2_gui || allow_titlebar_removed || style.contains(WindowStyle::CAPTION) && ex_style.contains(ExtendedWindowStyle::WINDOWEDGE))