From 71e28b33e3e29f08c70b62409d972e80c6ba63f8 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 2 Nov 2021 14:14:27 -0700 Subject: [PATCH] feat(wm): add resize-delta cmd This commit adds a command to set the resize delta used under the hood by the resize-edge and resize-axis commands. The resize delta defaults to 50 pixels as was hard-coded previously. --- Cargo.lock | 4 ++-- README.md | 16 +++++++++---- komorebi-core/src/default_layout.rs | 36 ++++++++++++++--------------- komorebi-core/src/lib.rs | 1 + komorebi/src/process_command.rs | 21 +++++++++-------- komorebi/src/process_event.rs | 4 ++-- komorebi/src/window_manager.rs | 8 +++++-- komorebic.lib.sample.ahk | 4 ++++ komorebic/src/main.rs | 12 ++++++++++ 9 files changed, 68 insertions(+), 38 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2180bb94..4e8ee340 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -375,9 +375,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.26.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81a03ce013ffccead76c11a15751231f777d9295b845cc1266ed4d34fcbd7977" +checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4" [[package]] name = "hashbrown" diff --git a/README.md b/README.md index ed206870..56829639 100644 --- a/README.md +++ b/README.md @@ -289,16 +289,17 @@ query Query the current window manager state subscribe Subscribe to komorebi events unsubscribe Unsubscribe from komorebi events log Tail komorebi.exe's process logs (cancel with Ctrl-C) -quick-save Quicksave the current resize layout dimensions -quick-load Load the last quicksaved resize layout dimensions -save Save the current resize layout dimensions to a file -load Load the resize layout dimensions from a file +quick-save-resize Quicksave the current resize layout dimensions +quick-load-resize Load the last quicksaved resize layout dimensions +save-resize Save the current resize layout dimensions to a file +load-resize Load the resize layout dimensions from a file focus Change focus to the window in the specified direction move Move the focused window in the specified direction cycle-focus Change focus to the window in the specified cycle direction cycle-move Move the focused window in the specified cycle direction stack Stack the focused window in the specified direction -resize Resize the focused window in the specified direction +resize-edge Resize the focused window in the specified direction +resize-axis Resize the focused window along the specified axis unstack Unstack the focused window cycle-stack Cycle the focused stack in the specified cycle direction move-to-monitor Move the focused window to the specified monitor @@ -310,6 +311,7 @@ focus-workspace Focus the specified workspace on the focused monit cycle-monitor Focus the monitor in the given cycle direction cycle-workspace Focus the workspace in the given cycle direction new-workspace Create and append a new workspace on the focused monitor +resize-delta Set the resize delta (used by resize-edge and resize-axis) invisible-borders Set the invisible border dimensions around each window work-area-offset Set offsets to exclude parts of the work area from tiling adjust-container-padding Adjust container padding on the focused workspace @@ -343,6 +345,8 @@ identify-tray-application Identify an application that closes to the system identify-border-overflow Identify an application that has overflowing borders focus-follows-mouse Enable or disable focus follows mouse for the operating system toggle-focus-follows-mouse Toggle focus follows mouse for the operating system +mouse-follows-focus Enable or disable mouse follows focus on all workspaces +toggle-mouse-follows-focus Toggle mouse follows focus on all workspaces ahk-library Generate a library of AutoHotKey helper functions help Print this message or the help of the given subcommand(s) ``` @@ -371,6 +375,8 @@ used [is available here](komorebi.sample.with.lib.ahk). - [x] Send focused window container to workspace - [x] Mouse follows focused container - [x] Resize window container in direction +- [x] Resize window container on axis +- [x] Set custom resize delta - [ ] Resize child window containers by split ratio - [x] Quicksave and quickload layouts with resize dimensions - [x] Save and load layouts with resize dimensions to/from specific files diff --git a/komorebi-core/src/default_layout.rs b/komorebi-core/src/default_layout.rs index 3461b562..b792b9a5 100644 --- a/komorebi-core/src/default_layout.rs +++ b/komorebi-core/src/default_layout.rs @@ -28,7 +28,7 @@ impl DefaultLayout { resize: &Option, edge: OperationDirection, sizing: Sizing, - step: Option, + delta: i32, ) -> Option { if !matches!(self, Self::BSP) { return None; @@ -37,7 +37,7 @@ impl DefaultLayout { let max_divisor = 1.005; let mut r = resize.unwrap_or_default(); - let resize_step = step.unwrap_or(50); + let resize_delta = delta; match edge { OperationDirection::Left => match sizing { @@ -52,65 +52,65 @@ impl DefaultLayout { // with index 0. I don't think it's worth trying to defensively program // against this; if people end up in this situation they are better off // just hitting the retile command - let diff = ((r.left + -resize_step) as f32).abs(); + let diff = ((r.left + -resize_delta) as f32).abs(); let max = unaltered.right as f32 / max_divisor; if diff < max { - r.left += -resize_step; + r.left += -resize_delta; } } Sizing::Decrease => { - let diff = ((r.left - -resize_step) as f32).abs(); + let diff = ((r.left - -resize_delta) as f32).abs(); let max = unaltered.right as f32 / max_divisor; if diff < max { - r.left -= -resize_step; + r.left -= -resize_delta; } } }, OperationDirection::Up => match sizing { Sizing::Increase => { - let diff = ((r.top + resize_step) as f32).abs(); + let diff = ((r.top + resize_delta) as f32).abs(); let max = unaltered.bottom as f32 / max_divisor; if diff < max { - r.top += -resize_step; + r.top += -resize_delta; } } Sizing::Decrease => { - let diff = ((r.top - resize_step) as f32).abs(); + let diff = ((r.top - resize_delta) as f32).abs(); let max = unaltered.bottom as f32 / max_divisor; if diff < max { - r.top -= -resize_step; + r.top -= -resize_delta; } } }, OperationDirection::Right => match sizing { Sizing::Increase => { - let diff = ((r.right + resize_step) as f32).abs(); + let diff = ((r.right + resize_delta) as f32).abs(); let max = unaltered.right as f32 / max_divisor; if diff < max { - r.right += resize_step; + r.right += resize_delta; } } Sizing::Decrease => { - let diff = ((r.right - resize_step) as f32).abs(); + let diff = ((r.right - resize_delta) as f32).abs(); let max = unaltered.right as f32 / max_divisor; if diff < max { - r.right -= resize_step; + r.right -= resize_delta; } } }, OperationDirection::Down => match sizing { Sizing::Increase => { - let diff = ((r.bottom + resize_step) as f32).abs(); + let diff = ((r.bottom + resize_delta) as f32).abs(); let max = unaltered.bottom as f32 / max_divisor; if diff < max { - r.bottom += resize_step; + r.bottom += resize_delta; } } Sizing::Decrease => { - let diff = ((r.bottom - resize_step) as f32).abs(); + let diff = ((r.bottom - resize_delta) as f32).abs(); let max = unaltered.bottom as f32 / max_divisor; if diff < max { - r.bottom -= resize_step; + r.bottom -= resize_delta; } } }, diff --git a/komorebi-core/src/lib.rs b/komorebi-core/src/lib.rs index 2dc38f7e..225fd990 100644 --- a/komorebi-core/src/lib.rs +++ b/komorebi-core/src/lib.rs @@ -85,6 +85,7 @@ pub enum SocketMessage { WatchConfiguration(bool), InvisibleBorders(Rect), WorkAreaOffset(Rect), + ResizeDelta(i32), WorkspaceRule(ApplicationIdentifier, String, usize, usize), FloatRule(ApplicationIdentifier, String), ManageRule(ApplicationIdentifier, String), diff --git a/komorebi/src/process_command.rs b/komorebi/src/process_command.rs index e9e30992..7bdcd726 100644 --- a/komorebi/src/process_command.rs +++ b/komorebi/src/process_command.rs @@ -263,7 +263,7 @@ impl WindowManager { stream.write_all(response.as_bytes())?; } SocketMessage::ResizeWindowEdge(direction, sizing) => { - self.resize_window(direction, sizing, Option::from(50), true)?; + self.resize_window(direction, sizing, self.resize_delta, true)?; } SocketMessage::ResizeWindowAxis(axis, sizing) => { match axis { @@ -271,13 +271,13 @@ impl WindowManager { self.resize_window( OperationDirection::Left, sizing, - Option::from(50), + self.resize_delta, false, )?; self.resize_window( OperationDirection::Right, sizing, - Option::from(50), + self.resize_delta, false, )?; } @@ -285,13 +285,13 @@ impl WindowManager { self.resize_window( OperationDirection::Up, sizing, - Option::from(50), + self.resize_delta, false, )?; self.resize_window( OperationDirection::Down, sizing, - Option::from(50), + self.resize_delta, false, )?; } @@ -299,25 +299,25 @@ impl WindowManager { self.resize_window( OperationDirection::Left, sizing, - Option::from(50), + self.resize_delta, false, )?; self.resize_window( OperationDirection::Right, sizing, - Option::from(50), + self.resize_delta, false, )?; self.resize_window( OperationDirection::Up, sizing, - Option::from(50), + self.resize_delta, false, )?; self.resize_window( OperationDirection::Down, sizing, - Option::from(50), + self.resize_delta, false, )?; } @@ -524,6 +524,9 @@ impl WindowManager { SocketMessage::ToggleMouseFollowsFocus => { self.mouse_follows_focus = !self.mouse_follows_focus; } + SocketMessage::ResizeDelta(delta) => { + self.resize_delta = delta; + } }; tracing::info!("processed"); diff --git a/komorebi/src/process_event.rs b/komorebi/src/process_event.rs index c24e8514..cfe391a4 100644 --- a/komorebi/src/process_event.rs +++ b/komorebi/src/process_event.rs @@ -383,8 +383,8 @@ impl WindowManager { ops.push(resize_op!(resize.bottom, <, OperationDirection::Down)); } - for (edge, sizing, step) in ops { - self.resize_window(edge, sizing, Option::from(step), true)?; + for (edge, sizing, delta) in ops { + self.resize_window(edge, sizing, delta, true)?; } self.update_focused_workspace(false)?; diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index 38ab0e57..51bc36ba 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -49,6 +49,7 @@ pub struct WindowManager { pub is_paused: bool, pub invisible_borders: Rect, pub work_area_offset: Option, + pub resize_delta: i32, pub focus_follows_mouse: Option, pub mouse_follows_focus: bool, pub hotwatch: Hotwatch, @@ -62,6 +63,7 @@ pub struct State { pub monitors: Ring, pub is_paused: bool, pub invisible_borders: Rect, + pub resize_delta: i32, pub work_area_offset: Option, pub focus_follows_mouse: Option, pub mouse_follows_focus: bool, @@ -80,6 +82,7 @@ impl From<&WindowManager> for State { is_paused: wm.is_paused, invisible_borders: wm.invisible_borders, work_area_offset: wm.work_area_offset, + resize_delta: wm.resize_delta, focus_follows_mouse: wm.focus_follows_mouse.clone(), mouse_follows_focus: wm.mouse_follows_focus, has_pending_raise_op: wm.has_pending_raise_op, @@ -153,6 +156,7 @@ impl WindowManager { bottom: 7, }, work_area_offset: None, + resize_delta: 50, focus_follows_mouse: None, mouse_follows_focus: true, hotwatch: Hotwatch::new()?, @@ -676,7 +680,7 @@ impl WindowManager { &mut self, direction: OperationDirection, sizing: Sizing, - step: Option, + delta: i32, update: bool, ) -> Result<()> { let work_area = self.focused_monitor_work_area()?; @@ -741,7 +745,7 @@ impl WindowManager { focused_idx_resize, direction, sizing, - step, + delta, ); workspace.resize_dimensions_mut()[focused_idx] = resize; diff --git a/komorebic.lib.sample.ahk b/komorebic.lib.sample.ahk index e88e1633..d8ba170c 100644 --- a/komorebic.lib.sample.ahk +++ b/komorebic.lib.sample.ahk @@ -116,6 +116,10 @@ NewWorkspace() { Run, komorebic.exe new-workspace, , Hide } +ResizeDelta(pixels) { + Run, komorebic.exe resize-delta %pixels%, , Hide +} + InvisibleBorders(left, top, right, bottom) { Run, komorebic.exe invisible-borders %left% %top% %right% %bottom%, , Hide } diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 7ab2a6c0..756ef75f 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -176,6 +176,12 @@ struct ResizeAxis { sizing: Sizing, } +#[derive(Parser, AhkFunction)] +struct ResizeDelta { + /// The delta of pixels by which to increase or decrease window dimensions when resizing + pixels: i32, +} + #[derive(Parser, AhkFunction)] struct InvisibleBorders { /// Size of the left invisible border @@ -428,6 +434,9 @@ enum SubCommand { CycleWorkspace(CycleWorkspace), /// Create and append a new workspace on the focused monitor NewWorkspace, + /// Set the resize delta (used by resize-edge and resize-axis) + #[clap(setting = AppSettings::ArgRequiredElseHelp)] + ResizeDelta(ResizeDelta), /// Set the invisible border dimensions around each window #[clap(setting = AppSettings::ArgRequiredElseHelp)] InvisibleBorders(InvisibleBorders), @@ -946,6 +955,9 @@ fn main() -> Result<()> { SubCommand::MouseFollowsFocus(arg) => { send_message(&*SocketMessage::MouseFollowsFocus(arg.boolean_state.into()).as_bytes()?)?; } + SubCommand::ResizeDelta(arg) => { + send_message(&*SocketMessage::ResizeDelta(arg.pixels).as_bytes()?)?; + } } Ok(())