layout: Move scrolling width resolution to workspace

This is required now with per-output and per-workspace options.
This commit is contained in:
Ivan Molodetskikh
2025-09-26 17:16:53 +03:00
parent 9ff1c90fa6
commit 67ca2cb06c
3 changed files with 59 additions and 42 deletions

View File

@@ -865,7 +865,6 @@ impl<W: LayoutElement> Layout<W> {
is_floating: bool,
activate: ActivateWindow,
) -> Option<&Output> {
let scrolling_width = self.resolve_scrolling_width(&window, width);
let scrolling_height = height.map(SizeChange::from);
let id = window.id().clone();
@@ -933,6 +932,10 @@ impl<W: LayoutElement> Layout<W> {
};
let mon = &mut monitors[mon_idx];
let (ws_idx, _) = mon.resolve_add_window_target(target);
let ws = &mon.workspaces[ws_idx];
let scrolling_width = ws.resolve_scrolling_width(&window, width);
mon.add_window(
window,
target,
@@ -1012,6 +1015,8 @@ impl<W: LayoutElement> Layout<W> {
};
let ws = &mut workspaces[ws_idx];
let scrolling_width = ws.resolve_scrolling_width(&window, width);
let tile = ws.make_tile(window);
ws.add_tile(
tile,
@@ -4901,25 +4906,6 @@ impl<W: LayoutElement> Layout<W> {
pub fn is_overview_open(&self) -> bool {
self.overview_open
}
fn resolve_scrolling_width(&self, window: &W, width: Option<PresetSize>) -> ColumnWidth {
let width = width.unwrap_or_else(|| PresetSize::Fixed(window.size().w));
match width {
PresetSize::Fixed(fixed) => {
let mut fixed = f64::from(fixed);
// Add border width since ColumnWidth includes borders.
let rules = window.rules();
let border = self.options.layout.border.merged_with(&rules.border);
if !border.off {
fixed += border.width * 2.;
}
ColumnWidth::Fixed(fixed)
}
PresetSize::Proportion(prop) => ColumnWidth::Proportion(prop),
}
}
}
impl<W: LayoutElement> Default for MonitorSet<W> {

View File

@@ -480,6 +480,34 @@ impl<W: LayoutElement> Monitor<W> {
}
}
pub(super) fn resolve_add_window_target<'a>(
&mut self,
target: MonitorAddWindowTarget<'a, W>,
) -> (usize, WorkspaceAddWindowTarget<'a, W>) {
match target {
MonitorAddWindowTarget::Auto => {
(self.active_workspace_idx, WorkspaceAddWindowTarget::Auto)
}
MonitorAddWindowTarget::Workspace { id, column_idx } => {
let idx = self.workspaces.iter().position(|ws| ws.id() == id).unwrap();
let target = if let Some(column_idx) = column_idx {
WorkspaceAddWindowTarget::NewColumnAt(column_idx)
} else {
WorkspaceAddWindowTarget::Auto
};
(idx, target)
}
MonitorAddWindowTarget::NextTo(win_id) => {
let idx = self
.workspaces
.iter_mut()
.position(|ws| ws.has_window(win_id))
.unwrap();
(idx, WorkspaceAddWindowTarget::NextTo(win_id))
}
}
}
pub fn add_window(
&mut self,
window: W,
@@ -539,28 +567,7 @@ impl<W: LayoutElement> Monitor<W> {
is_full_width: bool,
is_floating: bool,
) {
let (mut workspace_idx, target) = match target {
MonitorAddWindowTarget::Auto => {
(self.active_workspace_idx, WorkspaceAddWindowTarget::Auto)
}
MonitorAddWindowTarget::Workspace { id, column_idx } => {
let idx = self.workspaces.iter().position(|ws| ws.id() == id).unwrap();
let target = if let Some(column_idx) = column_idx {
WorkspaceAddWindowTarget::NewColumnAt(column_idx)
} else {
WorkspaceAddWindowTarget::Auto
};
(idx, target)
}
MonitorAddWindowTarget::NextTo(win_id) => {
let idx = self
.workspaces
.iter_mut()
.position(|ws| ws.has_window(win_id))
.unwrap();
(idx, WorkspaceAddWindowTarget::NextTo(win_id))
}
};
let (mut workspace_idx, target) = self.resolve_add_window_target(target);
let workspace = &mut self.workspaces[workspace_idx];

View File

@@ -2,6 +2,7 @@ use std::cmp::max;
use std::rc::Rc;
use std::time::Duration;
use niri_config::utils::MergeWith as _;
use niri_config::{
CenterFocusedColumn, CornerRadius, OutputName, PresetSize, Workspace as WorkspaceConfig,
};
@@ -882,6 +883,29 @@ impl<W: LayoutElement> Workspace<W> {
});
}
pub(super) fn resolve_scrolling_width(
&self,
window: &W,
width: Option<PresetSize>,
) -> ColumnWidth {
let width = width.unwrap_or_else(|| PresetSize::Fixed(window.size().w));
match width {
PresetSize::Fixed(fixed) => {
let mut fixed = f64::from(fixed);
// Add border width since ColumnWidth includes borders.
let rules = window.rules();
let border = self.options.layout.border.merged_with(&rules.border);
if !border.off {
fixed += border.width * 2.;
}
ColumnWidth::Fixed(fixed)
}
PresetSize::Proportion(prop) => ColumnWidth::Proportion(prop),
}
}
pub fn focus_left(&mut self) -> bool {
if self.floating_is_active.get() {
self.floating.focus_left()