mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-18 14:59:46 +02:00
feat(cli): add cmds to clear workspace rules
This commit adds three new commands, clear-workspace-rules, clear-named-workspace-rules and clear-all-workspace-rules, to allow users to remove workspace rules at runtime. These commands do not distinguish between initial or persistent workspace rules. If there is a clear use case for this distinction, this decision can be revisited at a later date. resolve #908
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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()?)?;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user