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
65 | <kbd>Mod</kbd><kbd>Ctrl</kbd><kbd>I</kbd> | Move the focused window to the workspace above |65 | <kbd>Mod</kbd><kbd>Ctrl</kbd><kbd>I</kbd> | Move the focused window to the workspace above |
66 | <kbd>Mod</kbd><kbd>,</kbd> | Consume the window to the right into the focused column |66 | <kbd>Mod</kbd><kbd>,</kbd> | Consume the window to the right into the focused column |
67 | <kbd>Mod</kbd><kbd>.</kbd> | Expel the focused window into its own column |67 | <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 |
68 | <kbd>Mod</kbd><kbd>Shift</kbd><kbd>E</kbd> | Exit niri |69 | <kbd>Mod</kbd><kbd>Shift</kbd><kbd>E</kbd> | Exit niri |
69 70
70 [PaperWM]: https://github.com/paperwm/PaperWM71 [PaperWM]: https://github.com/paperwm/PaperWM
src/input.rsmodified+5 -0
@@ -32,6 +32,7 @@ enum Action {
32 SwitchWorkspaceUp,32 SwitchWorkspaceUp,
33 MoveToWorkspaceDown,33 MoveToWorkspaceDown,
34 MoveToWorkspaceUp,34 MoveToWorkspaceUp,
35+ ToggleWidth,
35 }36 }
36 37
37 pub enum CompositorMod {38 pub enum CompositorMod {
@@ -88,6 +89,7 @@ fn action(comp_mod: CompositorMod, keysym: KeysymHandle, mods: ModifiersState) -
88 KEY_i => Action::SwitchWorkspaceUp,89 KEY_i => Action::SwitchWorkspaceUp,
89 KEY_comma => Action::ConsumeIntoColumn,90 KEY_comma => Action::ConsumeIntoColumn,
90 KEY_period => Action::ExpelFromColumn,91 KEY_period => Action::ExpelFromColumn,
92+ KEY_r => Action::ToggleWidth,
91 _ => Action::None,93 _ => Action::None,
92 }94 }
93 }95 }
@@ -225,6 +227,9 @@ impl Niri {
225 // FIXME: granular227 // FIXME: granular
226 self.queue_redraw_all();228 self.queue_redraw_all();
227 }229 }
230+ Action::ToggleWidth => {
231+ self.monitor_set.toggle_width();
232+ }
228 }233 }
229 }234 }
230 }235 }
src/layout.rsmodified+45 -0
@@ -50,6 +50,11 @@ use smithay::wayland::shell::xdg::XdgToplevelSurfaceData;
50 use crate::animation::Animation;50 use crate::animation::Animation;
51 51
52 const PADDING: i32 = 16;52 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+];
53 58
54 #[derive(Debug, Clone, PartialEq, Eq)]59 #[derive(Debug, Clone, PartialEq, Eq)]
55 pub struct OutputId(String);60 pub struct OutputId(String);
@@ -135,6 +140,11 @@ pub struct Workspace<W: LayoutElement> {
135 enum ColumnWidth {140 enum ColumnWidth {
136 /// Proportion of the current view width.141 /// Proportion of the current view width.
137 Proportion(f64),142 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),
138 /// Fixed width in logical pixels.148 /// Fixed width in logical pixels.
139 Fixed(i32),149 Fixed(i32),
140 }150 }
@@ -199,6 +209,7 @@ impl ColumnWidth {
199 fn resolve(self, view_width: i32) -> i32 {209 fn resolve(self, view_width: i32) -> i32 {
200 match self {210 match self {
201 ColumnWidth::Proportion(proportion) => (view_width as f64 * proportion).floor() as i32,211 ColumnWidth::Proportion(proportion) => (view_width as f64 * proportion).floor() as i32,
212+ ColumnWidth::PresetProportion(idx) => WIDTH_PROPORTIONS[idx].resolve(view_width),
202 ColumnWidth::Fixed(width) => width,213 ColumnWidth::Fixed(width) => width,
203 }214 }
204 }215 }
@@ -741,6 +752,13 @@ impl<W: LayoutElement> MonitorSet<W> {
741 }752 }
742 }753 }
743 }754 }
755+
756+ pub fn toggle_width(&mut self) {
757+ let Some(monitor) = self.active_monitor() else {
758+ return;
759+ };
760+ monitor.toggle_width();
761+ }
744 }762 }
745 763
746 impl MonitorSet<Window> {764 impl MonitorSet<Window> {
@@ -954,6 +972,10 @@ impl<W: LayoutElement> Monitor<W> {
954 ws.advance_animations(current_time);972 ws.advance_animations(current_time);
955 }973 }
956 }974 }
975+
976+ fn toggle_width(&mut self) {
977+ self.active_workspace().toggle_width();
978+ }
957 }979 }
958 980
959 impl Monitor<Window> {981 impl Monitor<Window> {
@@ -1362,6 +1384,14 @@ impl<W: LayoutElement> Workspace<W> {
1362 1384
1363 None1385 None
1364 }1386 }
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+ }
1365 }1395 }
1366 1396
1367 impl Workspace<Window> {1397 impl Workspace<Window> {
@@ -1510,6 +1540,21 @@ impl<W: LayoutElement> Column<W> {
1510 assert!(!self.windows.is_empty(), "columns can't be empty");1540 assert!(!self.windows.is_empty(), "columns can't be empty");
1511 assert!(self.active_window_idx < self.windows.len());1541 assert!(self.active_window_idx < self.windows.len());
1512 }1542 }
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+ }
1513 }1558 }
1514 1559
1515 pub fn output_size(output: &Output) -> Size<i32, Logical> {1560 pub fn output_size(output: &Output) -> Size<i32, Logical> {