Skip to content

Commit

Permalink
refactor(wm): float_rules > ignore_rules w/ compat
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
LGUG2Z authored and alex-ds13 committed Oct 10, 2024
1 parent 8b34449 commit 7d8e2ad
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 36 deletions.
23 changes: 12 additions & 11 deletions komorebi/src/core/config_generation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ pub struct ApplicationConfiguration {
#[serde(skip_serializing_if = "Option::is_none")]
pub options: Option<Vec<ApplicationOptions>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub float_identifiers: Option<Vec<MatchingRule>>,
#[serde(alias = "float_identifiers")]
pub ignore_identifiers: Option<Vec<MatchingRule>>,
}

impl ApplicationConfiguration {
Expand Down Expand Up @@ -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));
Expand All @@ -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}"));
Expand Down Expand Up @@ -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));
Expand All @@ -252,17 +253,17 @@ 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\")",
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}"));
Expand Down
3 changes: 2 additions & 1 deletion komorebi/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ lazy_static! {
static ref REGEX_IDENTIFIERS: Arc<Mutex<HashMap<String, Regex>>> =
Arc::new(Mutex::new(HashMap::new()));
static ref MANAGE_IDENTIFIERS: Arc<Mutex<Vec<MatchingRule>>> = Arc::new(Mutex::new(vec![]));
static ref FLOAT_IDENTIFIERS: Arc<Mutex<Vec<MatchingRule>>> = Arc::new(Mutex::new(vec![
static ref IGNORE_IDENTIFIERS: Arc<Mutex<Vec<MatchingRule>>> = 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 {
Expand Down
14 changes: 7 additions & 7 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down
10 changes: 5 additions & 5 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions komorebi/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
&regex_identifiers,
) {
debug.matches_float_identifier = Some(rule);
Expand Down
7 changes: 4 additions & 3 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -136,7 +136,8 @@ pub struct GlobalState {
pub stackbar_tab_width: i32,
pub stackbar_height: i32,
pub remove_titlebars: bool,
pub float_identifiers: Vec<MatchingRule>,
#[serde(alias = "float_identifiers")]
pub ignore_identifiers: Vec<MatchingRule>,
pub manage_identifiers: Vec<MatchingRule>,
pub layered_whitelist: Vec<MatchingRule>,
pub tray_and_multi_window_identifiers: Vec<MatchingRule>,
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 6 additions & 5 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ macro_rules! gen_application_target_subcommand_args {
}

gen_application_target_subcommand_args! {
FloatRule,
IgnoreRule,
ManageRule,
IdentifyTrayApplication,
IdentifyLayeredApplication,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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))?;
Expand Down

0 comments on commit 7d8e2ad

Please sign in to comment.