Skip to content

Commit

Permalink
layout: Deduplicate default width resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
YaLTeR committed Oct 10, 2024
1 parent 58fc5f3 commit 810ea24
Showing 1 changed file with 16 additions and 32 deletions.
48 changes: 16 additions & 32 deletions src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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, .. } => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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> {
Expand Down

0 comments on commit 810ea24

Please sign in to comment.