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:
LGUG2Z
2024-07-09 15:06:14 -07:00
parent 5b997b6ea6
commit 6eb6129618
3 changed files with 70 additions and 0 deletions

View File

@@ -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()?)?;
}