Skip to content

Commit

Permalink
feat(wm): impl drag to move in append mode
Browse files Browse the repository at this point in the history
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
  • Loading branch information
LGUG2Z committed Nov 15, 2021
1 parent 676b643 commit 4a19eda
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 33 deletions.
8 changes: 4 additions & 4 deletions komorebi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub enum SocketMessage {
ToggleFloat,
ToggleMonocle,
ToggleMaximize,
ToggleNewWindowBehaviour,
ToggleWindowContainerBehaviour,
// Current Workspace Commands
ManageFocusedWindow,
UnmanageFocusedWindow,
Expand Down Expand Up @@ -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)]
Expand Down
18 changes: 10 additions & 8 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
NewWindowBehaviour::AppendToFocusedContainer => {
self.new_window_behaviour = NewWindowBehaviour::CreateNewContainer;
SocketMessage::ToggleWindowContainerBehaviour => {
match self.window_container_behaviour {
WindowContainerBehaviour::Create => {
self.window_container_behaviour = WindowContainerBehaviour::Append;
}
WindowContainerBehaviour::Append => {
self.window_container_behaviour = WindowContainerBehaviour::Create;
}
}
},
}
};

tracing::info!("processed");
Expand Down
42 changes: 31 additions & 11 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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"))?
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -51,7 +51,7 @@ pub struct WindowManager {
pub invisible_borders: Rect,
pub work_area_offset: Option<Rect>,
pub resize_delta: i32,
pub new_window_behaviour: NewWindowBehaviour,
pub window_container_behaviour: WindowContainerBehaviour,
pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>,
pub mouse_follows_focus: bool,
pub hotwatch: Hotwatch,
Expand All @@ -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<Rect>,
pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>,
pub mouse_follows_focus: bool,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions komorebic.lib.sample.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()?)?;
}
}

Expand Down

0 comments on commit 4a19eda

Please sign in to comment.