diff options
Diffstat (limited to 'src/layout')
| -rw-r--r-- | src/layout/mod.rs | 29 | ||||
| -rw-r--r-- | src/layout/scrolling.rs | 21 | ||||
| -rw-r--r-- | src/layout/workspace.rs | 2 |
3 files changed, 49 insertions, 3 deletions
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<W: LayoutElement> Layout<W> { /// 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<W>, width: Option<ColumnWidth>, + height: Option<PresetSize>, 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<W: LayoutElement> Layout<W> { *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<W: LayoutElement> Layout<W> { 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(), diff --git a/src/layout/scrolling.rs b/src/layout/scrolling.rs index 6fa6fbfc..10101cca 100644 --- a/src/layout/scrolling.rs +++ b/src/layout/scrolling.rs @@ -399,6 +399,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { pub fn new_window_size( &self, width: Option<ColumnWidth>, + height: Option<PresetSize>, rules: &ResolvedWindowRules, ) -> Size<i32, Logical> { let border = rules.border.resolve_against(self.options.border); @@ -417,11 +418,27 @@ impl<W: LayoutElement> ScrollingSpace<W> { 0 }; - let mut height = self.working_area.size.h - self.options.gaps * 2.; + let mut full_height = self.working_area.size.h - self.options.gaps * 2.; if !border.off { - height -= border.width.0 * 2.; + full_height -= border.width.0 * 2.; } + let height = if let Some(height) = height { + let height = match resolve_preset_size(height, &self.options, self.working_area.size.h) + { + ResolvedSize::Tile(mut size) => { + if !border.off { + size -= border.width.0 * 2.; + } + size + } + ResolvedSize::Window(size) => size, + }; + f64::min(height, full_height) + } else { + full_height + }; + Size::from((width, max(height.floor() as i32, 1))) } diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 0e67f3b3..c77fb44f 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -740,7 +740,7 @@ impl<W: LayoutElement> Workspace<W> { let mut size = if is_floating { self.floating.new_window_size(width, height, rules) } else { - self.scrolling.new_window_size(width, rules) + self.scrolling.new_window_size(width, height, rules) }; // If the window has a fixed size, or we're picking some fixed size, apply min and max |
