aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2025-09-26 17:16:53 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2025-10-02 09:33:08 +0300
commit67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82 (patch)
tree04905e3ae42d7dbf574d50b2a3b356ec363ded1b
parent9ff1c90fa6a4bb962e0a9c76e18552a245177c53 (diff)
downloadniri-67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82.tar.gz
niri-67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82.tar.bz2
niri-67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82.zip
layout: Move scrolling width resolution to workspace
This is required now with per-output and per-workspace options.
-rw-r--r--src/layout/mod.rs26
-rw-r--r--src/layout/monitor.rs51
-rw-r--r--src/layout/workspace.rs24
3 files changed, 59 insertions, 42 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 09cc68c1..c04a72ba 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -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> {
diff --git a/src/layout/monitor.rs b/src/layout/monitor.rs
index 9e34ad35..5e463a7e 100644
--- a/src/layout/monitor.rs
+++ b/src/layout/monitor.rs
@@ -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];
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 3831ffe3..5bdd2624 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -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()