forge
Explore
Log in

Don't you dare go Hollow

Add Mod+R to toggle between preset widths

Browse files at this commit

2a163bb4b54954614ab07e1ce8b06abada169c7eIvan MolodetskikhParent: 6a1c149
README.mdmodified+1 -0
@@ -65,6 +65,7 @@ The general system is: if a hotkey switches somewhere, then adding <kbd>Ctrl</kb
6565 | <kbd>Mod</kbd><kbd>Ctrl</kbd><kbd>I</kbd> | Move the focused window to the workspace above |
6666 | <kbd>Mod</kbd><kbd>,</kbd> | Consume the window to the right into the focused column |
6767 | <kbd>Mod</kbd><kbd>.</kbd> | Expel the focused window into its own column |
68+| <kbd>Mod</kbd><kbd>R</kbd> | Toggle between preset window widths |
6869 | <kbd>Mod</kbd><kbd>Shift</kbd><kbd>E</kbd> | Exit niri |
6970
7071 [PaperWM]: https://github.com/paperwm/PaperWM
src/input.rsmodified+5 -0
@@ -32,6 +32,7 @@ enum Action {
3232 SwitchWorkspaceUp,
3333 MoveToWorkspaceDown,
3434 MoveToWorkspaceUp,
35+ ToggleWidth,
3536 }
3637
3738 pub enum CompositorMod {
@@ -88,6 +89,7 @@ fn action(comp_mod: CompositorMod, keysym: KeysymHandle, mods: ModifiersState) -
8889 KEY_i => Action::SwitchWorkspaceUp,
8990 KEY_comma => Action::ConsumeIntoColumn,
9091 KEY_period => Action::ExpelFromColumn,
92+ KEY_r => Action::ToggleWidth,
9193 _ => Action::None,
9294 }
9395 }
@@ -225,6 +227,9 @@ impl Niri {
225227 // FIXME: granular
226228 self.queue_redraw_all();
227229 }
230+ Action::ToggleWidth => {
231+ self.monitor_set.toggle_width();
232+ }
228233 }
229234 }
230235 }
src/layout.rsmodified+45 -0
@@ -50,6 +50,11 @@ use smithay::wayland::shell::xdg::XdgToplevelSurfaceData;
5050 use crate::animation::Animation;
5151
5252 const PADDING: i32 = 16;
53+const WIDTH_PROPORTIONS: [ColumnWidth; 3] = [
54+ ColumnWidth::Proportion(1. / 3.),
55+ ColumnWidth::Proportion(0.5),
56+ ColumnWidth::Proportion(2. / 3.),
57+];
5358
5459 #[derive(Debug, Clone, PartialEq, Eq)]
5560 pub struct OutputId(String);
@@ -135,6 +140,11 @@ pub struct Workspace<W: LayoutElement> {
135140 enum ColumnWidth {
136141 /// Proportion of the current view width.
137142 Proportion(f64),
143+ /// One of the proportion presets.
144+ ///
145+ /// This is separate from Proportion in order to be able to reliably cycle between preset
146+ /// proportions.
147+ PresetProportion(usize),
138148 /// Fixed width in logical pixels.
139149 Fixed(i32),
140150 }
@@ -199,6 +209,7 @@ impl ColumnWidth {
199209 fn resolve(self, view_width: i32) -> i32 {
200210 match self {
201211 ColumnWidth::Proportion(proportion) => (view_width as f64 * proportion).floor() as i32,
212+ ColumnWidth::PresetProportion(idx) => WIDTH_PROPORTIONS[idx].resolve(view_width),
202213 ColumnWidth::Fixed(width) => width,
203214 }
204215 }
@@ -741,6 +752,13 @@ impl<W: LayoutElement> MonitorSet<W> {
741752 }
742753 }
743754 }
755+
756+ pub fn toggle_width(&mut self) {
757+ let Some(monitor) = self.active_monitor() else {
758+ return;
759+ };
760+ monitor.toggle_width();
761+ }
744762 }
745763
746764 impl MonitorSet<Window> {
@@ -954,6 +972,10 @@ impl<W: LayoutElement> Monitor<W> {
954972 ws.advance_animations(current_time);
955973 }
956974 }
975+
976+ fn toggle_width(&mut self) {
977+ self.active_workspace().toggle_width();
978+ }
957979 }
958980
959981 impl Monitor<Window> {
@@ -1362,6 +1384,14 @@ impl<W: LayoutElement> Workspace<W> {
13621384
13631385 None
13641386 }
1387+
1388+ fn toggle_width(&mut self) {
1389+ if self.columns.is_empty() {
1390+ return;
1391+ }
1392+
1393+ self.columns[self.active_column_idx].toggle_width(self.view_size);
1394+ }
13651395 }
13661396
13671397 impl Workspace<Window> {
@@ -1510,6 +1540,21 @@ impl<W: LayoutElement> Column<W> {
15101540 assert!(!self.windows.is_empty(), "columns can't be empty");
15111541 assert!(self.active_window_idx < self.windows.len());
15121542 }
1543+
1544+ fn toggle_width(&mut self, view_size: Size<i32, Logical>) {
1545+ let idx = match self.width {
1546+ ColumnWidth::PresetProportion(idx) => (idx + 1) % WIDTH_PROPORTIONS.len(),
1547+ _ => {
1548+ let current = self.size().w;
1549+ WIDTH_PROPORTIONS
1550+ .into_iter()
1551+ .position(|prop| prop.resolve(view_size.w - PADDING) - PADDING > current)
1552+ .unwrap_or(0)
1553+ }
1554+ };
1555+ let width = ColumnWidth::PresetProportion(idx);
1556+ self.set_width(view_size, width);
1557+ }
15131558 }
15141559
15151560 pub fn output_size(output: &Output) -> Size<i32, Logical> {