diff --git a/komorebi-client/src/lib.rs b/komorebi-client/src/lib.rs index 8c0018b3..abd04df0 100644 --- a/komorebi-client/src/lib.rs +++ b/komorebi-client/src/lib.rs @@ -1,5 +1,7 @@ pub use komorebi::DATA_DIR; pub use komorebi::core::ApplicationIdentifier; +pub use komorebi::core::MoveBehaviour; +pub use komorebi::core::OperationBehaviour; pub use komorebi::core::Sizing; pub use komorebi::core::SocketMessage; pub use komorebi::core::StateQuery; diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index 67782e87..3db62d89 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -246,8 +246,8 @@ pub enum SocketMessage { ToggleFloatOverride, // WindowHidingBehaviour(HidingBehaviour), ToggleCrossMonitorMoveBehaviour, - // CrossMonitorMoveBehaviour(MoveBehaviour), - // UnmanagedWindowOperationBehaviour(OperationBehaviour), + CrossMonitorMoveBehaviour(MoveBehaviour), + UnmanagedWindowOperationBehaviour(OperationBehaviour), // Current Workspace Commands // ManageFocusedWindow, // UnmanageFocusedWindow, @@ -263,8 +263,8 @@ pub enum SocketMessage { // Monitor and Workspace Commands // MonitorIndexPreference(usize, i32, i32, i32, i32), // DisplayIndexPreference(usize, String), - // EnsureWorkspaces(usize, usize), - // EnsureNamedWorkspaces(usize, Vec), + EnsureWorkspaces(usize, usize), + EnsureNamedWorkspaces(usize, Vec), NewWorkspace, ToggleTiling, // Stop, @@ -376,8 +376,8 @@ pub enum SocketMessage { Query(StateQuery), // FocusFollowsMouse(FocusFollowsMouseImplementation, bool), // ToggleFocusFollowsMouse(FocusFollowsMouseImplementation), - // MouseFollowsFocus(bool), - // ToggleMouseFollowsFocus, + MouseFollowsFocus(bool), + ToggleMouseFollowsFocus, // RemoveTitleBar(ApplicationIdentifier, String), // ToggleTitleBars, // AddSubscriberSocket(String), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 50c53c8e..bcef2259 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -1384,6 +1384,24 @@ impl WindowManager { self.clear_workspace_layout_rules(monitor_idx, workspace_idx)?; } } + SocketMessage::EnsureWorkspaces(monitor_idx, workspace_count) => { + self.ensure_workspaces_for_monitor(monitor_idx, workspace_count)?; + } + SocketMessage::EnsureNamedWorkspaces(monitor_idx, ref names) => { + self.ensure_named_workspaces_for_monitor(monitor_idx, names)?; + } + SocketMessage::MouseFollowsFocus(enable) => { + self.mouse_follows_focus = enable; + } + SocketMessage::ToggleMouseFollowsFocus => { + self.mouse_follows_focus = !self.mouse_follows_focus; + } + SocketMessage::CrossMonitorMoveBehaviour(behaviour) => { + self.cross_monitor_move_behaviour = behaviour; + } + SocketMessage::UnmanagedWindowOperationBehaviour(behaviour) => { + self.unmanaged_window_operation_behaviour = behaviour; + } } self.update_known_window_ids(); diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 6dd54078..8634d91e 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -2522,4 +2522,46 @@ impl WindowManager { self.update_focused_workspace(false, false) } + + #[tracing::instrument(skip(self))] + pub fn ensure_workspaces_for_monitor( + &mut self, + monitor_idx: usize, + workspace_count: usize, + ) -> eyre::Result<()> { + tracing::info!("ensuring workspace count"); + + let monitor = self + .monitors_mut() + .get_mut(monitor_idx) + .ok_or_eyre("there is no monitor")?; + + monitor.ensure_workspace_count(workspace_count); + + Ok(()) + } + + #[tracing::instrument(skip(self))] + pub fn ensure_named_workspaces_for_monitor( + &mut self, + monitor_idx: usize, + names: &Vec, + ) -> eyre::Result<()> { + tracing::info!("ensuring workspace count"); + + let monitor = self + .monitors_mut() + .get_mut(monitor_idx) + .ok_or_eyre("there is no monitor")?; + + monitor.ensure_workspace_count(names.len()); + + for (workspace_idx, name) in names.iter().enumerate() { + if let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx) { + workspace.name = Option::from(name.clone()); + } + } + + Ok(()) + } } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index bf99f56d..de382fed 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -9,6 +9,8 @@ use komorebi_client::ApplicationIdentifier; use komorebi_client::Axis; use komorebi_client::CycleDirection; use komorebi_client::DefaultLayout; +use komorebi_client::MoveBehaviour; +use komorebi_client::OperationBehaviour; use komorebi_client::OperationDirection; use komorebi_client::PathExt; use komorebi_client::Rect; @@ -108,11 +110,11 @@ gen_enum_subcommand_args! { ChangeLayout: DefaultLayout, CycleLayout: CycleDirection, // WatchConfiguration: BooleanState, - // MouseFollowsFocus: BooleanState, + MouseFollowsFocus: BooleanState, Query: StateQuery, // WindowHidingBehaviour: HidingBehaviour, - // CrossMonitorMoveBehaviour: MoveBehaviour, - // UnmanagedWindowOperationBehaviour: OperationBehaviour, + CrossMonitorMoveBehaviour: MoveBehaviour, + UnmanagedWindowOperationBehaviour: OperationBehaviour, PromoteWindow: OperationDirection, } @@ -485,6 +487,49 @@ pub struct MoveToMonitorWorkspace { target_workspace: usize, } +#[derive(Parser)] +pub struct WorkspaceLayoutRule { + /// Monitor index (zero-indexed) + monitor: usize, + + /// Workspace index on the specified monitor (zero-indexed) + workspace: usize, + + /// The number of window containers on-screen required to trigger this layout rule + at_container_count: usize, + + #[clap(value_enum)] + layout: DefaultLayout, +} + +#[derive(Parser)] +pub struct NamedWorkspaceLayoutRule { + /// Target workspace name + workspace: String, + + /// The number of window containers on-screen required to trigger this layout rule + at_container_count: usize, + + #[clap(value_enum)] + layout: DefaultLayout, +} + +#[derive(Parser)] +struct EnsureWorkspaces { + /// Monitor index (zero-indexed) + monitor: usize, + /// Number of desired workspaces + workspace_count: usize, +} + +#[derive(Parser)] +struct EnsureNamedWorkspaces { + /// Monitor index (zero-indexed) + monitor: usize, + /// Names of desired workspaces + names: Vec, +} + #[derive(Parser)] #[allow(clippy::struct_excessive_bools)] struct Start { @@ -777,12 +822,12 @@ enum SubCommand { // /// Set the display index preference for a monitor identified using its display name // #[clap(arg_required_else_help = true)] // DisplayIndexPreference(DisplayIndexPreference), - // /// Create at least this many workspaces for the specified monitor - // #[clap(arg_required_else_help = true)] - // EnsureWorkspaces(EnsureWorkspaces), - // /// Create these many named workspaces for the specified monitor - // #[clap(arg_required_else_help = true)] - // EnsureNamedWorkspaces(EnsureNamedWorkspaces), + /// Create at least this many workspaces for the specified monitor + #[clap(arg_required_else_help = true)] + EnsureWorkspaces(EnsureWorkspaces), + /// Create these many named 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), @@ -809,12 +854,12 @@ enum SubCommand { // #[clap(hide = true)] // #[clap(arg_required_else_help = true)] // NamedWorkspaceCustomLayout(NamedWorkspaceCustomLayout), - // /// Add a dynamic layout rule for the specified workspace - // #[clap(arg_required_else_help = true)] - // WorkspaceLayoutRule(WorkspaceLayoutRule), - // /// Add a dynamic layout rule for the specified workspace - // #[clap(arg_required_else_help = true)] - // NamedWorkspaceLayoutRule(NamedWorkspaceLayoutRule), + /// Add a dynamic layout rule for the specified workspace + #[clap(arg_required_else_help = true)] + WorkspaceLayoutRule(WorkspaceLayoutRule), + /// Add a dynamic layout rule for the specified workspace + #[clap(arg_required_else_help = true)] + NamedWorkspaceLayoutRule(NamedWorkspaceLayoutRule), // /// Add a dynamic custom layout for the specified workspace // #[clap(hide = true)] // #[clap(arg_required_else_help = true)] @@ -887,14 +932,14 @@ enum SubCommand { // /// Set the window behaviour when switching workspaces / cycling stacks // #[clap(arg_required_else_help = true)] // WindowHidingBehaviour(WindowHidingBehaviour), - // /// Set the behaviour when moving windows across monitor boundaries - // #[clap(arg_required_else_help = true)] - // CrossMonitorMoveBehaviour(CrossMonitorMoveBehaviour), + /// Set the behaviour when moving windows across monitor boundaries + #[clap(arg_required_else_help = true)] + CrossMonitorMoveBehaviour(CrossMonitorMoveBehaviour), /// Toggle the behaviour when moving windows across monitor boundaries ToggleCrossMonitorMoveBehaviour, - // /// Set the operation behaviour when the focused window is not managed - // #[clap(arg_required_else_help = true)] - // UnmanagedWindowOperationBehaviour(UnmanagedWindowOperationBehaviour), + /// Set the operation behaviour when the focused window is not managed + #[clap(arg_required_else_help = true)] + UnmanagedWindowOperationBehaviour(UnmanagedWindowOperationBehaviour), /// Add a rule to float the foreground window for the rest of this session SessionFloatRule, /// Show all session float rules @@ -1001,11 +1046,11 @@ enum SubCommand { // #[clap(hide = true)] // #[clap(arg_required_else_help = true)] // ToggleFocusFollowsMouse(ToggleFocusFollowsMouse), - // /// Enable or disable mouse follows focus on all workspaces - // #[clap(arg_required_else_help = true)] - // MouseFollowsFocus(MouseFollowsFocus), - // /// Toggle mouse follows focus on all workspaces - // ToggleMouseFollowsFocus, + /// Enable or disable mouse follows focus on all workspaces + #[clap(arg_required_else_help = true)] + MouseFollowsFocus(MouseFollowsFocus), + /// Toggle mouse follows focus on all workspaces + ToggleMouseFollowsFocus, // /// Generate common app-specific configurations and fixes to use in komorebi.ahk // #[clap(arg_required_else_help = true)] // #[clap(alias = "ahk-asc")] @@ -1602,6 +1647,49 @@ fn main() -> eyre::Result<()> { arg.workspace, ))?; } + SubCommand::EnsureWorkspaces(workspaces) => { + send_message(&SocketMessage::EnsureWorkspaces( + workspaces.monitor, + workspaces.workspace_count, + ))?; + } + SubCommand::EnsureNamedWorkspaces(arg) => { + send_message(&SocketMessage::EnsureNamedWorkspaces( + arg.monitor, + arg.names, + ))?; + } + SubCommand::WorkspaceLayoutRule(arg) => { + send_message(&SocketMessage::WorkspaceLayoutRule( + arg.monitor, + arg.workspace, + arg.at_container_count, + arg.layout, + ))?; + } + SubCommand::NamedWorkspaceLayoutRule(arg) => { + send_message(&SocketMessage::NamedWorkspaceLayoutRule( + arg.workspace, + arg.at_container_count, + arg.layout, + ))?; + } + SubCommand::CrossMonitorMoveBehaviour(arg) => { + send_message(&SocketMessage::CrossMonitorMoveBehaviour( + arg.move_behaviour, + ))?; + } + SubCommand::UnmanagedWindowOperationBehaviour(arg) => { + send_message(&SocketMessage::UnmanagedWindowOperationBehaviour( + arg.operation_behaviour, + ))?; + } + SubCommand::ToggleMouseFollowsFocus => { + send_message(&SocketMessage::ToggleMouseFollowsFocus)?; + } + SubCommand::MouseFollowsFocus(arg) => { + send_message(&SocketMessage::MouseFollowsFocus(arg.boolean_state.into()))?; + } } Ok(())