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.
This commit is contained in:
LGUG2Z
2021-11-02 14:14:27 -07:00
parent 40226a2bbd
commit 71e28b33e3
9 changed files with 68 additions and 38 deletions
Generated
+2 -2
View File
@@ -375,9 +375,9 @@ dependencies = [
[[package]] [[package]]
name = "gimli" name = "gimli"
version = "0.26.0" version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "81a03ce013ffccead76c11a15751231f777d9295b845cc1266ed4d34fcbd7977" checksum = "78cc372d058dcf6d5ecd98510e7fbc9e5aec4d21de70f65fea8fecebcd881bd4"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
+11 -5
View File
@@ -289,16 +289,17 @@ query Query the current window manager state
subscribe Subscribe to komorebi events subscribe Subscribe to komorebi events
unsubscribe Unsubscribe from komorebi events unsubscribe Unsubscribe from komorebi events
log Tail komorebi.exe's process logs (cancel with Ctrl-C) log Tail komorebi.exe's process logs (cancel with Ctrl-C)
quick-save Quicksave the current resize layout dimensions quick-save-resize Quicksave the current resize layout dimensions
quick-load Load the last quicksaved resize layout dimensions quick-load-resize Load the last quicksaved resize layout dimensions
save Save the current resize layout dimensions to a file save-resize Save the current resize layout dimensions to a file
load Load the resize layout dimensions from a file load-resize Load the resize layout dimensions from a file
focus Change focus to the window in the specified direction focus Change focus to the window in the specified direction
move Move the focused 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-focus Change focus to the window in the specified cycle direction
cycle-move Move the focused 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 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 unstack Unstack the focused window
cycle-stack Cycle the focused stack in the specified cycle direction cycle-stack Cycle the focused stack in the specified cycle direction
move-to-monitor Move the focused window to the specified monitor 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-monitor Focus the monitor in the given cycle direction
cycle-workspace Focus the workspace 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 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 invisible-borders Set the invisible border dimensions around each window
work-area-offset Set offsets to exclude parts of the work area from tiling work-area-offset Set offsets to exclude parts of the work area from tiling
adjust-container-padding Adjust container padding on the focused workspace 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 identify-border-overflow Identify an application that has overflowing borders
focus-follows-mouse Enable or disable focus follows mouse for the operating system 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 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 ahk-library Generate a library of AutoHotKey helper functions
help Print this message or the help of the given subcommand(s) 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] Send focused window container to workspace
- [x] Mouse follows focused container - [x] Mouse follows focused container
- [x] Resize window container in direction - [x] Resize window container in direction
- [x] Resize window container on axis
- [x] Set custom resize delta
- [ ] Resize child window containers by split ratio - [ ] Resize child window containers by split ratio
- [x] Quicksave and quickload layouts with resize dimensions - [x] Quicksave and quickload layouts with resize dimensions
- [x] Save and load layouts with resize dimensions to/from specific files - [x] Save and load layouts with resize dimensions to/from specific files
+18 -18
View File
@@ -28,7 +28,7 @@ impl DefaultLayout {
resize: &Option<Rect>, resize: &Option<Rect>,
edge: OperationDirection, edge: OperationDirection,
sizing: Sizing, sizing: Sizing,
step: Option<i32>, delta: i32,
) -> Option<Rect> { ) -> Option<Rect> {
if !matches!(self, Self::BSP) { if !matches!(self, Self::BSP) {
return None; return None;
@@ -37,7 +37,7 @@ impl DefaultLayout {
let max_divisor = 1.005; let max_divisor = 1.005;
let mut r = resize.unwrap_or_default(); let mut r = resize.unwrap_or_default();
let resize_step = step.unwrap_or(50); let resize_delta = delta;
match edge { match edge {
OperationDirection::Left => match sizing { OperationDirection::Left => match sizing {
@@ -52,65 +52,65 @@ impl DefaultLayout {
// with index 0. I don't think it's worth trying to defensively program // 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 // against this; if people end up in this situation they are better off
// just hitting the retile command // 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; let max = unaltered.right as f32 / max_divisor;
if diff < max { if diff < max {
r.left += -resize_step; r.left += -resize_delta;
} }
} }
Sizing::Decrease => { 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; let max = unaltered.right as f32 / max_divisor;
if diff < max { if diff < max {
r.left -= -resize_step; r.left -= -resize_delta;
} }
} }
}, },
OperationDirection::Up => match sizing { OperationDirection::Up => match sizing {
Sizing::Increase => { 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; let max = unaltered.bottom as f32 / max_divisor;
if diff < max { if diff < max {
r.top += -resize_step; r.top += -resize_delta;
} }
} }
Sizing::Decrease => { 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; let max = unaltered.bottom as f32 / max_divisor;
if diff < max { if diff < max {
r.top -= -resize_step; r.top -= -resize_delta;
} }
} }
}, },
OperationDirection::Right => match sizing { OperationDirection::Right => match sizing {
Sizing::Increase => { 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; let max = unaltered.right as f32 / max_divisor;
if diff < max { if diff < max {
r.right += resize_step; r.right += resize_delta;
} }
} }
Sizing::Decrease => { 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; let max = unaltered.right as f32 / max_divisor;
if diff < max { if diff < max {
r.right -= resize_step; r.right -= resize_delta;
} }
} }
}, },
OperationDirection::Down => match sizing { OperationDirection::Down => match sizing {
Sizing::Increase => { 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; let max = unaltered.bottom as f32 / max_divisor;
if diff < max { if diff < max {
r.bottom += resize_step; r.bottom += resize_delta;
} }
} }
Sizing::Decrease => { 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; let max = unaltered.bottom as f32 / max_divisor;
if diff < max { if diff < max {
r.bottom -= resize_step; r.bottom -= resize_delta;
} }
} }
}, },
+1
View File
@@ -85,6 +85,7 @@ pub enum SocketMessage {
WatchConfiguration(bool), WatchConfiguration(bool),
InvisibleBorders(Rect), InvisibleBorders(Rect),
WorkAreaOffset(Rect), WorkAreaOffset(Rect),
ResizeDelta(i32),
WorkspaceRule(ApplicationIdentifier, String, usize, usize), WorkspaceRule(ApplicationIdentifier, String, usize, usize),
FloatRule(ApplicationIdentifier, String), FloatRule(ApplicationIdentifier, String),
ManageRule(ApplicationIdentifier, String), ManageRule(ApplicationIdentifier, String),
+12 -9
View File
@@ -263,7 +263,7 @@ impl WindowManager {
stream.write_all(response.as_bytes())?; stream.write_all(response.as_bytes())?;
} }
SocketMessage::ResizeWindowEdge(direction, sizing) => { 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) => { SocketMessage::ResizeWindowAxis(axis, sizing) => {
match axis { match axis {
@@ -271,13 +271,13 @@ impl WindowManager {
self.resize_window( self.resize_window(
OperationDirection::Left, OperationDirection::Left,
sizing, sizing,
Option::from(50), self.resize_delta,
false, false,
)?; )?;
self.resize_window( self.resize_window(
OperationDirection::Right, OperationDirection::Right,
sizing, sizing,
Option::from(50), self.resize_delta,
false, false,
)?; )?;
} }
@@ -285,13 +285,13 @@ impl WindowManager {
self.resize_window( self.resize_window(
OperationDirection::Up, OperationDirection::Up,
sizing, sizing,
Option::from(50), self.resize_delta,
false, false,
)?; )?;
self.resize_window( self.resize_window(
OperationDirection::Down, OperationDirection::Down,
sizing, sizing,
Option::from(50), self.resize_delta,
false, false,
)?; )?;
} }
@@ -299,25 +299,25 @@ impl WindowManager {
self.resize_window( self.resize_window(
OperationDirection::Left, OperationDirection::Left,
sizing, sizing,
Option::from(50), self.resize_delta,
false, false,
)?; )?;
self.resize_window( self.resize_window(
OperationDirection::Right, OperationDirection::Right,
sizing, sizing,
Option::from(50), self.resize_delta,
false, false,
)?; )?;
self.resize_window( self.resize_window(
OperationDirection::Up, OperationDirection::Up,
sizing, sizing,
Option::from(50), self.resize_delta,
false, false,
)?; )?;
self.resize_window( self.resize_window(
OperationDirection::Down, OperationDirection::Down,
sizing, sizing,
Option::from(50), self.resize_delta,
false, false,
)?; )?;
} }
@@ -524,6 +524,9 @@ impl WindowManager {
SocketMessage::ToggleMouseFollowsFocus => { SocketMessage::ToggleMouseFollowsFocus => {
self.mouse_follows_focus = !self.mouse_follows_focus; self.mouse_follows_focus = !self.mouse_follows_focus;
} }
SocketMessage::ResizeDelta(delta) => {
self.resize_delta = delta;
}
}; };
tracing::info!("processed"); tracing::info!("processed");
+2 -2
View File
@@ -383,8 +383,8 @@ impl WindowManager {
ops.push(resize_op!(resize.bottom, <, OperationDirection::Down)); ops.push(resize_op!(resize.bottom, <, OperationDirection::Down));
} }
for (edge, sizing, step) in ops { for (edge, sizing, delta) in ops {
self.resize_window(edge, sizing, Option::from(step), true)?; self.resize_window(edge, sizing, delta, true)?;
} }
self.update_focused_workspace(false)?; self.update_focused_workspace(false)?;
+6 -2
View File
@@ -49,6 +49,7 @@ pub struct WindowManager {
pub is_paused: bool, pub is_paused: bool,
pub invisible_borders: Rect, pub invisible_borders: Rect,
pub work_area_offset: Option<Rect>, pub work_area_offset: Option<Rect>,
pub resize_delta: i32,
pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>, pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>,
pub mouse_follows_focus: bool, pub mouse_follows_focus: bool,
pub hotwatch: Hotwatch, pub hotwatch: Hotwatch,
@@ -62,6 +63,7 @@ pub struct State {
pub monitors: Ring<Monitor>, pub monitors: Ring<Monitor>,
pub is_paused: bool, pub is_paused: bool,
pub invisible_borders: Rect, pub invisible_borders: Rect,
pub resize_delta: i32,
pub work_area_offset: Option<Rect>, pub work_area_offset: Option<Rect>,
pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>, pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>,
pub mouse_follows_focus: bool, pub mouse_follows_focus: bool,
@@ -80,6 +82,7 @@ impl From<&WindowManager> for State {
is_paused: wm.is_paused, is_paused: wm.is_paused,
invisible_borders: wm.invisible_borders, invisible_borders: wm.invisible_borders,
work_area_offset: wm.work_area_offset, work_area_offset: wm.work_area_offset,
resize_delta: wm.resize_delta,
focus_follows_mouse: wm.focus_follows_mouse.clone(), focus_follows_mouse: wm.focus_follows_mouse.clone(),
mouse_follows_focus: wm.mouse_follows_focus, mouse_follows_focus: wm.mouse_follows_focus,
has_pending_raise_op: wm.has_pending_raise_op, has_pending_raise_op: wm.has_pending_raise_op,
@@ -153,6 +156,7 @@ impl WindowManager {
bottom: 7, bottom: 7,
}, },
work_area_offset: None, work_area_offset: None,
resize_delta: 50,
focus_follows_mouse: None, focus_follows_mouse: None,
mouse_follows_focus: true, mouse_follows_focus: true,
hotwatch: Hotwatch::new()?, hotwatch: Hotwatch::new()?,
@@ -676,7 +680,7 @@ impl WindowManager {
&mut self, &mut self,
direction: OperationDirection, direction: OperationDirection,
sizing: Sizing, sizing: Sizing,
step: Option<i32>, delta: i32,
update: bool, update: bool,
) -> Result<()> { ) -> Result<()> {
let work_area = self.focused_monitor_work_area()?; let work_area = self.focused_monitor_work_area()?;
@@ -741,7 +745,7 @@ impl WindowManager {
focused_idx_resize, focused_idx_resize,
direction, direction,
sizing, sizing,
step, delta,
); );
workspace.resize_dimensions_mut()[focused_idx] = resize; workspace.resize_dimensions_mut()[focused_idx] = resize;
+4
View File
@@ -116,6 +116,10 @@ NewWorkspace() {
Run, komorebic.exe new-workspace, , Hide Run, komorebic.exe new-workspace, , Hide
} }
ResizeDelta(pixels) {
Run, komorebic.exe resize-delta %pixels%, , Hide
}
InvisibleBorders(left, top, right, bottom) { InvisibleBorders(left, top, right, bottom) {
Run, komorebic.exe invisible-borders %left% %top% %right% %bottom%, , Hide Run, komorebic.exe invisible-borders %left% %top% %right% %bottom%, , Hide
} }
+12
View File
@@ -176,6 +176,12 @@ struct ResizeAxis {
sizing: Sizing, 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)] #[derive(Parser, AhkFunction)]
struct InvisibleBorders { struct InvisibleBorders {
/// Size of the left invisible border /// Size of the left invisible border
@@ -428,6 +434,9 @@ enum SubCommand {
CycleWorkspace(CycleWorkspace), CycleWorkspace(CycleWorkspace),
/// Create and append a new workspace on the focused monitor /// Create and append a new workspace on the focused monitor
NewWorkspace, 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 /// Set the invisible border dimensions around each window
#[clap(setting = AppSettings::ArgRequiredElseHelp)] #[clap(setting = AppSettings::ArgRequiredElseHelp)]
InvisibleBorders(InvisibleBorders), InvisibleBorders(InvisibleBorders),
@@ -946,6 +955,9 @@ fn main() -> Result<()> {
SubCommand::MouseFollowsFocus(arg) => { SubCommand::MouseFollowsFocus(arg) => {
send_message(&*SocketMessage::MouseFollowsFocus(arg.boolean_state.into()).as_bytes()?)?; send_message(&*SocketMessage::MouseFollowsFocus(arg.boolean_state.into()).as_bytes()?)?;
} }
SubCommand::ResizeDelta(arg) => {
send_message(&*SocketMessage::ResizeDelta(arg.pixels).as_bytes()?)?;
}
} }
Ok(()) Ok(())