Skip to content

Commit

Permalink
feat(wm): add resize-delta cmd
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
LGUG2Z committed Nov 2, 2021
1 parent 40226a2 commit 71e28b3
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
```
Expand Down Expand Up @@ -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
Expand Down
36 changes: 18 additions & 18 deletions komorebi-core/src/default_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand All @@ -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;
}
}
},
Expand Down
1 change: 1 addition & 0 deletions komorebi-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
21 changes: 12 additions & 9 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,61 +263,61 @@ 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 {
Axis::Horizontal => {
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,
)?;
}
Axis::Vertical => {
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,
)?;
}
Axis::HorizontalAndVertical => {
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,
)?;
}
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
8 changes: 6 additions & 2 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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()?,
Expand Down Expand Up @@ -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()?;
Expand Down Expand Up @@ -741,7 +745,7 @@ impl WindowManager {
focused_idx_resize,
direction,
sizing,
step,
delta,
);

workspace.resize_dimensions_mut()[focused_idx] = resize;
Expand Down
4 changes: 4 additions & 0 deletions komorebic.lib.sample.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(())
Expand Down

0 comments on commit 71e28b3

Please sign in to comment.