Take border into account for fixed preset-column-width for tiled windows
Browse files at this commita0e2a15c60162e4f0a589fb5f0ce0899bce213b5Parent: 88c677810 changed files +211 -189
- niri-visual-tests/src/cases/layout.rs +14 -15
- src/handlers/xdg_shell.rs +3 -3
- src/layout/floating.rs +19 -44
- src/layout/mod.rs +31 -41
- src/layout/scrolling.rs +69 -70
- src/layout/tests.rs +65 -0
- src/layout/workspace.rs +4 -4
- src/window/mod.rs +3 -8
- src/window/unmapped.rs +2 -3
- wiki/Configuration:-Layout.md +1 -1
niri-visual-tests/src/cases/layout.rsmodified+14 -15
| @@ -2,10 +2,9 @@ use std::collections::HashMap; | ||
| 2 | 2 | use std::time::Duration; |
| 3 | 3 | |
| 4 | 4 | use niri::animation::Clock; |
| 5 | -use niri::layout::scrolling::ColumnWidth; | |
| 6 | 5 | use niri::layout::{ActivateWindow, AddWindowTarget, LayoutElement as _, Options}; |
| 7 | 6 | use niri::render_helpers::RenderTarget; |
| 8 | -use niri_config::{Color, FloatOrInt, OutputName}; | |
| 7 | +use niri_config::{Color, FloatOrInt, OutputName, PresetSize}; | |
| 9 | 8 | use smithay::backend::renderer::element::RenderElement; |
| 10 | 9 | use smithay::backend::renderer::gles::GlesRenderer; |
| 11 | 10 | use smithay::desktop::layer_map_for_output; |
| @@ -84,13 +83,13 @@ impl Layout { | ||
| 84 | 83 | pub fn open_in_between(args: Args) -> Self { |
| 85 | 84 | let mut rv = Self::new(args); |
| 86 | 85 | |
| 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))); | |
| 89 | 88 | rv.layout.activate_window(&0); |
| 90 | 89 | |
| 91 | 90 | rv.add_step(500, |l| { |
| 92 | 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 | 93 | l.layout.start_open_animation_for_window(win.id()); |
| 95 | 94 | }); |
| 96 | 95 | |
| @@ -103,7 +102,7 @@ impl Layout { | ||
| 103 | 102 | for delay in [100, 200, 300] { |
| 104 | 103 | rv.add_step(delay, move |l| { |
| 105 | 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 | 106 | l.layout.start_open_animation_for_window(win.id()); |
| 108 | 107 | }); |
| 109 | 108 | } |
| @@ -117,7 +116,7 @@ impl Layout { | ||
| 117 | 116 | for delay in [100, 200, 300] { |
| 118 | 117 | rv.add_step(delay, move |l| { |
| 119 | 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 | 120 | l.layout.start_open_animation_for_window(win.id()); |
| 122 | 121 | }); |
| 123 | 122 | } |
| @@ -128,13 +127,13 @@ impl Layout { | ||
| 128 | 127 | pub fn open_to_the_left(args: Args) -> Self { |
| 129 | 128 | let mut rv = Self::new(args); |
| 130 | 129 | |
| 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))); | |
| 133 | 132 | |
| 134 | 133 | rv.add_step(500, |l| { |
| 135 | 134 | let win = TestWindow::freeform(2); |
| 136 | 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 | 137 | l.layout.start_open_animation_for_window(win.id()); |
| 139 | 138 | }); |
| 140 | 139 | |
| @@ -144,20 +143,20 @@ impl Layout { | ||
| 144 | 143 | pub fn open_to_the_left_big(args: Args) -> Self { |
| 145 | 144 | let mut rv = Self::new(args); |
| 146 | 145 | |
| 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))); | |
| 149 | 148 | |
| 150 | 149 | rv.add_step(500, |l| { |
| 151 | 150 | let win = TestWindow::freeform(2); |
| 152 | 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 | 153 | l.layout.start_open_animation_for_window(win.id()); |
| 155 | 154 | }); |
| 156 | 155 | |
| 157 | 156 | 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 | 160 | let ws = self.layout.active_workspace().unwrap(); |
| 162 | 161 | let min_size = window.min_size(); |
| 163 | 162 | let max_size = window.max_size(); |
| @@ -184,7 +183,7 @@ impl Layout { | ||
| 184 | 183 | &mut self, |
| 185 | 184 | right_of: &TestWindow, |
| 186 | 185 | mut window: TestWindow, |
| 187 | - width: Option<ColumnWidth>, | |
| 186 | + width: Option<PresetSize>, | |
| 188 | 187 | ) { |
| 189 | 188 | let ws = self.layout.active_workspace().unwrap(); |
| 190 | 189 | let min_size = window.min_size(); |
src/handlers/xdg_shell.rsmodified+3 -3
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | use std::cell::Cell; |
| 2 | 2 | |
| 3 | 3 | use calloop::Interest; |
| 4 | +use niri_config::PresetSize; | |
| 4 | 5 | use smithay::desktop::{ |
| 5 | 6 | find_popup_root_surface, get_popup_toplevel_coords, layer_map_for_output, utils, LayerSurface, |
| 6 | 7 | PopupKeyboardGrab, PopupKind, PopupManager, PopupPointerGrab, PopupUngrabStrategy, Window, |
| @@ -42,7 +43,6 @@ use crate::input::resize_grab::ResizeGrab; | ||
| 42 | 43 | use crate::input::touch_move_grab::TouchMoveGrab; |
| 43 | 44 | use crate::input::touch_resize_grab::TouchResizeGrab; |
| 44 | 45 | use crate::input::{PointerOrTouchStartData, DOUBLE_CLICK_TIME}; |
| 45 | -use crate::layout::scrolling::ColumnWidth; | |
| 46 | 46 | use crate::niri::{PopupGrabState, State}; |
| 47 | 47 | use crate::utils::transaction::Transaction; |
| 48 | 48 | use crate::utils::{get_monotonic_time, output_matches_name, send_scale_transform, ResizeEdge}; |
| @@ -591,7 +591,7 @@ impl XdgShellHandler for State { | ||
| 591 | 591 | let configure_width = if is_floating { |
| 592 | 592 | *floating_width |
| 593 | 593 | } else if *is_full_width { |
| 594 | - Some(ColumnWidth::Proportion(1.)) | |
| 594 | + Some(PresetSize::Proportion(1.)) | |
| 595 | 595 | } else { |
| 596 | 596 | *width |
| 597 | 597 | }; |
| @@ -917,7 +917,7 @@ impl State { | ||
| 917 | 917 | let configure_width = if is_floating { |
| 918 | 918 | floating_width |
| 919 | 919 | } else if is_full_width { |
| 920 | - Some(ColumnWidth::Proportion(1.)) | |
| 920 | + Some(PresetSize::Proportion(1.)) | |
| 921 | 921 | } else { |
| 922 | 922 | width |
| 923 | 923 | }; |
src/layout/floating.rsmodified+19 -44
| @@ -623,7 +623,7 @@ impl<W: LayoutElement> FloatingSpace<W> { | ||
| 623 | 623 | .preset_column_widths |
| 624 | 624 | .iter() |
| 625 | 625 | .position(|preset| { |
| 626 | - let resolved = preset.resolve_no_gaps(&self.options, available_size); | |
| 626 | + let resolved = resolve_preset_size(*preset, available_size); | |
| 627 | 627 | match resolved { |
| 628 | 628 | // Some allowance for fractional scaling purposes. |
| 629 | 629 | ResolvedSize::Tile(resolved) => current_tile + 1. < resolved, |
| @@ -634,13 +634,7 @@ impl<W: LayoutElement> FloatingSpace<W> { | ||
| 634 | 634 | }; |
| 635 | 635 | |
| 636 | 636 | 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); | |
| 644 | 638 | |
| 645 | 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 | 1135 | pub fn new_window_size( |
| 1150 | 1136 | &self, |
| 1151 | - width: Option<ColumnWidth>, | |
| 1137 | + width: Option<PresetSize>, | |
| 1152 | 1138 | height: Option<PresetSize>, |
| 1153 | 1139 | rules: &ResolvedWindowRules, |
| 1154 | 1140 | ) -> Size<i32, Logical> { |
| 1155 | 1141 | let border = rules.border.resolve_against(self.options.border); |
| 1156 | 1142 | |
| 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 | |
| 1162 | 1151 | } |
| 1163 | - size | |
| 1164 | - } | |
| 1165 | - ResolvedSize::Window(size) => size, | |
| 1166 | - }; | |
| 1152 | + ResolvedSize::Window(size) => size, | |
| 1153 | + }; | |
| 1167 | 1154 | |
| 1168 | - max(1, width.floor() as i32) | |
| 1169 | - } else { | |
| 1170 | - 0 | |
| 1155 | + max(1, size.floor() as i32) | |
| 1156 | + } else { | |
| 1157 | + 0 | |
| 1158 | + } | |
| 1171 | 1159 | }; |
| 1172 | 1160 | |
| 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); | |
| 1188 | 1163 | |
| 1189 | 1164 | Size::from((width, height)) |
| 1190 | 1165 | } |
src/layout/mod.rsmodified+31 -41
| @@ -316,10 +316,10 @@ pub struct Options { | ||
| 316 | 316 | pub center_focused_column: CenterFocusedColumn, |
| 317 | 317 | pub always_center_single_column: bool, |
| 318 | 318 | 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>, | |
| 321 | 321 | /// Initial width for new columns. |
| 322 | - pub default_column_width: Option<ColumnWidth>, | |
| 322 | + pub default_column_width: Option<PresetSize>, | |
| 323 | 323 | /// Window height that `toggle_window_height()` switches between. |
| 324 | 324 | pub preset_window_heights: Vec<PresetSize>, |
| 325 | 325 | pub animations: niri_config::Animations, |
| @@ -341,9 +341,9 @@ impl Default for Options { | ||
| 341 | 341 | always_center_single_column: false, |
| 342 | 342 | empty_workspace_above_first: false, |
| 343 | 343 | 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.), | |
| 347 | 347 | ], |
| 348 | 348 | default_column_width: None, |
| 349 | 349 | animations: Default::default(), |
| @@ -492,12 +492,7 @@ impl Options { | ||
| 492 | 492 | let preset_column_widths = if layout.preset_column_widths.is_empty() { |
| 493 | 493 | Options::default().preset_column_widths |
| 494 | 494 | } else { |
| 495 | - layout | |
| 496 | - .preset_column_widths | |
| 497 | - .iter() | |
| 498 | - .copied() | |
| 499 | - .map(ColumnWidth::from) | |
| 500 | - .collect() | |
| 495 | + layout.preset_column_widths.clone() | |
| 501 | 496 | }; |
| 502 | 497 | let preset_window_heights = if layout.preset_window_heights.is_empty() { |
| 503 | 498 | Options::default().preset_window_heights |
| @@ -505,13 +500,13 @@ impl Options { | ||
| 505 | 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 | 504 | // while present, but empty, maps to None. |
| 510 | 505 | let default_column_width = layout |
| 511 | 506 | .default_column_width |
| 512 | 507 | .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))); | |
| 515 | 510 | |
| 516 | 511 | Self { |
| 517 | 512 | gaps: layout.gaps.0, |
| @@ -855,14 +850,14 @@ impl<W: LayoutElement> Layout<W> { | ||
| 855 | 850 | &mut self, |
| 856 | 851 | window: W, |
| 857 | 852 | target: AddWindowTarget<W>, |
| 858 | - width: Option<ColumnWidth>, | |
| 853 | + width: Option<PresetSize>, | |
| 859 | 854 | height: Option<PresetSize>, |
| 860 | 855 | is_full_width: bool, |
| 861 | 856 | is_floating: bool, |
| 862 | 857 | activate: ActivateWindow, |
| 863 | 858 | ) -> 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); | |
| 866 | 861 | let id = window.id().clone(); |
| 867 | 862 | |
| 868 | 863 | match &mut self.monitor_set { |
| @@ -933,7 +928,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 933 | 928 | window, |
| 934 | 929 | target, |
| 935 | 930 | activate, |
| 936 | - resolved_width, | |
| 931 | + scrolling_width, | |
| 937 | 932 | is_full_width, |
| 938 | 933 | is_floating, |
| 939 | 934 | ); |
| @@ -944,7 +939,7 @@ impl<W: LayoutElement> Layout<W> { | ||
| 944 | 939 | |
| 945 | 940 | // Set the default height for scrolling windows. |
| 946 | 941 | if !is_floating { |
| 947 | - if let Some(change) = resolved_height { | |
| 942 | + if let Some(change) = scrolling_height { | |
| 948 | 943 | let ws = mon |
| 949 | 944 | .workspaces |
| 950 | 945 | .iter_mut() |
| @@ -1005,14 +1000,14 @@ impl<W: LayoutElement> Layout<W> { | ||
| 1005 | 1000 | tile, |
| 1006 | 1001 | target, |
| 1007 | 1002 | activate, |
| 1008 | - resolved_width, | |
| 1003 | + scrolling_width, | |
| 1009 | 1004 | is_full_width, |
| 1010 | 1005 | is_floating, |
| 1011 | 1006 | ); |
| 1012 | 1007 | |
| 1013 | 1008 | // Set the default height for scrolling windows. |
| 1014 | 1009 | if !is_floating { |
| 1015 | - if let Some(change) = resolved_height { | |
| 1010 | + if let Some(change) = scrolling_height { | |
| 1016 | 1011 | ws.set_window_height(Some(&id), change); |
| 1017 | 1012 | } |
| 1018 | 1013 | } |
| @@ -4283,28 +4278,23 @@ impl<W: LayoutElement> Layout<W> { | ||
| 4283 | 4278 | self.windows().any(|(_, win)| win.id() == window) |
| 4284 | 4279 | } |
| 4285 | 4280 | |
| 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); | |
| 4296 | 4286 | |
| 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) | |
| 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 | 162 | /// upon unfullscreening and untoggling full-width. |
| 163 | 163 | width: ColumnWidth, |
| 164 | 164 | |
| 165 | + /// Currently selected preset width index. | |
| 166 | + preset_width_idx: Option<usize>, | |
| 167 | + | |
| 165 | 168 | /// Whether this column is full-width. |
| 166 | 169 | is_full_width: bool, |
| 167 | 170 | |
| @@ -209,8 +212,6 @@ pub enum ColumnWidth { | ||
| 209 | 212 | Proportion(f64), |
| 210 | 213 | /// Fixed width in logical pixels. |
| 211 | 214 | Fixed(f64), |
| 212 | - /// One of the preset widths. | |
| 213 | - Preset(usize), | |
| 214 | 215 | } |
| 215 | 216 | |
| 216 | 217 | /// Height of a window in a column. |
| @@ -417,22 +418,24 @@ impl<W: LayoutElement> ScrollingSpace<W> { | ||
| 417 | 418 | |
| 418 | 419 | pub fn new_window_size( |
| 419 | 420 | &self, |
| 420 | - width: Option<ColumnWidth>, | |
| 421 | + width: Option<PresetSize>, | |
| 421 | 422 | height: Option<PresetSize>, |
| 422 | 423 | rules: &ResolvedWindowRules, |
| 423 | 424 | ) -> Size<i32, Logical> { |
| 424 | 425 | let border = rules.border.resolve_against(self.options.border); |
| 425 | 426 | |
| 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 | + }; | |
| 434 | 437 | |
| 435 | - max(1, width.floor() as i32) | |
| 438 | + max(1, size.floor() as i32) | |
| 436 | 439 | } else { |
| 437 | 440 | 0 |
| 438 | 441 | }; |
| @@ -2173,7 +2176,7 @@ impl<W: LayoutElement> ScrollingSpace<W> { | ||
| 2173 | 2176 | } |
| 2174 | 2177 | |
| 2175 | 2178 | let col = &mut self.columns[self.active_column_idx]; |
| 2176 | - col.toggle_width(); | |
| 2179 | + col.toggle_width(None); | |
| 2177 | 2180 | |
| 2178 | 2181 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2179 | 2182 | } |
| @@ -2266,18 +2269,21 @@ impl<W: LayoutElement> ScrollingSpace<W> { | ||
| 2266 | 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 | 2273 | self.columns |
| 2271 | 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 | 2281 | .unwrap() |
| 2274 | 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 made | |
| 2279 | - // window-specific to resolve the correct window width. | |
| 2280 | - col.toggle_width(); | |
| 2286 | + col.toggle_width(tile_idx); | |
| 2281 | 2287 | |
| 2282 | 2288 | cancel_resize_for_column(&mut self.interactive_resize, col); |
| 2283 | 2289 | } |
| @@ -3103,22 +3109,9 @@ impl ColumnWidth { | ||
| 3103 | 3109 | ColumnWidth::Proportion(proportion) => { |
| 3104 | 3110 | (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 | 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 | 3117 | impl From<PresetSize> for ColumnWidth { |
| @@ -3152,6 +3145,7 @@ impl<W: LayoutElement> Column<W> { | ||
| 3152 | 3145 | data: vec![], |
| 3153 | 3146 | active_tile_idx: 0, |
| 3154 | 3147 | width, |
| 3148 | + preset_width_idx: None, | |
| 3155 | 3149 | is_full_width, |
| 3156 | 3150 | is_fullscreen: false, |
| 3157 | 3151 | move_animation: None, |
| @@ -3186,11 +3180,9 @@ impl<W: LayoutElement> Column<W> { | ||
| 3186 | 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 | 3184 | 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; | |
| 3194 | 3186 | } |
| 3195 | 3187 | |
| 3196 | 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 | 3219 | pub fn advance_animations(&mut self) { |
| 3234 | 3220 | if let Some(anim) = &mut self.move_animation { |
| 3235 | 3221 | if anim.is_done() { |
| @@ -3673,30 +3659,42 @@ impl<W: LayoutElement> Column<W> { | ||
| 3673 | 3659 | true |
| 3674 | 3660 | } |
| 3675 | 3661 | |
| 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 | |
| 3679 | 3667 | } else { |
| 3680 | - self.width | |
| 3668 | + self.preset_width_idx | |
| 3681 | 3669 | }; |
| 3682 | 3670 | |
| 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 { | |
| 3692 | 3686 | // 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) | |
| 3697 | 3692 | }; |
| 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); | |
| 3700 | 3698 | } |
| 3701 | 3699 | |
| 3702 | 3700 | fn toggle_full_width(&mut self) { |
| @@ -3705,18 +3703,13 @@ impl<W: LayoutElement> Column<W> { | ||
| 3705 | 3703 | } |
| 3706 | 3704 | |
| 3707 | 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 | 3707 | ColumnWidth::Proportion(1.) |
| 3710 | 3708 | } else { |
| 3711 | 3709 | self.width |
| 3712 | 3710 | }; |
| 3713 | 3711 | |
| 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); | |
| 3720 | 3713 | |
| 3721 | 3714 | // FIXME: fix overflows then remove limits. |
| 3722 | 3715 | const MAX_PX: f64 = 100000.; |
| @@ -3755,10 +3748,12 @@ impl<W: LayoutElement> Column<W> { | ||
| 3755 | 3748 | let proportion = (current + delta / 100.).clamp(0., MAX_F); |
| 3756 | 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 | 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 | 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 | 4045 | let tile_count = self.tiles.len(); |
| 4047 | 4046 | if tile_count == 1 { |
| 4048 | 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 | 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 | 3070 | fn parent_id_causes_loop(layout: &Layout<TestWindow>, id: usize, mut parent_id: usize) -> bool { |
| 3006 | 3071 | if parent_id == id { |
| 3007 | 3072 | return true; |
src/layout/workspace.rsmodified+4 -4
| @@ -713,9 +713,9 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 713 | 713 | |
| 714 | 714 | pub fn resolve_default_width( |
| 715 | 715 | &self, |
| 716 | - default_width: Option<Option<ColumnWidth>>, | |
| 716 | + default_width: Option<Option<PresetSize>>, | |
| 717 | 717 | is_floating: bool, |
| 718 | - ) -> Option<ColumnWidth> { | |
| 718 | + ) -> Option<PresetSize> { | |
| 719 | 719 | match default_width { |
| 720 | 720 | Some(Some(width)) => Some(width), |
| 721 | 721 | Some(None) => None, |
| @@ -740,7 +740,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 740 | 740 | |
| 741 | 741 | pub fn new_window_size( |
| 742 | 742 | &self, |
| 743 | - width: Option<ColumnWidth>, | |
| 743 | + width: Option<PresetSize>, | |
| 744 | 744 | height: Option<PresetSize>, |
| 745 | 745 | is_floating: bool, |
| 746 | 746 | rules: &ResolvedWindowRules, |
| @@ -772,7 +772,7 @@ impl<W: LayoutElement> Workspace<W> { | ||
| 772 | 772 | pub fn configure_new_window( |
| 773 | 773 | &self, |
| 774 | 774 | window: &Window, |
| 775 | - width: Option<ColumnWidth>, | |
| 775 | + width: Option<PresetSize>, | |
| 776 | 776 | height: Option<PresetSize>, |
| 777 | 777 | is_floating: bool, |
| 778 | 778 | rules: &ResolvedWindowRules, |
src/window/mod.rsmodified+3 -8
| @@ -11,7 +11,6 @@ use smithay::wayland::shell::xdg::{ | ||
| 11 | 11 | SurfaceCachedState, ToplevelSurface, XdgToplevelSurfaceRoleAttributes, |
| 12 | 12 | }; |
| 13 | 13 | |
| 14 | -use crate::layout::scrolling::ColumnWidth; | |
| 15 | 14 | use crate::utils::with_toplevel_role; |
| 16 | 15 | |
| 17 | 16 | pub mod mapped; |
| @@ -35,7 +34,7 @@ pub struct ResolvedWindowRules { | ||
| 35 | 34 | /// - `None`: unset (global default should be used). |
| 36 | 35 | /// - `Some(None)`: set to empty (window picks its own width). |
| 37 | 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 | 39 | /// Default height for this window. |
| 41 | 40 | /// |
| @@ -230,12 +229,8 @@ impl ResolvedWindowRules { | ||
| 230 | 229 | continue; |
| 231 | 230 | } |
| 232 | 231 | |
| 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); | |
| 239 | 234 | } |
| 240 | 235 | |
| 241 | 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 | 5 | use smithay::wayland::xdg_activation::XdgActivationTokenData; |
| 6 | 6 | |
| 7 | 7 | use super::ResolvedWindowRules; |
| 8 | -use crate::layout::scrolling::ColumnWidth; | |
| 9 | 8 | |
| 10 | 9 | #[derive(Debug)] |
| 11 | 10 | pub struct Unmapped { |
| @@ -34,7 +33,7 @@ pub enum InitialConfigureState { | ||
| 34 | 33 | /// Resolved scrolling default width for this window. |
| 35 | 34 | /// |
| 36 | 35 | /// `None` means that the window will pick its own width. |
| 37 | - width: Option<ColumnWidth>, | |
| 36 | + width: Option<PresetSize>, | |
| 38 | 37 | |
| 39 | 38 | /// Resolved scrolling default height for this window. |
| 40 | 39 | /// |
| @@ -44,7 +43,7 @@ pub enum InitialConfigureState { | ||
| 44 | 43 | /// Resolved floating default width for this window. |
| 45 | 44 | /// |
| 46 | 45 | /// `None` means that the window will pick its own width. |
| 47 | - floating_width: Option<ColumnWidth>, | |
| 46 | + floating_width: Option<PresetSize>, | |
| 48 | 47 | |
| 49 | 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 | 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 | 150 | > I.e., preset `fixed 1000` with 4-wide borders will make the window 992 logical pixels wide. |
| 151 | 151 | > This may eventually be corrected. |
| 152 | 152 | > |