From 1c14a0a2a97867878c65ea33fa8b927618efb555 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 11 May 2024 09:33:23 +0400 Subject: Add a reset-window-height action --- src/input.rs | 3 +++ src/layout/mod.rs | 9 +++++++++ src/layout/monitor.rs | 4 ++++ src/layout/workspace.rs | 17 +++++++++++++++++ 4 files changed, 33 insertions(+) (limited to 'src') 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 Layout { 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 Monitor { 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 Workspace { 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 Column { self.update_tile_sizes(animate); } + fn reset_window_height(&mut self, tile_idx: Option, 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; -- cgit