diff options
| author | Ivan Molodetskikh <yalterz@gmail.com> | 2024-10-10 10:40:59 +0300 |
|---|---|---|
| committer | Ivan Molodetskikh <yalterz@gmail.com> | 2024-10-10 10:40:59 +0300 |
| commit | 810ea245f9d6da11123c87d5c54f990cebd67932 (patch) | |
| tree | 8e52ce7b5e082e12cd77618e3340beba242e58de /src | |
| parent | 58fc5f3b06242fc6d6d3e3339222ebba6a4aac59 (diff) | |
| download | niri-810ea245f9d6da11123c87d5c54f990cebd67932.tar.gz niri-810ea245f9d6da11123c87d5c54f990cebd67932.tar.bz2 niri-810ea245f9d6da11123c87d5c54f990cebd67932.zip | |
layout: Deduplicate default width resolution
Diffstat (limited to 'src')
| -rw-r--r-- | src/layout/mod.rs | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 710ba848..7fe0d230 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -543,14 +543,7 @@ impl<W: LayoutElement> Layout<W> { width: Option<ColumnWidth>, is_full_width: bool, ) -> Option<&Output> { - let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); - if let ColumnWidth::Fixed(w) = &mut width { - let rules = window.rules(); - let border_config = rules.border.resolve_against(self.options.border); - if !border_config.off { - *w += border_config.width.0 * 2.; - } - } + let width = self.resolve_default_width(&window, width); match &mut self.monitor_set { MonitorSet::Normal { @@ -632,14 +625,7 @@ impl<W: LayoutElement> Layout<W> { width: Option<ColumnWidth>, is_full_width: bool, ) -> Option<&Output> { - let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); - if let ColumnWidth::Fixed(w) = &mut width { - let rules = window.rules(); - let border_config = rules.border.resolve_against(self.options.border); - if !border_config.off { - *w += border_config.width.0 * 2.; - } - } + let width = self.resolve_default_width(&window, width); match &mut self.monitor_set { MonitorSet::Normal { @@ -690,14 +676,7 @@ impl<W: LayoutElement> Layout<W> { width: Option<ColumnWidth>, is_full_width: bool, ) -> Option<&Output> { - let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); - if let ColumnWidth::Fixed(w) = &mut width { - let rules = window.rules(); - let border_config = rules.border.resolve_against(self.options.border); - if !border_config.off { - *w += border_config.width.0 * 2.; - } - } + let width = self.resolve_default_width(&window, width); match &mut self.monitor_set { MonitorSet::Normal { monitors, .. } => { @@ -728,14 +707,7 @@ impl<W: LayoutElement> Layout<W> { width: Option<ColumnWidth>, is_full_width: bool, ) { - let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); - if let ColumnWidth::Fixed(w) = &mut width { - let rules = window.rules(); - let border_config = rules.border.resolve_against(self.options.border); - if !border_config.off { - *w += border_config.width.0 * 2.; - } - } + let width = self.resolve_default_width(&window, width); let MonitorSet::Normal { monitors, @@ -2686,6 +2658,18 @@ impl<W: LayoutElement> Layout<W> { pub fn has_window(&self, window: &W::Id) -> bool { self.windows().any(|(_, win)| win.id() == window) } + + fn resolve_default_width(&self, window: &W, width: Option<ColumnWidth>) -> ColumnWidth { + let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); + if let ColumnWidth::Fixed(w) = &mut width { + let rules = window.rules(); + let border_config = rules.border.resolve_against(self.options.border); + if !border_config.off { + *w += border_config.width.0 * 2.; + } + } + width + } } impl<W: LayoutElement> Default for MonitorSet<W> { |
