From 3b20e4b2fe99f6c7db52dec6f13f8fd89039daa3 Mon Sep 17 00:00:00 2001 From: alex-ds13 <145657253+alex-ds13@users.noreply.github.com> Date: Thu, 28 Nov 2024 19:05:18 +0000 Subject: [PATCH] refacor(wm): use helper function on move to workspace Use the same `add_container_with_direction` function on `move_container_to_workspace` as it is being used on `move_container_to_monitor` or `move_container_in_direction`. This way we bring parity between all methods and make it easier to change the way a container is added on a monitor workspace when taking the move direction into consideration. --- komorebi/src/monitor.rs | 58 +++++++---------------------------------- 1 file changed, 9 insertions(+), 49 deletions(-) diff --git a/komorebi/src/monitor.rs b/komorebi/src/monitor.rs index ff40b162..d4a151a2 100644 --- a/komorebi/src/monitor.rs +++ b/komorebi/src/monitor.rs @@ -142,7 +142,7 @@ impl Monitor { /// Adds a container to this `Monitor` using the move direction to calculate if the container /// should be added in front of all containers, in the back or in place of the focused /// container, moving the rest along. The move direction should be from the origin monitor - /// towards the target monitor. + /// towards the target monitor or from the origin workspace towards the target workspace. pub fn add_container_with_direction( &mut self, container: Container, @@ -295,54 +295,14 @@ impl Monitor { Some(workspace) => workspace, }; - match direction { - Some(OperationDirection::Left) => match target_workspace.layout() { - Layout::Default(layout) => match layout { - DefaultLayout::RightMainVerticalStack => { - target_workspace.add_container_to_front(container); - } - DefaultLayout::UltrawideVerticalStack => { - if target_workspace.containers().len() == 1 { - target_workspace.insert_container_at_idx(0, container); - } else { - target_workspace.add_container_to_back(container); - } - } - _ => { - target_workspace.add_container_to_back(container); - } - }, - Layout::Custom(_) => { - target_workspace.add_container_to_back(container); - } - }, - Some(OperationDirection::Right) => match target_workspace.layout() { - Layout::Default(layout) => { - let target_index = - layout.leftmost_index(target_workspace.containers().len()); - - match layout { - DefaultLayout::RightMainVerticalStack - | DefaultLayout::UltrawideVerticalStack => { - if target_workspace.containers().len() == 1 { - target_workspace.add_container_to_back(container); - } else { - target_workspace - .insert_container_at_idx(target_index, container); - } - } - _ => { - target_workspace.insert_container_at_idx(target_index, container); - } - } - } - Layout::Custom(_) => { - target_workspace.add_container_to_front(container); - } - }, - _ => { - target_workspace.add_container_to_back(container); - } + if let Some(direction) = direction { + self.add_container_with_direction( + container, + Some(target_workspace_idx), + direction, + )?; + } else { + target_workspace.add_container_to_back(container); } }