layout: Deduplicate default width resolution
Browse files at this commit810ea245f9d6da11123c87d5c54f990cebd67932Parent: 58fc5f31 changed file +16 -32
- src/layout/mod.rs +16 -32
src/layout/mod.rsmodified+16 -32
| @@ -543,14 +543,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 543 | width: Option<ColumnWidth>, | 543 | width: Option<ColumnWidth>, |
| 544 | is_full_width: bool, | 544 | is_full_width: bool, |
| 545 | ) -> Option<&Output> { | 545 | ) -> Option<&Output> { |
| 546 | - let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); | 546 | + let width = self.resolve_default_width(&window, width); |
| 547 | - if let ColumnWidth::Fixed(w) = &mut width { | ||
| 548 | - let rules = window.rules(); | ||
| 549 | - let border_config = rules.border.resolve_against(self.options.border); | ||
| 550 | - if !border_config.off { | ||
| 551 | - *w += border_config.width.0 * 2.; | ||
| 552 | - } | ||
| 553 | - } | ||
| 554 | 547 | ||
| 555 | match &mut self.monitor_set { | 548 | match &mut self.monitor_set { |
| 556 | MonitorSet::Normal { | 549 | MonitorSet::Normal { |
| @@ -632,14 +625,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 632 | width: Option<ColumnWidth>, | 625 | width: Option<ColumnWidth>, |
| 633 | is_full_width: bool, | 626 | is_full_width: bool, |
| 634 | ) -> Option<&Output> { | 627 | ) -> Option<&Output> { |
| 635 | - let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); | 628 | + let width = self.resolve_default_width(&window, width); |
| 636 | - if let ColumnWidth::Fixed(w) = &mut width { | ||
| 637 | - let rules = window.rules(); | ||
| 638 | - let border_config = rules.border.resolve_against(self.options.border); | ||
| 639 | - if !border_config.off { | ||
| 640 | - *w += border_config.width.0 * 2.; | ||
| 641 | - } | ||
| 642 | - } | ||
| 643 | 629 | ||
| 644 | match &mut self.monitor_set { | 630 | match &mut self.monitor_set { |
| 645 | MonitorSet::Normal { | 631 | MonitorSet::Normal { |
| @@ -690,14 +676,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 690 | width: Option<ColumnWidth>, | 676 | width: Option<ColumnWidth>, |
| 691 | is_full_width: bool, | 677 | is_full_width: bool, |
| 692 | ) -> Option<&Output> { | 678 | ) -> Option<&Output> { |
| 693 | - let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); | 679 | + let width = self.resolve_default_width(&window, width); |
| 694 | - if let ColumnWidth::Fixed(w) = &mut width { | ||
| 695 | - let rules = window.rules(); | ||
| 696 | - let border_config = rules.border.resolve_against(self.options.border); | ||
| 697 | - if !border_config.off { | ||
| 698 | - *w += border_config.width.0 * 2.; | ||
| 699 | - } | ||
| 700 | - } | ||
| 701 | 680 | ||
| 702 | match &mut self.monitor_set { | 681 | match &mut self.monitor_set { |
| 703 | MonitorSet::Normal { monitors, .. } => { | 682 | MonitorSet::Normal { monitors, .. } => { |
| @@ -728,14 +707,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 728 | width: Option<ColumnWidth>, | 707 | width: Option<ColumnWidth>, |
| 729 | is_full_width: bool, | 708 | is_full_width: bool, |
| 730 | ) { | 709 | ) { |
| 731 | - let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); | 710 | + let width = self.resolve_default_width(&window, width); |
| 732 | - if let ColumnWidth::Fixed(w) = &mut width { | ||
| 733 | - let rules = window.rules(); | ||
| 734 | - let border_config = rules.border.resolve_against(self.options.border); | ||
| 735 | - if !border_config.off { | ||
| 736 | - *w += border_config.width.0 * 2.; | ||
| 737 | - } | ||
| 738 | - } | ||
| 739 | 711 | ||
| 740 | let MonitorSet::Normal { | 712 | let MonitorSet::Normal { |
| 741 | monitors, | 713 | monitors, |
| @@ -2686,6 +2658,18 @@ impl<W: LayoutElement> Layout<W> { | |||
| 2686 | pub fn has_window(&self, window: &W::Id) -> bool { | 2658 | pub fn has_window(&self, window: &W::Id) -> bool { |
| 2687 | self.windows().any(|(_, win)| win.id() == window) | 2659 | self.windows().any(|(_, win)| win.id() == window) |
| 2688 | } | 2660 | } |
| 2661 | + | ||
| 2662 | + fn resolve_default_width(&self, window: &W, width: Option<ColumnWidth>) -> ColumnWidth { | ||
| 2663 | + let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w))); | ||
| 2664 | + if let ColumnWidth::Fixed(w) = &mut width { | ||
| 2665 | + let rules = window.rules(); | ||
| 2666 | + let border_config = rules.border.resolve_against(self.options.border); | ||
| 2667 | + if !border_config.off { | ||
| 2668 | + *w += border_config.width.0 * 2.; | ||
| 2669 | + } | ||
| 2670 | + } | ||
| 2671 | + width | ||
| 2672 | + } | ||
| 2689 | } | 2673 | } |
| 2690 | 2674 | ||
| 2691 | impl<W: LayoutElement> Default for MonitorSet<W> { | 2675 | impl<W: LayoutElement> Default for MonitorSet<W> { |