From 8409107a5bb04980ea196a5d7095d5c34f6b2e4e Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Mon, 30 Dec 2024 08:48:05 +0300 Subject: Implement default-window-height for scrolling windows --- src/layout/mod.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/layout/mod.rs') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 2e05392d..97d3d1e1 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -839,16 +839,23 @@ impl Layout { /// Adds a new window to the layout. /// /// Returns an output that the window was added to, if there were any outputs. + #[allow(clippy::too_many_arguments)] pub fn add_window( &mut self, window: W, target: AddWindowTarget, width: Option, + height: Option, is_full_width: bool, is_floating: bool, activate: ActivateWindow, ) -> Option<&Output> { let resolved_width = self.resolve_default_width(&window, width, is_floating); + let resolved_height = height.map(|h| match h { + PresetSize::Proportion(prop) => SizeChange::SetProportion(prop * 100.), + PresetSize::Fixed(fixed) => SizeChange::SetFixed(fixed), + }); + let id = window.id().clone(); match &mut self.monitor_set { MonitorSet::Normal { @@ -927,6 +934,18 @@ impl Layout { *active_monitor_idx = mon_idx; } + // Set the default height for scrolling windows. + if !is_floating { + if let Some(change) = resolved_height { + let ws = mon + .workspaces + .iter_mut() + .find(|ws| ws.has_window(&id)) + .unwrap(); + ws.set_window_height(Some(&id), change); + } + } + Some(&mon.output) } MonitorSet::NoOutputs { workspaces } => { @@ -983,6 +1002,13 @@ impl Layout { is_floating, ); + // Set the default height for scrolling windows. + if !is_floating { + if let Some(change) = resolved_height { + ws.set_window_height(Some(&id), change); + } + } + None } } @@ -4693,6 +4719,7 @@ mod tests { win, AddWindowTarget::Auto, None, + None, false, params.is_floating, ActivateWindow::default(), @@ -4760,6 +4787,7 @@ mod tests { win, AddWindowTarget::NextTo(&next_to_id), None, + None, false, params.is_floating, ActivateWindow::default(), @@ -4832,6 +4860,7 @@ mod tests { win, AddWindowTarget::Workspace(ws_id), None, + None, false, params.is_floating, ActivateWindow::default(), -- cgit