forge
Explore
Log in

Don't you dare go Hollow

Take border into account for fixed preset-column-width for tiled windows

Browse files at this commit

a0e2a15c60162e4f0a589fb5f0ce0899bce213b5Ivan MolodetskikhParent: 88c6778
niri-visual-tests/src/cases/layout.rsmodified+14 -15
@@ -2,10 +2,9 @@ use std::collections::HashMap;
2 use std::time::Duration;2 use std::time::Duration;
3 3
4 use niri::animation::Clock;4 use niri::animation::Clock;
5-use niri::layout::scrolling::ColumnWidth;
6 use niri::layout::{ActivateWindow, AddWindowTarget, LayoutElement as _, Options};5 use niri::layout::{ActivateWindow, AddWindowTarget, LayoutElement as _, Options};
7 use niri::render_helpers::RenderTarget;6 use niri::render_helpers::RenderTarget;
8-use niri_config::{Color, FloatOrInt, OutputName};7+use niri_config::{Color, FloatOrInt, OutputName, PresetSize};
9 use smithay::backend::renderer::element::RenderElement;8 use smithay::backend::renderer::element::RenderElement;
10 use smithay::backend::renderer::gles::GlesRenderer;9 use smithay::backend::renderer::gles::GlesRenderer;
11 use smithay::desktop::layer_map_for_output;10 use smithay::desktop::layer_map_for_output;
@@ -84,13 +83,13 @@ impl Layout {
84 pub fn open_in_between(args: Args) -> Self {83 pub fn open_in_between(args: Args) -> Self {
85 let mut rv = Self::new(args);84 let mut rv = Self::new(args);
86 85
87- rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));86+ rv.add_window(TestWindow::freeform(0), Some(PresetSize::Proportion(0.3)));
88- rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));87+ rv.add_window(TestWindow::freeform(1), Some(PresetSize::Proportion(0.3)));
89 rv.layout.activate_window(&0);88 rv.layout.activate_window(&0);
90 89
91 rv.add_step(500, |l| {90 rv.add_step(500, |l| {
92 let win = TestWindow::freeform(2);91 let win = TestWindow::freeform(2);
93- l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.3)));92+ l.add_window(win.clone(), Some(PresetSize::Proportion(0.3)));
94 l.layout.start_open_animation_for_window(win.id());93 l.layout.start_open_animation_for_window(win.id());
95 });94 });
96 95
@@ -103,7 +102,7 @@ impl Layout {
103 for delay in [100, 200, 300] {102 for delay in [100, 200, 300] {
104 rv.add_step(delay, move |l| {103 rv.add_step(delay, move |l| {
105 let win = TestWindow::freeform(delay as usize);104 let win = TestWindow::freeform(delay as usize);
106- l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.3)));105+ l.add_window(win.clone(), Some(PresetSize::Proportion(0.3)));
107 l.layout.start_open_animation_for_window(win.id());106 l.layout.start_open_animation_for_window(win.id());
108 });107 });
109 }108 }
@@ -117,7 +116,7 @@ impl Layout {
117 for delay in [100, 200, 300] {116 for delay in [100, 200, 300] {
118 rv.add_step(delay, move |l| {117 rv.add_step(delay, move |l| {
119 let win = TestWindow::freeform(delay as usize);118 let win = TestWindow::freeform(delay as usize);
120- l.add_window(win.clone(), Some(ColumnWidth::Proportion(0.5)));119+ l.add_window(win.clone(), Some(PresetSize::Proportion(0.5)));
121 l.layout.start_open_animation_for_window(win.id());120 l.layout.start_open_animation_for_window(win.id());
122 });121 });
123 }122 }
@@ -128,13 +127,13 @@ impl Layout {
128 pub fn open_to_the_left(args: Args) -> Self {127 pub fn open_to_the_left(args: Args) -> Self {
129 let mut rv = Self::new(args);128 let mut rv = Self::new(args);
130 129
131- rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));130+ rv.add_window(TestWindow::freeform(0), Some(PresetSize::Proportion(0.3)));
132- rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));131+ rv.add_window(TestWindow::freeform(1), Some(PresetSize::Proportion(0.3)));
133 132
134 rv.add_step(500, |l| {133 rv.add_step(500, |l| {
135 let win = TestWindow::freeform(2);134 let win = TestWindow::freeform(2);
136 let right_of = l.windows[0].clone();135 let right_of = l.windows[0].clone();
137- l.add_window_right_of(&right_of, win.clone(), Some(ColumnWidth::Proportion(0.3)));136+ l.add_window_right_of(&right_of, win.clone(), Some(PresetSize::Proportion(0.3)));
138 l.layout.start_open_animation_for_window(win.id());137 l.layout.start_open_animation_for_window(win.id());
139 });138 });
140 139
@@ -144,20 +143,20 @@ impl Layout {
144 pub fn open_to_the_left_big(args: Args) -> Self {143 pub fn open_to_the_left_big(args: Args) -> Self {
145 let mut rv = Self::new(args);144 let mut rv = Self::new(args);
146 145
147- rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));146+ rv.add_window(TestWindow::freeform(0), Some(PresetSize::Proportion(0.3)));
148- rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.8)));147+ rv.add_window(TestWindow::freeform(1), Some(PresetSize::Proportion(0.8)));
149 148
150 rv.add_step(500, |l| {149 rv.add_step(500, |l| {
151 let win = TestWindow::freeform(2);150 let win = TestWindow::freeform(2);
152 let right_of = l.windows[0].clone();151 let right_of = l.windows[0].clone();
153- l.add_window_right_of(&right_of, win.clone(), Some(ColumnWidth::Proportion(0.5)));152+ l.add_window_right_of(&right_of, win.clone(), Some(PresetSize::Proportion(0.5)));
154 l.layout.start_open_animation_for_window(win.id());153 l.layout.start_open_animation_for_window(win.id());
155 });154 });
156 155
157 rv156 rv
158 }157 }
159 158
160- fn add_window(&mut self, mut window: TestWindow, width: Option<ColumnWidth>) {159+ fn add_window(&mut self, mut window: TestWindow, width: Option<PresetSize>) {
161 let ws = self.layout.active_workspace().unwrap();160 let ws = self.layout.active_workspace().unwrap();
162 let min_size = window.min_size();161 let min_size = window.min_size();
163 let max_size = window.max_size();162 let max_size = window.max_size();
@@ -184,7 +183,7 @@ impl Layout {
184 &mut self,183 &mut self,
185 right_of: &TestWindow,184 right_of: &TestWindow,
186 mut window: TestWindow,185 mut window: TestWindow,
187- width: Option<ColumnWidth>,186+ width: Option<PresetSize>,
188 ) {187 ) {
189 let ws = self.layout.active_workspace().unwrap();188 let ws = self.layout.active_workspace().unwrap();
190 let min_size = window.min_size();189 let min_size = window.min_size();
src/handlers/xdg_shell.rsmodified+3 -3
@@ -1,6 +1,7 @@
1 use std::cell::Cell;1 use std::cell::Cell;
2 2
3 use calloop::Interest;3 use calloop::Interest;
4+use niri_config::PresetSize;
4 use smithay::desktop::{5 use smithay::desktop::{
5 find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, utils, LayerSurface,6 find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, utils, LayerSurface,
6 PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window,7 PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window,
@@ -42,7 +43,6 @@ use crate::input::resize_grab::ResizeGrab;
42 use crate::input::touch_move_grab::TouchMoveGrab;43 use crate::input::touch_move_grab::TouchMoveGrab;
43 use crate::input::touch_resize_grab::TouchResizeGrab;44 use crate::input::touch_resize_grab::TouchResizeGrab;
44 use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME};45 use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME};
45-use crate::layout::scrolling::ColumnWidth;
46 use crate::niri::{PopupGrabState, State};46 use crate::niri::{PopupGrabState, State};
47 use crate::utils::transaction::Transaction;47 use crate::utils::transaction::Transaction;
48 use crate::utils::{get_monotonic_time, output_matches_name, send_scale_transform, ResizeEdge};48 use crate::utils::{get_monotonic_time, output_matches_name, send_scale_transform, ResizeEdge};
@@ -591,7 +591,7 @@ impl XdgShellHandler for State {
591 let configure_width = if is_floating {591 let configure_width = if is_floating {
592 *floating_width592 *floating_width
593 } else if *is_full_width {593 } else if *is_full_width {
594- Some(ColumnWidth::Proportion(1.))594+ Some(PresetSize::Proportion(1.))
595 } else {595 } else {
596 *width596 *width
597 };597 };
@@ -917,7 +917,7 @@ impl State {
917 let configure_width = if is_floating {917 let configure_width = if is_floating {
918 floating_width918 floating_width
919 } else if is_full_width {919 } else if is_full_width {
920- Some(ColumnWidth::Proportion(1.))920+ Some(PresetSize::Proportion(1.))
921 } else {921 } else {
922 width922 width
923 };923 };
src/layout/floating.rsmodified+19 -44
@@ -623,7 +623,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
623 .preset_column_widths623 .preset_column_widths
624 .iter()624 .iter()
625 .position(|preset| {625 .position(|preset| {
626- let resolved = preset.resolve_no_gaps(&self.options, available_size);626+ let resolved = resolve_preset_size(*preset, available_size);
627 match resolved {627 match resolved {
628 // Some allowance for fractional scaling purposes.628 // Some allowance for fractional scaling purposes.
629 ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,629 ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,
@@ -634,13 +634,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
634 };634 };
635 635
636 let preset = self.options.preset_column_widths[preset_idx];636 let preset = self.options.preset_column_widths[preset_idx];
637- let change = match preset {637+ self.set_window_width(Some(&id), SizeChange::from(preset), true);
638- ColumnWidth::Proportion(prop) => SizeChange::SetProportion(prop * 100.),
639- ColumnWidth::Fixed(fixed) => SizeChange::SetFixed(fixed.round() as i32),
640- _ => unreachable!(),
641- };
642-
643- self.set_window_width(Some(&id), change, true);
644 638
645 self.tiles[idx].floating_preset_width_idx = Some(preset_idx);639 self.tiles[idx].floating_preset_width_idx = Some(preset_idx);
646 640
@@ -1138,53 +1132,34 @@ impl<W: LayoutElement> FloatingSpace<W> {
1138 }1132 }
1139 }1133 }
1140 1134
1141- pub fn resolve_width(&self, width: ColumnWidth) -> ResolvedSize {
1142- width.resolve_no_gaps(&self.options, self.working_area.size.w)
1143- }
1144-
1145- pub fn resolve_height(&self, height: PresetSize) -> ResolvedSize {
1146- resolve_preset_size(height, self.working_area.size.h)
1147- }
1148-
1149 pub fn new_window_size(1135 pub fn new_window_size(
1150 &self,1136 &self,
1151- width: Option<ColumnWidth>,1137+ width: Option<PresetSize>,
1152 height: Option<PresetSize>,1138 height: Option<PresetSize>,
1153 rules: &ResolvedWindowRules,1139 rules: &ResolvedWindowRules,
1154 ) -> Size<i32, Logical> {1140 ) -> Size<i32, Logical> {
1155 let border = rules.border.resolve_against(self.options.border);1141 let border = rules.border.resolve_against(self.options.border);
1156 1142
1157- let width = if let Some(width) = width {1143+ let resolve = |size: Option<PresetSize>, working_area_size: f64| {
1158- let width = match self.resolve_width(width) {1144+ if let Some(size) = size {
1159- ResolvedSize::Tile(mut size) => {1145+ let size = match resolve_preset_size(size, working_area_size) {
1160- if !border.off {1146+ ResolvedSize::Tile(mut size) => {
1161- size -= border.width.0 * 2.;1147+ if !border.off {
1148+ size -= border.width.0 * 2.;
1149+ }
1150+ size
1162 }1151 }
1163- size1152+ ResolvedSize::Window(size) => size,
1164- }1153+ };
1165- ResolvedSize::Window(size) => size,
1166- };
1167 1154
1168- max(1, width.floor() as i32)1155+ max(1, size.floor() as i32)
1169- } else {1156+ } else {
1170- 01157+ 0
1158+ }
1171 };1159 };
1172 1160
1173- let height = if let Some(height) = height {1161+ let width = resolve(width, self.working_area.size.w);
1174- let height = match self.resolve_height(height) {1162+ let height = resolve(height, self.working_area.size.h);
1175- ResolvedSize::Tile(mut size) => {
1176- if !border.off {
1177- size -= border.width.0 * 2.;
1178- }
1179- size
1180- }
1181- ResolvedSize::Window(size) => size,
1182- };
1183-
1184- max(1, height.floor() as i32)
1185- } else {
1186- 0
1187- };
1188 1163
1189 Size::from((width, height))1164 Size::from((width, height))
1190 }1165 }
src/layout/mod.rsmodified+31 -41
@@ -316,10 +316,10 @@ pub struct Options {
316 pub center_focused_column: CenterFocusedColumn,316 pub center_focused_column: CenterFocusedColumn,
317 pub always_center_single_column: bool,317 pub always_center_single_column: bool,
318 pub empty_workspace_above_first: bool,318 pub empty_workspace_above_first: bool,
319- /// Column widths that `toggle_width()` switches between.319+ /// Column or window widths that `toggle_width()` switches between.
320- pub preset_column_widths: Vec<ColumnWidth>,320+ pub preset_column_widths: Vec<PresetSize>,
321 /// Initial width for new columns.321 /// Initial width for new columns.
322- pub default_column_width: Option<ColumnWidth>,322+ pub default_column_width: Option<PresetSize>,
323 /// Window height that `toggle_window_height()` switches between.323 /// Window height that `toggle_window_height()` switches between.
324 pub preset_window_heights: Vec<PresetSize>,324 pub preset_window_heights: Vec<PresetSize>,
325 pub animations: niri_config::Animations,325 pub animations: niri_config::Animations,
@@ -341,9 +341,9 @@ impl Default for Options {
341 always_center_single_column: false,341 always_center_single_column: false,
342 empty_workspace_above_first: false,342 empty_workspace_above_first: false,
343 preset_column_widths: vec![343 preset_column_widths: vec![
344- ColumnWidth::Proportion(1. / 3.),344+ PresetSize::Proportion(1. / 3.),
345- ColumnWidth::Proportion(0.5),345+ PresetSize::Proportion(0.5),
346- ColumnWidth::Proportion(2. / 3.),346+ PresetSize::Proportion(2. / 3.),
347 ],347 ],
348 default_column_width: None,348 default_column_width: None,
349 animations: Default::default(),349 animations: Default::default(),
@@ -492,12 +492,7 @@ impl Options {
492 let preset_column_widths = if layout.preset_column_widths.is_empty() {492 let preset_column_widths = if layout.preset_column_widths.is_empty() {
493 Options::default().preset_column_widths493 Options::default().preset_column_widths
494 } else {494 } else {
495- layout495+ layout.preset_column_widths.clone()
496- .preset_column_widths
497- .iter()
498- .copied()
499- .map(ColumnWidth::from)
500- .collect()
501 };496 };
502 let preset_window_heights = if layout.preset_window_heights.is_empty() {497 let preset_window_heights = if layout.preset_window_heights.is_empty() {
503 Options::default().preset_window_heights498 Options::default().preset_window_heights
@@ -505,13 +500,13 @@ impl Options {
505 layout.preset_window_heights.clone()500 layout.preset_window_heights.clone()
506 };501 };
507 502
508- // Missing default_column_width maps to Some(ColumnWidth::Proportion(0.5)),503+ // Missing default_column_width maps to Some(PresetSize::Proportion(0.5)),
509 // while present, but empty, maps to None.504 // while present, but empty, maps to None.
510 let default_column_width = layout505 let default_column_width = layout
511 .default_column_width506 .default_column_width
512 .as_ref()507 .as_ref()
513- .map(|w| w.0.map(ColumnWidth::from))508+ .map(|w| w.0)
514- .unwrap_or(Some(ColumnWidth::Proportion(0.5)));509+ .unwrap_or(Some(PresetSize::Proportion(0.5)));
515 510
516 Self {511 Self {
517 gaps: layout.gaps.0,512 gaps: layout.gaps.0,
@@ -855,14 +850,14 @@ impl<W: LayoutElement> Layout<W> {
855 &mut self,850 &mut self,
856 window: W,851 window: W,
857 target: AddWindowTarget<W>,852 target: AddWindowTarget<W>,
858- width: Option<ColumnWidth>,853+ width: Option<PresetSize>,
859 height: Option<PresetSize>,854 height: Option<PresetSize>,
860 is_full_width: bool,855 is_full_width: bool,
861 is_floating: bool,856 is_floating: bool,
862 activate: ActivateWindow,857 activate: ActivateWindow,
863 ) -> Option<&Output> {858 ) -> Option<&Output> {
864- let resolved_width = self.resolve_default_width(&window, width, is_floating);859+ let scrolling_width = self.resolve_scrolling_width(&window, width);
865- let resolved_height = height.map(SizeChange::from);860+ let scrolling_height = height.map(SizeChange::from);
866 let id = window.id().clone();861 let id = window.id().clone();
867 862
868 match &mut self.monitor_set {863 match &mut self.monitor_set {
@@ -933,7 +928,7 @@ impl<W: LayoutElement> Layout<W> {
933 window,928 window,
934 target,929 target,
935 activate,930 activate,
936- resolved_width,931+ scrolling_width,
937 is_full_width,932 is_full_width,
938 is_floating,933 is_floating,
939 );934 );
@@ -944,7 +939,7 @@ impl<W: LayoutElement> Layout<W> {
944 939
945 // Set the default height for scrolling windows.940 // Set the default height for scrolling windows.
946 if !is_floating {941 if !is_floating {
947- if let Some(change) = resolved_height {942+ if let Some(change) = scrolling_height {
948 let ws = mon943 let ws = mon
949 .workspaces944 .workspaces
950 .iter_mut()945 .iter_mut()
@@ -1005,14 +1000,14 @@ impl<W: LayoutElement> Layout<W> {
1005 tile,1000 tile,
1006 target,1001 target,
1007 activate,1002 activate,
1008- resolved_width,1003+ scrolling_width,
1009 is_full_width,1004 is_full_width,
1010 is_floating,1005 is_floating,
1011 );1006 );
1012 1007
1013 // Set the default height for scrolling windows.1008 // Set the default height for scrolling windows.
1014 if !is_floating {1009 if !is_floating {
1015- if let Some(change) = resolved_height {1010+ if let Some(change) = scrolling_height {
1016 ws.set_window_height(Some(&id), change);1011 ws.set_window_height(Some(&id), change);
1017 }1012 }
1018 }1013 }
@@ -4283,28 +4278,23 @@ impl<W: LayoutElement> Layout<W> {
4283 self.windows().any(|(_, win)| win.id() == window)4278 self.windows().any(|(_, win)| win.id() == window)
4284 }4279 }
4285 4280
4286- fn resolve_default_width(4281+ fn resolve_scrolling_width(&self, window: &W, width: Option<PresetSize>) -> ColumnWidth {
4287- &self,4282+ let width = width.unwrap_or_else(|| PresetSize::Fixed(window.size().w));
4288- window: &W,4283+ match width {
4289- width: Option<ColumnWidth>,4284+ PresetSize::Fixed(fixed) => {
4290- is_floating: bool,4285+ let mut fixed = f64::from(fixed);
4291- ) -> ColumnWidth {
4292- let mut width = width.unwrap_or_else(|| ColumnWidth::Fixed(f64::from(window.size().w)));
4293- if is_floating {
4294- return width;
4295- }
4296 4286
4297- // Add border width to account for the issue that the scrolling layout currently doesn't4287+ // Add border width since ColumnWidth includes borders.
4298- // take borders into account for fixed sizes.4288+ let rules = window.rules();
4299- if let ColumnWidth::Fixed(w) = &mut width {4289+ let border = rules.border.resolve_against(self.options.border);
4300- let rules = window.rules();4290+ if !border.off {
4301- let border_config = rules.border.resolve_against(self.options.border);4291+ fixed += border.width.0 * 2.;
4302- if !border_config.off {4292+ }
4303- *w += border_config.width.0 * 2.;4293+
4294+ ColumnWidth::Fixed(fixed)
4304 }4295 }
4296+ PresetSize::Proportion(prop) => ColumnWidth::Proportion(prop),
4305 }4297 }
4306-
4307- width
4308 }4298 }
4309 }4299 }
4310 4300
src/layout/scrolling.rsmodified+69 -70
@@ -162,6 +162,9 @@ pub struct Column<W: LayoutElement> {
162 /// upon unfullscreening and untoggling full-width.162 /// upon unfullscreening and untoggling full-width.
163 width: ColumnWidth,163 width: ColumnWidth,
164 164
165+ /// Currently selected preset width index.
166+ preset_width_idx: Option<usize>,
167+
165 /// Whether this column is full-width.168 /// Whether this column is full-width.
166 is_full_width: bool,169 is_full_width: bool,
167 170
@@ -209,8 +212,6 @@ pub enum ColumnWidth {
209 Proportion(f64),212 Proportion(f64),
210 /// Fixed width in logical pixels.213 /// Fixed width in logical pixels.
211 Fixed(f64),214 Fixed(f64),
212- /// One of the preset widths.
213- Preset(usize),
214 }215 }
215 216
216 /// Height of a window in a column.217 /// Height of a window in a column.
@@ -417,22 +418,24 @@ impl<W: LayoutElement> ScrollingSpace<W> {
417 418
418 pub fn new_window_size(419 pub fn new_window_size(
419 &self,420 &self,
420- width: Option<ColumnWidth>,421+ width: Option<PresetSize>,
421 height: Option<PresetSize>,422 height: Option<PresetSize>,
422 rules: &ResolvedWindowRules,423 rules: &ResolvedWindowRules,
423 ) -> Size<i32, Logical> {424 ) -> Size<i32, Logical> {
424 let border = rules.border.resolve_against(self.options.border);425 let border = rules.border.resolve_against(self.options.border);
425 426
426- let width = if let Some(width) = width {427+ let width = if let Some(size) = width {
427- let is_fixed = matches!(width, ColumnWidth::Fixed(_));428+ let size = match resolve_preset_size(size, &self.options, self.working_area.size.w) {
428-429+ ResolvedSize::Tile(mut size) => {
429- let mut width = width.resolve(&self.options, self.working_area.size.w);430+ if !border.off {
430-431+ size -= border.width.0 * 2.;
431- if !is_fixed && !border.off {432+ }
432- width -= border.width.0 * 2.;433+ size
433- }434+ }
435+ ResolvedSize::Window(size) => size,
436+ };
434 437
435- max(1, width.floor() as i32)438+ max(1, size.floor() as i32)
436 } else {439 } else {
437 0440 0
438 };441 };
@@ -2173,7 +2176,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2173 }2176 }
2174 2177
2175 let col = &mut self.columns[self.active_column_idx];2178 let col = &mut self.columns[self.active_column_idx];
2176- col.toggle_width();2179+ col.toggle_width(None);
2177 2180
2178 cancel_resize_for_column(&mut self.interactive_resize, col);2181 cancel_resize_for_column(&mut self.interactive_resize, col);
2179 }2182 }
@@ -2266,18 +2269,21 @@ impl<W: LayoutElement> ScrollingSpace<W> {
2266 return;2269 return;
2267 }2270 }
2268 2271
2269- let col = if let Some(window) = window {2272+ let (col, tile_idx) = if let Some(window) = window {
2270 self.columns2273 self.columns
2271 .iter_mut()2274 .iter_mut()
2272- .find(|col| col.contains(window))2275+ .find_map(|col| {
2276+ col.tiles
2277+ .iter()
2278+ .position(|tile| tile.window().id() == window)
2279+ .map(|tile_idx| (col, Some(tile_idx)))
2280+ })
2273 .unwrap()2281 .unwrap()
2274 } else {2282 } else {
2275- &mut self.columns[self.active_column_idx]2283+ (&mut self.columns[self.active_column_idx], None)
2276 };2284 };
2277 2285
2278- // FIXME: when we fix preset fixed width to be per-window, this should also be made2286+ col.toggle_width(tile_idx);
2279- // window-specific to resolve the correct window width.
2280- col.toggle_width();
2281 2287
2282 cancel_resize_for_column(&mut self.interactive_resize, col);2288 cancel_resize_for_column(&mut self.interactive_resize, col);
2283 }2289 }
@@ -3103,22 +3109,9 @@ impl ColumnWidth {
3103 ColumnWidth::Proportion(proportion) => {3109 ColumnWidth::Proportion(proportion) => {
3104 (view_width - options.gaps) * proportion - options.gaps3110 (view_width - options.gaps) * proportion - options.gaps
3105 }3111 }
3106- ColumnWidth::Preset(idx) => {
3107- options.preset_column_widths[idx].resolve(options, view_width)
3108- }
3109 ColumnWidth::Fixed(width) => width,3112 ColumnWidth::Fixed(width) => width,
3110 }3113 }
3111 }3114 }
3112-
3113- pub fn resolve_no_gaps(self, options: &Options, view_width: f64) -> ResolvedSize {
3114- match self {
3115- ColumnWidth::Proportion(proportion) => ResolvedSize::Tile(view_width * proportion),
3116- ColumnWidth::Preset(idx) => {
3117- options.preset_column_widths[idx].resolve_no_gaps(options, view_width)
3118- }
3119- ColumnWidth::Fixed(width) => ResolvedSize::Window(width),
3120- }
3121- }
3122 }3115 }
3123 3116
3124 impl From<PresetSize> for ColumnWidth {3117 impl From<PresetSize> for ColumnWidth {
@@ -3152,6 +3145,7 @@ impl<W: LayoutElement> Column<W> {
3152 data: vec![],3145 data: vec![],
3153 active_tile_idx: 0,3146 active_tile_idx: 0,
3154 width,3147 width,
3148+ preset_width_idx: None,
3155 is_full_width,3149 is_full_width,
3156 is_fullscreen: false,3150 is_fullscreen: false,
3157 move_animation: None,3151 move_animation: None,
@@ -3186,11 +3180,9 @@ impl<W: LayoutElement> Column<W> {
3186 update_sizes = true;3180 update_sizes = true;
3187 }3181 }
3188 3182
3189- // If preset widths changed, make our width non-preset.3183+ // If preset widths changed, clear our stored preset index.
3190 if self.options.preset_column_widths != options.preset_column_widths {3184 if self.options.preset_column_widths != options.preset_column_widths {
3191- if let ColumnWidth::Preset(idx) = self.width {3185+ self.preset_width_idx = None;
3192- self.width = self.options.preset_column_widths[idx];
3193- }
3194 }3186 }
3195 3187
3196 // If preset heights changed, make our heights non-preset.3188 // If preset heights changed, make our heights non-preset.
@@ -3224,12 +3216,6 @@ impl<W: LayoutElement> Column<W> {
3224 }3216 }
3225 }3217 }
3226 3218
3227- fn set_width(&mut self, width: ColumnWidth, animate: bool) {
3228- self.width = width;
3229- self.is_full_width = false;
3230- self.update_tile_sizes(animate);
3231- }
3232-
3233 pub fn advance_animations(&mut self) {3219 pub fn advance_animations(&mut self) {
3234 if let Some(anim) = &mut self.move_animation {3220 if let Some(anim) = &mut self.move_animation {
3235 if anim.is_done() {3221 if anim.is_done() {
@@ -3673,30 +3659,42 @@ impl<W: LayoutElement> Column<W> {
3673 true3659 true
3674 }3660 }
3675 3661
3676- fn toggle_width(&mut self) {3662+ fn toggle_width(&mut self, tile_idx: Option<usize>) {
3677- let width = if self.is_full_width {3663+ let tile_idx = tile_idx.unwrap_or(self.active_tile_idx);
3678- ColumnWidth::Proportion(1.)3664+
3665+ let preset_idx = if self.is_full_width {
3666+ None
3679 } else {3667 } else {
3680- self.width3668+ self.preset_width_idx
3681 };3669 };
3682 3670
3683- let idx = match width {3671+ let preset_idx = if let Some(idx) = preset_idx {
3684- ColumnWidth::Preset(idx) => (idx + 1) % self.options.preset_column_widths.len(),3672+ (idx + 1) % self.options.preset_column_widths.len()
3685- _ => {3673+ } else {
3686- let current = self.width();3674+ let tile = &self.tiles[tile_idx];
3687- self.options3675+ let current_window = tile.window_expected_or_current_size().w;
3688- .preset_column_widths3676+ let current_tile = tile.tile_expected_or_current_size().w;
3689- .iter()3677+
3690- .position(|prop| {3678+ let available_size = self.working_area.size.w;
3691- let resolved = prop.resolve(&self.options, self.working_area.size.w);3679+
3680+ self.options
3681+ .preset_column_widths
3682+ .iter()
3683+ .position(|prop| {
3684+ let resolved = resolve_preset_size(*prop, &self.options, available_size);
3685+ match resolved {
3692 // Some allowance for fractional scaling purposes.3686 // Some allowance for fractional scaling purposes.
3693- current + 1. < resolved3687+ ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,
3694- })3688+ ResolvedSize::Window(resolved) => current_window + 1. < resolved,
3695- .unwrap_or(0)3689+ }
3696- }3690+ })
3691+ .unwrap_or(0)
3697 };3692 };
3698- let width = ColumnWidth::Preset(idx);3693+
3699- self.set_width(width, true);3694+ let preset = self.options.preset_column_widths[preset_idx];
3695+ self.set_column_width(SizeChange::from(preset), Some(tile_idx), true);
3696+
3697+ self.preset_width_idx = Some(preset_idx);
3700 }3698 }
3701 3699
3702 fn toggle_full_width(&mut self) {3700 fn toggle_full_width(&mut self) {
@@ -3705,18 +3703,13 @@ impl<W: LayoutElement> Column<W> {
3705 }3703 }
3706 3704
3707 fn set_column_width(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) {3705 fn set_column_width(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) {
3708- let width = if self.is_full_width {3706+ let current = if self.is_full_width {
3709 ColumnWidth::Proportion(1.)3707 ColumnWidth::Proportion(1.)
3710 } else {3708 } else {
3711 self.width3709 self.width
3712 };3710 };
3713 3711
3714- let current_px = width.resolve(&self.options, self.working_area.size.w);3712+ let current_px = current.resolve(&self.options, self.working_area.size.w);
3715-
3716- let current = match width {
3717- ColumnWidth::Preset(idx) => self.options.preset_column_widths[idx],
3718- current => current,
3719- };
3720 3713
3721 // FIXME: fix overflows then remove limits.3714 // FIXME: fix overflows then remove limits.
3722 const MAX_PX: f64 = 100000.;3715 const MAX_PX: f64 = 100000.;
@@ -3755,10 +3748,12 @@ impl<W: LayoutElement> Column<W> {
3755 let proportion = (current + delta / 100.).clamp(0., MAX_F);3748 let proportion = (current + delta / 100.).clamp(0., MAX_F);
3756 ColumnWidth::Proportion(proportion)3749 ColumnWidth::Proportion(proportion)
3757 }3750 }
3758- (ColumnWidth::Preset(_), _) => unreachable!(),
3759 };3751 };
3760 3752
3761- self.set_width(width, animate);3753+ self.width = width;
3754+ self.preset_width_idx = None;
3755+ self.is_full_width = false;
3756+ self.update_tile_sizes(animate);
3762 }3757 }
3763 3758
3764 fn set_window_height(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) {3759 fn set_window_height(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) {
@@ -4043,6 +4038,10 @@ impl<W: LayoutElement> Column<W> {
4043 assert_eq!(self.tiles.len(), 1);4038 assert_eq!(self.tiles.len(), 1);
4044 }4039 }
4045 4040
4041+ if let Some(idx) = self.preset_width_idx {
4042+ assert!(idx < self.options.preset_column_widths.len());
4043+ }
4044+
4046 let tile_count = self.tiles.len();4045 let tile_count = self.tiles.len();
4047 if tile_count == 1 {4046 if tile_count == 1 {
4048 if let WindowHeight::Auto { weight } = self.data[0].height {4047 if let WindowHeight::Auto { weight } = self.data[0].height {
src/layout/tests.rsmodified+65 -0
@@ -3002,6 +3002,71 @@ fn move_workspace_to_same_monitor_doesnt_reorder() {
3002 assert_eq!(counts, &[1, 2, 0]);3002 assert_eq!(counts, &[1, 2, 0]);
3003 }3003 }
3004 3004
3005+#[test]
3006+fn preset_column_width_fixed_correct_with_border() {
3007+ let ops = [
3008+ Op::AddOutput(0),
3009+ Op::AddWindow {
3010+ params: TestWindowParams::new(0),
3011+ },
3012+ Op::SwitchPresetColumnWidth,
3013+ ];
3014+
3015+ let options = Options {
3016+ preset_column_widths: vec![PresetSize::Fixed(500)],
3017+ ..Default::default()
3018+ };
3019+ let mut layout = check_ops_with_options(options, &ops);
3020+
3021+ let win = layout.windows().next().unwrap().1;
3022+ assert_eq!(win.requested_size().unwrap().w, 500);
3023+
3024+ // Add border.
3025+ let options = Options {
3026+ preset_column_widths: vec![PresetSize::Fixed(500)],
3027+ border: niri_config::Border {
3028+ off: false,
3029+ width: FloatOrInt(5.),
3030+ ..Default::default()
3031+ },
3032+ ..Default::default()
3033+ };
3034+ layout.update_options(options);
3035+
3036+ // With border, the window gets less size.
3037+ let win = layout.windows().next().unwrap().1;
3038+ assert_eq!(win.requested_size().unwrap().w, 490);
3039+
3040+ // However, preset fixed width will still work correctly.
3041+ layout.toggle_width();
3042+ let win = layout.windows().next().unwrap().1;
3043+ assert_eq!(win.requested_size().unwrap().w, 500);
3044+}
3045+
3046+#[test]
3047+fn preset_column_width_reset_after_set_width() {
3048+ let ops = [
3049+ Op::AddOutput(0),
3050+ Op::AddWindow {
3051+ params: TestWindowParams::new(0),
3052+ },
3053+ Op::SwitchPresetColumnWidth,
3054+ Op::SetWindowWidth {
3055+ id: None,
3056+ change: SizeChange::AdjustFixed(-10),
3057+ },
3058+ Op::SwitchPresetColumnWidth,
3059+ ];
3060+
3061+ let options = Options {
3062+ preset_column_widths: vec![PresetSize::Fixed(500), PresetSize::Fixed(1000)],
3063+ ..Default::default()
3064+ };
3065+ let layout = check_ops_with_options(options, &ops);
3066+ let win = layout.windows().next().unwrap().1;
3067+ assert_eq!(win.requested_size().unwrap().w, 500);
3068+}
3069+
3005 fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool {3070 fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool {
3006 if parent_id == id {3071 if parent_id == id {
3007 return true;3072 return true;
src/layout/workspace.rsmodified+4 -4
@@ -713,9 +713,9 @@ impl<W: LayoutElement> Workspace<W> {
713 713
714 pub fn resolve_default_width(714 pub fn resolve_default_width(
715 &self,715 &self,
716- default_width: Option<Option<ColumnWidth>>,716+ default_width: Option<Option<PresetSize>>,
717 is_floating: bool,717 is_floating: bool,
718- ) -> Option<ColumnWidth> {718+ ) -> Option<PresetSize> {
719 match default_width {719 match default_width {
720 Some(Some(width)) => Some(width),720 Some(Some(width)) => Some(width),
721 Some(None) => None,721 Some(None) => None,
@@ -740,7 +740,7 @@ impl<W: LayoutElement> Workspace<W> {
740 740
741 pub fn new_window_size(741 pub fn new_window_size(
742 &self,742 &self,
743- width: Option<ColumnWidth>,743+ width: Option<PresetSize>,
744 height: Option<PresetSize>,744 height: Option<PresetSize>,
745 is_floating: bool,745 is_floating: bool,
746 rules: &ResolvedWindowRules,746 rules: &ResolvedWindowRules,
@@ -772,7 +772,7 @@ impl<W: LayoutElement> Workspace<W> {
772 pub fn configure_new_window(772 pub fn configure_new_window(
773 &self,773 &self,
774 window: &Window,774 window: &Window,
775- width: Option<ColumnWidth>,775+ width: Option<PresetSize>,
776 height: Option<PresetSize>,776 height: Option<PresetSize>,
777 is_floating: bool,777 is_floating: bool,
778 rules: &ResolvedWindowRules,778 rules: &ResolvedWindowRules,
src/window/mod.rsmodified+3 -8
@@ -11,7 +11,6 @@ use smithay::wayland::shell::xdg::{
11 SurfaceCachedState, ToplevelSurface, XdgToplevelSurfaceRoleAttributes,11 SurfaceCachedState, ToplevelSurface, XdgToplevelSurfaceRoleAttributes,
12 };12 };
13 13
14-use crate::layout::scrolling::ColumnWidth;
15 use crate::utils::with_toplevel_role;14 use crate::utils::with_toplevel_role;
16 15
17 pub mod mapped;16 pub mod mapped;
@@ -35,7 +34,7 @@ pub struct ResolvedWindowRules {
35 /// - `None`: unset (global default should be used).34 /// - `None`: unset (global default should be used).
36 /// - `Some(None)`: set to empty (window picks its own width).35 /// - `Some(None)`: set to empty (window picks its own width).
37 /// - `Some(Some(width))`: set to a particular width.36 /// - `Some(Some(width))`: set to a particular width.
38- pub default_width: Option<Option<ColumnWidth>>,37+ pub default_width: Option<Option<PresetSize>>,
39 38
40 /// Default height for this window.39 /// Default height for this window.
41 ///40 ///
@@ -230,12 +229,8 @@ impl ResolvedWindowRules {
230 continue;229 continue;
231 }230 }
232 231
233- if let Some(x) = rule232+ if let Some(x) = rule.default_column_width {
234- .default_column_width233+ resolved.default_width = Some(x.0);
235- .as_ref()
236- .map(|d| d.0.map(ColumnWidth::from))
237- {
238- resolved.default_width = Some(x);
239 }234 }
240 235
241 if let Some(x) = rule.default_window_height {236 if let Some(x) = rule.default_window_height {
src/window/unmapped.rsmodified+2 -3
@@ -5,7 +5,6 @@ use smithay::wayland::shell::xdg::ToplevelSurface;
5 use smithay::wayland::xdg_activation::XdgActivationTokenData;5 use smithay::wayland::xdg_activation::XdgActivationTokenData;
6 6
7 use super::ResolvedWindowRules;7 use super::ResolvedWindowRules;
8-use crate::layout::scrolling::ColumnWidth;
9 8
10 #[derive(Debug)]9 #[derive(Debug)]
11 pub struct Unmapped {10 pub struct Unmapped {
@@ -34,7 +33,7 @@ pub enum InitialConfigureState {
34 /// Resolved scrolling default width for this window.33 /// Resolved scrolling default width for this window.
35 ///34 ///
36 /// `None` means that the window will pick its own width.35 /// `None` means that the window will pick its own width.
37- width: Option<ColumnWidth>,36+ width: Option<PresetSize>,
38 37
39 /// Resolved scrolling default height for this window.38 /// Resolved scrolling default height for this window.
40 ///39 ///
@@ -44,7 +43,7 @@ pub enum InitialConfigureState {
44 /// Resolved floating default width for this window.43 /// Resolved floating default width for this window.
45 ///44 ///
46 /// `None` means that the window will pick its own width.45 /// `None` means that the window will pick its own width.
47- floating_width: Option<ColumnWidth>,46+ floating_width: Option<PresetSize>,
48 47
49 /// Resolved floating default height for this window.48 /// Resolved floating default height for this window.
50 ///49 ///
wiki/Configuration:-Layout.mdmodified+1 -1
@@ -146,7 +146,7 @@ layout {
146 ```146 ```
147 147
148 > [!NOTE]148 > [!NOTE]
149-> Currently, due to an oversight, a preset `fixed` width does not take borders into account in the tiling layout.149+> Until next release, a preset `fixed` width does not take borders into account in the tiling layout.
150 > I.e., preset `fixed 1000` with 4-wide borders will make the window 992 logical pixels wide.150 > I.e., preset `fixed 1000` with 4-wide borders will make the window 992 logical pixels wide.
151 > This may eventually be corrected.151 > This may eventually be corrected.
152 >152 >