From c05326d1b6dba32bc681b24ca178f471ae9e8044 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 14 Aug 2023 18:34:39 +0400 Subject: Add Mod+F to maximize --- README.md | 1 + src/input.rs | 7 ++++++- src/layout.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f0b74183..ae84166f 100644 --- a/README.md +++ b/README.md @@ -66,6 +66,7 @@ The general system is: if a hotkey switches somewhere, then adding CtrlMod, | Consume the window to the right into the focused column | | Mod. | Expel the focused window into its own column | | ModR | Toggle between preset window widths | +| ModF | Maximize window | | ModShiftE | Exit niri | [PaperWM]: https://github.com/paperwm/PaperWM diff --git a/src/input.rs b/src/input.rs index 7ea2e457..ec25b22c 100644 --- a/src/input.rs +++ b/src/input.rs @@ -33,6 +33,7 @@ enum Action { MoveToWorkspaceDown, MoveToWorkspaceUp, ToggleWidth, + ToggleFullWidth, } pub enum CompositorMod { @@ -74,7 +75,7 @@ fn action(comp_mod: CompositorMod, keysym: KeysymHandle, mods: ModifiersState) - KEY_E => Action::Quit, KEY_t => Action::SpawnTerminal, KEY_q => Action::CloseWindow, - KEY_f => Action::ToggleFullscreen, + KEY_F => Action::ToggleFullscreen, KEY_h | KEY_Left if mods.ctrl => Action::MoveLeft, KEY_l | KEY_Right if mods.ctrl => Action::MoveRight, KEY_j | KEY_Down if mods.ctrl => Action::MoveDown, @@ -90,6 +91,7 @@ fn action(comp_mod: CompositorMod, keysym: KeysymHandle, mods: ModifiersState) - KEY_comma => Action::ConsumeIntoColumn, KEY_period => Action::ExpelFromColumn, KEY_r => Action::ToggleWidth, + KEY_f => Action::ToggleFullWidth, _ => Action::None, } } @@ -230,6 +232,9 @@ impl Niri { Action::ToggleWidth => { self.monitor_set.toggle_width(); } + Action::ToggleFullWidth => { + self.monitor_set.toggle_full_width(); + } } } } diff --git a/src/layout.rs b/src/layout.rs index 6e4d9306..c4ab517b 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -759,6 +759,13 @@ impl MonitorSet { }; monitor.toggle_width(); } + + pub fn toggle_full_width(&mut self) { + let Some(monitor) = self.active_monitor() else { + return; + }; + monitor.toggle_full_width(); + } } impl MonitorSet { @@ -976,6 +983,10 @@ impl Monitor { fn toggle_width(&mut self) { self.active_workspace().toggle_width(); } + + fn toggle_full_width(&mut self) { + self.active_workspace().toggle_full_width(); + } } impl Monitor { @@ -1392,6 +1403,14 @@ impl Workspace { self.columns[self.active_column_idx].toggle_width(self.view_size); } + + fn toggle_full_width(&mut self) { + if self.columns.is_empty() { + return; + } + + self.columns[self.active_column_idx].toggle_full_width(self.view_size); + } } impl Workspace { @@ -1555,6 +1574,17 @@ impl Column { let width = ColumnWidth::PresetProportion(idx); self.set_width(view_size, width); } + + fn toggle_full_width(&mut self, view_size: Size) { + let width = match self.width { + ColumnWidth::Proportion(1.) => { + // FIXME: would be good to restore to previous width here. + ColumnWidth::default() + } + _ => ColumnWidth::Proportion(1.), + }; + self.set_width(view_size, width); + } } pub fn output_size(output: &Output) -> Size { -- cgit