mirror of
https://github.com/YaLTeR/niri.git
synced 2025-10-05 16:12:47 +02:00
layout: Move scrolling width resolution to workspace
This is required now with per-output and per-workspace options.
This commit is contained in:
@@ -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> {
|
||||
|
@@ -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];
|
||||
|
||||
|
@@ -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()
|
||||
|
Reference in New Issue
Block a user