feat(wm): allow resize-axis for custom primary col

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.
This commit is contained in:
LGUG2Z
2021-11-03 10:04:48 -07:00
parent 71e28b33e3
commit 4d7ccc5519
7 changed files with 104 additions and 57 deletions
Generated
+12
View File
@@ -96,6 +96,7 @@ dependencies = [
"os_str_bytes", "os_str_bytes",
"strsim", "strsim",
"termcolor", "termcolor",
"terminal_size",
"textwrap", "textwrap",
"unicase", "unicase",
] ]
@@ -1197,12 +1198,23 @@ dependencies = [
"winapi-util", "winapi-util",
] ]
[[package]]
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.14.2" version = "0.14.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80"
dependencies = [ dependencies = [
"terminal_size",
"unicode-width", "unicode-width",
] ]
+1 -1
View File
@@ -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 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-edge 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 resize-axis Resize the focused window or primary column 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
+15
View File
@@ -2,6 +2,7 @@ use std::collections::HashMap;
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
use std::ops::Deref; use std::ops::Deref;
use std::ops::DerefMut;
use std::path::PathBuf; use std::path::PathBuf;
use color_eyre::eyre::anyhow; use color_eyre::eyre::anyhow;
@@ -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 { impl CustomLayout {
pub fn from_path_buf(path: PathBuf) -> Result<Self> { pub fn from_path_buf(path: PathBuf) -> Result<Self> {
let invalid_filetype = anyhow!("custom layouts must be json or yaml files"); let invalid_filetype = anyhow!("custom layouts must be json or yaml files");
@@ -75,6 +82,14 @@ impl CustomLayout {
None 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] #[must_use]
pub fn is_valid(&self) -> bool { pub fn is_valid(&self) -> bool {
// A valid layout must have at least one column // A valid layout must have at least one column
+73 -53
View File
@@ -17,8 +17,10 @@ use uds_windows::UnixStream;
use komorebi_core::Axis; use komorebi_core::Axis;
use komorebi_core::FocusFollowsMouseImplementation; use komorebi_core::FocusFollowsMouseImplementation;
use komorebi_core::Layout;
use komorebi_core::OperationDirection; use komorebi_core::OperationDirection;
use komorebi_core::Rect; use komorebi_core::Rect;
use komorebi_core::Sizing;
use komorebi_core::SocketMessage; use komorebi_core::SocketMessage;
use komorebi_core::StateQuery; use komorebi_core::StateQuery;
@@ -266,62 +268,80 @@ impl WindowManager {
self.resize_window(direction, sizing, self.resize_delta, true)?; self.resize_window(direction, sizing, self.resize_delta, true)?;
} }
SocketMessage::ResizeWindowAxis(axis, sizing) => { SocketMessage::ResizeWindowAxis(axis, sizing) => {
match axis { // If the user has a custom layout, allow for the resizing of the primary column
Axis::Horizontal => { // with this signal
self.resize_window( if let Layout::Custom(ref mut custom) = self.focused_workspace_mut()?.layout_mut() {
OperationDirection::Left, if matches!(axis, Axis::Horizontal) {
sizing, let percentage = custom
self.resize_delta, .primary_width_percentage()
false, .unwrap_or_else(|| 100 / custom.len());
)?;
self.resize_window( match sizing {
OperationDirection::Right, Sizing::Increase => custom.set_primary_width_percentage(percentage + 5),
sizing, Sizing::Decrease => custom.set_primary_width_percentage(percentage - 5),
self.resize_delta, }
false,
)?;
} }
Axis::Vertical => { // Otherwise proceed with the resizing logic for individual window containers in the
self.resize_window( // assumed BSP layout
OperationDirection::Up, } else {
sizing, match axis {
self.resize_delta, Axis::Horizontal => {
false, self.resize_window(
)?; OperationDirection::Left,
self.resize_window( sizing,
OperationDirection::Down, self.resize_delta,
sizing, false,
self.resize_delta, )?;
false, self.resize_window(
)?; OperationDirection::Right,
} sizing,
Axis::HorizontalAndVertical => { self.resize_delta,
self.resize_window( false,
OperationDirection::Left, )?;
sizing, }
self.resize_delta, Axis::Vertical => {
false, self.resize_window(
)?; OperationDirection::Up,
self.resize_window( sizing,
OperationDirection::Right, self.resize_delta,
sizing, false,
self.resize_delta, )?;
false, self.resize_window(
)?; OperationDirection::Down,
self.resize_window( sizing,
OperationDirection::Up, self.resize_delta,
sizing, false,
self.resize_delta, )?;
false, }
)?; Axis::HorizontalAndVertical => {
self.resize_window( self.resize_window(
OperationDirection::Down, OperationDirection::Left,
sizing, sizing,
self.resize_delta, self.resize_delta,
false, 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)?; self.update_focused_workspace(false)?;
} }
SocketMessage::FocusFollowsMouse(mut implementation, enable) => { SocketMessage::FocusFollowsMouse(mut implementation, enable) => {
+1 -1
View File
@@ -38,7 +38,7 @@ pub struct Workspace {
maximized_window_restore_idx: Option<usize>, maximized_window_restore_idx: Option<usize>,
#[getset(get = "pub", get_mut = "pub")] #[getset(get = "pub", get_mut = "pub")]
floating_windows: Vec<Window>, floating_windows: Vec<Window>,
#[getset(get = "pub", set = "pub")] #[getset(get = "pub", get_mut = "pub", set = "pub")]
layout: Layout, layout: Layout,
#[getset(get_copy = "pub", set = "pub")] #[getset(get_copy = "pub", set = "pub")]
layout_flip: Option<Axis>, layout_flip: Option<Axis>,
+1 -1
View File
@@ -14,7 +14,7 @@ edition = "2021"
derive-ahk = { path = "../derive-ahk" } derive-ahk = { path = "../derive-ahk" }
komorebi-core = { path = "../komorebi-core" } 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" color-eyre = "0.5"
dirs = "4" dirs = "4"
fs-tail = "0.1" fs-tail = "0.1"
+1 -1
View File
@@ -400,7 +400,7 @@ enum SubCommand {
#[clap(setting = AppSettings::ArgRequiredElseHelp)] #[clap(setting = AppSettings::ArgRequiredElseHelp)]
#[clap(alias = "resize")] #[clap(alias = "resize")]
ResizeEdge(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)] #[clap(setting = AppSettings::ArgRequiredElseHelp)]
ResizeAxis(ResizeAxis), ResizeAxis(ResizeAxis),
/// Unstack the focused window /// Unstack the focused window