From bdf10452f10ebf15ec1978cb05d0aac79ef5611f Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 4 May 2026 19:06:39 -0700 Subject: [PATCH] feat(wm): add monocle_focus_behaviour to gate monocle cycling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LGUG2Z/komorebi@5f629e1 made directional focus cycle the monocle container in the underlying ring. Useful on a single monitor, but undesired when focusing across monitors — the focus stays trapped on the monocle workspace instead of crossing the boundary. This commit adds a new top-level monocle_focus_behaviour option with two variants, Cycle (the post-5f629e1f behaviour) and NoOp (the pre-5f629e1f behaviour, now the default), along with a ToggleMonocleFocusBehaviour socket message and corresponding komorebic subcommands to flip between them at runtime. --- komorebi-client/src/lib.rs | 1 + komorebi/src/core/mod.rs | 15 +++++++++++++++ komorebi/src/process_command.rs | 10 ++++++++++ komorebi/src/state.rs | 7 +++++++ komorebi/src/static_config.rs | 8 ++++++++ komorebi/src/window_manager.rs | 18 ++++++++++++------ komorebic/src/main.rs | 18 ++++++++++++++++++ 7 files changed, 71 insertions(+), 6 deletions(-) diff --git a/komorebi-client/src/lib.rs b/komorebi-client/src/lib.rs index 907cb2b1..746464c3 100644 --- a/komorebi-client/src/lib.rs +++ b/komorebi-client/src/lib.rs @@ -8,6 +8,7 @@ pub use komorebi::core::Axis; pub use komorebi::core::CycleDirection; pub use komorebi::core::DefaultLayout; pub use komorebi::core::Layout; +pub use komorebi::core::MonocleFocusBehaviour; pub use komorebi::core::MoveBehaviour; pub use komorebi::core::OperationBehaviour; pub use komorebi::core::OperationDirection; diff --git a/komorebi/src/core/mod.rs b/komorebi/src/core/mod.rs index a73d3a48..ecea9d70 100644 --- a/komorebi/src/core/mod.rs +++ b/komorebi/src/core/mod.rs @@ -185,6 +185,19 @@ pub enum CrossBoundaryBehaviour { Monitor, } +#[derive( + Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq, +)] +#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))] +/// Behaviour when focusing in a direction while a monocle container is active +pub enum MonocleFocusBehaviour { + /// Cycle the monocle container to the next/previous container in the workspace + Cycle, + /// Do nothing, allowing focus to fall through to cross-monitor logic + #[default] + NoOp, +} + #[derive( Copy, Clone, Debug, Eq, PartialEq, Serialize, Deserialize, Display, EnumString, ValueEnum, )] @@ -308,6 +321,8 @@ pub enum SocketMessage { // WindowHidingBehaviour(HidingBehaviour), ToggleCrossMonitorMoveBehaviour, CrossMonitorMoveBehaviour(MoveBehaviour), + ToggleMonocleFocusBehaviour, + MonocleFocusBehaviour(MonocleFocusBehaviour), UnmanagedWindowOperationBehaviour(OperationBehaviour), // Current Workspace Commands ManageFocusedWindow, diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 4281751f..8dd9901b 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -24,6 +24,7 @@ use crate::core::ApplicationIdentifier; use crate::core::Axis; use crate::core::Layout; use crate::core::LayoutOptions; +use crate::core::MonocleFocusBehaviour; use crate::core::MoveBehaviour; use crate::core::OperationDirection; use crate::core::Rect; @@ -1579,6 +1580,15 @@ impl WindowManager { SocketMessage::CrossMonitorMoveBehaviour(behaviour) => { self.cross_monitor_move_behaviour = behaviour; } + SocketMessage::ToggleMonocleFocusBehaviour => { + self.monocle_focus_behaviour = match self.monocle_focus_behaviour { + MonocleFocusBehaviour::Cycle => MonocleFocusBehaviour::NoOp, + MonocleFocusBehaviour::NoOp => MonocleFocusBehaviour::Cycle, + }; + } + SocketMessage::MonocleFocusBehaviour(behaviour) => { + self.monocle_focus_behaviour = behaviour; + } SocketMessage::UnmanagedWindowOperationBehaviour(behaviour) => { self.unmanaged_window_operation_behaviour = behaviour; } diff --git a/komorebi/src/state.rs b/komorebi/src/state.rs index cd6677fb..0539b30b 100644 --- a/komorebi/src/state.rs +++ b/komorebi/src/state.rs @@ -4,6 +4,7 @@ use crate::HOME_DIR; use crate::IGNORE_IDENTIFIERS; use crate::MANAGE_IDENTIFIERS; use crate::WORKSPACE_MATCHING_RULES; +use crate::core::MonocleFocusBehaviour; use crate::core::MoveBehaviour; use crate::core::OperationBehaviour; use crate::core::Rect; @@ -79,6 +80,7 @@ pub struct State { pub new_window_behaviour: WindowContainerBehaviour, pub float_override: bool, pub cross_monitor_move_behaviour: MoveBehaviour, + pub monocle_focus_behaviour: MonocleFocusBehaviour, pub unmanaged_window_operation_behaviour: OperationBehaviour, pub work_area_offset: Option, // pub focus_follows_mouse: Option, @@ -170,6 +172,7 @@ impl From<&WindowManager> for State { new_window_behaviour: wm.window_management_behaviour.current_behaviour, float_override: wm.window_management_behaviour.float_override, cross_monitor_move_behaviour: wm.cross_monitor_move_behaviour, + monocle_focus_behaviour: wm.monocle_focus_behaviour, // focus_follows_mouse: wm.focus_follows_mouse, mouse_follows_focus: wm.mouse_follows_focus, // has_pending_raise_op: wm.has_pending_raise_op, @@ -203,6 +206,10 @@ impl State { return true; } + if self.monocle_focus_behaviour != new.monocle_focus_behaviour { + return true; + } + if self.unmanaged_window_operation_behaviour != new.unmanaged_window_operation_behaviour { return true; } diff --git a/komorebi/src/static_config.rs b/komorebi/src/static_config.rs index 56110cd8..39050660 100644 --- a/komorebi/src/static_config.rs +++ b/komorebi/src/static_config.rs @@ -32,6 +32,7 @@ use crate::core::FloatingLayerBehaviour; use crate::core::Layout; use crate::core::LayoutDefaultEntry; use crate::core::LayoutOptions; +use crate::core::MonocleFocusBehaviour; use crate::core::MoveBehaviour; use crate::core::OperationBehaviour; use crate::core::Placement; @@ -486,6 +487,10 @@ pub struct StaticConfig { #[serde(skip_serializing_if = "Option::is_none")] #[cfg_attr(feature = "schemars", schemars(extend("default" = CrossBoundaryBehaviour::Monitor)))] pub cross_boundary_behaviour: Option, + /// Determine what happens when focusing in a direction while a monocle container is active + #[serde(skip_serializing_if = "Option::is_none")] + #[cfg_attr(feature = "schemars", schemars(extend("default" = MonocleFocusBehaviour::NoOp)))] + pub monocle_focus_behaviour: Option, /// Determine what happens when commands are sent while an unmanaged window is in the foreground #[serde(skip_serializing_if = "Option::is_none")] #[cfg_attr(feature = "schemars", schemars(extend("default" = OperationBehaviour::Op)))] @@ -740,6 +745,7 @@ impl From<&WindowManager> for StaticConfig { ), cross_monitor_move_behaviour: Option::from(value.cross_monitor_move_behaviour), cross_boundary_behaviour: Option::from(value.cross_boundary_behaviour), + monocle_focus_behaviour: Option::from(value.monocle_focus_behaviour), unmanaged_window_operation_behaviour: Option::from( value.unmanaged_window_operation_behaviour, ), @@ -1199,6 +1205,7 @@ impl StaticConfig { cross_boundary_behaviour: value .cross_boundary_behaviour .unwrap_or(CrossBoundaryBehaviour::Monitor), + monocle_focus_behaviour: value.monocle_focus_behaviour.unwrap_or_default(), unmanaged_window_operation_behaviour: value .unmanaged_window_operation_behaviour .unwrap_or(OperationBehaviour::Op), @@ -1574,6 +1581,7 @@ impl StaticConfig { value.float_rule_placement.unwrap_or(Placement::None); wm.cross_monitor_move_behaviour = value.cross_monitor_move_behaviour.unwrap_or_default(); wm.cross_boundary_behaviour = value.cross_boundary_behaviour.unwrap_or_default(); + wm.monocle_focus_behaviour = value.monocle_focus_behaviour.unwrap_or_default(); wm.unmanaged_window_operation_behaviour = value .unmanaged_window_operation_behaviour .unwrap_or_default(); diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 6459b85e..fa79bf84 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -15,6 +15,7 @@ use crate::core::CrossBoundaryBehaviour; use crate::core::CycleDirection; use crate::core::DefaultLayout; use crate::core::Layout; +use crate::core::MonocleFocusBehaviour; use crate::core::MoveBehaviour; use crate::core::OperationBehaviour; use crate::core::OperationDirection; @@ -75,6 +76,7 @@ pub struct WindowManager { pub window_management_behaviour: WindowManagementBehaviour, pub cross_monitor_move_behaviour: MoveBehaviour, pub cross_boundary_behaviour: CrossBoundaryBehaviour, + pub monocle_focus_behaviour: MonocleFocusBehaviour, pub mouse_follows_focus: bool, pub work_area_offset: Option, pub incoming_events: Receiver, @@ -158,6 +160,7 @@ impl WindowManager { window_management_behaviour: behaviour, cross_monitor_move_behaviour: Default::default(), cross_boundary_behaviour: Default::default(), + monocle_focus_behaviour: MonocleFocusBehaviour::default(), mouse_follows_focus: true, work_area_offset: None, incoming_events: incoming, @@ -509,7 +512,9 @@ impl WindowManager { tracing::info!("focusing container"); - if workspace.monocle_container.is_some() { + if workspace.monocle_container.is_some() + && matches!(self.monocle_focus_behaviour, MonocleFocusBehaviour::Cycle) + { let cycle_direction = match direction { OperationDirection::Left | OperationDirection::Down => CycleDirection::Previous, OperationDirection::Right | OperationDirection::Up => CycleDirection::Next, @@ -517,11 +522,12 @@ impl WindowManager { return self.cycle_monocle(cycle_direction); } - let new_idx = if workspace.maximized_window.is_some() { - None - } else { - workspace.new_idx_for_direction(direction) - }; + let new_idx = + if workspace.maximized_window.is_some() || workspace.monocle_container.is_some() { + None + } else { + workspace.new_idx_for_direction(direction) + }; let mut cross_monitor_monocle_or_max = false; diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 5f39e413..d874ef87 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -146,6 +146,13 @@ gen_target_subcommand_args! { FocusStackWindow, } +#[derive(Parser)] +struct MonocleFocusBehaviour { + /// Desired monocle focus behaviour + #[clap(value_enum)] + behaviour: komorebi_client::MonocleFocusBehaviour, +} + macro_rules! gen_named_target_subcommand_args { // SubCommand Pattern ( $( $name:ident ),+ $(,)? ) => { @@ -1119,6 +1126,11 @@ enum SubCommand { CrossMonitorMoveBehaviour(CrossMonitorMoveBehaviour), /// Toggle the behaviour when moving windows across monitor boundaries ToggleCrossMonitorMoveBehaviour, + /// Set the behaviour when focusing in a direction while a monocle container is active + #[clap(arg_required_else_help = true)] + MonocleFocusBehaviour(MonocleFocusBehaviour), + /// Toggle the behaviour when focusing in a direction while a monocle container is active + ToggleMonocleFocusBehaviour, /// Set the operation behaviour when the focused window is not managed #[clap(arg_required_else_help = true)] UnmanagedWindowOperationBehaviour(UnmanagedWindowOperationBehaviour), @@ -2024,6 +2036,9 @@ exit 1 SubCommand::ToggleCrossMonitorMoveBehaviour => { send_message(&SocketMessage::ToggleCrossMonitorMoveBehaviour)?; } + SubCommand::ToggleMonocleFocusBehaviour => { + send_message(&SocketMessage::ToggleMonocleFocusBehaviour)?; + } SubCommand::FocusMonitor(args) => { send_message(&SocketMessage::FocusMonitorNumber(args.target))?; } @@ -2401,6 +2416,9 @@ exit 1 args.move_behaviour, ))?; } + SubCommand::MonocleFocusBehaviour(args) => { + send_message(&SocketMessage::MonocleFocusBehaviour(args.behaviour))?; + } SubCommand::UnmanagedWindowOperationBehaviour(args) => { send_message(&SocketMessage::UnmanagedWindowOperationBehaviour( args.operation_behaviour,