aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-05-11 09:33:23 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-05-11 09:33:23 +0400
commit1c14a0a2a97867878c65ea33fa8b927618efb555 (patch)
tree16bb26bf1d8b83fca5d768bce7577443e26584e5
parent2fd9a03bd71b4709659cdd35192109b47c3b0e10 (diff)
downloadniri-1c14a0a2a97867878c65ea33fa8b927618efb555.tar.gz
niri-1c14a0a2a97867878c65ea33fa8b927618efb555.tar.bz2
niri-1c14a0a2a97867878c65ea33fa8b927618efb555.zip
Add a reset-window-height action
-rw-r--r--niri-config/src/lib.rs2
-rw-r--r--niri-ipc/src/lib.rs2
-rw-r--r--resources/default-config.kdl1
-rw-r--r--src/input.rs3
-rw-r--r--src/layout/mod.rs9
-rw-r--r--src/layout/monitor.rs4
-rw-r--r--src/layout/workspace.rs17
7 files changed, 38 insertions, 0 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index c1fc4b1d..9f61bce3 100644
--- a/niri-config/src/lib.rs
+++ b/niri-config/src/lib.rs
@@ -898,6 +898,7 @@ pub enum Action {
MoveColumnToMonitorDown,
MoveColumnToMonitorUp,
SetWindowHeight(#[knuffel(argument, str)] SizeChange),
+ ResetWindowHeight,
SwitchPresetColumnWidth,
MaximizeColumn,
SetColumnWidth(#[knuffel(argument, str)] SizeChange),
@@ -969,6 +970,7 @@ impl From<niri_ipc::Action> for Action {
niri_ipc::Action::MoveColumnToMonitorDown => Self::MoveColumnToMonitorDown,
niri_ipc::Action::MoveColumnToMonitorUp => Self::MoveColumnToMonitorUp,
niri_ipc::Action::SetWindowHeight { change } => Self::SetWindowHeight(change),
+ niri_ipc::Action::ResetWindowHeight => Self::ResetWindowHeight,
niri_ipc::Action::SwitchPresetColumnWidth => Self::SwitchPresetColumnWidth,
niri_ipc::Action::MaximizeColumn => Self::MaximizeColumn,
niri_ipc::Action::SetColumnWidth { change } => Self::SetColumnWidth(change),
diff --git a/niri-ipc/src/lib.rs b/niri-ipc/src/lib.rs
index e7489165..beabfcbc 100644
--- a/niri-ipc/src/lib.rs
+++ b/niri-ipc/src/lib.rs
@@ -208,6 +208,8 @@ pub enum Action {
#[cfg_attr(feature = "clap", arg())]
change: SizeChange,
},
+ /// Reset the height of the focused window back to automatic.
+ ResetWindowHeight,
/// Switch between preset column widths.
SwitchPresetColumnWidth,
/// Toggle the maximized state of the focused column.
diff --git a/resources/default-config.kdl b/resources/default-config.kdl
index e529dd20..fda3ad84 100644
--- a/resources/default-config.kdl
+++ b/resources/default-config.kdl
@@ -418,6 +418,7 @@ binds {
// Mod+BracketRight { consume-or-expel-window-right; }
Mod+R { switch-preset-column-width; }
+ Mod+Shift+R { reset-window-height; }
Mod+F { maximize-column; }
Mod+Shift+F { fullscreen-window; }
Mod+C { center-column; }
diff --git a/src/input.rs b/src/input.rs
index 95f16b9b..208d48f0 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -780,6 +780,9 @@ impl State {
Action::SetWindowHeight(change) => {
self.niri.layout.set_window_height(change);
}
+ Action::ResetWindowHeight => {
+ self.niri.layout.reset_window_height();
+ }
Action::ShowHotkeyOverlay => {
if self.niri.hotkey_overlay.show() {
self.niri.queue_redraw_all();
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 22aaa7fa..75f6cd4c 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -1477,6 +1477,13 @@ impl<W: LayoutElement> Layout<W> {
monitor.set_window_height(change);
}
+ pub fn reset_window_height(&mut self) {
+ let Some(monitor) = self.active_monitor() else {
+ return;
+ };
+ monitor.reset_window_height();
+ }
+
pub fn focus_output(&mut self, output: &Output) {
if let MonitorSet::Normal {
monitors,
@@ -2335,6 +2342,7 @@ mod tests {
MaximizeColumn,
SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
SetWindowHeight(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
+ ResetWindowHeight,
Communicate(#[proptest(strategy = "1..=5usize")] usize),
MoveWorkspaceToOutput(#[proptest(strategy = "1..=5u8")] u8),
ViewOffsetGestureBegin {
@@ -2563,6 +2571,7 @@ mod tests {
Op::MaximizeColumn => layout.toggle_full_width(),
Op::SetColumnWidth(change) => layout.set_column_width(change),
Op::SetWindowHeight(change) => layout.set_window_height(change),
+ Op::ResetWindowHeight => layout.reset_window_height(),
Op::Communicate(id) => {
let mut update = false;
match &mut layout.monitor_set {
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index 3833a61a..e12d544a 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -614,6 +614,10 @@ impl<W: LayoutElement> Monitor<W> {
self.active_workspace().set_window_height(change);
}
+ pub fn reset_window_height(&mut self) {
+ self.active_workspace().reset_window_height();
+ }
+
pub fn move_workspace_down(&mut self) {
let new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1);
if new_idx == self.active_workspace_idx {
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 5deae266..3dbb473b 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -1988,6 +1988,17 @@ impl<W: LayoutElement> Workspace<W> {
cancel_resize_if_this_column(&mut self.interactive_resize, col);
}
+ pub fn reset_window_height(&mut self) {
+ if self.columns.is_empty() {
+ return;
+ }
+
+ let col = &mut self.columns[self.active_column_idx];
+ col.reset_window_height(None, true);
+
+ cancel_resize_if_this_column(&mut self.interactive_resize, col);
+ }
+
pub fn set_fullscreen(&mut self, window: &W::Id, is_fullscreen: bool) {
let (mut col_idx, tile_idx) = self
.columns
@@ -3091,6 +3102,12 @@ impl<W: LayoutElement> Column<W> {
self.update_tile_sizes(animate);
}
+ fn reset_window_height(&mut self, tile_idx: Option<usize>, animate: bool) {
+ let tile_idx = tile_idx.unwrap_or(self.active_tile_idx);
+ self.heights[tile_idx] = WindowHeight::Auto;
+ self.update_tile_sizes(animate);
+ }
+
fn set_fullscreen(&mut self, is_fullscreen: bool) {
assert_eq!(self.tiles.len(), 1);
self.is_fullscreen = is_fullscreen;