From 810ea245f9d6da11123c87d5c54f990cebd67932 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Thu, 10 Oct 2024 10:40:59 +0300 Subject: layout: Deduplicate default width resolution --- src/layout/mod.rs | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) (limited to 'src') 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 Layout { width: Option, 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 Layout { width: Option, 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 Layout { width: Option, 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 Layout { width: Option, 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 Layout { 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 { + 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 Default for MonitorSet { -- cgit