mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-04-25 10:08:33 +02:00
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:
@@ -127,8 +127,10 @@ pub enum SocketMessage {
|
|||||||
WorkAreaOffset(Rect),
|
WorkAreaOffset(Rect),
|
||||||
MonitorWorkAreaOffset(usize, Rect),
|
MonitorWorkAreaOffset(usize, Rect),
|
||||||
ResizeDelta(i32),
|
ResizeDelta(i32),
|
||||||
WorkspaceRule(ApplicationIdentifier, String, usize, usize, bool),
|
InitialWorkspaceRule(ApplicationIdentifier, String, usize, usize),
|
||||||
NamedWorkspaceRule(ApplicationIdentifier, String, String, bool),
|
InitialNamedWorkspaceRule(ApplicationIdentifier, String, String),
|
||||||
|
WorkspaceRule(ApplicationIdentifier, String, usize, usize),
|
||||||
|
NamedWorkspaceRule(ApplicationIdentifier, String, String),
|
||||||
FloatRule(ApplicationIdentifier, String),
|
FloatRule(ApplicationIdentifier, String),
|
||||||
ManageRule(ApplicationIdentifier, String),
|
ManageRule(ApplicationIdentifier, String),
|
||||||
IdentifyObjectNameChangeApplication(ApplicationIdentifier, String),
|
IdentifyObjectNameChangeApplication(ApplicationIdentifier, String),
|
||||||
|
|||||||
@@ -215,41 +215,24 @@ impl WindowManager {
|
|||||||
self.set_workspace_padding(monitor_idx, workspace_idx, size)?;
|
self.set_workspace_padding(monitor_idx, workspace_idx, size)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SocketMessage::WorkspaceRule(
|
SocketMessage::InitialWorkspaceRule(_, ref id, monitor_idx, workspace_idx) => {
|
||||||
_,
|
self.handle_initial_workspace_rules(id, monitor_idx, workspace_idx)?;
|
||||||
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::NamedWorkspaceRule(
|
SocketMessage::InitialNamedWorkspaceRule(_, ref id, ref workspace) => {
|
||||||
_,
|
|
||||||
ref id,
|
|
||||||
ref workspace,
|
|
||||||
apply_on_first_show_only,
|
|
||||||
) => {
|
|
||||||
if let Some((monitor_idx, workspace_idx)) =
|
if let Some((monitor_idx, workspace_idx)) =
|
||||||
self.monitor_workspace_index_by_name(workspace)
|
self.monitor_workspace_index_by_name(workspace)
|
||||||
{
|
{
|
||||||
{
|
self.handle_initial_workspace_rules(id, monitor_idx, workspace_idx)?;
|
||||||
let mut workspace_rules = WORKSPACE_RULES.lock();
|
}
|
||||||
workspace_rules.insert(
|
}
|
||||||
id.to_string(),
|
SocketMessage::WorkspaceRule(_, ref id, monitor_idx, workspace_idx) => {
|
||||||
(monitor_idx, workspace_idx, apply_on_first_show_only),
|
self.handle_definitive_workspace_rules(id, monitor_idx, workspace_idx)?;
|
||||||
);
|
}
|
||||||
}
|
SocketMessage::NamedWorkspaceRule(_, ref id, ref workspace) => {
|
||||||
|
if let Some((monitor_idx, workspace_idx)) =
|
||||||
self.enforce_workspace_rules()?;
|
self.monitor_workspace_index_by_name(workspace)
|
||||||
|
{
|
||||||
|
self.handle_definitive_workspace_rules(id, monitor_idx, workspace_idx)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SocketMessage::ManageRule(_, ref id) => {
|
SocketMessage::ManageRule(_, ref id) => {
|
||||||
@@ -1197,6 +1180,51 @@ impl WindowManager {
|
|||||||
tracing::info!("processed");
|
tracing::info!("processed");
|
||||||
Ok(())
|
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<()> {
|
pub fn read_commands_uds(wm: &Arc<Mutex<WindowManager>>, stream: UnixStream) -> Result<()> {
|
||||||
|
|||||||
@@ -515,6 +515,28 @@ gen_application_target_subcommand_args! {
|
|||||||
IdentifyBorderOverflowApplication,
|
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)]
|
#[derive(Parser, AhkFunction)]
|
||||||
struct WorkspaceRule {
|
struct WorkspaceRule {
|
||||||
#[clap(value_enum)]
|
#[clap(value_enum)]
|
||||||
@@ -525,9 +547,6 @@ struct WorkspaceRule {
|
|||||||
monitor: usize,
|
monitor: usize,
|
||||||
/// Workspace index on the specified monitor (zero-indexed)
|
/// Workspace index on the specified monitor (zero-indexed)
|
||||||
workspace: usize,
|
workspace: usize,
|
||||||
#[clap(short, long)]
|
|
||||||
/// Only apply once on first app load
|
|
||||||
apply_on_first_show_only: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, AhkFunction)]
|
#[derive(Parser, AhkFunction)]
|
||||||
@@ -538,9 +557,6 @@ struct NamedWorkspaceRule {
|
|||||||
id: String,
|
id: String,
|
||||||
/// Name of a workspace
|
/// Name of a workspace
|
||||||
workspace: String,
|
workspace: String,
|
||||||
#[clap(short, long)]
|
|
||||||
/// Only apply once on first app load
|
|
||||||
apply_on_first_show_only: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser, AhkFunction)]
|
#[derive(Parser, AhkFunction)]
|
||||||
@@ -927,6 +943,12 @@ enum SubCommand {
|
|||||||
/// Add a rule to always manage the specified application
|
/// Add a rule to always manage the specified application
|
||||||
#[clap(arg_required_else_help = true)]
|
#[clap(arg_required_else_help = true)]
|
||||||
ManageRule(ManageRule),
|
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
|
/// Add a rule to associate an application with a workspace
|
||||||
#[clap(arg_required_else_help = true)]
|
#[clap(arg_required_else_help = true)]
|
||||||
WorkspaceRule(WorkspaceRule),
|
WorkspaceRule(WorkspaceRule),
|
||||||
@@ -1453,27 +1475,33 @@ fn main() -> Result<()> {
|
|||||||
SubCommand::ManageRule(arg) => {
|
SubCommand::ManageRule(arg) => {
|
||||||
send_message(&SocketMessage::ManageRule(arg.identifier, arg.id).as_bytes()?)?;
|
send_message(&SocketMessage::ManageRule(arg.identifier, arg.id).as_bytes()?)?;
|
||||||
}
|
}
|
||||||
SubCommand::WorkspaceRule(arg) => {
|
SubCommand::InitialWorkspaceRule(arg) => {
|
||||||
send_message(
|
send_message(
|
||||||
&SocketMessage::WorkspaceRule(
|
&SocketMessage::InitialWorkspaceRule(
|
||||||
arg.identifier,
|
arg.identifier,
|
||||||
arg.id,
|
arg.id,
|
||||||
arg.monitor,
|
arg.monitor,
|
||||||
arg.workspace,
|
arg.workspace,
|
||||||
arg.apply_on_first_show_only,
|
|
||||||
)
|
)
|
||||||
.as_bytes()?,
|
.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) => {
|
SubCommand::NamedWorkspaceRule(arg) => {
|
||||||
send_message(
|
send_message(
|
||||||
&SocketMessage::NamedWorkspaceRule(
|
&SocketMessage::NamedWorkspaceRule(arg.identifier, arg.id, arg.workspace)
|
||||||
arg.identifier,
|
.as_bytes()?,
|
||||||
arg.id,
|
|
||||||
arg.workspace,
|
|
||||||
arg.apply_on_first_show_only,
|
|
||||||
)
|
|
||||||
.as_bytes()?,
|
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
SubCommand::Stack(arg) => {
|
SubCommand::Stack(arg) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user