feat(wm): add named workspace commands

This commit introduces three new commands, ensure-named-workspaces,
named-workspace-rule, and focus-named-workspace, which email to reduce
the configuration complexity by allowing users to refer to workspace
names instead of monitor and workspace indices.
This commit is contained in:
LGUG2Z
2023-02-12 15:18:14 -08:00
parent bda6054044
commit 6b918dae7f
5 changed files with 126 additions and 1 deletions
+47
View File
@@ -318,6 +318,14 @@ struct EnsureWorkspaces {
workspace_count: usize,
}
#[derive(Parser, AhkFunction)]
struct EnsureNamedWorkspaces {
/// Monitor index (zero-indexed)
monitor: usize,
/// Names of desired workspaces
names: Vec<String>,
}
#[derive(Parser, AhkFunction)]
struct FocusMonitorWorkspace {
/// Target monitor index (zero-indexed)
@@ -326,6 +334,12 @@ struct FocusMonitorWorkspace {
target_workspace: usize,
}
#[derive(Parser, AhkFunction)]
struct FocusNamedWorkspace {
/// Target workspace name
name: String,
}
#[derive(Parser, AhkFunction)]
pub struct SendToMonitorWorkspace {
/// Target monitor index (zero-indexed)
@@ -412,6 +426,16 @@ struct WorkspaceRule {
workspace: usize,
}
#[derive(Parser, AhkFunction)]
struct NamedWorkspaceRule {
#[clap(value_enum)]
identifier: ApplicationIdentifier,
/// Identifier as a string
id: String,
/// Name of a workspace
workspace: String,
}
#[derive(Parser, AhkFunction)]
struct ToggleFocusFollowsMouse {
#[clap(value_enum, short, long, default_value = "windows")]
@@ -622,6 +646,9 @@ enum SubCommand {
/// Focus the specified workspace on the target monitor
#[clap(arg_required_else_help = true)]
FocusMonitorWorkspace(FocusMonitorWorkspace),
/// Focus the specified workspace on the target monitor
#[clap(arg_required_else_help = true)]
FocusNamedWorkspace(FocusNamedWorkspace),
/// Focus the monitor in the given cycle direction
#[clap(arg_required_else_help = true)]
CycleMonitor(CycleMonitor),
@@ -673,6 +700,9 @@ enum SubCommand {
/// Create at least this many workspaces for the specified monitor
#[clap(arg_required_else_help = true)]
EnsureWorkspaces(EnsureWorkspaces),
/// Create at least this many workspaces for the specified monitor
#[clap(arg_required_else_help = true)]
EnsureNamedWorkspaces(EnsureNamedWorkspaces),
/// Set the container padding for the specified workspace
#[clap(arg_required_else_help = true)]
ContainerPadding(ContainerPadding),
@@ -748,6 +778,9 @@ enum SubCommand {
/// Add a rule to associate an application with a workspace
#[clap(arg_required_else_help = true)]
WorkspaceRule(WorkspaceRule),
/// Add a rule to associate an application with a named workspace
#[clap(arg_required_else_help = true)]
NamedWorkspaceRule(NamedWorkspaceRule),
/// Identify an application that sends EVENT_OBJECT_NAMECHANGE on launch
#[clap(arg_required_else_help = true)]
IdentifyObjectNameChangeApplication(IdentifyObjectNameChangeApplication),
@@ -1158,6 +1191,12 @@ fn main() -> Result<()> {
.as_bytes()?,
)?;
}
SubCommand::NamedWorkspaceRule(arg) => {
send_message(
&SocketMessage::NamedWorkspaceRule(arg.identifier, arg.id, arg.workspace)
.as_bytes()?,
)?;
}
SubCommand::Stack(arg) => {
send_message(&SocketMessage::StackWindow(arg.operation_direction).as_bytes()?)?;
}
@@ -1193,6 +1232,9 @@ fn main() -> Result<()> {
.as_bytes()?,
)?;
}
SubCommand::FocusNamedWorkspace(arg) => {
send_message(&SocketMessage::FocusNamedWorkspace(arg.name).as_bytes()?)?;
}
SubCommand::CycleMonitor(arg) => {
send_message(&SocketMessage::CycleFocusMonitor(arg.cycle_direction).as_bytes()?)?;
}
@@ -1226,6 +1268,11 @@ fn main() -> Result<()> {
.as_bytes()?,
)?;
}
SubCommand::EnsureNamedWorkspaces(arg) => {
send_message(
&SocketMessage::EnsureNamedWorkspaces(arg.monitor, arg.names).as_bytes()?,
)?;
}
SubCommand::State => {
let home = DATA_DIR.clone();
let mut socket = home;