From d0a547cda0602e8ed4c418b0f221d561a5e0e1bf Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 18:50:56 -0700 Subject: [PATCH] refactor(windows): eight cross-workspace and cross-monitor arms call komorebi-core BEHAVIOUR (Windows runtime): CycleMoveContainerToWorkspace, CycleSendContainerToWorkspace, CycleFocusMonitor, CycleMoveContainerToMonitor, CycleSendContainerToMonitor, FocusMonitorWorkspaceNumber, MoveContainerToMonitorWorkspaceNumber and SendContainerToMonitorWorkspaceNumber are one call each of the functions of komorebi_core::command (the text that moved is the one the Windows arms had byte for byte), and WindowManager implements MonitorCommandHost by forwarding to its own methods. By construction the calls are the old ones; marked because it was only type-checked. Windows e2e scenarios needed: commands (cycle-move-to-workspace, cycle-send-to-workspace, cycle-monitor, cycle-move-to-monitor, cycle-send-to-monitor, focus-monitor-workspace, move-to-monitor-workspace, send-to-monitor-workspace) with two monitors if the guest has them, and workspaces. Verified: Windows cargo clippy -p komorebi-windows --locked --all-targets -D warnings: PASS. Not run: Windows tests, e2e. --- komorebi/src/process_command.rs | 113 +++++++++++++------------------- 1 file changed, 46 insertions(+), 67 deletions(-) diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 6219ea63..5ff03bd9 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -655,18 +655,7 @@ impl WindowManager { self.move_container_to_workspace(workspace_idx, true, None)?; } SocketMessage::CycleMoveContainerToWorkspace(direction) => { - let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?; - - let focused_workspace_idx = focused_monitor.focused_workspace_idx(); - let workspaces = focused_monitor.workspaces().len(); - - let workspace_idx = direction.next_idx( - focused_workspace_idx, - NonZeroUsize::new(workspaces) - .ok_or_eyre("there must be at least one workspace")?, - ); - - self.move_container_to_workspace(workspace_idx, true, None)?; + komorebi_core::cycle_move_container_to_workspace(self, direction, true)? } SocketMessage::MoveContainerToMonitorNumber(monitor_idx) => { let direction = self.direction_from_monitor_idx(monitor_idx); @@ -676,63 +665,36 @@ impl WindowManager { self.swap_focused_monitor(monitor_idx)?; } SocketMessage::CycleMoveContainerToMonitor(direction) => { - let monitor_idx = direction.next_idx( - self.focused_monitor_idx(), - NonZeroUsize::new(self.monitors().len()) - .ok_or_eyre("there must be at least one monitor")?, - ); - - let direction = self.direction_from_monitor_idx(monitor_idx); - self.move_container_to_monitor(monitor_idx, None, true, direction)?; + komorebi_core::cycle_move_container_to_monitor(self, direction, true)? } SocketMessage::SendContainerToWorkspaceNumber(workspace_idx) => { self.move_container_to_workspace(workspace_idx, false, None)?; } SocketMessage::CycleSendContainerToWorkspace(direction) => { - let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?; - - let focused_workspace_idx = focused_monitor.focused_workspace_idx(); - let workspaces = focused_monitor.workspaces().len(); - - let workspace_idx = direction.next_idx( - focused_workspace_idx, - NonZeroUsize::new(workspaces) - .ok_or_eyre("there must be at least one workspace")?, - ); - - self.move_container_to_workspace(workspace_idx, false, None)?; + komorebi_core::cycle_move_container_to_workspace(self, direction, false)? } SocketMessage::SendContainerToMonitorNumber(monitor_idx) => { let direction = self.direction_from_monitor_idx(monitor_idx); self.move_container_to_monitor(monitor_idx, None, false, direction)?; } SocketMessage::CycleSendContainerToMonitor(direction) => { - let monitor_idx = direction.next_idx( - self.focused_monitor_idx(), - NonZeroUsize::new(self.monitors().len()) - .ok_or_eyre("there must be at least one monitor")?, - ); - - let direction = self.direction_from_monitor_idx(monitor_idx); - self.move_container_to_monitor(monitor_idx, None, false, direction)?; + komorebi_core::cycle_move_container_to_monitor(self, direction, false)? } SocketMessage::SendContainerToMonitorWorkspaceNumber(monitor_idx, workspace_idx) => { - let direction = self.direction_from_monitor_idx(monitor_idx); - self.move_container_to_monitor( + komorebi_core::move_container_to_monitor_workspace_number( + self, monitor_idx, - Option::from(workspace_idx), + workspace_idx, false, - direction, - )?; + )? } SocketMessage::MoveContainerToMonitorWorkspaceNumber(monitor_idx, workspace_idx) => { - let direction = self.direction_from_monitor_idx(monitor_idx); - self.move_container_to_monitor( + komorebi_core::move_container_to_monitor_workspace_number( + self, monitor_idx, - Option::from(workspace_idx), + workspace_idx, true, - direction, - )?; + )? } SocketMessage::SendContainerToNamedWorkspace(ref workspace) => { if let Some((monitor_idx, workspace_idx)) = @@ -787,14 +749,7 @@ impl WindowManager { self.toggle_tiling()?; } SocketMessage::CycleFocusMonitor(direction) => { - let monitor_idx = direction.next_idx( - self.focused_monitor_idx(), - NonZeroUsize::new(self.monitors().len()) - .ok_or_eyre("there must be at least one monitor")?, - ); - - self.focus_monitor(monitor_idx)?; - self.update_focused_workspace(self.mouse_follows_focus, true)?; + komorebi_core::cycle_focus_monitor(self, direction)? } SocketMessage::FocusMonitorNumber(monitor_idx) => { self.focus_monitor(monitor_idx)?; @@ -983,15 +938,7 @@ impl WindowManager { self.focus_workspace_numbers(workspace_idx)?; } SocketMessage::FocusMonitorWorkspaceNumber(monitor_idx, workspace_idx) => { - let focused_monitor_idx = self.focused_monitor_idx(); - let focused_workspace_idx = self.focused_workspace_idx().unwrap_or_default(); - - let focused_pair = (focused_monitor_idx, focused_workspace_idx); - - if focused_pair != (monitor_idx, workspace_idx) { - self.focus_monitor(monitor_idx)?; - self.focus_workspace(workspace_idx)?; - } + komorebi_core::focus_monitor_workspace_number(self, monitor_idx, workspace_idx)? } SocketMessage::FocusNamedWorkspace(ref name) => { if let Some((monitor_idx, workspace_idx)) = @@ -2378,6 +2325,38 @@ impl komorebi_core::CommandHost for WindowManager { } } +impl komorebi_core::MonitorCommandHost for WindowManager { + fn mouse_follows_focus(&self) -> bool { + self.mouse_follows_focus + } + + fn update_focused_workspace( + &mut self, + follow_focus: bool, + trigger_focus: bool, + ) -> eyre::Result<()> { + WindowManager::update_focused_workspace(self, follow_focus, trigger_focus) + } + + fn direction_from_monitor_idx(&self, idx: usize) -> Option { + WindowManager::direction_from_monitor_idx(self, idx) + } + + fn move_container_to_monitor( + &mut self, + idx: usize, + workspace_idx: Option, + follow: bool, + direction: Option, + ) -> eyre::Result<()> { + WindowManager::move_container_to_monitor(self, idx, workspace_idx, follow, direction) + } + + fn focused_workspace_idx(&self) -> eyre::Result { + WindowManager::focused_workspace_idx(self) + } +} + #[cfg(test)] mod tests { use super::push_simple_rule;