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;
22 use std::time::Duration;
33
44 use niri::animation::Clock;
5-use niri::layout::scrolling::ColumnWidth;
65 use niri::layout::{ActivateWindow, AddWindowTarget, LayoutElement as _, Options};
76 use niri::render_helpers::RenderTarget;
8-use niri_config::{Color, FloatOrInt, OutputName};
7+use niri_config::{Color, FloatOrInt, OutputName, PresetSize};
98 use smithay::backend::renderer::element::RenderElement;
109 use smithay::backend::renderer::gles::GlesRenderer;
1110 use smithay::desktop::layer_map_for_output;
@@ -84,13 +83,13 @@ impl Layout {
8483 pub fn open_in_between(args: Args) -> Self {
8584 let mut rv = Self::new(args);
8685
87- rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
88- rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));
86+ rv.add_window(TestWindow::freeform(0), Some(PresetSize::Proportion(0.3)));
87+ rv.add_window(TestWindow::freeform(1), Some(PresetSize::Proportion(0.3)));
8988 rv.layout.activate_window(&0);
9089
9190 rv.add_step(500, |l| {
9291 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)));
9493 l.layout.start_open_animation_for_window(win.id());
9594 });
9695
@@ -103,7 +102,7 @@ impl Layout {
103102 for delay in [100, 200, 300] {
104103 rv.add_step(delay, move |l| {
105104 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)));
107106 l.layout.start_open_animation_for_window(win.id());
108107 });
109108 }
@@ -117,7 +116,7 @@ impl Layout {
117116 for delay in [100, 200, 300] {
118117 rv.add_step(delay, move |l| {
119118 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)));
121120 l.layout.start_open_animation_for_window(win.id());
122121 });
123122 }
@@ -128,13 +127,13 @@ impl Layout {
128127 pub fn open_to_the_left(args: Args) -> Self {
129128 let mut rv = Self::new(args);
130129
131- rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
132- rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.3)));
130+ rv.add_window(TestWindow::freeform(0), Some(PresetSize::Proportion(0.3)));
131+ rv.add_window(TestWindow::freeform(1), Some(PresetSize::Proportion(0.3)));
133132
134133 rv.add_step(500, |l| {
135134 let win = TestWindow::freeform(2);
136135 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)));
138137 l.layout.start_open_animation_for_window(win.id());
139138 });
140139
@@ -144,20 +143,20 @@ impl Layout {
144143 pub fn open_to_the_left_big(args: Args) -> Self {
145144 let mut rv = Self::new(args);
146145
147- rv.add_window(TestWindow::freeform(0), Some(ColumnWidth::Proportion(0.3)));
148- rv.add_window(TestWindow::freeform(1), Some(ColumnWidth::Proportion(0.8)));
146+ rv.add_window(TestWindow::freeform(0), Some(PresetSize::Proportion(0.3)));
147+ rv.add_window(TestWindow::freeform(1), Some(PresetSize::Proportion(0.8)));
149148
150149 rv.add_step(500, |l| {
151150 let win = TestWindow::freeform(2);
152151 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)));
154153 l.layout.start_open_animation_for_window(win.id());
155154 });
156155
157156 rv
158157 }
159158
160- fn add_window(&mut self, mut window: TestWindow, width: Option<ColumnWidth>) {
159+ fn add_window(&mut self, mut window: TestWindow, width: Option<PresetSize>) {
161160 let ws = self.layout.active_workspace().unwrap();
162161 let min_size = window.min_size();
163162 let max_size = window.max_size();
@@ -184,7 +183,7 @@ impl Layout {
184183 &mut self,
185184 right_of: &TestWindow,
186185 mut window: TestWindow,
187- width: Option<ColumnWidth>,
186+ width: Option<PresetSize>,
188187 ) {
189188 let ws = self.layout.active_workspace().unwrap();
190189 let min_size = window.min_size();
src/handlers/xdg_shell.rsmodified+3 -3
@@ -1,6 +1,7 @@
11 use std::cell::Cell;
22
33 use calloop::Interest;
4+use niri_config::PresetSize;
45 use smithay::desktop::{
56 find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, utils, LayerSurface,
67 PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window,
@@ -42,7 +43,6 @@ use crate::input::resize_grab::ResizeGrab;
4243 use crate::input::touch_move_grab::TouchMoveGrab;
4344 use crate::input::touch_resize_grab::TouchResizeGrab;
4445 use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME};
45-use crate::layout::scrolling::ColumnWidth;
4646 use crate::niri::{PopupGrabState, State};
4747 use crate::utils::transaction::Transaction;
4848 use crate::utils::{get_monotonic_time, output_matches_name, send_scale_transform, ResizeEdge};
@@ -591,7 +591,7 @@ impl XdgShellHandler for State {
591591 let configure_width = if is_floating {
592592 *floating_width
593593 } else if *is_full_width {
594- Some(ColumnWidth::Proportion(1.))
594+ Some(PresetSize::Proportion(1.))
595595 } else {
596596 *width
597597 };
@@ -917,7 +917,7 @@ impl State {
917917 let configure_width = if is_floating {
918918 floating_width
919919 } else if is_full_width {
920- Some(ColumnWidth::Proportion(1.))
920+ Some(PresetSize::Proportion(1.))
921921 } else {
922922 width
923923 };
src/layout/floating.rsmodified+19 -44
@@ -623,7 +623,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
623623 .preset_column_widths
624624 .iter()
625625 .position(|preset| {
626- let resolved = preset.resolve_no_gaps(&self.options, available_size);
626+ let resolved = resolve_preset_size(*preset, available_size);
627627 match resolved {
628628 // Some allowance for fractional scaling purposes.
629629 ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,
@@ -634,13 +634,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
634634 };
635635
636636 let preset = self.options.preset_column_widths[preset_idx];
637- let change = match preset {
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);
637+ self.set_window_width(Some(&id), SizeChange::from(preset), true);
644638
645639 self.tiles[idx].floating_preset_width_idx = Some(preset_idx);
646640
@@ -1138,53 +1132,34 @@ impl<W: LayoutElement> FloatingSpace<W> {
11381132 }
11391133 }
11401134
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-
11491135 pub fn new_window_size(
11501136 &self,
1151- width: Option<ColumnWidth>,
1137+ width: Option<PresetSize>,
11521138 height: Option<PresetSize>,
11531139 rules: &ResolvedWindowRules,
11541140 ) -> Size<i32, Logical> {
11551141 let border = rules.border.resolve_against(self.options.border);
11561142
1157- let width = if let Some(width) = width {
1158- let width = match self.resolve_width(width) {
1159- ResolvedSize::Tile(mut size) => {
1160- if !border.off {
1161- size -= border.width.0 * 2.;
1143+ let resolve = |size: Option<PresetSize>, working_area_size: f64| {
1144+ if let Some(size) = size {
1145+ let size = match resolve_preset_size(size, working_area_size) {
1146+ ResolvedSize::Tile(mut size) => {
1147+ if !border.off {
1148+ size -= border.width.0 * 2.;
1149+ }
1150+ size
11621151 }
1163- size
1164- }
1165- ResolvedSize::Window(size) => size,
1166- };
1152+ ResolvedSize::Window(size) => size,
1153+ };
11671154
1168- max(1, width.floor() as i32)
1169- } else {
1170- 0
1155+ max(1, size.floor() as i32)
1156+ } else {
1157+ 0
1158+ }
11711159 };
11721160
1173- let height = if let Some(height) = height {
1174- let height = match self.resolve_height(height) {
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- };
1161+ let width = resolve(width, self.working_area.size.w);
1162+ let height = resolve(height, self.working_area.size.h);
11881163
11891164 Size::from((width, height))
11901165 }
src/layout/mod.rsmodified+31 -41
@@ -316,10 +316,10 @@ pub struct Options {
316316 pub center_focused_column: CenterFocusedColumn,
317317 pub always_center_single_column: bool,
318318 pub empty_workspace_above_first: bool,
319- /// Column widths that `toggle_width()` switches between.
320- pub preset_column_widths: Vec<ColumnWidth>,
319+ /// Column or window widths that `toggle_width()` switches between.
320+ pub preset_column_widths: Vec<PresetSize>,
321321 /// Initial width for new columns.
322- pub default_column_width: Option<ColumnWidth>,
322+ pub default_column_width: Option<PresetSize>,
323323 /// Window height that `toggle_window_height()` switches between.
324324 pub preset_window_heights: Vec<PresetSize>,
325325 pub animations: niri_config::Animations,
@@ -341,9 +341,9 @@ impl Default for Options {
341341 always_center_single_column: false,
342342 empty_workspace_above_first: false,
343343 preset_column_widths: vec![
344- ColumnWidth::Proportion(1. / 3.),
345- ColumnWidth::Proportion(0.5),
346- ColumnWidth::Proportion(2. / 3.),
344+ PresetSize::Proportion(1. / 3.),
345+ PresetSize::Proportion(0.5),
346+ PresetSize::Proportion(2. / 3.),
347347 ],
348348 default_column_width: None,
349349 animations: Default::default(),
@@ -492,12 +492,7 @@ impl Options {
492492 let preset_column_widths = if layout.preset_column_widths.is_empty() {
493493 Options::default().preset_column_widths
494494 } else {
495- layout
496- .preset_column_widths
497- .iter()
498- .copied()
499- .map(ColumnWidth::from)
500- .collect()
495+ layout.preset_column_widths.clone()
501496 };
502497 let preset_window_heights = if layout.preset_window_heights.is_empty() {
503498 Options::default().preset_window_heights
@@ -505,13 +500,13 @@ impl Options {
505500 layout.preset_window_heights.clone()
506501 };
507502
508- // Missing default_column_width maps to Some(ColumnWidth::Proportion(0.5)),
503+ // Missing default_column_width maps to Some(PresetSize::Proportion(0.5)),
509504 // while present, but empty, maps to None.
510505 let default_column_width = layout
511506 .default_column_width
512507 .as_ref()
513- .map(|w| w.0.map(ColumnWidth::from))
514- .unwrap_or(Some(ColumnWidth::Proportion(0.5)));
508+ .map(|w| w.0)
509+ .unwrap_or(Some(PresetSize::Proportion(0.5)));
515510
516511 Self {
517512 gaps: layout.gaps.0,
@@ -855,14 +850,14 @@ impl<W: LayoutElement> Layout<W> {
855850 &mut self,
856851 window: W,
857852 target: AddWindowTarget<W>,
858- width: Option<ColumnWidth>,
853+ width: Option<PresetSize>,
859854 height: Option<PresetSize>,
860855 is_full_width: bool,
861856 is_floating: bool,
862857 activate: ActivateWindow,
863858 ) -> Option<&Output> {
864- let resolved_width = self.resolve_default_width(&window, width, is_floating);
865- let resolved_height = height.map(SizeChange::from);
859+ let scrolling_width = self.resolve_scrolling_width(&window, width);
860+ let scrolling_height = height.map(SizeChange::from);
866861 let id = window.id().clone();
867862
868863 match &mut self.monitor_set {
@@ -933,7 +928,7 @@ impl<W: LayoutElement> Layout<W> {
933928 window,
934929 target,
935930 activate,
936- resolved_width,
931+ scrolling_width,
937932 is_full_width,
938933 is_floating,
939934 );
@@ -944,7 +939,7 @@ impl<W: LayoutElement> Layout<W> {
944939
945940 // Set the default height for scrolling windows.
946941 if !is_floating {
947- if let Some(change) = resolved_height {
942+ if let Some(change) = scrolling_height {
948943 let ws = mon
949944 .workspaces
950945 .iter_mut()
@@ -1005,14 +1000,14 @@ impl<W: LayoutElement> Layout<W> {
10051000 tile,
10061001 target,
10071002 activate,
1008- resolved_width,
1003+ scrolling_width,
10091004 is_full_width,
10101005 is_floating,
10111006 );
10121007
10131008 // Set the default height for scrolling windows.
10141009 if !is_floating {
1015- if let Some(change) = resolved_height {
1010+ if let Some(change) = scrolling_height {
10161011 ws.set_window_height(Some(&id), change);
10171012 }
10181013 }
@@ -4283,28 +4278,23 @@ impl<W: LayoutElement> Layout<W> {
42834278 self.windows().any(|(_, win)| win.id() == window)
42844279 }
42854280
4286- fn resolve_default_width(
4287- &self,
4288- window: &W,
4289- width: Option<ColumnWidth>,
4290- is_floating: bool,
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- }
4281+ fn resolve_scrolling_width(&self, window: &W, width: Option<PresetSize>) -> ColumnWidth {
4282+ let width = width.unwrap_or_else(|| PresetSize::Fixed(window.size().w));
4283+ match width {
4284+ PresetSize::Fixed(fixed) => {
4285+ let mut fixed = f64::from(fixed);
42964286
4297- // Add border width to account for the issue that the scrolling layout currently doesn't
4298- // take borders into account for fixed sizes.
4299- if let ColumnWidth::Fixed(w) = &mut width {
4300- let rules = window.rules();
4301- let border_config = rules.border.resolve_against(self.options.border);
4302- if !border_config.off {
4303- *w += border_config.width.0 * 2.;
4287+ // Add border width since ColumnWidth includes borders.
4288+ let rules = window.rules();
4289+ let border = rules.border.resolve_against(self.options.border);
4290+ if !border.off {
4291+ fixed += border.width.0 * 2.;
4292+ }
4293+
4294+ ColumnWidth::Fixed(fixed)
43044295 }
4296+ PresetSize::Proportion(prop) => ColumnWidth::Proportion(prop),
43054297 }
4306-
4307- width
43084298 }
43094299 }
43104300
src/layout/scrolling.rsmodified+69 -70
@@ -162,6 +162,9 @@ pub struct Column<W: LayoutElement> {
162162 /// upon unfullscreening and untoggling full-width.
163163 width: ColumnWidth,
164164
165+ /// Currently selected preset width index.
166+ preset_width_idx: Option<usize>,
167+
165168 /// Whether this column is full-width.
166169 is_full_width: bool,
167170
@@ -209,8 +212,6 @@ pub enum ColumnWidth {
209212 Proportion(f64),
210213 /// Fixed width in logical pixels.
211214 Fixed(f64),
212- /// One of the preset widths.
213- Preset(usize),
214215 }
215216
216217 /// Height of a window in a column.
@@ -417,22 +418,24 @@ impl<W: LayoutElement> ScrollingSpace<W> {
417418
418419 pub fn new_window_size(
419420 &self,
420- width: Option<ColumnWidth>,
421+ width: Option<PresetSize>,
421422 height: Option<PresetSize>,
422423 rules: &ResolvedWindowRules,
423424 ) -> Size<i32, Logical> {
424425 let border = rules.border.resolve_against(self.options.border);
425426
426- let width = if let Some(width) = width {
427- let is_fixed = matches!(width, ColumnWidth::Fixed(_));
428-
429- let mut width = width.resolve(&self.options, self.working_area.size.w);
430-
431- if !is_fixed && !border.off {
432- width -= border.width.0 * 2.;
433- }
427+ let width = if let Some(size) = width {
428+ let size = match resolve_preset_size(size, &self.options, self.working_area.size.w) {
429+ ResolvedSize::Tile(mut size) => {
430+ if !border.off {
431+ size -= border.width.0 * 2.;
432+ }
433+ size
434+ }
435+ ResolvedSize::Window(size) => size,
436+ };
434437
435- max(1, width.floor() as i32)
438+ max(1, size.floor() as i32)
436439 } else {
437440 0
438441 };
@@ -2173,7 +2176,7 @@ impl<W: LayoutElement> ScrollingSpace<W> {
21732176 }
21742177
21752178 let col = &mut self.columns[self.active_column_idx];
2176- col.toggle_width();
2179+ col.toggle_width(None);
21772180
21782181 cancel_resize_for_column(&mut self.interactive_resize, col);
21792182 }
@@ -2266,18 +2269,21 @@ impl<W: LayoutElement> ScrollingSpace<W> {
22662269 return;
22672270 }
22682271
2269- let col = if let Some(window) = window {
2272+ let (col, tile_idx) = if let Some(window) = window {
22702273 self.columns
22712274 .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+ })
22732281 .unwrap()
22742282 } else {
2275- &mut self.columns[self.active_column_idx]
2283+ (&mut self.columns[self.active_column_idx], None)
22762284 };
22772285
2278- // FIXME: when we fix preset fixed width to be per-window, this should also be made
2279- // window-specific to resolve the correct window width.
2280- col.toggle_width();
2286+ col.toggle_width(tile_idx);
22812287
22822288 cancel_resize_for_column(&mut self.interactive_resize, col);
22832289 }
@@ -3103,22 +3109,9 @@ impl ColumnWidth {
31033109 ColumnWidth::Proportion(proportion) => {
31043110 (view_width - options.gaps) * proportion - options.gaps
31053111 }
3106- ColumnWidth::Preset(idx) => {
3107- options.preset_column_widths[idx].resolve(options, view_width)
3108- }
31093112 ColumnWidth::Fixed(width) => width,
31103113 }
31113114 }
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- }
31223115 }
31233116
31243117 impl From<PresetSize> for ColumnWidth {
@@ -3152,6 +3145,7 @@ impl<W: LayoutElement> Column<W> {
31523145 data: vec![],
31533146 active_tile_idx: 0,
31543147 width,
3148+ preset_width_idx: None,
31553149 is_full_width,
31563150 is_fullscreen: false,
31573151 move_animation: None,
@@ -3186,11 +3180,9 @@ impl<W: LayoutElement> Column<W> {
31863180 update_sizes = true;
31873181 }
31883182
3189- // If preset widths changed, make our width non-preset.
3183+ // If preset widths changed, clear our stored preset index.
31903184 if self.options.preset_column_widths != options.preset_column_widths {
3191- if let ColumnWidth::Preset(idx) = self.width {
3192- self.width = self.options.preset_column_widths[idx];
3193- }
3185+ self.preset_width_idx = None;
31943186 }
31953187
31963188 // If preset heights changed, make our heights non-preset.
@@ -3224,12 +3216,6 @@ impl<W: LayoutElement> Column<W> {
32243216 }
32253217 }
32263218
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-
32333219 pub fn advance_animations(&mut self) {
32343220 if let Some(anim) = &mut self.move_animation {
32353221 if anim.is_done() {
@@ -3673,30 +3659,42 @@ impl<W: LayoutElement> Column<W> {
36733659 true
36743660 }
36753661
3676- fn toggle_width(&mut self) {
3677- let width = if self.is_full_width {
3678- ColumnWidth::Proportion(1.)
3662+ fn toggle_width(&mut self, tile_idx: Option<usize>) {
3663+ let tile_idx = tile_idx.unwrap_or(self.active_tile_idx);
3664+
3665+ let preset_idx = if self.is_full_width {
3666+ None
36793667 } else {
3680- self.width
3668+ self.preset_width_idx
36813669 };
36823670
3683- let idx = match width {
3684- ColumnWidth::Preset(idx) => (idx + 1) % self.options.preset_column_widths.len(),
3685- _ => {
3686- let current = self.width();
3687- self.options
3688- .preset_column_widths
3689- .iter()
3690- .position(|prop| {
3691- let resolved = prop.resolve(&self.options, self.working_area.size.w);
3671+ let preset_idx = if let Some(idx) = preset_idx {
3672+ (idx + 1) % self.options.preset_column_widths.len()
3673+ } else {
3674+ let tile = &self.tiles[tile_idx];
3675+ let current_window = tile.window_expected_or_current_size().w;
3676+ let current_tile = tile.tile_expected_or_current_size().w;
3677+
3678+ let available_size = 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 {
36923686 // Some allowance for fractional scaling purposes.
3693- current + 1. < resolved
3694- })
3695- .unwrap_or(0)
3696- }
3687+ ResolvedSize::Tile(resolved) => current_tile + 1. < resolved,
3688+ ResolvedSize::Window(resolved) => current_window + 1. < resolved,
3689+ }
3690+ })
3691+ .unwrap_or(0)
36973692 };
3698- let width = ColumnWidth::Preset(idx);
3699- self.set_width(width, true);
3693+
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);
37003698 }
37013699
37023700 fn toggle_full_width(&mut self) {
@@ -3705,18 +3703,13 @@ impl<W: LayoutElement> Column<W> {
37053703 }
37063704
37073705 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 {
37093707 ColumnWidth::Proportion(1.)
37103708 } else {
37113709 self.width
37123710 };
37133711
3714- let current_px = width.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- };
3712+ let current_px = current.resolve(&self.options, self.working_area.size.w);
37203713
37213714 // FIXME: fix overflows then remove limits.
37223715 const MAX_PX: f64 = 100000.;
@@ -3755,10 +3748,12 @@ impl<W: LayoutElement> Column<W> {
37553748 let proportion = (current + delta / 100.).clamp(0., MAX_F);
37563749 ColumnWidth::Proportion(proportion)
37573750 }
3758- (ColumnWidth::Preset(_), _) => unreachable!(),
37593751 };
37603752
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);
37623757 }
37633758
37643759 fn set_window_height(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) {
@@ -4043,6 +4038,10 @@ impl<W: LayoutElement> Column<W> {
40434038 assert_eq!(self.tiles.len(), 1);
40444039 }
40454040
4041+ if let Some(idx) = self.preset_width_idx {
4042+ assert!(idx < self.options.preset_column_widths.len());
4043+ }
4044+
40464045 let tile_count = self.tiles.len();
40474046 if tile_count == 1 {
40484047 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() {
30023002 assert_eq!(counts, &[1, 2, 0]);
30033003 }
30043004
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+
30053070 fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool {
30063071 if parent_id == id {
30073072 return true;
src/layout/workspace.rsmodified+4 -4
@@ -713,9 +713,9 @@ impl<W: LayoutElement> Workspace<W> {
713713
714714 pub fn resolve_default_width(
715715 &self,
716- default_width: Option<Option<ColumnWidth>>,
716+ default_width: Option<Option<PresetSize>>,
717717 is_floating: bool,
718- ) -> Option<ColumnWidth> {
718+ ) -> Option<PresetSize> {
719719 match default_width {
720720 Some(Some(width)) => Some(width),
721721 Some(None) => None,
@@ -740,7 +740,7 @@ impl<W: LayoutElement> Workspace<W> {
740740
741741 pub fn new_window_size(
742742 &self,
743- width: Option<ColumnWidth>,
743+ width: Option<PresetSize>,
744744 height: Option<PresetSize>,
745745 is_floating: bool,
746746 rules: &ResolvedWindowRules,
@@ -772,7 +772,7 @@ impl<W: LayoutElement> Workspace<W> {
772772 pub fn configure_new_window(
773773 &self,
774774 window: &Window,
775- width: Option<ColumnWidth>,
775+ width: Option<PresetSize>,
776776 height: Option<PresetSize>,
777777 is_floating: bool,
778778 rules: &ResolvedWindowRules,
src/window/mod.rsmodified+3 -8
@@ -11,7 +11,6 @@ use smithay::wayland::shell::xdg::{
1111 SurfaceCachedState, ToplevelSurface, XdgToplevelSurfaceRoleAttributes,
1212 };
1313
14-use crate::layout::scrolling::ColumnWidth;
1514 use crate::utils::with_toplevel_role;
1615
1716 pub mod mapped;
@@ -35,7 +34,7 @@ pub struct ResolvedWindowRules {
3534 /// - `None`: unset (global default should be used).
3635 /// - `Some(None)`: set to empty (window picks its own width).
3736 /// - `Some(Some(width))`: set to a particular width.
38- pub default_width: Option<Option<ColumnWidth>>,
37+ pub default_width: Option<Option<PresetSize>>,
3938
4039 /// Default height for this window.
4140 ///
@@ -230,12 +229,8 @@ impl ResolvedWindowRules {
230229 continue;
231230 }
232231
233- if let Some(x) = rule
234- .default_column_width
235- .as_ref()
236- .map(|d| d.0.map(ColumnWidth::from))
237- {
238- resolved.default_width = Some(x);
232+ if let Some(x) = rule.default_column_width {
233+ resolved.default_width = Some(x.0);
239234 }
240235
241236 if let Some(x) = rule.default_window_height {
src/window/unmapped.rsmodified+2 -3
@@ -5,7 +5,6 @@ use smithay::wayland::shell::xdg::ToplevelSurface;
55 use smithay::wayland::xdg_activation::XdgActivationTokenData;
66
77 use super::ResolvedWindowRules;
8-use crate::layout::scrolling::ColumnWidth;
98
109 #[derive(Debug)]
1110 pub struct Unmapped {
@@ -34,7 +33,7 @@ pub enum InitialConfigureState {
3433 /// Resolved scrolling default width for this window.
3534 ///
3635 /// `None` means that the window will pick its own width.
37- width: Option<ColumnWidth>,
36+ width: Option<PresetSize>,
3837
3938 /// Resolved scrolling default height for this window.
4039 ///
@@ -44,7 +43,7 @@ pub enum InitialConfigureState {
4443 /// Resolved floating default width for this window.
4544 ///
4645 /// `None` means that the window will pick its own width.
47- floating_width: Option<ColumnWidth>,
46+ floating_width: Option<PresetSize>,
4847
4948 /// Resolved floating default height for this window.
5049 ///
wiki/Configuration:-Layout.mdmodified+1 -1
@@ -146,7 +146,7 @@ layout {
146146 ```
147147
148148 > [!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.
150150 > I.e., preset `fixed 1000` with 4-wide borders will make the window 992 logical pixels wide.
151151 > This may eventually be corrected.
152152 >