Skip to content

Commit

Permalink
feat(wm): allow resize-axis for custom primary col
Browse files Browse the repository at this point in the history
This commit allows the resize-axis cmd on Axis::Horizontal to operate on
the Primary column of a CustomLayout.

Note that this will only operate on a CustomLayout that has met the
window count threshold to enable the tertiary column. If it has not, the
layout will render as DefaultLayout::Columns, which does not support the
resize-axis cmd.
  • Loading branch information
LGUG2Z committed Nov 3, 2021
1 parent 71e28b3 commit 4d7ccc5
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 57 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ cycle-focus Change focus to the window in the specified cycle
cycle-move Move the focused window in the specified cycle direction
stack Stack 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
resize-axis Resize the focused window or primary column 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 Down
15 changes: 15 additions & 0 deletions komorebi-core/src/custom_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::fs::File;
use std::io::BufReader;
use std::ops::Deref;
use std::ops::DerefMut;
use std::path::PathBuf;

use color_eyre::eyre::anyhow;
Expand All @@ -22,6 +23,12 @@ impl Deref for CustomLayout {
}
}

impl DerefMut for CustomLayout {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}

impl CustomLayout {
pub fn from_path_buf(path: PathBuf) -> Result<Self> {
let invalid_filetype = anyhow!("custom layouts must be json or yaml files");
Expand Down Expand Up @@ -75,6 +82,14 @@ impl CustomLayout {
None
}

pub fn set_primary_width_percentage(&mut self, percentage: usize) {
for column in self.iter_mut() {
if let Column::Primary(Option::Some(ColumnWidth::WidthPercentage(current))) = column {
*current = percentage;
}
}
}

#[must_use]
pub fn is_valid(&self) -> bool {
// A valid layout must have at least one column
Expand Down
126 changes: 73 additions & 53 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ use uds_windows::UnixStream;

use komorebi_core::Axis;
use komorebi_core::FocusFollowsMouseImplementation;
use komorebi_core::Layout;
use komorebi_core::OperationDirection;
use komorebi_core::Rect;
use komorebi_core::Sizing;
use komorebi_core::SocketMessage;
use komorebi_core::StateQuery;

Expand Down Expand Up @@ -266,62 +268,80 @@ impl WindowManager {
self.resize_window(direction, sizing, self.resize_delta, true)?;
}
SocketMessage::ResizeWindowAxis(axis, sizing) => {
match axis {
Axis::Horizontal => {
self.resize_window(
OperationDirection::Left,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Right,
sizing,
self.resize_delta,
false,
)?;
}
Axis::Vertical => {
self.resize_window(
OperationDirection::Up,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Down,
sizing,
self.resize_delta,
false,
)?;
// If the user has a custom layout, allow for the resizing of the primary column
// with this signal
if let Layout::Custom(ref mut custom) = self.focused_workspace_mut()?.layout_mut() {
if matches!(axis, Axis::Horizontal) {
let percentage = custom
.primary_width_percentage()
.unwrap_or_else(|| 100 / custom.len());

match sizing {
Sizing::Increase => custom.set_primary_width_percentage(percentage + 5),
Sizing::Decrease => custom.set_primary_width_percentage(percentage - 5),
}
}
Axis::HorizontalAndVertical => {
self.resize_window(
OperationDirection::Left,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Right,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Up,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Down,
sizing,
self.resize_delta,
false,
)?;
// Otherwise proceed with the resizing logic for individual window containers in the
// assumed BSP layout
} else {
match axis {
Axis::Horizontal => {
self.resize_window(
OperationDirection::Left,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Right,
sizing,
self.resize_delta,
false,
)?;
}
Axis::Vertical => {
self.resize_window(
OperationDirection::Up,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Down,
sizing,
self.resize_delta,
false,
)?;
}
Axis::HorizontalAndVertical => {
self.resize_window(
OperationDirection::Left,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Right,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Up,
sizing,
self.resize_delta,
false,
)?;
self.resize_window(
OperationDirection::Down,
sizing,
self.resize_delta,
false,
)?;
}
}
}

self.update_focused_workspace(false)?;
}
SocketMessage::FocusFollowsMouse(mut implementation, enable) => {
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct Workspace {
maximized_window_restore_idx: Option<usize>,
#[getset(get = "pub", get_mut = "pub")]
floating_windows: Vec<Window>,
#[getset(get = "pub", set = "pub")]
#[getset(get = "pub", get_mut = "pub", set = "pub")]
layout: Layout,
#[getset(get_copy = "pub", set = "pub")]
layout_flip: Option<Axis>,
Expand Down
2 changes: 1 addition & 1 deletion komorebic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ edition = "2021"
derive-ahk = { path = "../derive-ahk" }
komorebi-core = { path = "../komorebi-core" }

clap = "3.0.0-beta.5"
clap = { version = "3.0.0-beta.5", features = ["wrap_help"] }
color-eyre = "0.5"
dirs = "4"
fs-tail = "0.1"
Expand Down
2 changes: 1 addition & 1 deletion komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ enum SubCommand {
#[clap(setting = AppSettings::ArgRequiredElseHelp)]
#[clap(alias = "resize")]
ResizeEdge(Resize),
/// Resize the focused window along the specified axis
/// Resize the focused window or primary column along the specified axis
#[clap(setting = AppSettings::ArgRequiredElseHelp)]
ResizeAxis(ResizeAxis),
/// Unstack the focused window
Expand Down

0 comments on commit 4d7ccc5

Please sign in to comment.