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

4
Cargo.lock generated
View File

@@ -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"

View File

@@ -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

View File

@@ -28,7 +28,7 @@ impl DefaultLayout {
resize: &Option<Rect>,
edge: OperationDirection,
sizing: Sizing,
step: Option<i32>,
delta: i32,
) -> Option<Rect> {
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;
}
}
},

View File

@@ -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),

View File

@@ -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");

View File

@@ -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)?;

View File

@@ -49,6 +49,7 @@ pub struct WindowManager {
pub is_paused: bool,
pub invisible_borders: Rect,
pub work_area_offset: Option<Rect>,
pub resize_delta: i32,
pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>,
pub mouse_follows_focus: bool,
pub hotwatch: Hotwatch,
@@ -62,6 +63,7 @@ pub struct State {
pub monitors: Ring<Monitor>,
pub is_paused: bool,
pub invisible_borders: Rect,
pub resize_delta: i32,
pub work_area_offset: Option<Rect>,
pub focus_follows_mouse: Option<FocusFollowsMouseImplementation>,
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<i32>,
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;

View File

@@ -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
}

View File

@@ -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(())