forge
Explore
Log in

Don't you dare go Hollow

layout: Move scrolling width resolution to workspace

Browse files at this commit

67ca2cb06cce62e75ea7077f0fdaf54b9f45ea82Ivan MolodetskikhParent: 9ff1c90
This is required now with per-output and per-workspace options.
src/layout/mod.rsmodified+6 -20
@@ -865,7 +865,6 @@ impl<W: LayoutElement> Layout<W> {
865 is_floating: bool,865 is_floating: bool,
866 activate: ActivateWindow,866 activate: ActivateWindow,
867 ) -> Option<&Output> {867 ) -> Option<&Output> {
868- let scrolling_width = self.resolve_scrolling_width(&window, width);
869 let scrolling_height = height.map(SizeChange::from);868 let scrolling_height = height.map(SizeChange::from);
870 let id = window.id().clone();869 let id = window.id().clone();
871 870
@@ -933,6 +932,10 @@ impl<W: LayoutElement> Layout<W> {
933 };932 };
934 let mon = &mut monitors[mon_idx];933 let mon = &mut monitors[mon_idx];
935 934
935+ let (ws_idx, _) = mon.resolve_add_window_target(target);
936+ let ws = &mon.workspaces[ws_idx];
937+ let scrolling_width = ws.resolve_scrolling_width(&window, width);
938+
936 mon.add_window(939 mon.add_window(
937 window,940 window,
938 target,941 target,
@@ -1012,6 +1015,8 @@ impl<W: LayoutElement> Layout<W> {
1012 };1015 };
1013 let ws = &mut workspaces[ws_idx];1016 let ws = &mut workspaces[ws_idx];
1014 1017
1018+ let scrolling_width = ws.resolve_scrolling_width(&window, width);
1019+
1015 let tile = ws.make_tile(window);1020 let tile = ws.make_tile(window);
1016 ws.add_tile(1021 ws.add_tile(
1017 tile,1022 tile,
@@ -4901,25 +4906,6 @@ impl<W: LayoutElement> Layout<W> {
4901 pub fn is_overview_open(&self) -> bool {4906 pub fn is_overview_open(&self) -> bool {
4902 self.overview_open4907 self.overview_open
4903 }4908 }
4904-
4905- fn resolve_scrolling_width(&self, window: &W, width: Option<PresetSize>) -> ColumnWidth {
4906- let width = width.unwrap_or_else(|| PresetSize::Fixed(window.size().w));
4907- match width {
4908- PresetSize::Fixed(fixed) => {
4909- let mut fixed = f64::from(fixed);
4910-
4911- // Add border width since ColumnWidth includes borders.
4912- let rules = window.rules();
4913- let border = self.options.layout.border.merged_with(&rules.border);
4914- if !border.off {
4915- fixed += border.width * 2.;
4916- }
4917-
4918- ColumnWidth::Fixed(fixed)
4919- }
4920- PresetSize::Proportion(prop) => ColumnWidth::Proportion(prop),
4921- }
4922- }
4923 }4909 }
4924 4910
4925 impl<W: LayoutElement> Default for MonitorSet<W> {4911 impl<W: LayoutElement> Default for MonitorSet<W> {
src/layout/monitor.rsmodified+29 -22
@@ -480,6 +480,34 @@ impl<W: LayoutElement> Monitor<W> {
480 }480 }
481 }481 }
482 482
483+ pub(super) fn resolve_add_window_target<'a>(
484+ &mut self,
485+ target: MonitorAddWindowTarget<'a, W>,
486+ ) -> (usize, WorkspaceAddWindowTarget<'a, W>) {
487+ match target {
488+ MonitorAddWindowTarget::Auto => {
489+ (self.active_workspace_idx, WorkspaceAddWindowTarget::Auto)
490+ }
491+ MonitorAddWindowTarget::Workspace { id, column_idx } => {
492+ let idx = self.workspaces.iter().position(|ws| ws.id() == id).unwrap();
493+ let target = if let Some(column_idx) = column_idx {
494+ WorkspaceAddWindowTarget::NewColumnAt(column_idx)
495+ } else {
496+ WorkspaceAddWindowTarget::Auto
497+ };
498+ (idx, target)
499+ }
500+ MonitorAddWindowTarget::NextTo(win_id) => {
501+ let idx = self
502+ .workspaces
503+ .iter_mut()
504+ .position(|ws| ws.has_window(win_id))
505+ .unwrap();
506+ (idx, WorkspaceAddWindowTarget::NextTo(win_id))
507+ }
508+ }
509+ }
510+
483 pub fn add_window(511 pub fn add_window(
484 &mut self,512 &mut self,
485 window: W,513 window: W,
@@ -539,28 +567,7 @@ impl<W: LayoutElement> Monitor<W> {
539 is_full_width: bool,567 is_full_width: bool,
540 is_floating: bool,568 is_floating: bool,
541 ) {569 ) {
542- let (mut workspace_idx, target) = match target {570+ let (mut workspace_idx, target) = self.resolve_add_window_target(target);
543- MonitorAddWindowTarget::Auto => {
544- (self.active_workspace_idx, WorkspaceAddWindowTarget::Auto)
545- }
546- MonitorAddWindowTarget::Workspace { id, column_idx } => {
547- let idx = self.workspaces.iter().position(|ws| ws.id() == id).unwrap();
548- let target = if let Some(column_idx) = column_idx {
549- WorkspaceAddWindowTarget::NewColumnAt(column_idx)
550- } else {
551- WorkspaceAddWindowTarget::Auto
552- };
553- (idx, target)
554- }
555- MonitorAddWindowTarget::NextTo(win_id) => {
556- let idx = self
557- .workspaces
558- .iter_mut()
559- .position(|ws| ws.has_window(win_id))
560- .unwrap();
561- (idx, WorkspaceAddWindowTarget::NextTo(win_id))
562- }
563- };
564 571
565 let workspace = &mut self.workspaces[workspace_idx];572 let workspace = &mut self.workspaces[workspace_idx];
566 573
src/layout/workspace.rsmodified+24 -0
@@ -2,6 +2,7 @@ use std::cmp::max;
2 use std::rc::Rc;2 use std::rc::Rc;
3 use std::time::Duration;3 use std::time::Duration;
4 4
5+use niri_config::utils::MergeWith as _;
5 use niri_config::{6 use niri_config::{
6 CenterFocusedColumn, CornerRadius, OutputName, PresetSize, Workspace as WorkspaceConfig,7 CenterFocusedColumn, CornerRadius, OutputName, PresetSize, Workspace as WorkspaceConfig,
7 };8 };
@@ -882,6 +883,29 @@ impl<W: LayoutElement> Workspace<W> {
882 });883 });
883 }884 }
884 885
886+ pub(super) fn resolve_scrolling_width(
887+ &self,
888+ window: &W,
889+ width: Option<PresetSize>,
890+ ) -> ColumnWidth {
891+ let width = width.unwrap_or_else(|| PresetSize::Fixed(window.size().w));
892+ match width {
893+ PresetSize::Fixed(fixed) => {
894+ let mut fixed = f64::from(fixed);
895+
896+ // Add border width since ColumnWidth includes borders.
897+ let rules = window.rules();
898+ let border = self.options.layout.border.merged_with(&rules.border);
899+ if !border.off {
900+ fixed += border.width * 2.;
901+ }
902+
903+ ColumnWidth::Fixed(fixed)
904+ }
905+ PresetSize::Proportion(prop) => ColumnWidth::Proportion(prop),
906+ }
907+ }
908+
885 pub fn focus_left(&mut self) -> bool {909 pub fn focus_left(&mut self) -> bool {
886 if self.floating_is_active.get() {910 if self.floating_is_active.get() {
887 self.floating.focus_left()911 self.floating.focus_left()