forge
Explore
Log in

Don't you dare go Hollow

Add set-window-height action

Browse files at this commit

c1060cd26b1eb00e1bd1f8fda367ffd7b332fc0cIvan MolodetskikhParent: dc9cee4
resources/default-config.kdlmodified+4 -0
@@ -226,6 +226,10 @@ binds {
226 Mod+Minus { set-column-width "-10%"; }226 Mod+Minus { set-column-width "-10%"; }
227 Mod+Equal { set-column-width "+10%"; }227 Mod+Equal { set-column-width "+10%"; }
228 228
229+ // Finer height adjustments when in column with other windows.
230+ Mod+Shift+Minus { set-window-height "-10%"; }
231+ Mod+Shift+Equal { set-window-height "+10%"; }
232+
229 Print { screenshot; }233 Print { screenshot; }
230 Ctrl+Print { screenshot-screen; }234 Ctrl+Print { screenshot-screen; }
231 Alt+Print { screenshot-window; }235 Alt+Print { screenshot-window; }
src/config.rsmodified+1 -0
@@ -284,6 +284,7 @@ pub enum Action {
284 MoveWindowToMonitorRight,284 MoveWindowToMonitorRight,
285 MoveWindowToMonitorDown,285 MoveWindowToMonitorDown,
286 MoveWindowToMonitorUp,286 MoveWindowToMonitorUp,
287+ SetWindowHeight(#[knuffel(argument, str)] SizeChange),
287 SwitchPresetColumnWidth,288 SwitchPresetColumnWidth,
288 MaximizeColumn,289 MaximizeColumn,
289 SetColumnWidth(#[knuffel(argument, str)] SizeChange),290 SetColumnWidth(#[knuffel(argument, str)] SizeChange),
src/input.rsmodified+3 -0
@@ -325,6 +325,9 @@ impl State {
325 Action::SetColumnWidth(change) => {325 Action::SetColumnWidth(change) => {
326 self.niri.layout.set_column_width(change);326 self.niri.layout.set_column_width(change);
327 }327 }
328+ Action::SetWindowHeight(change) => {
329+ self.niri.layout.set_window_height(change);
330+ }
328 }331 }
329 }332 }
330 InputEvent::PointerMotion { event, .. } => {333 InputEvent::PointerMotion { event, .. } => {
src/layout.rsmodified+65 -0
@@ -1223,6 +1223,13 @@ impl<W: LayoutElement> Layout<W> {
1223 monitor.set_column_width(change);1223 monitor.set_column_width(change);
1224 }1224 }
1225 1225
1226+ pub fn set_window_height(&mut self, change: SizeChange) {
1227+ let Some(monitor) = self.active_monitor() else {
1228+ return;
1229+ };
1230+ monitor.set_window_height(change);
1231+ }
1232+
1226 pub fn focus_output(&mut self, output: &Output) {1233 pub fn focus_output(&mut self, output: &Output) {
1227 if let MonitorSet::Normal {1234 if let MonitorSet::Normal {
1228 monitors,1235 monitors,
@@ -1738,6 +1745,10 @@ impl<W: LayoutElement> Monitor<W> {
1738 self.active_workspace().set_column_width(change);1745 self.active_workspace().set_column_width(change);
1739 }1746 }
1740 1747
1748+ fn set_window_height(&mut self, change: SizeChange) {
1749+ self.active_workspace().set_window_height(change);
1750+ }
1751+
1741 fn move_workspace_down(&mut self) {1752 fn move_workspace_down(&mut self) {
1742 let new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1);1753 let new_idx = min(self.active_workspace_idx + 1, self.workspaces.len() - 1);
1743 if new_idx == self.active_workspace_idx {1754 if new_idx == self.active_workspace_idx {
@@ -2453,6 +2464,14 @@ impl<W: LayoutElement> Workspace<W> {
2453 self.columns[self.active_column_idx].set_column_width(change);2464 self.columns[self.active_column_idx].set_column_width(change);
2454 }2465 }
2455 2466
2467+ fn set_window_height(&mut self, change: SizeChange) {
2468+ if self.columns.is_empty() {
2469+ return;
2470+ }
2471+
2472+ self.columns[self.active_column_idx].set_window_height(change);
2473+ }
2474+
2456 pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) {2475 pub fn set_fullscreen(&mut self, window: &W, is_fullscreen: bool) {
2457 let (mut col_idx, win_idx) = self2476 let (mut col_idx, win_idx) = self
2458 .columns2477 .columns
@@ -2944,6 +2963,50 @@ impl<W: LayoutElement> Column<W> {
2944 self.set_width(width);2963 self.set_width(width);
2945 }2964 }
2946 2965
2966+ fn set_window_height(&mut self, change: SizeChange) {
2967+ let current = self.heights[self.active_window_idx];
2968+ let current_px = match current {
2969+ WindowHeight::Auto => self.windows[self.active_window_idx].geometry().size.h,
2970+ WindowHeight::Fixed(height) => height,
2971+ };
2972+ let current_prop = (current_px + self.options.gaps) as f64
2973+ / (self.working_area.size.h - self.options.gaps) as f64;
2974+
2975+ // FIXME: fix overflows then remove limits.
2976+ const MAX_PX: i32 = 100000;
2977+
2978+ let mut height = match change {
2979+ SizeChange::SetFixed(fixed) => fixed,
2980+ SizeChange::SetProportion(proportion) => {
2981+ ((self.working_area.size.h - self.options.gaps) as f64 * proportion
2982+ - self.options.gaps as f64)
2983+ .round() as i32
2984+ }
2985+ SizeChange::AdjustFixed(delta) => current_px.saturating_add(delta),
2986+ SizeChange::AdjustProportion(delta) => {
2987+ let proportion = current_prop + delta / 100.;
2988+ ((self.working_area.size.h - self.options.gaps) as f64 * proportion
2989+ - self.options.gaps as f64)
2990+ .round() as i32
2991+ }
2992+ };
2993+
2994+ // Clamp it against the window height constraints.
2995+ let win = &self.windows[self.active_window_idx];
2996+ let min_h = win.min_size().h;
2997+ let max_h = win.max_size().h;
2998+
2999+ if max_h > 0 {
3000+ height = height.min(max_h);
3001+ }
3002+ if min_h > 0 {
3003+ height = height.max(min_h);
3004+ }
3005+
3006+ self.heights[self.active_window_idx] = WindowHeight::Fixed(height.clamp(1, MAX_PX));
3007+ self.update_window_sizes();
3008+ }
3009+
2947 fn set_fullscreen(&mut self, is_fullscreen: bool) {3010 fn set_fullscreen(&mut self, is_fullscreen: bool) {
2948 assert_eq!(self.windows.len(), 1);3011 assert_eq!(self.windows.len(), 1);
2949 self.is_fullscreen = is_fullscreen;3012 self.is_fullscreen = is_fullscreen;
@@ -3189,6 +3252,7 @@ mod tests {
3189 SwitchPresetColumnWidth,3252 SwitchPresetColumnWidth,
3190 MaximizeColumn,3253 MaximizeColumn,
3191 SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),3254 SetColumnWidth(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
3255+ SetWindowHeight(#[proptest(strategy = "arbitrary_size_change()")] SizeChange),
3192 Communicate(#[proptest(strategy = "1..=5usize")] usize),3256 Communicate(#[proptest(strategy = "1..=5usize")] usize),
3193 }3257 }
3194 3258
@@ -3301,6 +3365,7 @@ mod tests {
3301 Op::SwitchPresetColumnWidth => layout.toggle_width(),3365 Op::SwitchPresetColumnWidth => layout.toggle_width(),
3302 Op::MaximizeColumn => layout.toggle_full_width(),3366 Op::MaximizeColumn => layout.toggle_full_width(),
3303 Op::SetColumnWidth(change) => layout.set_column_width(change),3367 Op::SetColumnWidth(change) => layout.set_column_width(change),
3368+ Op::SetWindowHeight(change) => layout.set_window_height(change),
3304 Op::Communicate(id) => {3369 Op::Communicate(id) => {
3305 let mut window = None;3370 let mut window = None;
3306 match &mut layout.monitor_set {3371 match &mut layout.monitor_set {