mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-24 02:01:18 +07:00
layout: Deduplicate default width resolution
This commit is contained in:
+16
-32
@@ -543,14 +543,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
width: Option<ColumnWidth>,
|
width: Option<ColumnWidth>,
|
||||||
is_full_width: bool,
|
is_full_width: bool,
|
||||||
) -> Option<&Output> {
|
) -> Option<&Output> {
|
||||||
let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
|
let width = self.resolve_default_width(&window, width);
|
||||||
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.;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match &mut self.monitor_set {
|
match &mut self.monitor_set {
|
||||||
MonitorSet::Normal {
|
MonitorSet::Normal {
|
||||||
@@ -632,14 +625,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
width: Option<ColumnWidth>,
|
width: Option<ColumnWidth>,
|
||||||
is_full_width: bool,
|
is_full_width: bool,
|
||||||
) -> Option<&Output> {
|
) -> Option<&Output> {
|
||||||
let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
|
let width = self.resolve_default_width(&window, width);
|
||||||
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.;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match &mut self.monitor_set {
|
match &mut self.monitor_set {
|
||||||
MonitorSet::Normal {
|
MonitorSet::Normal {
|
||||||
@@ -690,14 +676,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
width: Option<ColumnWidth>,
|
width: Option<ColumnWidth>,
|
||||||
is_full_width: bool,
|
is_full_width: bool,
|
||||||
) -> Option<&Output> {
|
) -> Option<&Output> {
|
||||||
let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
|
let width = self.resolve_default_width(&window, width);
|
||||||
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.;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match &mut self.monitor_set {
|
match &mut self.monitor_set {
|
||||||
MonitorSet::Normal { monitors, .. } => {
|
MonitorSet::Normal { monitors, .. } => {
|
||||||
@@ -728,14 +707,7 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
width: Option<ColumnWidth>,
|
width: Option<ColumnWidth>,
|
||||||
is_full_width: bool,
|
is_full_width: bool,
|
||||||
) {
|
) {
|
||||||
let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
|
let width = self.resolve_default_width(&window, width);
|
||||||
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 MonitorSet::Normal {
|
let MonitorSet::Normal {
|
||||||
monitors,
|
monitors,
|
||||||
@@ -2686,6 +2658,18 @@ impl<W: LayoutElement> Layout<W> {
|
|||||||
pub fn has_window(&self, window: &W::Id) -> bool {
|
pub fn has_window(&self, window: &W::Id) -> bool {
|
||||||
self.windows().any(|(_, win)| win.id() == window)
|
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> {
|
impl<W: LayoutElement> Default for MonitorSet<W> {
|
||||||
|
|||||||
Reference in New Issue
Block a user