diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index 407ac94e..2384851d 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -160,6 +160,9 @@ pub enum SocketMessage { InitialNamedWorkspaceRule(ApplicationIdentifier, String, String), WorkspaceRule(ApplicationIdentifier, String, usize, usize), NamedWorkspaceRule(ApplicationIdentifier, String, String), + ClearWorkspaceRules(usize, usize), + ClearNamedWorkspaceRules(String), + ClearAllWorkspaceRules, FloatRule(ApplicationIdentifier, String), ManageRule(ApplicationIdentifier, String), IdentifyObjectNameChangeApplication(ApplicationIdentifier, String), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 4b72bb4f..f18012fc 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -277,6 +277,40 @@ impl WindowManager { self.handle_definitive_workspace_rules(id, monitor_idx, workspace_idx)?; } } + SocketMessage::ClearWorkspaceRules(monitor_idx, workspace_idx) => { + let mut workspace_rules = WORKSPACE_RULES.lock(); + let mut to_remove = vec![]; + for (id, (m_idx, w_idx, _)) in workspace_rules.iter() { + if monitor_idx == *m_idx && workspace_idx == *w_idx { + to_remove.push(id.clone()); + } + } + + for rule in to_remove { + workspace_rules.remove(&rule); + } + } + SocketMessage::ClearNamedWorkspaceRules(ref workspace) => { + if let Some((monitor_idx, workspace_idx)) = + self.monitor_workspace_index_by_name(workspace) + { + let mut workspace_rules = WORKSPACE_RULES.lock(); + let mut to_remove = vec![]; + for (id, (m_idx, w_idx, _)) in workspace_rules.iter() { + if monitor_idx == *m_idx && workspace_idx == *w_idx { + to_remove.push(id.clone()); + } + } + + for rule in to_remove { + workspace_rules.remove(&rule); + } + } + } + SocketMessage::ClearAllWorkspaceRules => { + let mut workspace_rules = WORKSPACE_RULES.lock(); + workspace_rules.clear(); + } SocketMessage::ManageRule(identifier, ref id) => { let mut manage_identifiers = MANAGE_IDENTIFIERS.lock(); diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index e163f586..b2623c45 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -631,6 +631,20 @@ struct NamedWorkspaceRule { workspace: String, } +#[derive(Parser)] +struct ClearWorkspaceRules { + /// Monitor index (zero-indexed) + monitor: usize, + /// Workspace index on the specified monitor (zero-indexed) + workspace: usize, +} + +#[derive(Parser)] +struct ClearNamedWorkspaceRules { + /// Name of a workspace + workspace: String, +} + #[derive(Parser)] struct ToggleFocusFollowsMouse { #[clap(value_enum, short, long, default_value = "windows")] @@ -1157,6 +1171,14 @@ enum SubCommand { /// Add a rule to associate an application with a named workspace #[clap(arg_required_else_help = true)] NamedWorkspaceRule(NamedWorkspaceRule), + /// Remove all application association rules for a workspace by monitor and workspace index + #[clap(arg_required_else_help = true)] + ClearWorkspaceRules(ClearWorkspaceRules), + /// Remove all application association rules for a named workspace + #[clap(arg_required_else_help = true)] + ClearNamedWorkspaceRules(ClearNamedWorkspaceRules), + /// Remove all application association rules for all workspaces + ClearAllWorkspaceRules, /// Identify an application that sends EVENT_OBJECT_NAMECHANGE on launch #[clap(arg_required_else_help = true)] IdentifyObjectNameChangeApplication(IdentifyObjectNameChangeApplication), @@ -2063,6 +2085,17 @@ Stop-Process -Name:komorebi -ErrorAction SilentlyContinue .as_bytes()?, )?; } + SubCommand::ClearWorkspaceRules(arg) => { + send_message( + &SocketMessage::ClearWorkspaceRules(arg.monitor, arg.workspace).as_bytes()?, + )?; + } + SubCommand::ClearNamedWorkspaceRules(arg) => { + send_message(&SocketMessage::ClearNamedWorkspaceRules(arg.workspace).as_bytes()?)?; + } + SubCommand::ClearAllWorkspaceRules => { + send_message(&SocketMessage::ClearAllWorkspaceRules.as_bytes()?)?; + } SubCommand::Stack(arg) => { send_message(&SocketMessage::StackWindow(arg.operation_direction).as_bytes()?)?; }