From 7d8e2ad814f0cf407267e574c403a39daaf5ce38 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sun, 29 Sep 2024 11:33:04 -0700 Subject: [PATCH] refactor(wm): float_rules > ignore_rules w/ compat WIP --- komorebi/src/core/config_generation.rs | 23 ++++++++++++----------- komorebi/src/core/mod.rs | 3 ++- komorebi/src/lib.rs | 2 +- komorebi/src/process_command.rs | 14 +++++++------- komorebi/src/static_config.rs | 10 +++++----- komorebi/src/window.rs | 6 +++--- komorebi/src/window_manager.rs | 7 ++++--- komorebic/src/main.rs | 11 ++++++----- 8 files changed, 40 insertions(+), 36 deletions(-) diff --git a/komorebi/src/core/config_generation.rs b/komorebi/src/core/config_generation.rs index fe67134f..932a5f8a 100644 --- a/komorebi/src/core/config_generation.rs +++ b/komorebi/src/core/config_generation.rs @@ -116,7 +116,8 @@ pub struct ApplicationConfiguration { #[serde(skip_serializing_if = "Option::is_none")] pub options: Option>, #[serde(skip_serializing_if = "Option::is_none")] - pub float_identifiers: Option>, + #[serde(alias = "float_identifiers")] + pub ignore_identifiers: Option>, } impl ApplicationConfiguration { @@ -187,7 +188,7 @@ impl ApplicationConfigurationGenerator { let mut lines = vec![String::from("# Generated by komorebic.exe"), String::new()]; - let mut float_rules = vec![]; + let mut ignore_rules = vec![]; for app in cfgen { lines.push(format!("# {}", app.name)); @@ -201,15 +202,15 @@ impl ApplicationConfigurationGenerator { } } - if let Some(float_identifiers) = app.float_identifiers { - for matching_rule in float_identifiers { + if let Some(ignore_identifiers) = app.ignore_identifiers { + for matching_rule in ignore_identifiers { if let MatchingRule::Simple(float) = matching_rule { let float_rule = format!("komorebic.exe float-rule {} \"{}\"", float.kind, float.id); // Don't want to send duped signals especially as configs get larger - if !float_rules.contains(&float_rule) { - float_rules.push(float_rule.clone()); + if !ignore_rules.contains(&float_rule) { + ignore_rules.push(float_rule.clone()); // if let Some(comment) = float.comment { // lines.push(format!("# {comment}")); @@ -238,7 +239,7 @@ impl ApplicationConfigurationGenerator { let mut lines = vec![String::from("; Generated by komorebic.exe"), String::new()]; - let mut float_rules = vec![]; + let mut ignore_rules = vec![]; for app in cfgen { lines.push(format!("; {}", app.name)); @@ -252,8 +253,8 @@ impl ApplicationConfigurationGenerator { } } - if let Some(float_identifiers) = app.float_identifiers { - for matching_rule in float_identifiers { + if let Some(ignore_identifiers) = app.ignore_identifiers { + for matching_rule in ignore_identifiers { if let MatchingRule::Simple(float) = matching_rule { let float_rule = format!( "RunWait('komorebic.exe float-rule {} \"{}\"', , \"Hide\")", @@ -261,8 +262,8 @@ impl ApplicationConfigurationGenerator { ); // Don't want to send duped signals especially as configs get larger - if !float_rules.contains(&float_rule) { - float_rules.push(float_rule.clone()); + if !ignore_rules.contains(&float_rule) { + ignore_rules.push(float_rule.clone()); // if let Some(comment) = float.comment { // lines.push(format!("; {comment}")); diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 4c59012d..c08cb4b7 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -174,7 +174,8 @@ pub enum SocketMessage { ClearWorkspaceRules(usize, usize), ClearNamedWorkspaceRules(String), ClearAllWorkspaceRules, - FloatRule(ApplicationIdentifier, String), + #[serde(alias = "FloatRule")] + IgnoreRule(ApplicationIdentifier, String), ManageRule(ApplicationIdentifier, String), IdentifyObjectNameChangeApplication(ApplicationIdentifier, String), IdentifyTrayApplication(ApplicationIdentifier, String), diff --git a/komorebi/src/lib.rs b/komorebi/src/lib.rs index 9a3a3e8e..b001e577 100644 --- a/komorebi/src/lib.rs +++ b/komorebi/src/lib.rs @@ -139,7 +139,7 @@ lazy_static! { static ref REGEX_IDENTIFIERS: Arc>> = Arc::new(Mutex::new(HashMap::new())); static ref MANAGE_IDENTIFIERS: Arc>> = Arc::new(Mutex::new(vec![])); - static ref FLOAT_IDENTIFIERS: Arc>> = Arc::new(Mutex::new(vec![ + static ref IGNORE_IDENTIFIERS: Arc>> = Arc::new(Mutex::new(vec![ // mstsc.exe creates these on Windows 11 when a WSL process is launched // https://github.com/LGUG2Z/komorebi/issues/74 MatchingRule::Simple(IdWithIdentifier { diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 6d766e40..09fa303a 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -68,8 +68,8 @@ use crate::ANIMATION_STYLE; use crate::CUSTOM_FFM; use crate::DATA_DIR; use crate::DISPLAY_INDEX_PREFERENCES; -use crate::FLOAT_IDENTIFIERS; use crate::HIDING_BEHAVIOUR; +use crate::IGNORE_IDENTIFIERS; use crate::INITIAL_CONFIGURATION_LOADED; use crate::LAYERED_WHITELIST; use crate::MANAGE_IDENTIFIERS; @@ -394,20 +394,20 @@ impl WindowManager { })); } } - SocketMessage::FloatRule(identifier, ref id) => { - let mut float_identifiers = FLOAT_IDENTIFIERS.lock(); + SocketMessage::IgnoreRule(identifier, ref id) => { + let mut ignore_identifiers = IGNORE_IDENTIFIERS.lock(); let mut should_push = true; - for f in &*float_identifiers { - if let MatchingRule::Simple(f) = f { - if f.id.eq(id) { + for i in &*ignore_identifiers { + if let MatchingRule::Simple(i) = i { + if i.id.eq(id) { should_push = false; } } } if should_push { - float_identifiers.push(MatchingRule::Simple(IdWithIdentifier { + ignore_identifiers.push(MatchingRule::Simple(IdWithIdentifier { kind: identifier, id: id.clone(), matching_strategy: Option::from(MatchingStrategy::Legacy), diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 32022785..2114bc6c 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -36,8 +36,8 @@ use crate::DEFAULT_CONTAINER_PADDING; use crate::DEFAULT_WORKSPACE_PADDING; use crate::DISPLAY_INDEX_PREFERENCES; use crate::FLOATING_APPLICATIONS; -use crate::FLOAT_IDENTIFIERS; use crate::HIDING_BEHAVIOUR; +use crate::IGNORE_IDENTIFIERS; use crate::LAYERED_WHITELIST; use crate::MANAGE_IDENTIFIERS; use crate::MONITOR_INDEX_PREFERENCES; @@ -672,7 +672,7 @@ impl StaticConfig { transparency_manager::TRANSPARENCY_ALPHA .store(self.transparency_alpha.unwrap_or(200), Ordering::SeqCst); - let mut float_identifiers = FLOAT_IDENTIFIERS.lock(); + let mut ignore_identifiers = IGNORE_IDENTIFIERS.lock(); let mut regex_identifiers = REGEX_IDENTIFIERS.lock(); let mut manage_identifiers = MANAGE_IDENTIFIERS.lock(); let mut tray_and_multi_window_identifiers = TRAY_AND_MULTI_WINDOW_IDENTIFIERS.lock(); @@ -683,7 +683,7 @@ impl StaticConfig { let mut floating_applications = FLOATING_APPLICATIONS.lock(); if let Some(rules) = &mut self.ignore_rules { - populate_rules(rules, &mut float_identifiers, &mut regex_identifiers)?; + populate_rules(rules, &mut ignore_identifiers, &mut regex_identifiers)?; } if let Some(rules) = &mut self.floating_applications { @@ -916,8 +916,8 @@ impl StaticConfig { let asc = ApplicationConfigurationGenerator::load(&content)?; for mut entry in asc { - if let Some(rules) = &mut entry.float_identifiers { - populate_rules(rules, &mut float_identifiers, &mut regex_identifiers)?; + if let Some(rules) = &mut entry.ignore_identifiers { + populate_rules(rules, &mut ignore_identifiers, &mut regex_identifiers)?; } if let Some(ref options) = entry.options { diff --git a/komorebi/src/window.rs b/komorebi/src/window.rs index 8b16ad3f..1b9b56a1 100644 --- a/komorebi/src/window.rs +++ b/komorebi/src/window.rs @@ -41,9 +41,9 @@ use crate::styles::WindowStyle; use crate::transparency_manager; use crate::window_manager_event::WindowManagerEvent; use crate::windows_api::WindowsApi; -use crate::FLOAT_IDENTIFIERS; use crate::HIDDEN_HWNDS; use crate::HIDING_BEHAVIOUR; +use crate::IGNORE_IDENTIFIERS; use crate::LAYERED_WHITELIST; use crate::MANAGE_IDENTIFIERS; use crate::NO_TITLEBAR; @@ -566,13 +566,13 @@ fn window_is_eligible( let regex_identifiers = REGEX_IDENTIFIERS.lock(); - let float_identifiers = FLOAT_IDENTIFIERS.lock(); + let ignore_identifiers = IGNORE_IDENTIFIERS.lock(); let should_float = if let Some(rule) = should_act( title, exe_name, class, path, - &float_identifiers, + &ignore_identifiers, ®ex_identifiers, ) { debug.matches_float_identifier = Some(rule); diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 4fefb4a5..92f222a6 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -71,9 +71,9 @@ use crate::Rgb; use crate::CUSTOM_FFM; use crate::DATA_DIR; use crate::DISPLAY_INDEX_PREFERENCES; -use crate::FLOAT_IDENTIFIERS; use crate::HIDING_BEHAVIOUR; use crate::HOME_DIR; +use crate::IGNORE_IDENTIFIERS; use crate::LAYERED_WHITELIST; use crate::MANAGE_IDENTIFIERS; use crate::MONITOR_INDEX_PREFERENCES; @@ -136,7 +136,8 @@ pub struct GlobalState { pub stackbar_tab_width: i32, pub stackbar_height: i32, pub remove_titlebars: bool, - pub float_identifiers: Vec, + #[serde(alias = "float_identifiers")] + pub ignore_identifiers: Vec, pub manage_identifiers: Vec, pub layered_whitelist: Vec, pub tray_and_multi_window_identifiers: Vec, @@ -185,7 +186,7 @@ impl Default for GlobalState { stackbar_tab_width: STACKBAR_TAB_WIDTH.load(Ordering::SeqCst), stackbar_height: STACKBAR_TAB_HEIGHT.load(Ordering::SeqCst), remove_titlebars: REMOVE_TITLEBARS.load(Ordering::SeqCst), - float_identifiers: FLOAT_IDENTIFIERS.lock().clone(), + ignore_identifiers: IGNORE_IDENTIFIERS.lock().clone(), manage_identifiers: MANAGE_IDENTIFIERS.lock().clone(), layered_whitelist: LAYERED_WHITELIST.lock().clone(), tray_and_multi_window_identifiers: TRAY_AND_MULTI_WINDOW_IDENTIFIERS.lock().clone(), diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 248cf6b8..0079f43f 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -583,7 +583,7 @@ macro_rules! gen_application_target_subcommand_args { } gen_application_target_subcommand_args! { - FloatRule, + IgnoreRule, ManageRule, IdentifyTrayApplication, IdentifyLayeredApplication, @@ -1208,9 +1208,10 @@ enum SubCommand { /// Set the operation behaviour when the focused window is not managed #[clap(arg_required_else_help = true)] UnmanagedWindowOperationBehaviour(UnmanagedWindowOperationBehaviour), - /// Add a rule to always float the specified application + /// Add a rule to ignore the specified application #[clap(arg_required_else_help = true)] - FloatRule(FloatRule), + #[clap(alias = "float-rule")] + IgnoreRule(IgnoreRule), /// Add a rule to always manage the specified application #[clap(arg_required_else_help = true)] ManageRule(ManageRule), @@ -2154,8 +2155,8 @@ Stop-Process -Name:komorebi -ErrorAction SilentlyContinue } } } - SubCommand::FloatRule(arg) => { - send_message(&SocketMessage::FloatRule(arg.identifier, arg.id))?; + SubCommand::IgnoreRule(arg) => { + send_message(&SocketMessage::IgnoreRule(arg.identifier, arg.id))?; } SubCommand::ManageRule(arg) => { send_message(&SocketMessage::ManageRule(arg.identifier, arg.id))?;