feat(workspace-rules): add InitialWorkspaceRule and InitialNamedWorkspaceRule command

- Added the two new commands to prevent breaking changes due to AHK
  users.
This commit is contained in:
Alvin Truong
2023-04-22 11:18:56 -07:00
committed by جاد
parent 7d1aef8203
commit 27e0758089
3 changed files with 107 additions and 49 deletions

View File

@@ -127,8 +127,10 @@ pub enum SocketMessage {
WorkAreaOffset(Rect),
MonitorWorkAreaOffset(usize, Rect),
ResizeDelta(i32),
WorkspaceRule(ApplicationIdentifier, String, usize, usize, bool),
NamedWorkspaceRule(ApplicationIdentifier, String, String, bool),
InitialWorkspaceRule(ApplicationIdentifier, String, usize, usize),
InitialNamedWorkspaceRule(ApplicationIdentifier, String, String),
WorkspaceRule(ApplicationIdentifier, String, usize, usize),
NamedWorkspaceRule(ApplicationIdentifier, String, String),
FloatRule(ApplicationIdentifier, String),
ManageRule(ApplicationIdentifier, String),
IdentifyObjectNameChangeApplication(ApplicationIdentifier, String),

View File

@@ -215,41 +215,24 @@ impl WindowManager {
self.set_workspace_padding(monitor_idx, workspace_idx, size)?;
}
}
SocketMessage::WorkspaceRule(
_,
ref id,
monitor_idx,
workspace_idx,
apply_on_first_show_only,
) => {
{
let mut workspace_rules = WORKSPACE_RULES.lock();
workspace_rules.insert(
id.to_string(),
(monitor_idx, workspace_idx, apply_on_first_show_only),
);
}
self.enforce_workspace_rules()?;
SocketMessage::InitialWorkspaceRule(_, ref id, monitor_idx, workspace_idx) => {
self.handle_initial_workspace_rules(id, monitor_idx, workspace_idx)?;
}
SocketMessage::NamedWorkspaceRule(
_,
ref id,
ref workspace,
apply_on_first_show_only,
) => {
SocketMessage::InitialNamedWorkspaceRule(_, ref id, ref workspace) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
{
let mut workspace_rules = WORKSPACE_RULES.lock();
workspace_rules.insert(
id.to_string(),
(monitor_idx, workspace_idx, apply_on_first_show_only),
);
}
self.enforce_workspace_rules()?;
self.handle_initial_workspace_rules(id, monitor_idx, workspace_idx)?;
}
}
SocketMessage::WorkspaceRule(_, ref id, monitor_idx, workspace_idx) => {
self.handle_definitive_workspace_rules(id, monitor_idx, workspace_idx)?;
}
SocketMessage::NamedWorkspaceRule(_, ref id, ref workspace) => {
if let Some((monitor_idx, workspace_idx)) =
self.monitor_workspace_index_by_name(workspace)
{
self.handle_definitive_workspace_rules(id, monitor_idx, workspace_idx)?;
}
}
SocketMessage::ManageRule(_, ref id) => {
@@ -1197,6 +1180,51 @@ impl WindowManager {
tracing::info!("processed");
Ok(())
}
#[tracing::instrument(skip(self))]
fn handle_initial_workspace_rules(
&mut self,
id: &String,
monitor_idx: usize,
workspace_idx: usize,
) -> Result<()> {
self.handle_workspace_rules(id, monitor_idx, workspace_idx, true)?;
Ok(())
}
#[tracing::instrument(skip(self))]
fn handle_definitive_workspace_rules(
&mut self,
id: &String,
monitor_idx: usize,
workspace_idx: usize,
) -> Result<()> {
self.handle_workspace_rules(id, monitor_idx, workspace_idx, false)?;
Ok(())
}
#[tracing::instrument(skip(self))]
fn handle_workspace_rules(
&mut self,
id: &String,
monitor_idx: usize,
workspace_idx: usize,
initial_workspace_rule: bool,
) -> Result<()> {
{
let mut workspace_rules = WORKSPACE_RULES.lock();
workspace_rules.insert(
id.to_string(),
(monitor_idx, workspace_idx, initial_workspace_rule),
);
}
self.enforce_workspace_rules()?;
Ok(())
}
}
pub fn read_commands_uds(wm: &Arc<Mutex<WindowManager>>, stream: UnixStream) -> Result<()> {

View File

@@ -515,6 +515,28 @@ gen_application_target_subcommand_args! {
IdentifyBorderOverflowApplication,
}
#[derive(Parser, AhkFunction)]
struct InitialWorkspaceRule {
#[clap(value_enum)]
identifier: ApplicationIdentifier,
/// Identifier as a string
id: String,
/// Monitor index (zero-indexed)
monitor: usize,
/// Workspace index on the specified monitor (zero-indexed)
workspace: usize,
}
#[derive(Parser, AhkFunction)]
struct InitialNamedWorkspaceRule {
#[clap(value_enum)]
identifier: ApplicationIdentifier,
/// Identifier as a string
id: String,
/// Name of a workspace
workspace: String,
}
#[derive(Parser, AhkFunction)]
struct WorkspaceRule {
#[clap(value_enum)]
@@ -525,9 +547,6 @@ struct WorkspaceRule {
monitor: usize,
/// Workspace index on the specified monitor (zero-indexed)
workspace: usize,
#[clap(short, long)]
/// Only apply once on first app load
apply_on_first_show_only: bool,
}
#[derive(Parser, AhkFunction)]
@@ -538,9 +557,6 @@ struct NamedWorkspaceRule {
id: String,
/// Name of a workspace
workspace: String,
#[clap(short, long)]
/// Only apply once on first app load
apply_on_first_show_only: bool,
}
#[derive(Parser, AhkFunction)]
@@ -927,6 +943,12 @@ enum SubCommand {
/// Add a rule to always manage the specified application
#[clap(arg_required_else_help = true)]
ManageRule(ManageRule),
/// Add a rule to associate an application with a workspace on first show
#[clap(arg_required_else_help = true)]
InitialWorkspaceRule(InitialWorkspaceRule),
/// Add a rule to associate an application with a named workspace on first show
#[clap(arg_required_else_help = true)]
InitialNamedWorkspaceRule(InitialNamedWorkspaceRule),
/// Add a rule to associate an application with a workspace
#[clap(arg_required_else_help = true)]
WorkspaceRule(WorkspaceRule),
@@ -1453,27 +1475,33 @@ fn main() -> Result<()> {
SubCommand::ManageRule(arg) => {
send_message(&SocketMessage::ManageRule(arg.identifier, arg.id).as_bytes()?)?;
}
SubCommand::WorkspaceRule(arg) => {
SubCommand::InitialWorkspaceRule(arg) => {
send_message(
&SocketMessage::WorkspaceRule(
&SocketMessage::InitialWorkspaceRule(
arg.identifier,
arg.id,
arg.monitor,
arg.workspace,
arg.apply_on_first_show_only,
)
.as_bytes()?,
)?;
}
SubCommand::InitialNamedWorkspaceRule(arg) => {
send_message(
&SocketMessage::InitialNamedWorkspaceRule(arg.identifier, arg.id, arg.workspace)
.as_bytes()?,
)?;
}
SubCommand::WorkspaceRule(arg) => {
send_message(
&SocketMessage::WorkspaceRule(arg.identifier, arg.id, arg.monitor, arg.workspace)
.as_bytes()?,
)?;
}
SubCommand::NamedWorkspaceRule(arg) => {
send_message(
&SocketMessage::NamedWorkspaceRule(
arg.identifier,
arg.id,
arg.workspace,
arg.apply_on_first_show_only,
)
.as_bytes()?,
&SocketMessage::NamedWorkspaceRule(arg.identifier, arg.id, arg.workspace)
.as_bytes()?,
)?;
}
SubCommand::Stack(arg) => {