From 4a19edaab2bef63043ba14a3a1cd6b9820e580af Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Mon, 15 Nov 2021 12:38:08 -0800 Subject: [PATCH] feat(wm): impl drag to move in append mode This commit ensures that when a window is dragged over another window container while WindowContainerBehaviour::Append is set, the window will be removed from its current container and appended to the target container instead of swapping the positions of the two containers, as would be the case for WindowContainerBehaviour::Create. re #72 --- komorebi-core/src/lib.rs | 8 +++---- komorebi/src/process_command.rs | 18 +++++++------- komorebi/src/process_event.rs | 42 ++++++++++++++++++++++++--------- komorebi/src/window_manager.rs | 10 ++++---- komorebic.lib.sample.ahk | 4 ++-- komorebic/src/main.rs | 6 ++--- 6 files changed, 55 insertions(+), 33 deletions(-) diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index 26c6a3dc..99830104 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -51,7 +51,7 @@ pub enum SocketMessage { ToggleFloat, ToggleMonocle, ToggleMaximize, - ToggleNewWindowBehaviour, + ToggleWindowContainerBehaviour, // Current Workspace Commands ManageFocusedWindow, UnmanageFocusedWindow, @@ -142,9 +142,9 @@ pub enum FocusFollowsMouseImplementation { #[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)] #[strum(serialize_all = "snake_case")] -pub enum NewWindowBehaviour { - CreateNewContainer, - AppendToFocusedContainer, +pub enum WindowContainerBehaviour { + Create, + Append, } #[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)] diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index 70571b42..7a25f8d3 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -18,12 +18,12 @@ use uds_windows::UnixStream; use komorebi_core::Axis; use komorebi_core::FocusFollowsMouseImplementation; use komorebi_core::Layout; -use komorebi_core::NewWindowBehaviour; use komorebi_core::OperationDirection; use komorebi_core::Rect; use komorebi_core::Sizing; use komorebi_core::SocketMessage; use komorebi_core::StateQuery; +use komorebi_core::WindowContainerBehaviour; use crate::notify_subscribers; use crate::window_manager; @@ -548,14 +548,16 @@ impl WindowManager { SocketMessage::ResizeDelta(delta) => { self.resize_delta = delta; } - SocketMessage::ToggleNewWindowBehaviour => match self.new_window_behaviour { - NewWindowBehaviour::CreateNewContainer => { - self.new_window_behaviour = NewWindowBehaviour::AppendToFocusedContainer; + SocketMessage::ToggleWindowContainerBehaviour => { + match self.window_container_behaviour { + WindowContainerBehaviour::Create => { + self.window_container_behaviour = WindowContainerBehaviour::Append; + } + WindowContainerBehaviour::Append => { + self.window_container_behaviour = WindowContainerBehaviour::Create; + } } - NewWindowBehaviour::AppendToFocusedContainer => { - self.new_window_behaviour = NewWindowBehaviour::CreateNewContainer; - } - }, + } }; tracing::info!("processed"); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index 2f3d625d..91c0860a 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -7,10 +7,10 @@ use color_eyre::Result; use crossbeam_channel::select; use parking_lot::Mutex; -use komorebi_core::NewWindowBehaviour; use komorebi_core::OperationDirection; use komorebi_core::Rect; use komorebi_core::Sizing; +use komorebi_core::WindowContainerBehaviour; use crate::notify_subscribers; use crate::window_manager::WindowManager; @@ -202,16 +202,16 @@ impl WindowManager { } } - let behaviour = self.new_window_behaviour; + let behaviour = self.window_container_behaviour; let workspace = self.focused_workspace_mut()?; if !workspace.contains_window(window.hwnd) { match behaviour { - NewWindowBehaviour::CreateNewContainer => { + WindowContainerBehaviour::Create => { workspace.new_container_for_window(*window); self.update_focused_workspace(false)?; } - NewWindowBehaviour::AppendToFocusedContainer => { + WindowContainerBehaviour::Append => { workspace .focused_container_mut() .ok_or_else(|| anyhow!("there is no focused container"))? @@ -247,6 +247,8 @@ impl WindowManager { .monitor_idx_from_current_pos() .ok_or_else(|| anyhow!("cannot get monitor idx from current position"))?; + let new_window_behaviour = self.window_container_behaviour; + let workspace = self.focused_workspace_mut()?; if workspace .floating_windows() @@ -352,15 +354,33 @@ impl WindowManager { self.focus_workspace(target_workspace_idx)?; self.update_focused_workspace(false)?; } + // Here we handle a simple move on the same monitor which is treated as + // a container swap } else { - // Here we handle a simple move on the same monitor which is treated as - // a container swap - match workspace.container_idx_from_current_point() { - Some(target_idx) => { - workspace.swap_containers(focused_container_idx, target_idx); - self.update_focused_workspace(false)?; + match new_window_behaviour { + WindowContainerBehaviour::Create => { + match workspace.container_idx_from_current_point() { + Some(target_idx) => { + workspace + .swap_containers(focused_container_idx, target_idx); + self.update_focused_workspace(false)?; + } + None => { + self.update_focused_workspace(self.mouse_follows_focus)?; + } + } + } + WindowContainerBehaviour::Append => { + match workspace.container_idx_from_current_point() { + Some(target_idx) => { + workspace.move_window_to_container(target_idx)?; + self.update_focused_workspace(false)?; + } + None => { + self.update_focused_workspace(self.mouse_follows_focus)?; + } + } } - None => self.update_focused_workspace(self.mouse_follows_focus)?, } } } else { diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 2583de50..f77f1fe2 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -21,10 +21,10 @@ use komorebi_core::CycleDirection; use komorebi_core::DefaultLayout; use komorebi_core::FocusFollowsMouseImplementation; use komorebi_core::Layout; -use komorebi_core::NewWindowBehaviour; use komorebi_core::OperationDirection; use komorebi_core::Rect; use komorebi_core::Sizing; +use komorebi_core::WindowContainerBehaviour; use crate::container::Container; use crate::load_configuration; @@ -51,7 +51,7 @@ pub struct WindowManager { pub invisible_borders: Rect, pub work_area_offset: Option, pub resize_delta: i32, - pub new_window_behaviour: NewWindowBehaviour, + pub window_container_behaviour: WindowContainerBehaviour, pub focus_follows_mouse: Option, pub mouse_follows_focus: bool, pub hotwatch: Hotwatch, @@ -66,7 +66,7 @@ pub struct State { pub is_paused: bool, pub invisible_borders: Rect, pub resize_delta: i32, - pub new_window_behaviour: NewWindowBehaviour, + pub new_window_behaviour: WindowContainerBehaviour, pub work_area_offset: Option, pub focus_follows_mouse: Option, pub mouse_follows_focus: bool, @@ -86,7 +86,7 @@ impl From<&WindowManager> for State { invisible_borders: wm.invisible_borders, work_area_offset: wm.work_area_offset, resize_delta: wm.resize_delta, - new_window_behaviour: wm.new_window_behaviour, + new_window_behaviour: wm.window_container_behaviour, focus_follows_mouse: wm.focus_follows_mouse.clone(), mouse_follows_focus: wm.mouse_follows_focus, has_pending_raise_op: wm.has_pending_raise_op, @@ -160,7 +160,7 @@ impl WindowManager { bottom: 7, }, work_area_offset: None, - new_window_behaviour: NewWindowBehaviour::CreateNewContainer, + window_container_behaviour: WindowContainerBehaviour::Create, resize_delta: 50, focus_follows_mouse: None, mouse_follows_focus: true, diff --git a/komorebic.lib.sample.ahk b/komorebic.lib.sample.ahk index bd0b98a1..f5d464a5 100644 --- a/komorebic.lib.sample.ahk +++ b/komorebic.lib.sample.ahk @@ -184,8 +184,8 @@ WorkspaceName(monitor, workspace, value) { Run, komorebic.exe workspace-name %monitor% %workspace% %value%, , Hide } -ToggleNewWindowBehaviour() { - Run, komorebic.exe toggle-new-window-behaviour, , Hide +ToggleWindowContainerBehaviour() { + Run, komorebic.exe toggle-window-container-behaviour, , Hide } TogglePause() { diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 5745d398..60044e06 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -484,7 +484,7 @@ enum SubCommand { #[clap(setting = AppSettings::ArgRequiredElseHelp)] WorkspaceName(WorkspaceName), /// Toggle the behaviour for new windows (stacking or dynamic tiling) - ToggleNewWindowBehaviour, + ToggleWindowContainerBehaviour, /// Toggle window tiling on the focused workspace TogglePause, /// Toggle window tiling on the focused workspace @@ -960,8 +960,8 @@ fn main() -> Result<()> { SubCommand::ResizeDelta(arg) => { send_message(&*SocketMessage::ResizeDelta(arg.pixels).as_bytes()?)?; } - SubCommand::ToggleNewWindowBehaviour => { - send_message(&*SocketMessage::ToggleNewWindowBehaviour.as_bytes()?)?; + SubCommand::ToggleWindowContainerBehaviour => { + send_message(&*SocketMessage::ToggleWindowContainerBehaviour.as_bytes()?)?; } }