Refactor column and tile offsets, fix a few issues
Browse files at this commit5f402210510aff0051abd080d664581c26e77c2bParent: b1440594 changed files +459 -367
- src/handlers/xdg_shell.rs +1 -3
- src/layout/mod.rs +3 -28
- src/layout/tile.rs +6 -9
- src/layout/workspace.rs +449 -327
src/handlers/xdg_shell.rsmodified+1 -3
| @@ -759,7 +759,7 @@ impl State { | |||
| 759 | // height. | 759 | // height. |
| 760 | let mut target = | 760 | let mut target = |
| 761 | Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h)); | 761 | Rectangle::from_loc_and_size((0, 0), (window_geo.size.w, output_geo.size.h)); |
| 762 | - target.loc.y -= self.niri.layout.window_y(window).unwrap(); | 762 | + target.loc -= self.niri.layout.window_loc(window).unwrap(); |
| 763 | target.loc -= get_popup_toplevel_coords(popup); | 763 | target.loc -= get_popup_toplevel_coords(popup); |
| 764 | 764 | ||
| 765 | self.position_popup_within_rect(popup, target); | 765 | self.position_popup_within_rect(popup, target); |
| @@ -953,8 +953,6 @@ pub fn add_mapped_toplevel_pre_commit_hook(toplevel: &ToplevelSurface) -> HookId | |||
| 953 | state.backend.with_primary_renderer(|renderer| { | 953 | state.backend.with_primary_renderer(|renderer| { |
| 954 | mapped.store_animation_snapshot(renderer); | 954 | mapped.store_animation_snapshot(renderer); |
| 955 | }); | 955 | }); |
| 956 | - | ||
| 957 | - state.niri.layout.prepare_for_resize_animation(&window); | ||
| 958 | } | 956 | } |
| 959 | 957 | ||
| 960 | // The toplevel remains mapped; clear any stored unmap snapshot. | 958 | // The toplevel remains mapped; clear any stored unmap snapshot. |
src/layout/mod.rsmodified+3 -28
| @@ -745,14 +745,14 @@ impl<W: LayoutElement> Layout<W> { | |||
| 745 | None | 745 | None |
| 746 | } | 746 | } |
| 747 | 747 | ||
| 748 | - pub fn window_y(&self, window: &W::Id) -> Option<i32> { | 748 | + pub fn window_loc(&self, window: &W::Id) -> Option<Point<i32, Logical>> { |
| 749 | match &self.monitor_set { | 749 | match &self.monitor_set { |
| 750 | MonitorSet::Normal { monitors, .. } => { | 750 | MonitorSet::Normal { monitors, .. } => { |
| 751 | for mon in monitors { | 751 | for mon in monitors { |
| 752 | for ws in &mon.workspaces { | 752 | for ws in &mon.workspaces { |
| 753 | for col in &ws.columns { | 753 | for col in &ws.columns { |
| 754 | if let Some(idx) = col.position(window) { | 754 | if let Some(idx) = col.position(window) { |
| 755 | - return Some(col.window_y(idx)); | 755 | + return Some(col.window_loc(idx)); |
| 756 | } | 756 | } |
| 757 | } | 757 | } |
| 758 | } | 758 | } |
| @@ -762,7 +762,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 762 | for ws in workspaces { | 762 | for ws in workspaces { |
| 763 | for col in &ws.columns { | 763 | for col in &ws.columns { |
| 764 | if let Some(idx) = col.position(window) { | 764 | if let Some(idx) = col.position(window) { |
| 765 | - return Some(col.window_y(idx)); | 765 | + return Some(col.window_loc(idx)); |
| 766 | } | 766 | } |
| 767 | } | 767 | } |
| 768 | } | 768 | } |
| @@ -1995,31 +1995,6 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1995 | } | 1995 | } |
| 1996 | } | 1996 | } |
| 1997 | 1997 | ||
| 1998 | - pub fn prepare_for_resize_animation(&mut self, window: &W::Id) { | ||
| 1999 | - let _span = tracy_client::span!("Layout::prepare_for_resize_animation"); | ||
| 2000 | - | ||
| 2001 | - match &mut self.monitor_set { | ||
| 2002 | - MonitorSet::Normal { monitors, .. } => { | ||
| 2003 | - for mon in monitors { | ||
| 2004 | - for ws in &mut mon.workspaces { | ||
| 2005 | - if ws.has_window(window) { | ||
| 2006 | - ws.prepare_for_resize_animation(window); | ||
| 2007 | - return; | ||
| 2008 | - } | ||
| 2009 | - } | ||
| 2010 | - } | ||
| 2011 | - } | ||
| 2012 | - MonitorSet::NoOutputs { workspaces, .. } => { | ||
| 2013 | - for ws in workspaces { | ||
| 2014 | - if ws.has_window(window) { | ||
| 2015 | - ws.prepare_for_resize_animation(window); | ||
| 2016 | - return; | ||
| 2017 | - } | ||
| 2018 | - } | ||
| 2019 | - } | ||
| 2020 | - } | ||
| 2021 | - } | ||
| 2022 | - | ||
| 2023 | pub fn refresh(&mut self) { | 1998 | pub fn refresh(&mut self) { |
| 2024 | let _span = tracy_client::span!("Layout::refresh"); | 1999 | let _span = tracy_client::span!("Layout::refresh"); |
| 2025 | 2000 | ||
src/layout/tile.rsmodified+6 -9
| @@ -1,4 +1,3 @@ | |||
| 1 | -use std::cell::RefCell; | ||
| 2 | use std::cmp::max; | 1 | use std::cmp::max; |
| 3 | use std::rc::Rc; | 2 | use std::rc::Rc; |
| 4 | use std::time::Duration; | 3 | use std::time::Duration; |
| @@ -67,7 +66,7 @@ pub struct Tile<W: LayoutElement> { | |||
| 67 | move_y_animation: Option<MoveAnimation>, | 66 | move_y_animation: Option<MoveAnimation>, |
| 68 | 67 | ||
| 69 | /// Snapshot of the last render for use in the close animation. | 68 | /// Snapshot of the last render for use in the close animation. |
| 70 | - unmap_snapshot: RefCell<Option<TileRenderSnapshot>>, | 69 | + unmap_snapshot: Option<TileRenderSnapshot>, |
| 71 | 70 | ||
| 72 | /// Extra damage for clipped surface corner radius changes. | 71 | /// Extra damage for clipped surface corner radius changes. |
| 73 | rounded_corner_damage: RoundedCornerDamage, | 72 | rounded_corner_damage: RoundedCornerDamage, |
| @@ -122,7 +121,7 @@ impl<W: LayoutElement> Tile<W> { | |||
| 122 | resize_animation: None, | 121 | resize_animation: None, |
| 123 | move_x_animation: None, | 122 | move_x_animation: None, |
| 124 | move_y_animation: None, | 123 | move_y_animation: None, |
| 125 | - unmap_snapshot: RefCell::new(None), | 124 | + unmap_snapshot: None, |
| 126 | rounded_corner_damage: Default::default(), | 125 | rounded_corner_damage: Default::default(), |
| 127 | options, | 126 | options, |
| 128 | } | 127 | } |
| @@ -237,9 +236,7 @@ impl<W: LayoutElement> Tile<W> { | |||
| 237 | || self.move_y_animation.is_some() | 236 | || self.move_y_animation.is_some() |
| 238 | } | 237 | } |
| 239 | 238 | ||
| 240 | - pub fn update(&mut self, is_active: bool, mut view_rect: Rectangle<i32, Logical>) { | 239 | + pub fn update(&mut self, is_active: bool, view_rect: Rectangle<i32, Logical>) { |
| 241 | - view_rect.loc -= self.render_offset(); | ||
| 242 | - | ||
| 243 | let rules = self.window.rules(); | 240 | let rules = self.window.rules(); |
| 244 | 241 | ||
| 245 | let draw_border_with_background = rules | 242 | let draw_border_with_background = rules |
| @@ -840,11 +837,11 @@ impl<W: LayoutElement> Tile<W> { | |||
| 840 | renderer: &mut GlesRenderer, | 837 | renderer: &mut GlesRenderer, |
| 841 | scale: Scale<f64>, | 838 | scale: Scale<f64>, |
| 842 | ) { | 839 | ) { |
| 843 | - if self.unmap_snapshot.get_mut().is_some() { | 840 | + if self.unmap_snapshot.is_some() { |
| 844 | return; | 841 | return; |
| 845 | } | 842 | } |
| 846 | 843 | ||
| 847 | - *self.unmap_snapshot.get_mut() = Some(self.render_snapshot(renderer, scale)); | 844 | + self.unmap_snapshot = Some(self.render_snapshot(renderer, scale)); |
| 848 | } | 845 | } |
| 849 | 846 | ||
| 850 | fn render_snapshot( | 847 | fn render_snapshot( |
| @@ -881,7 +878,7 @@ impl<W: LayoutElement> Tile<W> { | |||
| 881 | } | 878 | } |
| 882 | } | 879 | } |
| 883 | 880 | ||
| 884 | - pub fn take_unmap_snapshot(&self) -> Option<TileRenderSnapshot> { | 881 | + pub fn take_unmap_snapshot(&mut self) -> Option<TileRenderSnapshot> { |
| 885 | self.unmap_snapshot.take() | 882 | self.unmap_snapshot.take() |
| 886 | } | 883 | } |
| 887 | } | 884 | } |
src/layout/workspace.rsmodified+449 -327
| @@ -54,6 +54,9 @@ pub struct Workspace<W: LayoutElement> { | |||
| 54 | /// Columns of windows on this workspace. | 54 | /// Columns of windows on this workspace. |
| 55 | pub columns: Vec<Column<W>>, | 55 | pub columns: Vec<Column<W>>, |
| 56 | 56 | ||
| 57 | + /// Extra per-column data. | ||
| 58 | + data: Vec<ColumnData>, | ||
| 59 | + | ||
| 57 | /// Index of the currently active column, if any. | 60 | /// Index of the currently active column, if any. |
| 58 | pub active_column_idx: usize, | 61 | pub active_column_idx: usize, |
| 59 | 62 | ||
| @@ -116,6 +119,13 @@ niri_render_elements! { | |||
| 116 | } | 119 | } |
| 117 | } | 120 | } |
| 118 | 121 | ||
| 122 | +/// Extra per-column data. | ||
| 123 | +#[derive(Debug, Clone, Copy, PartialEq)] | ||
| 124 | +struct ColumnData { | ||
| 125 | + /// Cached actual column width. | ||
| 126 | + width: i32, | ||
| 127 | +} | ||
| 128 | + | ||
| 119 | #[derive(Debug)] | 129 | #[derive(Debug)] |
| 120 | enum ViewOffsetAdjustment { | 130 | enum ViewOffsetAdjustment { |
| 121 | Animation(Animation), | 131 | Animation(Animation), |
| @@ -181,12 +191,10 @@ pub struct Column<W: LayoutElement> { | |||
| 181 | /// Must be non-empty. | 191 | /// Must be non-empty. |
| 182 | pub tiles: Vec<Tile<W>>, | 192 | pub tiles: Vec<Tile<W>>, |
| 183 | 193 | ||
| 184 | - /// Heights of the windows. | 194 | + /// Extra per-tile data. |
| 185 | /// | 195 | /// |
| 186 | /// Must have the same number of elements as `tiles`. | 196 | /// Must have the same number of elements as `tiles`. |
| 187 | - /// | 197 | + data: Vec<TileData>, |
| 188 | - /// These heights are window heights, not tile heights, so they exclude tile decorations. | ||
| 189 | - heights: Vec<WindowHeight>, | ||
| 190 | 198 | ||
| 191 | /// Index of the currently active tile. | 199 | /// Index of the currently active tile. |
| 192 | pub active_tile_idx: usize, | 200 | pub active_tile_idx: usize, |
| @@ -206,9 +214,6 @@ pub struct Column<W: LayoutElement> { | |||
| 206 | /// Animation of the render offset during window swapping. | 214 | /// Animation of the render offset during window swapping. |
| 207 | move_animation: Option<Animation>, | 215 | move_animation: Option<Animation>, |
| 208 | 216 | ||
| 209 | - /// Width right before a resize animation on one of the windows of the column. | ||
| 210 | - pub width_before_resize: Option<i32>, | ||
| 211 | - | ||
| 212 | /// Latest known view size for this column's workspace. | 217 | /// Latest known view size for this column's workspace. |
| 213 | view_size: Size<i32, Logical>, | 218 | view_size: Size<i32, Logical>, |
| 214 | 219 | ||
| @@ -219,6 +224,21 @@ pub struct Column<W: LayoutElement> { | |||
| 219 | options: Rc<Options>, | 224 | options: Rc<Options>, |
| 220 | } | 225 | } |
| 221 | 226 | ||
| 227 | +/// Extra per-tile data. | ||
| 228 | +#[derive(Debug, Clone, Copy, PartialEq)] | ||
| 229 | +struct TileData { | ||
| 230 | + /// Requested height of the window. | ||
| 231 | + /// | ||
| 232 | + /// This is window height, not tile height, so it excludes tile decorations. | ||
| 233 | + height: WindowHeight, | ||
| 234 | + | ||
| 235 | + /// Cached actual size of the tile. | ||
| 236 | + size: Size<i32, Logical>, | ||
| 237 | + | ||
| 238 | + /// Cached whether the tile is being interactively resized by its left edge. | ||
| 239 | + interactively_resizing_by_left_edge: bool, | ||
| 240 | +} | ||
| 241 | + | ||
| 222 | impl OutputId { | 242 | impl OutputId { |
| 223 | pub fn new(output: &Output) -> Self { | 243 | pub fn new(output: &Output) -> Self { |
| 224 | Self(output.name()) | 244 | Self(output.name()) |
| @@ -238,6 +258,18 @@ impl ViewOffsetAdjustment { | |||
| 238 | } | 258 | } |
| 239 | } | 259 | } |
| 240 | 260 | ||
| 261 | +impl ColumnData { | ||
| 262 | + pub fn new<W: LayoutElement>(column: &Column<W>) -> Self { | ||
| 263 | + let mut rv = Self { width: 0 }; | ||
| 264 | + rv.update(column); | ||
| 265 | + rv | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + pub fn update<W: LayoutElement>(&mut self, column: &Column<W>) { | ||
| 269 | + self.width = column.width(); | ||
| 270 | + } | ||
| 271 | +} | ||
| 272 | + | ||
| 241 | impl ColumnWidth { | 273 | impl ColumnWidth { |
| 242 | fn resolve(self, options: &Options, view_width: i32) -> i32 { | 274 | fn resolve(self, options: &Options, view_width: i32) -> i32 { |
| 243 | match self { | 275 | match self { |
| @@ -259,6 +291,26 @@ impl From<PresetWidth> for ColumnWidth { | |||
| 259 | } | 291 | } |
| 260 | } | 292 | } |
| 261 | 293 | ||
| 294 | +impl TileData { | ||
| 295 | + pub fn new<W: LayoutElement>(tile: &Tile<W>, height: WindowHeight) -> Self { | ||
| 296 | + let mut rv = Self { | ||
| 297 | + height, | ||
| 298 | + size: Size::default(), | ||
| 299 | + interactively_resizing_by_left_edge: false, | ||
| 300 | + }; | ||
| 301 | + rv.update(tile); | ||
| 302 | + rv | ||
| 303 | + } | ||
| 304 | + | ||
| 305 | + pub fn update<W: LayoutElement>(&mut self, tile: &Tile<W>) { | ||
| 306 | + self.size = tile.tile_size(); | ||
| 307 | + self.interactively_resizing_by_left_edge = tile | ||
| 308 | + .window() | ||
| 309 | + .interactive_resize_data() | ||
| 310 | + .map_or(false, |data| data.edges.contains(ResizeEdge::LEFT)); | ||
| 311 | + } | ||
| 312 | +} | ||
| 313 | + | ||
| 262 | impl<W: LayoutElement> Workspace<W> { | 314 | impl<W: LayoutElement> Workspace<W> { |
| 263 | pub fn new(output: Output, options: Rc<Options>) -> Self { | 315 | pub fn new(output: Output, options: Rc<Options>) -> Self { |
| 264 | let working_area = compute_working_area(&output, options.struts); | 316 | let working_area = compute_working_area(&output, options.struts); |
| @@ -268,6 +320,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 268 | working_area, | 320 | working_area, |
| 269 | output: Some(output), | 321 | output: Some(output), |
| 270 | columns: vec![], | 322 | columns: vec![], |
| 323 | + data: vec![], | ||
| 271 | active_column_idx: 0, | 324 | active_column_idx: 0, |
| 272 | interactive_resize: None, | 325 | interactive_resize: None, |
| 273 | view_offset: 0, | 326 | view_offset: 0, |
| @@ -287,6 +340,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 287 | view_size: Size::from((1280, 720)), | 340 | view_size: Size::from((1280, 720)), |
| 288 | working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)), | 341 | working_area: Rectangle::from_loc_and_size((0, 0), (1280, 720)), |
| 289 | columns: vec![], | 342 | columns: vec![], |
| 343 | + data: vec![], | ||
| 290 | active_column_idx: 0, | 344 | active_column_idx: 0, |
| 291 | interactive_resize: None, | 345 | interactive_resize: None, |
| 292 | view_offset: 0, | 346 | view_offset: 0, |
| @@ -339,12 +393,15 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 339 | } | 393 | } |
| 340 | 394 | ||
| 341 | pub fn update_render_elements(&mut self, is_active: bool) { | 395 | pub fn update_render_elements(&mut self, is_active: bool) { |
| 342 | - let mut view_rect = Rectangle::from_loc_and_size((self.view_pos(), 0), self.view_size); | 396 | + let view_pos = Point::from((self.view_pos(), 0)); |
| 343 | - | 397 | + let view_size = self.view_size(); |
| 344 | - for (col_idx, col) in self.columns.iter_mut().enumerate() { | 398 | + let active_idx = self.active_column_idx; |
| 345 | - let is_active = is_active && col_idx == self.active_column_idx; | 399 | + for (col_idx, (col, col_x)) in self.columns_mut().enumerate() { |
| 400 | + let is_active = is_active && col_idx == active_idx; | ||
| 401 | + let col_off = Point::from((col_x, 0)); | ||
| 402 | + let col_pos = view_pos - col_off - col.render_offset(); | ||
| 403 | + let view_rect = Rectangle::from_loc_and_size(col_pos, view_size); | ||
| 346 | col.update_render_elements(is_active, view_rect); | 404 | col.update_render_elements(is_active, view_rect); |
| 347 | - view_rect.loc.x -= col.width() + self.options.gaps; | ||
| 348 | } | 405 | } |
| 349 | } | 406 | } |
| 350 | 407 | ||
| @@ -730,17 +787,6 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 730 | self.windows_mut().find(|win| win.is_wl_surface(wl_surface)) | 787 | self.windows_mut().find(|win| win.is_wl_surface(wl_surface)) |
| 731 | } | 788 | } |
| 732 | 789 | ||
| 733 | - /// Computes the X position of the windows in the given column, in logical coordinates. | ||
| 734 | - pub fn column_x(&self, column_idx: usize) -> i32 { | ||
| 735 | - let mut x = 0; | ||
| 736 | - | ||
| 737 | - for column in self.columns.iter().take(column_idx) { | ||
| 738 | - x += column.width() + self.options.gaps; | ||
| 739 | - } | ||
| 740 | - | ||
| 741 | - x | ||
| 742 | - } | ||
| 743 | - | ||
| 744 | pub fn add_window_at( | 790 | pub fn add_window_at( |
| 745 | &mut self, | 791 | &mut self, |
| 746 | col_idx: usize, | 792 | col_idx: usize, |
| @@ -776,6 +822,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 776 | true, | 822 | true, |
| 777 | ); | 823 | ); |
| 778 | let width = column.width(); | 824 | let width = column.width(); |
| 825 | + self.data.insert(col_idx, ColumnData::new(&column)); | ||
| 779 | self.columns.insert(col_idx, column); | 826 | self.columns.insert(col_idx, column); |
| 780 | 827 | ||
| 781 | if activate { | 828 | if activate { |
| @@ -874,6 +921,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 874 | is_full_width, | 921 | is_full_width, |
| 875 | true, | 922 | true, |
| 876 | ); | 923 | ); |
| 924 | + self.data.insert(idx, ColumnData::new(&column)); | ||
| 877 | self.columns.insert(idx, column); | 925 | self.columns.insert(idx, column); |
| 878 | 926 | ||
| 879 | // Activate the new window if right_of was active. | 927 | // Activate the new window if right_of was active. |
| @@ -913,6 +961,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 913 | 961 | ||
| 914 | column.set_view_size(self.view_size, self.working_area); | 962 | column.set_view_size(self.view_size, self.working_area); |
| 915 | let width = column.width(); | 963 | let width = column.width(); |
| 964 | + self.data.insert(idx, ColumnData::new(&column)); | ||
| 916 | self.columns.insert(idx, column); | 965 | self.columns.insert(idx, column); |
| 917 | 966 | ||
| 918 | if activate { | 967 | if activate { |
| @@ -958,15 +1007,18 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 958 | let offset = self.column_x(column_idx + 1) - self.column_x(column_idx); | 1007 | let offset = self.column_x(column_idx + 1) - self.column_x(column_idx); |
| 959 | 1008 | ||
| 960 | let column = &mut self.columns[column_idx]; | 1009 | let column = &mut self.columns[column_idx]; |
| 1010 | + let prev_width = self.data[column_idx].width; | ||
| 961 | 1011 | ||
| 962 | // Animate movement of other tiles. | 1012 | // Animate movement of other tiles. |
| 963 | - let offset_y = column.tile_y(window_idx + 1) - column.tile_y(window_idx); | 1013 | + // FIXME: tiles can move by X too, in a centered or resizing layout with one window smaller |
| 1014 | + // than the others. | ||
| 1015 | + let offset_y = column.tile_offset(window_idx + 1).y - column.tile_offset(window_idx).y; | ||
| 964 | for tile in &mut column.tiles[window_idx + 1..] { | 1016 | for tile in &mut column.tiles[window_idx + 1..] { |
| 965 | tile.animate_move_y_from(offset_y); | 1017 | tile.animate_move_y_from(offset_y); |
| 966 | } | 1018 | } |
| 967 | 1019 | ||
| 968 | let tile = column.tiles.remove(window_idx); | 1020 | let tile = column.tiles.remove(window_idx); |
| 969 | - column.heights.remove(window_idx); | 1021 | + column.data.remove(window_idx); |
| 970 | 1022 | ||
| 971 | if let Some(output) = &self.output { | 1023 | if let Some(output) = &self.output { |
| 972 | tile.window().output_leave(output); | 1024 | tile.window().output_leave(output); |
| @@ -979,7 +1031,30 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 979 | } | 1031 | } |
| 980 | } | 1032 | } |
| 981 | 1033 | ||
| 982 | - if column.tiles.is_empty() { | 1034 | + let became_empty = column.tiles.is_empty(); |
| 1035 | + let offset = if became_empty { | ||
| 1036 | + offset | ||
| 1037 | + } else { | ||
| 1038 | + column.active_tile_idx = min(column.active_tile_idx, column.tiles.len() - 1); | ||
| 1039 | + column.update_tile_sizes(true); | ||
| 1040 | + self.data[column_idx].update(column); | ||
| 1041 | + | ||
| 1042 | + prev_width - column.width() | ||
| 1043 | + }; | ||
| 1044 | + | ||
| 1045 | + // Animate movement of the other columns. | ||
| 1046 | + let movement_config = anim_config.unwrap_or(self.options.animations.window_movement.0); | ||
| 1047 | + if self.active_column_idx <= column_idx { | ||
| 1048 | + for col in &mut self.columns[column_idx + 1..] { | ||
| 1049 | + col.animate_move_from_with_config(offset, movement_config); | ||
| 1050 | + } | ||
| 1051 | + } else { | ||
| 1052 | + for col in &mut self.columns[..=column_idx] { | ||
| 1053 | + col.animate_move_from_with_config(-offset, movement_config); | ||
| 1054 | + } | ||
| 1055 | + } | ||
| 1056 | + | ||
| 1057 | + if became_empty { | ||
| 983 | if column_idx + 1 == self.active_column_idx { | 1058 | if column_idx + 1 == self.active_column_idx { |
| 984 | // The previous column, that we were going to activate upon removal of the active | 1059 | // The previous column, that we were going to activate upon removal of the active |
| 985 | // column, has just been itself removed. | 1060 | // column, has just been itself removed. |
| @@ -990,19 +1065,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 990 | self.view_offset_before_fullscreen = None; | 1065 | self.view_offset_before_fullscreen = None; |
| 991 | } | 1066 | } |
| 992 | 1067 | ||
| 993 | - // Animate movement of the other columns. | ||
| 994 | - let movement_config = anim_config.unwrap_or(self.options.animations.window_movement.0); | ||
| 995 | - if self.active_column_idx <= column_idx { | ||
| 996 | - for col in &mut self.columns[column_idx + 1..] { | ||
| 997 | - col.animate_move_from_with_config(offset, movement_config); | ||
| 998 | - } | ||
| 999 | - } else { | ||
| 1000 | - for col in &mut self.columns[..column_idx] { | ||
| 1001 | - col.animate_move_from_with_config(-offset, movement_config); | ||
| 1002 | - } | ||
| 1003 | - } | ||
| 1004 | - | ||
| 1005 | self.columns.remove(column_idx); | 1068 | self.columns.remove(column_idx); |
| 1069 | + self.data.remove(column_idx); | ||
| 1006 | if self.columns.is_empty() { | 1070 | if self.columns.is_empty() { |
| 1007 | return tile; | 1071 | return tile; |
| 1008 | } | 1072 | } |
| @@ -1050,9 +1114,6 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1050 | return tile; | 1114 | return tile; |
| 1051 | } | 1115 | } |
| 1052 | 1116 | ||
| 1053 | - column.active_tile_idx = min(column.active_tile_idx, column.tiles.len() - 1); | ||
| 1054 | - column.update_tile_sizes(true); | ||
| 1055 | - | ||
| 1056 | tile | 1117 | tile |
| 1057 | } | 1118 | } |
| 1058 | 1119 | ||
| @@ -1070,6 +1131,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1070 | } | 1131 | } |
| 1071 | 1132 | ||
| 1072 | let column = self.columns.remove(column_idx); | 1133 | let column = self.columns.remove(column_idx); |
| 1134 | + self.data.remove(column_idx); | ||
| 1073 | 1135 | ||
| 1074 | if let Some(output) = &self.output { | 1136 | if let Some(output) = &self.output { |
| 1075 | for tile in &column.tiles { | 1137 | for tile in &column.tiles { |
| @@ -1149,22 +1211,29 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1149 | .enumerate() | 1211 | .enumerate() |
| 1150 | .find(|(_, col)| col.contains(window)) | 1212 | .find(|(_, col)| col.contains(window)) |
| 1151 | .unwrap(); | 1213 | .unwrap(); |
| 1152 | - let tile_idx = column | 1214 | + let (tile_idx, tile) = column |
| 1153 | .tiles | 1215 | .tiles |
| 1154 | - .iter() | 1216 | + .iter_mut() |
| 1155 | - .position(|tile| tile.window().id() == window) | 1217 | + .enumerate() |
| 1218 | + .find(|(_, tile)| tile.window().id() == window) | ||
| 1156 | .unwrap(); | 1219 | .unwrap(); |
| 1157 | 1220 | ||
| 1158 | - let offset = column | 1221 | + let was_fullscreen = tile.is_fullscreen(); |
| 1159 | - .width_before_resize | 1222 | + let resize = tile.window_mut().interactive_resize_data(); |
| 1160 | - .take() | ||
| 1161 | - .map_or(0, |prev| prev - column.width()); | ||
| 1162 | 1223 | ||
| 1163 | - let was_fullscreen = column.tiles[tile_idx].is_fullscreen(); | 1224 | + // Do this before calling update_window() so it can get up-to-date info. |
| 1225 | + if let Some(serial) = serial { | ||
| 1226 | + tile.window_mut().update_interactive_resize(serial); | ||
| 1227 | + } | ||
| 1228 | + | ||
| 1229 | + let prev_width = self.data[col_idx].width; | ||
| 1164 | 1230 | ||
| 1165 | column.update_window(window); | 1231 | column.update_window(window); |
| 1232 | + self.data[col_idx].update(column); | ||
| 1166 | column.update_tile_sizes(false); | 1233 | column.update_tile_sizes(false); |
| 1167 | 1234 | ||
| 1235 | + let offset = prev_width - self.data[col_idx].width; | ||
| 1236 | + | ||
| 1168 | // Move other columns in tandem with resizing. | 1237 | // Move other columns in tandem with resizing. |
| 1169 | let started_resize_anim = | 1238 | let started_resize_anim = |
| 1170 | column.tiles[tile_idx].resize_animation().is_some() && offset != 0; | 1239 | column.tiles[tile_idx].resize_animation().is_some() && offset != 0; |
| @@ -1190,12 +1259,6 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1190 | let tile = &mut col.tiles[tile_idx]; | 1259 | let tile = &mut col.tiles[tile_idx]; |
| 1191 | let window = tile.window_mut(); | 1260 | let window = tile.window_mut(); |
| 1192 | 1261 | ||
| 1193 | - let resize = window.interactive_resize_data(); | ||
| 1194 | - | ||
| 1195 | - if let Some(serial) = serial { | ||
| 1196 | - window.update_interactive_resize(serial); | ||
| 1197 | - } | ||
| 1198 | - | ||
| 1199 | // If this was the last resize commit, this function will now return None. This way we can | 1262 | // If this was the last resize commit, this function will now return None. This way we can |
| 1200 | // animate the window into view after the last resize commit. | 1263 | // animate the window into view after the last resize commit. |
| 1201 | let resize_still_ongoing = window.interactive_resize_data().is_some(); | 1264 | let resize_still_ongoing = window.interactive_resize_data().is_some(); |
| @@ -1270,28 +1333,15 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1270 | .map(|o| Scale::from(o.current_scale().fractional_scale())) | 1333 | .map(|o| Scale::from(o.current_scale().fractional_scale())) |
| 1271 | .unwrap_or(Scale::from(1.)); | 1334 | .unwrap_or(Scale::from(1.)); |
| 1272 | 1335 | ||
| 1273 | - let mut view_rect_ws = Rectangle::from_loc_and_size((self.view_pos(), 0), self.view_size); | 1336 | + let view_size = self.view_size(); |
| 1274 | - for col in &mut self.columns { | 1337 | + for (tile, tile_pos) in self.tiles_with_render_positions_mut() { |
| 1275 | - let col_width = col.width(); | 1338 | + if tile.window().id() == window { |
| 1276 | - | 1339 | + let view_pos = Point::from((-tile_pos.x, -tile_pos.y)); |
| 1277 | - let mut view_rect = view_rect_ws; | 1340 | + let view_rect = Rectangle::from_loc_and_size(view_pos, view_size); |
| 1278 | - view_rect.loc -= col.render_offset(); | 1341 | + tile.update(false, view_rect); |
| 1279 | - if !col.is_fullscreen { | 1342 | + tile.store_unmap_snapshot_if_empty(renderer, output_scale); |
| 1280 | - view_rect.loc.y -= self.working_area.loc.y + self.options.gaps; | 1343 | + return; |
| 1281 | - } | ||
| 1282 | - | ||
| 1283 | - for tile in &mut col.tiles { | ||
| 1284 | - if tile.window().id() == window { | ||
| 1285 | - view_rect.loc -= Column::render_offset_for_tile(tile, col_width, &self.options); | ||
| 1286 | - tile.update(false, view_rect); | ||
| 1287 | - tile.store_unmap_snapshot_if_empty(renderer, output_scale); | ||
| 1288 | - return; | ||
| 1289 | - } | ||
| 1290 | - | ||
| 1291 | - view_rect.loc.y -= tile.tile_size().h + self.options.gaps; | ||
| 1292 | } | 1344 | } |
| 1293 | - | ||
| 1294 | - view_rect_ws.loc.x -= col_width + self.options.gaps; | ||
| 1295 | } | 1345 | } |
| 1296 | } | 1346 | } |
| 1297 | 1347 | ||
| @@ -1311,11 +1361,6 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1311 | renderer: &mut GlesRenderer, | 1361 | renderer: &mut GlesRenderer, |
| 1312 | window: &W::Id, | 1362 | window: &W::Id, |
| 1313 | ) { | 1363 | ) { |
| 1314 | - let (tile, mut tile_pos) = self | ||
| 1315 | - .tiles_in_render_order() | ||
| 1316 | - .find(|(tile, _)| tile.window().id() == window) | ||
| 1317 | - .unwrap(); | ||
| 1318 | - | ||
| 1319 | // FIXME: workspaces should probably cache their last used scale so they can be correctly | 1364 | // FIXME: workspaces should probably cache their last used scale so they can be correctly |
| 1320 | // rendered even with no outputs connected. | 1365 | // rendered even with no outputs connected. |
| 1321 | let output_scale = self | 1366 | let output_scale = self |
| @@ -1324,36 +1369,53 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1324 | .map(|o| Scale::from(o.current_scale().fractional_scale())) | 1369 | .map(|o| Scale::from(o.current_scale().fractional_scale())) |
| 1325 | .unwrap_or(Scale::from(1.)); | 1370 | .unwrap_or(Scale::from(1.)); |
| 1326 | 1371 | ||
| 1372 | + let (tile, mut tile_pos) = self | ||
| 1373 | + .tiles_with_render_positions_mut() | ||
| 1374 | + .find(|(tile, _)| tile.window().id() == window) | ||
| 1375 | + .unwrap(); | ||
| 1376 | + | ||
| 1327 | let Some(snapshot) = tile.take_unmap_snapshot() else { | 1377 | let Some(snapshot) = tile.take_unmap_snapshot() else { |
| 1328 | return; | 1378 | return; |
| 1329 | }; | 1379 | }; |
| 1330 | 1380 | ||
| 1331 | - let col_idx = self | 1381 | + let tile_size = tile.tile_size(); |
| 1382 | + | ||
| 1383 | + let (col_idx, tile_idx) = self | ||
| 1332 | .columns | 1384 | .columns |
| 1333 | .iter() | 1385 | .iter() |
| 1334 | - .position(|col| col.contains(window)) | 1386 | + .enumerate() |
| 1387 | + .find_map(|(col_idx, col)| { | ||
| 1388 | + col.tiles | ||
| 1389 | + .iter() | ||
| 1390 | + .position(|tile| tile.window().id() == window) | ||
| 1391 | + .map(move |tile_idx| (col_idx, tile_idx)) | ||
| 1392 | + }) | ||
| 1335 | .unwrap(); | 1393 | .unwrap(); |
| 1336 | 1394 | ||
| 1337 | let col = &self.columns[col_idx]; | 1395 | let col = &self.columns[col_idx]; |
| 1338 | let removing_last = col.tiles.len() == 1; | 1396 | let removing_last = col.tiles.len() == 1; |
| 1339 | - let offset = self.column_x(col_idx + 1) - self.column_x(col_idx); | ||
| 1340 | 1397 | ||
| 1341 | tile_pos.x += self.view_pos(); | 1398 | tile_pos.x += self.view_pos(); |
| 1342 | 1399 | ||
| 1343 | - if col_idx < self.active_column_idx && removing_last { | 1400 | + if col_idx < self.active_column_idx { |
| 1401 | + let offset = if removing_last { | ||
| 1402 | + self.column_x(col_idx + 1) - self.column_x(col_idx) | ||
| 1403 | + } else { | ||
| 1404 | + self.data[col_idx].width | ||
| 1405 | + - col | ||
| 1406 | + .data | ||
| 1407 | + .iter() | ||
| 1408 | + .enumerate() | ||
| 1409 | + .filter_map(|(idx, data)| (idx != tile_idx).then_some(data.size.w)) | ||
| 1410 | + .max() | ||
| 1411 | + .unwrap() | ||
| 1412 | + }; | ||
| 1344 | tile_pos.x -= offset; | 1413 | tile_pos.x -= offset; |
| 1345 | } | 1414 | } |
| 1346 | 1415 | ||
| 1347 | let anim = Animation::new(0., 1., 0., self.options.animations.window_close.anim); | 1416 | let anim = Animation::new(0., 1., 0., self.options.animations.window_close.anim); |
| 1348 | 1417 | ||
| 1349 | - let res = ClosingWindow::new( | 1418 | + let res = ClosingWindow::new(renderer, snapshot, output_scale, tile_size, tile_pos, anim); |
| 1350 | - renderer, | ||
| 1351 | - snapshot, | ||
| 1352 | - output_scale, | ||
| 1353 | - tile.tile_size(), | ||
| 1354 | - tile_pos, | ||
| 1355 | - anim, | ||
| 1356 | - ); | ||
| 1357 | match res { | 1419 | match res { |
| 1358 | Ok(closing) => { | 1420 | Ok(closing) => { |
| 1359 | self.closing_windows.push(closing); | 1421 | self.closing_windows.push(closing); |
| @@ -1364,27 +1426,22 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1364 | } | 1426 | } |
| 1365 | } | 1427 | } |
| 1366 | 1428 | ||
| 1367 | - pub fn prepare_for_resize_animation(&mut self, window: &W::Id) { | ||
| 1368 | - let column = self | ||
| 1369 | - .columns | ||
| 1370 | - .iter_mut() | ||
| 1371 | - .find(|col| col.contains(window)) | ||
| 1372 | - .unwrap(); | ||
| 1373 | - | ||
| 1374 | - column.width_before_resize = Some(column.width()); | ||
| 1375 | - } | ||
| 1376 | - | ||
| 1377 | #[cfg(test)] | 1429 | #[cfg(test)] |
| 1378 | pub fn verify_invariants(&self) { | 1430 | pub fn verify_invariants(&self) { |
| 1379 | assert!(self.view_size.w > 0); | 1431 | assert!(self.view_size.w > 0); |
| 1380 | assert!(self.view_size.h > 0); | 1432 | assert!(self.view_size.h > 0); |
| 1433 | + assert_eq!(self.columns.len(), self.data.len()); | ||
| 1381 | 1434 | ||
| 1382 | if !self.columns.is_empty() { | 1435 | if !self.columns.is_empty() { |
| 1383 | assert!(self.active_column_idx < self.columns.len()); | 1436 | assert!(self.active_column_idx < self.columns.len()); |
| 1384 | 1437 | ||
| 1385 | - for column in &self.columns { | 1438 | + for (column, data) in zip(&self.columns, &self.data) { |
| 1386 | assert!(Rc::ptr_eq(&self.options, &column.options)); | 1439 | assert!(Rc::ptr_eq(&self.options, &column.options)); |
| 1387 | column.verify_invariants(); | 1440 | column.verify_invariants(); |
| 1441 | + | ||
| 1442 | + let mut data2 = *data; | ||
| 1443 | + data2.update(column); | ||
| 1444 | + assert_eq!(data, &data2, "column data must be up to date"); | ||
| 1388 | } | 1445 | } |
| 1389 | 1446 | ||
| 1390 | let col = &self.columns[self.active_column_idx]; | 1447 | let col = &self.columns[self.active_column_idx]; |
| @@ -1461,8 +1518,10 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1461 | let next_col_x = self.column_x(self.active_column_idx + 1); | 1518 | let next_col_x = self.column_x(self.active_column_idx + 1); |
| 1462 | 1519 | ||
| 1463 | let mut column = self.columns.remove(self.active_column_idx); | 1520 | let mut column = self.columns.remove(self.active_column_idx); |
| 1521 | + let data = self.data.remove(self.active_column_idx); | ||
| 1464 | cancel_resize_if_this_column(&mut self.interactive_resize, &mut column); | 1522 | cancel_resize_if_this_column(&mut self.interactive_resize, &mut column); |
| 1465 | self.columns.insert(new_idx, column); | 1523 | self.columns.insert(new_idx, column); |
| 1524 | + self.data.insert(new_idx, data); | ||
| 1466 | 1525 | ||
| 1467 | // Preserve the camera position when moving to the left. | 1526 | // Preserve the camera position when moving to the left. |
| 1468 | let view_offset_delta = -self.column_x(self.active_column_idx) + current_col_x; | 1527 | let view_offset_delta = -self.column_x(self.active_column_idx) + current_col_x; |
| @@ -1540,21 +1599,22 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1540 | 1599 | ||
| 1541 | let source_col_idx = self.active_column_idx; | 1600 | let source_col_idx = self.active_column_idx; |
| 1542 | let source_column = &self.columns[source_col_idx]; | 1601 | let source_column = &self.columns[source_col_idx]; |
| 1543 | - let prev_y = source_column.tile_y(source_column.active_tile_idx); | 1602 | + let prev_off = source_column.tile_offset(source_column.active_tile_idx); |
| 1544 | 1603 | ||
| 1545 | if source_column.tiles.len() == 1 { | 1604 | if source_column.tiles.len() == 1 { |
| 1546 | if self.active_column_idx == 0 { | 1605 | if self.active_column_idx == 0 { |
| 1547 | return; | 1606 | return; |
| 1548 | } | 1607 | } |
| 1549 | 1608 | ||
| 1550 | - let offset_x = self.column_x(source_col_idx) - self.column_x(source_col_idx - 1); | 1609 | + let offset = self.column_x(source_col_idx) - self.column_x(source_col_idx - 1); |
| 1610 | + let mut offset = Point::from((offset, 0)); | ||
| 1551 | 1611 | ||
| 1552 | // Move into adjacent column. | 1612 | // Move into adjacent column. |
| 1553 | let target_column_idx = source_col_idx - 1; | 1613 | let target_column_idx = source_col_idx - 1; |
| 1554 | 1614 | ||
| 1555 | // Make sure the previous (target) column is activated so the animation looks right. | 1615 | // Make sure the previous (target) column is activated so the animation looks right. |
| 1556 | - self.activate_prev_column_on_removal = Some(self.static_view_offset() + offset_x); | 1616 | + self.activate_prev_column_on_removal = Some(self.static_view_offset() + offset.x); |
| 1557 | - let offset_x = offset_x + self.columns[source_col_idx].render_offset().x; | 1617 | + offset.x += self.columns[source_col_idx].render_offset().x; |
| 1558 | let tile = self.remove_tile_by_idx( | 1618 | let tile = self.remove_tile_by_idx( |
| 1559 | source_col_idx, | 1619 | source_col_idx, |
| 1560 | 0, | 1620 | 0, |
| @@ -1566,14 +1626,16 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1566 | let prev_next_x = self.column_x(next_col_idx); | 1626 | let prev_next_x = self.column_x(next_col_idx); |
| 1567 | 1627 | ||
| 1568 | let target_column = &mut self.columns[target_column_idx]; | 1628 | let target_column = &mut self.columns[target_column_idx]; |
| 1569 | - let offset_x = offset_x - target_column.render_offset().x; | 1629 | + offset.x -= target_column.render_offset().x; |
| 1570 | - let offset_y = prev_y - target_column.tile_y(target_column.tiles.len()); | ||
| 1571 | 1630 | ||
| 1572 | target_column.add_tile(tile, true); | 1631 | target_column.add_tile(tile, true); |
| 1632 | + self.data[target_column_idx].update(target_column); | ||
| 1573 | target_column.focus_last(); | 1633 | target_column.focus_last(); |
| 1574 | 1634 | ||
| 1635 | + offset += prev_off - target_column.tile_offset(target_column.tiles.len() - 1); | ||
| 1636 | + | ||
| 1575 | let new_tile = target_column.tiles.last_mut().unwrap(); | 1637 | let new_tile = target_column.tiles.last_mut().unwrap(); |
| 1576 | - new_tile.animate_move_from(Point::from((offset_x, offset_y))); | 1638 | + new_tile.animate_move_from(offset); |
| 1577 | 1639 | ||
| 1578 | // Consuming a window into a column could've increased its width if the new window had a | 1640 | // Consuming a window into a column could've increased its width if the new window had a |
| 1579 | // larger min width. Move the next columns to account for this. | 1641 | // larger min width. Move the next columns to account for this. |
| @@ -1586,7 +1648,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1586 | let width = source_column.width; | 1648 | let width = source_column.width; |
| 1587 | let is_full_width = source_column.is_full_width; | 1649 | let is_full_width = source_column.is_full_width; |
| 1588 | 1650 | ||
| 1589 | - let offset_x = source_column.render_offset().x; | 1651 | + let mut offset = Point::from((source_column.render_offset().x, 0)); |
| 1590 | 1652 | ||
| 1591 | let tile = self.remove_tile_by_idx(source_col_idx, source_column.active_tile_idx, None); | 1653 | let tile = self.remove_tile_by_idx(source_col_idx, source_column.active_tile_idx, None); |
| 1592 | 1654 | ||
| @@ -1603,8 +1665,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1603 | self.activate_prev_column_on_removal = None; | 1665 | self.activate_prev_column_on_removal = None; |
| 1604 | 1666 | ||
| 1605 | let new_col = &mut self.columns[self.active_column_idx]; | 1667 | let new_col = &mut self.columns[self.active_column_idx]; |
| 1606 | - let offset_y = prev_y - new_col.tile_y(0); | 1668 | + offset += prev_off - new_col.tile_offset(0); |
| 1607 | - new_col.tiles[0].animate_move_from(Point::from((offset_x, offset_y))); | 1669 | + new_col.tiles[0].animate_move_from(offset); |
| 1608 | } | 1670 | } |
| 1609 | } | 1671 | } |
| 1610 | 1672 | ||
| @@ -1614,11 +1676,12 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1614 | } | 1676 | } |
| 1615 | 1677 | ||
| 1616 | let source_col_idx = self.active_column_idx; | 1678 | let source_col_idx = self.active_column_idx; |
| 1617 | - let offset_x = self.column_x(source_col_idx) - self.column_x(source_col_idx + 1); | 1679 | + let offset = self.column_x(source_col_idx) - self.column_x(source_col_idx + 1); |
| 1680 | + let mut offset = Point::from((offset, 0)); | ||
| 1618 | 1681 | ||
| 1619 | let source_column = &self.columns[source_col_idx]; | 1682 | let source_column = &self.columns[source_col_idx]; |
| 1620 | - let offset_x = offset_x + source_column.render_offset().x; | 1683 | + offset.x += source_column.render_offset().x; |
| 1621 | - let prev_y = source_column.tile_y(source_column.active_tile_idx); | 1684 | + let prev_off = source_column.tile_offset(source_column.active_tile_idx); |
| 1622 | 1685 | ||
| 1623 | if source_column.tiles.len() == 1 { | 1686 | if source_column.tiles.len() == 1 { |
| 1624 | if self.active_column_idx + 1 == self.columns.len() { | 1687 | if self.active_column_idx + 1 == self.columns.len() { |
| @@ -1628,7 +1691,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1628 | // Move into adjacent column. | 1691 | // Move into adjacent column. |
| 1629 | let target_column_idx = source_col_idx; | 1692 | let target_column_idx = source_col_idx; |
| 1630 | 1693 | ||
| 1631 | - let offset_x = offset_x - self.columns[source_col_idx + 1].render_offset().x; | 1694 | + offset.x -= self.columns[source_col_idx + 1].render_offset().x; |
| 1632 | 1695 | ||
| 1633 | // Make sure the target column gets activated. | 1696 | // Make sure the target column gets activated. |
| 1634 | self.activate_prev_column_on_removal = None; | 1697 | self.activate_prev_column_on_removal = None; |
| @@ -1642,13 +1705,14 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1642 | let prev_next_x = self.column_x(target_column_idx + 1); | 1705 | let prev_next_x = self.column_x(target_column_idx + 1); |
| 1643 | 1706 | ||
| 1644 | let target_column = &mut self.columns[target_column_idx]; | 1707 | let target_column = &mut self.columns[target_column_idx]; |
| 1645 | - let offset_y = prev_y - target_column.tile_y(target_column.tiles.len()); | ||
| 1646 | - | ||
| 1647 | target_column.add_tile(tile, true); | 1708 | target_column.add_tile(tile, true); |
| 1709 | + self.data[target_column_idx].update(target_column); | ||
| 1648 | target_column.focus_last(); | 1710 | target_column.focus_last(); |
| 1649 | 1711 | ||
| 1712 | + offset += prev_off - target_column.tile_offset(target_column.tiles.len() - 1); | ||
| 1713 | + | ||
| 1650 | let new_tile = target_column.tiles.last_mut().unwrap(); | 1714 | let new_tile = target_column.tiles.last_mut().unwrap(); |
| 1651 | - new_tile.animate_move_from(Point::from((offset_x, offset_y))); | 1715 | + new_tile.animate_move_from(offset); |
| 1652 | 1716 | ||
| 1653 | // Consuming a window into a column could've increased its width if the new window had a | 1717 | // Consuming a window into a column could've increased its width if the new window had a |
| 1654 | // larger min width. Move the next columns to account for this. | 1718 | // larger min width. Move the next columns to account for this. |
| @@ -1672,8 +1736,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1672 | ); | 1736 | ); |
| 1673 | 1737 | ||
| 1674 | let new_col = &mut self.columns[self.active_column_idx]; | 1738 | let new_col = &mut self.columns[self.active_column_idx]; |
| 1675 | - let offset_y = prev_y - new_col.tile_y(0); | 1739 | + offset += prev_off - new_col.tile_offset(0); |
| 1676 | - new_col.tiles[0].animate_move_from(Point::from((offset_x, offset_y))); | 1740 | + new_col.tiles[0].animate_move_from(offset); |
| 1677 | } | 1741 | } |
| 1678 | } | 1742 | } |
| 1679 | 1743 | ||
| @@ -1688,10 +1752,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1688 | 1752 | ||
| 1689 | let source_column_idx = self.active_column_idx + 1; | 1753 | let source_column_idx = self.active_column_idx + 1; |
| 1690 | 1754 | ||
| 1691 | - let offset_x = self.column_x(source_column_idx) | 1755 | + let offset = self.column_x(source_column_idx) |
| 1692 | + self.columns[source_column_idx].render_offset().x | 1756 | + self.columns[source_column_idx].render_offset().x |
| 1693 | - self.column_x(self.active_column_idx); | 1757 | - self.column_x(self.active_column_idx); |
| 1694 | - let prev_y = self.columns[source_column_idx].tile_y(0); | 1758 | + let mut offset = Point::from((offset, 0)); |
| 1759 | + let prev_off = self.columns[source_column_idx].tile_offset(0); | ||
| 1695 | 1760 | ||
| 1696 | let tile = self.remove_tile_by_idx(source_column_idx, 0, None); | 1761 | let tile = self.remove_tile_by_idx(source_column_idx, 0, None); |
| 1697 | self.enter_output_for_window(tile.window()); | 1762 | self.enter_output_for_window(tile.window()); |
| @@ -1700,18 +1765,20 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1700 | 1765 | ||
| 1701 | let target_column = &mut self.columns[self.active_column_idx]; | 1766 | let target_column = &mut self.columns[self.active_column_idx]; |
| 1702 | let was_fullscreen = target_column.tiles[target_column.active_tile_idx].is_fullscreen(); | 1767 | let was_fullscreen = target_column.tiles[target_column.active_tile_idx].is_fullscreen(); |
| 1703 | - let offset_y = prev_y - target_column.tile_y(target_column.tiles.len()); | ||
| 1704 | 1768 | ||
| 1705 | target_column.add_tile(tile, true); | 1769 | target_column.add_tile(tile, true); |
| 1770 | + self.data[self.active_column_idx].update(target_column); | ||
| 1771 | + | ||
| 1772 | + offset += prev_off - target_column.tile_offset(target_column.tiles.len() - 1); | ||
| 1706 | 1773 | ||
| 1707 | if !was_fullscreen { | 1774 | if !was_fullscreen { |
| 1708 | self.view_offset_before_fullscreen = None; | 1775 | self.view_offset_before_fullscreen = None; |
| 1709 | } | 1776 | } |
| 1710 | 1777 | ||
| 1711 | - let offset_x = offset_x - target_column.render_offset().x; | 1778 | + offset.x -= target_column.render_offset().x; |
| 1712 | 1779 | ||
| 1713 | let new_tile = target_column.tiles.last_mut().unwrap(); | 1780 | let new_tile = target_column.tiles.last_mut().unwrap(); |
| 1714 | - new_tile.animate_move_from(Point::from((offset_x, offset_y))); | 1781 | + new_tile.animate_move_from(offset); |
| 1715 | 1782 | ||
| 1716 | // Consuming a window into a column could've increased its width if the new window had a | 1783 | // Consuming a window into a column could've increased its width if the new window had a |
| 1717 | // larger min width. Move the next columns to account for this. | 1784 | // larger min width. Move the next columns to account for this. |
| @@ -1726,17 +1793,17 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1726 | return; | 1793 | return; |
| 1727 | } | 1794 | } |
| 1728 | 1795 | ||
| 1729 | - let offset_x = | 1796 | + let offset = |
| 1730 | self.column_x(self.active_column_idx) - self.column_x(self.active_column_idx + 1); | 1797 | self.column_x(self.active_column_idx) - self.column_x(self.active_column_idx + 1); |
| 1798 | + let mut offset = Point::from((offset, 0)); | ||
| 1731 | 1799 | ||
| 1732 | let source_column = &self.columns[self.active_column_idx]; | 1800 | let source_column = &self.columns[self.active_column_idx]; |
| 1733 | if source_column.tiles.len() == 1 { | 1801 | if source_column.tiles.len() == 1 { |
| 1734 | return; | 1802 | return; |
| 1735 | } | 1803 | } |
| 1736 | 1804 | ||
| 1737 | - let offset_x = offset_x + source_column.render_offset().x; | 1805 | + offset.x += source_column.render_offset().x; |
| 1738 | - | 1806 | + let prev_off = source_column.tile_offset(source_column.active_tile_idx); |
| 1739 | - let prev_y = source_column.tile_y(source_column.active_tile_idx); | ||
| 1740 | 1807 | ||
| 1741 | let width = source_column.width; | 1808 | let width = source_column.width; |
| 1742 | let is_full_width = source_column.is_full_width; | 1809 | let is_full_width = source_column.is_full_width; |
| @@ -1752,8 +1819,8 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1752 | ); | 1819 | ); |
| 1753 | 1820 | ||
| 1754 | let new_col = &mut self.columns[self.active_column_idx]; | 1821 | let new_col = &mut self.columns[self.active_column_idx]; |
| 1755 | - let offset_y = prev_y - new_col.tile_y(0); | 1822 | + offset += prev_off - new_col.tile_offset(0); |
| 1756 | - new_col.tiles[0].animate_move_from(Point::from((offset_x, offset_y))); | 1823 | + new_col.tiles[0].animate_move_from(offset); |
| 1757 | } | 1824 | } |
| 1758 | 1825 | ||
| 1759 | pub fn center_column(&mut self) { | 1826 | pub fn center_column(&mut self) { |
| @@ -1786,89 +1853,113 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1786 | } | 1853 | } |
| 1787 | } | 1854 | } |
| 1788 | 1855 | ||
| 1789 | - fn tiles_in_render_order(&self) -> impl Iterator<Item = (&'_ Tile<W>, Point<i32, Logical>)> { | 1856 | + // HACK: pass a self.data iterator in manually as a workaround for the lack of method partial |
| 1790 | - let view_pos = self.view_pos(); | 1857 | + // borrowing. Note that this method's return value does not borrow the entire &Self! |
| 1791 | - | 1858 | + fn column_xs(&self, data: impl Iterator<Item = ColumnData>) -> impl Iterator<Item = i32> { |
| 1792 | - // Start with the active window since it's drawn on top. | 1859 | + let gaps = self.options.gaps; |
| 1793 | - let col = &self.columns[self.active_column_idx]; | 1860 | + let mut x = 0; |
| 1794 | - let col_width = col.width(); | ||
| 1795 | - let tile = &col.tiles[col.active_tile_idx]; | ||
| 1796 | - let tile_pos = Point::from((-self.view_offset, col.tile_y(col.active_tile_idx))) | ||
| 1797 | - + col.render_offset() | ||
| 1798 | - + Column::render_offset_for_tile(tile, col_width, &self.options) | ||
| 1799 | - + tile.render_offset(); | ||
| 1800 | - let first = iter::once((tile, tile_pos)); | ||
| 1801 | - | ||
| 1802 | - // Next, the rest of the tiles in the active column, since it should be drawn on top as a | ||
| 1803 | - // whole during animations. | ||
| 1804 | - let next = | ||
| 1805 | - zip(&col.tiles, col.tile_ys()) | ||
| 1806 | - .enumerate() | ||
| 1807 | - .filter_map(move |(tile_idx, (tile, y))| { | ||
| 1808 | - if tile_idx == col.active_tile_idx { | ||
| 1809 | - // Active tile comes first. | ||
| 1810 | - return None; | ||
| 1811 | - } | ||
| 1812 | 1861 | ||
| 1813 | - let tile_pos = Point::from((-self.view_offset, y)) | 1862 | + // Chain with a dummy value to be able to get one past all columns' X. |
| 1814 | - + col.render_offset() | 1863 | + let dummy = ColumnData { width: 0 }; |
| 1815 | - + Column::render_offset_for_tile(tile, col_width, &self.options) | 1864 | + let data = data.chain(iter::once(dummy)); |
| 1816 | - + tile.render_offset(); | ||
| 1817 | - Some((tile, tile_pos)) | ||
| 1818 | - }); | ||
| 1819 | 1865 | ||
| 1820 | - let mut x = -view_pos; | 1866 | + data.map(move |data| { |
| 1821 | - let rest = self | 1867 | + let rv = x; |
| 1822 | - .columns | 1868 | + x += data.width + gaps; |
| 1823 | - .iter() | 1869 | + rv |
| 1870 | + }) | ||
| 1871 | + } | ||
| 1872 | + | ||
| 1873 | + fn column_x(&self, column_idx: usize) -> i32 { | ||
| 1874 | + self.column_xs(self.data.iter().copied()) | ||
| 1875 | + .nth(column_idx) | ||
| 1876 | + .unwrap() | ||
| 1877 | + } | ||
| 1878 | + | ||
| 1879 | + fn column_xs_in_render_order( | ||
| 1880 | + &self, | ||
| 1881 | + data: impl Iterator<Item = ColumnData>, | ||
| 1882 | + ) -> impl Iterator<Item = i32> { | ||
| 1883 | + let active_idx = self.active_column_idx; | ||
| 1884 | + let active_pos = self.column_x(active_idx); | ||
| 1885 | + let offsets = self | ||
| 1886 | + .column_xs(data) | ||
| 1824 | .enumerate() | 1887 | .enumerate() |
| 1825 | - // Keep track of column X position. | 1888 | + .filter_map(move |(idx, pos)| (idx != active_idx).then_some(pos)); |
| 1826 | - .map(move |(col_idx, col)| { | 1889 | + iter::once(active_pos).chain(offsets) |
| 1827 | - let col_width = col.width(); | 1890 | + } |
| 1828 | - let rv = (col_idx, col, col_width, x); | ||
| 1829 | - x += col_width + self.options.gaps; | ||
| 1830 | - rv | ||
| 1831 | - }) | ||
| 1832 | - .filter_map(|(col_idx, col, col_width, x)| { | ||
| 1833 | - if col_idx == self.active_column_idx { | ||
| 1834 | - // Active column comes before. | ||
| 1835 | - return None; | ||
| 1836 | - } | ||
| 1837 | 1891 | ||
| 1838 | - Some((col, col_width, x)) | 1892 | + fn columns_mut(&mut self) -> impl Iterator<Item = (&mut Column<W>, i32)> + '_ { |
| 1839 | - }) | 1893 | + let offsets = self.column_xs(self.data.iter().copied()); |
| 1840 | - .flat_map(move |(col, col_width, x)| { | 1894 | + zip(&mut self.columns, offsets) |
| 1841 | - zip(&col.tiles, col.tile_ys()).map(move |(tile, y)| { | 1895 | + } |
| 1842 | - let tile_pos = Point::from((x, y)) | 1896 | + |
| 1843 | - + col.render_offset() | 1897 | + fn columns_in_render_order(&self) -> impl Iterator<Item = (&Column<W>, i32)> + '_ { |
| 1844 | - + Column::render_offset_for_tile(tile, col_width, &self.options) | 1898 | + let offsets = self.column_xs_in_render_order(self.data.iter().copied()); |
| 1845 | - + tile.render_offset(); | ||
| 1846 | - (tile, tile_pos) | ||
| 1847 | - }) | ||
| 1848 | - }); | ||
| 1849 | 1899 | ||
| 1850 | - first.chain(next).chain(rest) | 1900 | + let (first, rest) = self.columns.split_at(self.active_column_idx); |
| 1901 | + let (active, rest) = rest.split_at(1); | ||
| 1902 | + | ||
| 1903 | + let tiles = active.iter().chain(first).chain(rest); | ||
| 1904 | + zip(tiles, offsets) | ||
| 1851 | } | 1905 | } |
| 1852 | 1906 | ||
| 1853 | - fn active_column_ref(&self) -> Option<&Column<W>> { | 1907 | + fn columns_in_render_order_mut(&mut self) -> impl Iterator<Item = (&mut Column<W>, i32)> + '_ { |
| 1854 | - if self.columns.is_empty() { | 1908 | + let offsets = self.column_xs_in_render_order(self.data.iter().copied()); |
| 1855 | - return None; | 1909 | + |
| 1856 | - } | 1910 | + let (first, rest) = self.columns.split_at_mut(self.active_column_idx); |
| 1857 | - Some(&self.columns[self.active_column_idx]) | 1911 | + let (active, rest) = rest.split_at_mut(1); |
| 1912 | + | ||
| 1913 | + let tiles = active.iter_mut().chain(first).chain(rest); | ||
| 1914 | + zip(tiles, offsets) | ||
| 1915 | + } | ||
| 1916 | + | ||
| 1917 | + fn tiles_with_render_positions(&self) -> impl Iterator<Item = (&Tile<W>, Point<i32, Logical>)> { | ||
| 1918 | + let view_off = Point::from((-self.view_pos(), 0)); | ||
| 1919 | + self.columns_in_render_order() | ||
| 1920 | + .flat_map(move |(col, col_x)| { | ||
| 1921 | + let col_off = Point::from((col_x, 0)); | ||
| 1922 | + let col_render_off = col.render_offset(); | ||
| 1923 | + col.tiles_in_render_order().map(move |(tile, tile_off)| { | ||
| 1924 | + let pos = view_off + col_off + col_render_off + tile_off + tile.render_offset(); | ||
| 1925 | + (tile, pos) | ||
| 1926 | + }) | ||
| 1927 | + }) | ||
| 1928 | + } | ||
| 1929 | + | ||
| 1930 | + fn tiles_with_render_positions_mut( | ||
| 1931 | + &mut self, | ||
| 1932 | + ) -> impl Iterator<Item = (&mut Tile<W>, Point<i32, Logical>)> { | ||
| 1933 | + let view_off = Point::from((-self.view_pos(), 0)); | ||
| 1934 | + self.columns_in_render_order_mut() | ||
| 1935 | + .flat_map(move |(col, col_x)| { | ||
| 1936 | + let col_off = Point::from((col_x, 0)); | ||
| 1937 | + let col_render_off = col.render_offset(); | ||
| 1938 | + col.tiles_in_render_order_mut() | ||
| 1939 | + .map(move |(tile, tile_off)| { | ||
| 1940 | + let pos = | ||
| 1941 | + view_off + col_off + col_render_off + tile_off + tile.render_offset(); | ||
| 1942 | + (tile, pos) | ||
| 1943 | + }) | ||
| 1944 | + }) | ||
| 1858 | } | 1945 | } |
| 1859 | 1946 | ||
| 1860 | /// Returns the geometry of the active tile relative to and clamped to the view. | 1947 | /// Returns the geometry of the active tile relative to and clamped to the view. |
| 1861 | /// | 1948 | /// |
| 1862 | /// During animations, assumes the final view position. | 1949 | /// During animations, assumes the final view position. |
| 1863 | pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<i32, Logical>> { | 1950 | pub fn active_tile_visual_rectangle(&self) -> Option<Rectangle<i32, Logical>> { |
| 1864 | - let col = self.active_column_ref()?; | 1951 | + let col = self.columns.get(self.active_column_idx)?; |
| 1865 | - let view_pos = self | 1952 | + |
| 1953 | + let final_view_offset = self | ||
| 1866 | .view_offset_adj | 1954 | .view_offset_adj |
| 1867 | .as_ref() | 1955 | .as_ref() |
| 1868 | .map_or(self.view_offset, |adj| adj.target_view_offset() as i32); | 1956 | .map_or(self.view_offset, |adj| adj.target_view_offset() as i32); |
| 1957 | + let view_off = Point::from((-final_view_offset, 0)); | ||
| 1869 | 1958 | ||
| 1870 | - let tile_pos = Point::from((-view_pos, col.tile_y(col.active_tile_idx))); | 1959 | + let (tile, tile_off) = col.tiles().nth(col.active_tile_idx).unwrap(); |
| 1871 | - let tile_size = col.active_tile_ref().tile_size(); | 1960 | + |
| 1961 | + let tile_pos = view_off + tile_off; | ||
| 1962 | + let tile_size = tile.tile_size(); | ||
| 1872 | let tile_rect = Rectangle::from_loc_and_size(tile_pos, tile_size); | 1963 | let tile_rect = Rectangle::from_loc_and_size(tile_pos, tile_size); |
| 1873 | 1964 | ||
| 1874 | let view = Rectangle::from_loc_and_size((0, 0), self.view_size); | 1965 | let view = Rectangle::from_loc_and_size((0, 0), self.view_size); |
| @@ -1883,18 +1974,19 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1883 | return None; | 1974 | return None; |
| 1884 | } | 1975 | } |
| 1885 | 1976 | ||
| 1886 | - self.tiles_in_render_order().find_map(|(tile, tile_pos)| { | 1977 | + self.tiles_with_render_positions() |
| 1887 | - let pos_within_tile = pos - tile_pos.to_f64(); | 1978 | + .find_map(|(tile, tile_pos)| { |
| 1979 | + let pos_within_tile = pos - tile_pos.to_f64(); | ||
| 1888 | 1980 | ||
| 1889 | - if tile.is_in_input_region(pos_within_tile) { | 1981 | + if tile.is_in_input_region(pos_within_tile) { |
| 1890 | - let pos_within_surface = tile_pos + tile.buf_loc(); | 1982 | + let pos_within_surface = tile_pos + tile.buf_loc(); |
| 1891 | - return Some((tile.window(), Some(pos_within_surface))); | 1983 | + return Some((tile.window(), Some(pos_within_surface))); |
| 1892 | - } else if tile.is_in_activation_region(pos_within_tile) { | 1984 | + } else if tile.is_in_activation_region(pos_within_tile) { |
| 1893 | - return Some((tile.window(), None)); | 1985 | + return Some((tile.window(), None)); |
| 1894 | - } | 1986 | + } |
| 1895 | 1987 | ||
| 1896 | - None | 1988 | + None |
| 1897 | - }) | 1989 | + }) |
| 1898 | } | 1990 | } |
| 1899 | 1991 | ||
| 1900 | pub fn resize_edges_under(&self, pos: Point<f64, Logical>) -> Option<ResizeEdge> { | 1992 | pub fn resize_edges_under(&self, pos: Point<f64, Logical>) -> Option<ResizeEdge> { |
| @@ -1902,32 +1994,33 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 1902 | return None; | 1994 | return None; |
| 1903 | } | 1995 | } |
| 1904 | 1996 | ||
| 1905 | - self.tiles_in_render_order().find_map(|(tile, tile_pos)| { | 1997 | + self.tiles_with_render_positions() |
| 1906 | - let pos_within_tile = pos - tile_pos.to_f64(); | 1998 | + .find_map(|(tile, tile_pos)| { |
| 1999 | + let pos_within_tile = pos - tile_pos.to_f64(); | ||
| 1907 | 2000 | ||
| 1908 | - // This logic should be consistent with window_under() in when it returns Some vs. | 2001 | + // This logic should be consistent with window_under() in when it returns Some vs. |
| 1909 | - // None. | 2002 | + // None. |
| 1910 | - if tile.is_in_input_region(pos_within_tile) | 2003 | + if tile.is_in_input_region(pos_within_tile) |
| 1911 | - || tile.is_in_activation_region(pos_within_tile) | 2004 | + || tile.is_in_activation_region(pos_within_tile) |
| 1912 | - { | 2005 | + { |
| 1913 | - let size = tile.tile_size().to_f64(); | 2006 | + let size = tile.tile_size().to_f64(); |
| 1914 | 2007 | ||
| 1915 | - let mut edges = ResizeEdge::empty(); | 2008 | + let mut edges = ResizeEdge::empty(); |
| 1916 | - if pos_within_tile.x < size.w / 3. { | 2009 | + if pos_within_tile.x < size.w / 3. { |
| 1917 | - edges |= ResizeEdge::LEFT; | 2010 | + edges |= ResizeEdge::LEFT; |
| 1918 | - } else if 2. * size.w / 3. < pos_within_tile.x { | 2011 | + } else if 2. * size.w / 3. < pos_within_tile.x { |
| 1919 | - edges |= ResizeEdge::RIGHT; | 2012 | + edges |= ResizeEdge::RIGHT; |
| 1920 | - } | 2013 | + } |
| 1921 | - if pos_within_tile.y < size.h / 3. { | 2014 | + if pos_within_tile.y < size.h / 3. { |
| 1922 | - edges |= ResizeEdge::TOP; | 2015 | + edges |= ResizeEdge::TOP; |
| 1923 | - } else if 2. * size.h / 3. < pos_within_tile.y { | 2016 | + } else if 2. * size.h / 3. < pos_within_tile.y { |
| 1924 | - edges |= ResizeEdge::BOTTOM; | 2017 | + edges |= ResizeEdge::BOTTOM; |
| 2018 | + } | ||
| 2019 | + return Some(edges); | ||
| 1925 | } | 2020 | } |
| 1926 | - return Some(edges); | ||
| 1927 | - } | ||
| 1928 | 2021 | ||
| 1929 | - None | 2022 | + None |
| 1930 | - }) | 2023 | + }) |
| 1931 | } | 2024 | } |
| 1932 | 2025 | ||
| 1933 | pub fn toggle_width(&mut self) { | 2026 | pub fn toggle_width(&mut self) { |
| @@ -2009,25 +2102,25 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2009 | let target_window_was_focused = | 2102 | let target_window_was_focused = |
| 2010 | self.active_column_idx == col_idx && col.active_tile_idx == tile_idx; | 2103 | self.active_column_idx == col_idx && col.active_tile_idx == tile_idx; |
| 2011 | let window = col.tiles.remove(tile_idx).into_window(); | 2104 | let window = col.tiles.remove(tile_idx).into_window(); |
| 2012 | - col.heights.remove(tile_idx); | 2105 | + col.data.remove(tile_idx); |
| 2013 | col.active_tile_idx = min(col.active_tile_idx, col.tiles.len() - 1); | 2106 | col.active_tile_idx = min(col.active_tile_idx, col.tiles.len() - 1); |
| 2014 | col.update_tile_sizes(false); | 2107 | col.update_tile_sizes(false); |
| 2108 | + self.data[col_idx].update(col); | ||
| 2015 | let width = col.width; | 2109 | let width = col.width; |
| 2016 | let is_full_width = col.is_full_width; | 2110 | let is_full_width = col.is_full_width; |
| 2017 | 2111 | ||
| 2018 | col_idx += 1; | 2112 | col_idx += 1; |
| 2019 | - self.columns.insert( | 2113 | + let column = Column::new( |
| 2020 | - col_idx, | 2114 | + window, |
| 2021 | - Column::new( | 2115 | + self.view_size, |
| 2022 | - window, | 2116 | + self.working_area, |
| 2023 | - self.view_size, | 2117 | + self.options.clone(), |
| 2024 | - self.working_area, | 2118 | + width, |
| 2025 | - self.options.clone(), | 2119 | + is_full_width, |
| 2026 | - width, | 2120 | + false, |
| 2027 | - is_full_width, | ||
| 2028 | - false, | ||
| 2029 | - ), | ||
| 2030 | ); | 2121 | ); |
| 2122 | + self.data.insert(col_idx, ColumnData::new(&column)); | ||
| 2123 | + self.columns.insert(col_idx, column); | ||
| 2031 | 2124 | ||
| 2032 | if target_window_was_focused { | 2125 | if target_window_was_focused { |
| 2033 | self.activate_column(col_idx); | 2126 | self.activate_column(col_idx); |
| @@ -2104,7 +2197,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2104 | } | 2197 | } |
| 2105 | 2198 | ||
| 2106 | let mut first = true; | 2199 | let mut first = true; |
| 2107 | - for (tile, tile_pos) in self.tiles_in_render_order() { | 2200 | + for (tile, tile_pos) in self.tiles_with_render_positions() { |
| 2108 | // For the active tile (which comes first), draw the focus ring. | 2201 | // For the active tile (which comes first), draw the focus ring. |
| 2109 | let focus_ring = first; | 2202 | let focus_ring = first; |
| 2110 | first = false; | 2203 | first = false; |
| @@ -2521,13 +2614,12 @@ impl<W: LayoutElement> Column<W> { | |||
| 2521 | ) -> Self { | 2614 | ) -> Self { |
| 2522 | let mut rv = Self { | 2615 | let mut rv = Self { |
| 2523 | tiles: vec![], | 2616 | tiles: vec![], |
| 2524 | - heights: vec![], | 2617 | + data: vec![], |
| 2525 | active_tile_idx: 0, | 2618 | active_tile_idx: 0, |
| 2526 | width, | 2619 | width, |
| 2527 | is_full_width, | 2620 | is_full_width, |
| 2528 | is_fullscreen: false, | 2621 | is_fullscreen: false, |
| 2529 | move_animation: None, | 2622 | move_animation: None, |
| 2530 | - width_before_resize: None, | ||
| 2531 | view_size, | 2623 | view_size, |
| 2532 | working_area, | 2624 | working_area, |
| 2533 | options, | 2625 | options, |
| @@ -2612,27 +2704,14 @@ impl<W: LayoutElement> Column<W> { | |||
| 2612 | self.move_animation.is_some() || self.tiles.iter().any(Tile::are_animations_ongoing) | 2704 | self.move_animation.is_some() || self.tiles.iter().any(Tile::are_animations_ongoing) |
| 2613 | } | 2705 | } |
| 2614 | 2706 | ||
| 2615 | - pub fn update_render_elements( | 2707 | + pub fn update_render_elements(&mut self, is_active: bool, view_rect: Rectangle<i32, Logical>) { |
| 2616 | - &mut self, | 2708 | + let active_idx = self.active_tile_idx; |
| 2617 | - is_active: bool, | 2709 | + for (tile_idx, (tile, tile_off)) in self.tiles_mut().enumerate() { |
| 2618 | - mut view_rect: Rectangle<i32, Logical>, | 2710 | + let is_active = is_active && tile_idx == active_idx; |
| 2619 | - ) { | ||
| 2620 | - view_rect.loc -= self.render_offset(); | ||
| 2621 | - | ||
| 2622 | - if !self.is_fullscreen { | ||
| 2623 | - view_rect.loc.y -= self.working_area.loc.y + self.options.gaps; | ||
| 2624 | - } | ||
| 2625 | - | ||
| 2626 | - let col_width = self.width(); | ||
| 2627 | - | ||
| 2628 | - for (tile_idx, tile) in self.tiles.iter_mut().enumerate() { | ||
| 2629 | - let is_active = is_active && tile_idx == self.active_tile_idx; | ||
| 2630 | 2711 | ||
| 2631 | let mut tile_view_rect = view_rect; | 2712 | let mut tile_view_rect = view_rect; |
| 2632 | - tile_view_rect.loc -= Self::render_offset_for_tile(tile, col_width, &self.options); | 2713 | + tile_view_rect.loc -= tile_off + tile.render_offset(); |
| 2633 | tile.update(is_active, tile_view_rect); | 2714 | tile.update(is_active, tile_view_rect); |
| 2634 | - | ||
| 2635 | - view_rect.loc.y -= tile.tile_size().h + self.options.gaps; | ||
| 2636 | } | 2715 | } |
| 2637 | } | 2716 | } |
| 2638 | 2717 | ||
| @@ -2646,29 +2725,6 @@ impl<W: LayoutElement> Column<W> { | |||
| 2646 | offset.to_i32_round() | 2725 | offset.to_i32_round() |
| 2647 | } | 2726 | } |
| 2648 | 2727 | ||
| 2649 | - // HACK: this should really be a &self method, but I need to use it while also iterating over | ||
| 2650 | - // &mut self.tiles... | ||
| 2651 | - // FIXME: this does not get applied for animations. | ||
| 2652 | - pub fn render_offset_for_tile( | ||
| 2653 | - tile: &Tile<W>, | ||
| 2654 | - col_width: i32, | ||
| 2655 | - options: &Options, | ||
| 2656 | - ) -> Point<i32, Logical> { | ||
| 2657 | - let tile_width = tile.tile_size().w; | ||
| 2658 | - | ||
| 2659 | - if options.center_focused_column == CenterFocusedColumn::Always { | ||
| 2660 | - return Point::from(((col_width - tile_width) / 2, 0)); | ||
| 2661 | - } | ||
| 2662 | - | ||
| 2663 | - if let Some(resize) = tile.window().interactive_resize_data() { | ||
| 2664 | - if resize.edges.contains(ResizeEdge::LEFT) { | ||
| 2665 | - return Point::from((col_width - tile_width, 0)); | ||
| 2666 | - } | ||
| 2667 | - } | ||
| 2668 | - | ||
| 2669 | - Point::from((0, 0)) | ||
| 2670 | - } | ||
| 2671 | - | ||
| 2672 | pub fn animate_move_from(&mut self, from_x_offset: i32) { | 2728 | pub fn animate_move_from(&mut self, from_x_offset: i32) { |
| 2673 | self.animate_move_from_with_config( | 2729 | self.animate_move_from_with_config( |
| 2674 | from_x_offset, | 2730 | from_x_offset, |
| @@ -2712,8 +2768,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 2712 | 2768 | ||
| 2713 | fn add_tile(&mut self, tile: Tile<W>, animate: bool) { | 2769 | fn add_tile(&mut self, tile: Tile<W>, animate: bool) { |
| 2714 | self.is_fullscreen = false; | 2770 | self.is_fullscreen = false; |
| 2771 | + self.data.push(TileData::new(&tile, WindowHeight::Auto)); | ||
| 2715 | self.tiles.push(tile); | 2772 | self.tiles.push(tile); |
| 2716 | - self.heights.push(WindowHeight::Auto); | ||
| 2717 | self.update_tile_sizes(animate); | 2773 | self.update_tile_sizes(animate); |
| 2718 | } | 2774 | } |
| 2719 | 2775 | ||
| @@ -2732,6 +2788,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2732 | .map_or(0, |from| from.size.h - height); | 2788 | .map_or(0, |from| from.size.h - height); |
| 2733 | 2789 | ||
| 2734 | tile.update_window(); | 2790 | tile.update_window(); |
| 2791 | + self.data[tile_idx].update(tile); | ||
| 2735 | 2792 | ||
| 2736 | // Move windows below in tandem with resizing. | 2793 | // Move windows below in tandem with resizing. |
| 2737 | if tile.resize_animation().is_some() && offset != 0 { | 2794 | if tile.resize_animation().is_some() && offset != 0 { |
| @@ -2790,8 +2847,8 @@ impl<W: LayoutElement> Column<W> { | |||
| 2790 | let width = max(min(width, max_width), min_width); | 2847 | let width = max(min(width, max_width), min_width); |
| 2791 | 2848 | ||
| 2792 | // Compute the tile heights. Start by converting window heights to tile heights. | 2849 | // Compute the tile heights. Start by converting window heights to tile heights. |
| 2793 | - let mut heights = zip(&self.tiles, &self.heights) | 2850 | + let mut heights = zip(&self.tiles, &self.data) |
| 2794 | - .map(|(tile, height)| match *height { | 2851 | + .map(|(tile, data)| match data.height { |
| 2795 | WindowHeight::Auto => WindowHeight::Auto, | 2852 | WindowHeight::Auto => WindowHeight::Auto, |
| 2796 | WindowHeight::Fixed(height) => { | 2853 | WindowHeight::Fixed(height) => { |
| 2797 | WindowHeight::Fixed(tile.tile_height_for_window_height(height)) | 2854 | WindowHeight::Fixed(tile.tile_height_for_window_height(height)) |
| @@ -2902,11 +2959,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2902 | } | 2959 | } |
| 2903 | 2960 | ||
| 2904 | fn width(&self) -> i32 { | 2961 | fn width(&self) -> i32 { |
| 2905 | - self.tiles | 2962 | + self.data.iter().map(|data| data.size.w).max().unwrap() |
| 2906 | - .iter() | ||
| 2907 | - .map(|tile| tile.tile_size().w) | ||
| 2908 | - .max() | ||
| 2909 | - .unwrap() | ||
| 2910 | } | 2963 | } |
| 2911 | 2964 | ||
| 2912 | fn focus_up(&mut self) { | 2965 | fn focus_up(&mut self) { |
| @@ -2927,17 +2980,17 @@ impl<W: LayoutElement> Column<W> { | |||
| 2927 | return; | 2980 | return; |
| 2928 | } | 2981 | } |
| 2929 | 2982 | ||
| 2930 | - let mut ys = self.tile_ys().skip(self.active_tile_idx); | 2983 | + let mut ys = self.tile_offsets().skip(self.active_tile_idx); |
| 2931 | - let active_y = ys.next().unwrap(); | 2984 | + let active_y = ys.next().unwrap().y; |
| 2932 | - let next_y = ys.next().unwrap(); | 2985 | + let next_y = ys.next().unwrap().y; |
| 2933 | drop(ys); | 2986 | drop(ys); |
| 2934 | 2987 | ||
| 2935 | self.tiles.swap(self.active_tile_idx, new_idx); | 2988 | self.tiles.swap(self.active_tile_idx, new_idx); |
| 2936 | - self.heights.swap(self.active_tile_idx, new_idx); | 2989 | + self.data.swap(self.active_tile_idx, new_idx); |
| 2937 | self.active_tile_idx = new_idx; | 2990 | self.active_tile_idx = new_idx; |
| 2938 | 2991 | ||
| 2939 | // Animate the movement. | 2992 | // Animate the movement. |
| 2940 | - let new_active_y = self.tile_y(new_idx); | 2993 | + let new_active_y = self.tile_offset(new_idx).y; |
| 2941 | self.tiles[new_idx].animate_move_y_from(active_y - new_active_y); | 2994 | self.tiles[new_idx].animate_move_y_from(active_y - new_active_y); |
| 2942 | self.tiles[new_idx + 1].animate_move_y_from(active_y - next_y); | 2995 | self.tiles[new_idx + 1].animate_move_y_from(active_y - next_y); |
| 2943 | } | 2996 | } |
| @@ -2948,17 +3001,17 @@ impl<W: LayoutElement> Column<W> { | |||
| 2948 | return; | 3001 | return; |
| 2949 | } | 3002 | } |
| 2950 | 3003 | ||
| 2951 | - let mut ys = self.tile_ys().skip(self.active_tile_idx); | 3004 | + let mut ys = self.tile_offsets().skip(self.active_tile_idx); |
| 2952 | - let active_y = ys.next().unwrap(); | 3005 | + let active_y = ys.next().unwrap().y; |
| 2953 | - let next_y = ys.next().unwrap(); | 3006 | + let next_y = ys.next().unwrap().y; |
| 2954 | drop(ys); | 3007 | drop(ys); |
| 2955 | 3008 | ||
| 2956 | self.tiles.swap(self.active_tile_idx, new_idx); | 3009 | self.tiles.swap(self.active_tile_idx, new_idx); |
| 2957 | - self.heights.swap(self.active_tile_idx, new_idx); | 3010 | + self.data.swap(self.active_tile_idx, new_idx); |
| 2958 | self.active_tile_idx = new_idx; | 3011 | self.active_tile_idx = new_idx; |
| 2959 | 3012 | ||
| 2960 | // Animate the movement. | 3013 | // Animate the movement. |
| 2961 | - let new_active_y = self.tile_y(new_idx); | 3014 | + let new_active_y = self.tile_offset(new_idx).y; |
| 2962 | self.tiles[new_idx].animate_move_y_from(active_y - new_active_y); | 3015 | self.tiles[new_idx].animate_move_y_from(active_y - new_active_y); |
| 2963 | self.tiles[new_idx - 1].animate_move_y_from(next_y - active_y); | 3016 | self.tiles[new_idx - 1].animate_move_y_from(next_y - active_y); |
| 2964 | } | 3017 | } |
| @@ -2967,15 +3020,19 @@ impl<W: LayoutElement> Column<W> { | |||
| 2967 | fn verify_invariants(&self) { | 3020 | fn verify_invariants(&self) { |
| 2968 | assert!(!self.tiles.is_empty(), "columns can't be empty"); | 3021 | assert!(!self.tiles.is_empty(), "columns can't be empty"); |
| 2969 | assert!(self.active_tile_idx < self.tiles.len()); | 3022 | assert!(self.active_tile_idx < self.tiles.len()); |
| 2970 | - assert_eq!(self.tiles.len(), self.heights.len()); | 3023 | + assert_eq!(self.tiles.len(), self.data.len()); |
| 2971 | 3024 | ||
| 2972 | if self.is_fullscreen { | 3025 | if self.is_fullscreen { |
| 2973 | assert_eq!(self.tiles.len(), 1); | 3026 | assert_eq!(self.tiles.len(), 1); |
| 2974 | } | 3027 | } |
| 2975 | 3028 | ||
| 2976 | - for tile in &self.tiles { | 3029 | + for (tile, data) in zip(&self.tiles, &self.data) { |
| 2977 | assert!(Rc::ptr_eq(&self.options, &tile.options)); | 3030 | assert!(Rc::ptr_eq(&self.options, &tile.options)); |
| 2978 | assert_eq!(self.is_fullscreen, tile.window().is_pending_fullscreen()); | 3031 | assert_eq!(self.is_fullscreen, tile.window().is_pending_fullscreen()); |
| 3032 | + | ||
| 3033 | + let mut data2 = *data; | ||
| 3034 | + data2.update(tile); | ||
| 3035 | + assert_eq!(data, &data2, "tile data must be up to date"); | ||
| 2979 | } | 3036 | } |
| 2980 | } | 3037 | } |
| 2981 | 3038 | ||
| @@ -3060,7 +3117,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 3060 | 3117 | ||
| 3061 | fn set_window_height(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) { | 3118 | fn set_window_height(&mut self, change: SizeChange, tile_idx: Option<usize>, animate: bool) { |
| 3062 | let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); | 3119 | let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); |
| 3063 | - let current = self.heights[tile_idx]; | 3120 | + let current = self.data[tile_idx].height; |
| 3064 | let tile = &self.tiles[tile_idx]; | 3121 | let tile = &self.tiles[tile_idx]; |
| 3065 | let current_window_px = match current { | 3122 | let current_window_px = match current { |
| 3066 | WindowHeight::Auto => tile.window_size().h, | 3123 | WindowHeight::Auto => tile.window_size().h, |
| @@ -3105,13 +3162,13 @@ impl<W: LayoutElement> Column<W> { | |||
| 3105 | window_height = window_height.max(min_h); | 3162 | window_height = window_height.max(min_h); |
| 3106 | } | 3163 | } |
| 3107 | 3164 | ||
| 3108 | - self.heights[tile_idx] = WindowHeight::Fixed(window_height.clamp(1, MAX_PX)); | 3165 | + self.data[tile_idx].height = WindowHeight::Fixed(window_height.clamp(1, MAX_PX)); |
| 3109 | self.update_tile_sizes(animate); | 3166 | self.update_tile_sizes(animate); |
| 3110 | } | 3167 | } |
| 3111 | 3168 | ||
| 3112 | fn reset_window_height(&mut self, tile_idx: Option<usize>, animate: bool) { | 3169 | fn reset_window_height(&mut self, tile_idx: Option<usize>, animate: bool) { |
| 3113 | let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); | 3170 | let tile_idx = tile_idx.unwrap_or(self.active_tile_idx); |
| 3114 | - self.heights[tile_idx] = WindowHeight::Auto; | 3171 | + self.data[tile_idx].height = WindowHeight::Auto; |
| 3115 | self.update_tile_sizes(animate); | 3172 | self.update_tile_sizes(animate); |
| 3116 | } | 3173 | } |
| 3117 | 3174 | ||
| @@ -3121,35 +3178,100 @@ impl<W: LayoutElement> Column<W> { | |||
| 3121 | self.update_tile_sizes(false); | 3178 | self.update_tile_sizes(false); |
| 3122 | } | 3179 | } |
| 3123 | 3180 | ||
| 3124 | - pub fn window_y(&self, tile_idx: usize) -> i32 { | 3181 | + /// Returns the static window location, not taking the render offset into account. |
| 3125 | - let (tile, tile_y) = zip(&self.tiles, self.tile_ys()).nth(tile_idx).unwrap(); | 3182 | + pub fn window_loc(&self, tile_idx: usize) -> Point<i32, Logical> { |
| 3126 | - tile_y + tile.window_loc().y | 3183 | + let (tile, pos) = self.tiles().nth(tile_idx).unwrap(); |
| 3127 | - } | 3184 | + pos + tile.window_loc() |
| 3128 | - | ||
| 3129 | - fn tile_y(&self, tile_idx: usize) -> i32 { | ||
| 3130 | - self.tile_ys().nth(tile_idx).unwrap() | ||
| 3131 | } | 3185 | } |
| 3132 | 3186 | ||
| 3133 | - fn tile_ys(&self) -> impl Iterator<Item = i32> + '_ { | 3187 | + // HACK: pass a self.data iterator in manually as a workaround for the lack of method partial |
| 3188 | + // borrowing. Note that this method's return value does not borrow the entire &Self! | ||
| 3189 | + fn tile_offsets_iter( | ||
| 3190 | + &self, | ||
| 3191 | + data: impl Iterator<Item = TileData>, | ||
| 3192 | + ) -> impl Iterator<Item = Point<i32, Logical>> { | ||
| 3193 | + let center = self.options.center_focused_column == CenterFocusedColumn::Always; | ||
| 3194 | + let gaps = self.options.gaps; | ||
| 3195 | + let col_width = self.width(); | ||
| 3134 | let mut y = 0; | 3196 | let mut y = 0; |
| 3135 | 3197 | ||
| 3136 | if !self.is_fullscreen { | 3198 | if !self.is_fullscreen { |
| 3137 | y = self.working_area.loc.y + self.options.gaps; | 3199 | y = self.working_area.loc.y + self.options.gaps; |
| 3138 | } | 3200 | } |
| 3139 | 3201 | ||
| 3140 | - let heights = self.tiles.iter().map(|tile| tile.tile_size().h); | 3202 | + // Chain with a dummy value to be able to get one past all tiles' Y. |
| 3203 | + let dummy = TileData { | ||
| 3204 | + height: WindowHeight::Auto, | ||
| 3205 | + size: Size::default(), | ||
| 3206 | + interactively_resizing_by_left_edge: false, | ||
| 3207 | + }; | ||
| 3208 | + let data = data.chain(iter::once(dummy)); | ||
| 3209 | + | ||
| 3210 | + data.map(move |data| { | ||
| 3211 | + let mut pos = Point::from((0, y)); | ||
| 3141 | 3212 | ||
| 3142 | - // Chain an arbitrary height to be able to get the Y that the next tile past the end would | 3213 | + if center { |
| 3143 | - // have. | 3214 | + pos.x = (col_width - data.size.w) / 2; |
| 3144 | - heights.chain(iter::once(0)).map(move |h| { | 3215 | + } else if data.interactively_resizing_by_left_edge { |
| 3145 | - let pos = y; | 3216 | + pos.x = col_width - data.size.w; |
| 3146 | - y += h + self.options.gaps; | 3217 | + } |
| 3218 | + | ||
| 3219 | + y += data.size.h + gaps; | ||
| 3147 | pos | 3220 | pos |
| 3148 | }) | 3221 | }) |
| 3149 | } | 3222 | } |
| 3150 | 3223 | ||
| 3151 | - fn active_tile_ref(&self) -> &Tile<W> { | 3224 | + fn tile_offsets(&self) -> impl Iterator<Item = Point<i32, Logical>> + '_ { |
| 3152 | - &self.tiles[self.active_tile_idx] | 3225 | + self.tile_offsets_iter(self.data.iter().copied()) |
| 3226 | + } | ||
| 3227 | + | ||
| 3228 | + fn tile_offset(&self, tile_idx: usize) -> Point<i32, Logical> { | ||
| 3229 | + self.tile_offsets().nth(tile_idx).unwrap() | ||
| 3230 | + } | ||
| 3231 | + | ||
| 3232 | + fn tile_offsets_in_render_order( | ||
| 3233 | + &self, | ||
| 3234 | + data: impl Iterator<Item = TileData>, | ||
| 3235 | + ) -> impl Iterator<Item = Point<i32, Logical>> { | ||
| 3236 | + let active_idx = self.active_tile_idx; | ||
| 3237 | + let active_pos = self.tile_offset(active_idx); | ||
| 3238 | + let offsets = self | ||
| 3239 | + .tile_offsets_iter(data) | ||
| 3240 | + .enumerate() | ||
| 3241 | + .filter_map(move |(idx, pos)| (idx != active_idx).then_some(pos)); | ||
| 3242 | + iter::once(active_pos).chain(offsets) | ||
| 3243 | + } | ||
| 3244 | + | ||
| 3245 | + fn tiles(&self) -> impl Iterator<Item = (&Tile<W>, Point<i32, Logical>)> + '_ { | ||
| 3246 | + let offsets = self.tile_offsets_iter(self.data.iter().copied()); | ||
| 3247 | + zip(&self.tiles, offsets) | ||
| 3248 | + } | ||
| 3249 | + | ||
| 3250 | + fn tiles_mut(&mut self) -> impl Iterator<Item = (&mut Tile<W>, Point<i32, Logical>)> + '_ { | ||
| 3251 | + let offsets = self.tile_offsets_iter(self.data.iter().copied()); | ||
| 3252 | + zip(&mut self.tiles, offsets) | ||
| 3253 | + } | ||
| 3254 | + | ||
| 3255 | + fn tiles_in_render_order(&self) -> impl Iterator<Item = (&Tile<W>, Point<i32, Logical>)> + '_ { | ||
| 3256 | + let offsets = self.tile_offsets_in_render_order(self.data.iter().copied()); | ||
| 3257 | + | ||
| 3258 | + let (first, rest) = self.tiles.split_at(self.active_tile_idx); | ||
| 3259 | + let (active, rest) = rest.split_at(1); | ||
| 3260 | + | ||
| 3261 | + let tiles = active.iter().chain(first).chain(rest); | ||
| 3262 | + zip(tiles, offsets) | ||
| 3263 | + } | ||
| 3264 | + | ||
| 3265 | + fn tiles_in_render_order_mut( | ||
| 3266 | + &mut self, | ||
| 3267 | + ) -> impl Iterator<Item = (&mut Tile<W>, Point<i32, Logical>)> + '_ { | ||
| 3268 | + let offsets = self.tile_offsets_in_render_order(self.data.iter().copied()); | ||
| 3269 | + | ||
| 3270 | + let (first, rest) = self.tiles.split_at_mut(self.active_tile_idx); | ||
| 3271 | + let (active, rest) = rest.split_at_mut(1); | ||
| 3272 | + | ||
| 3273 | + let tiles = active.iter_mut().chain(first).chain(rest); | ||
| 3274 | + zip(tiles, offsets) | ||
| 3153 | } | 3275 | } |
| 3154 | } | 3276 | } |
| 3155 | 3277 | ||