forge
Explore
Log in

Don't you dare go Hollow

layout: Return Tile + info upon removal

Browse files at this commit

be7fbd418fcee2d2ff9f80aa15f1eb8ff0d83afbIvan MolodetskikhParent: 06ec9ee
src/layout/mod.rsmodified+23 -13
@@ -44,6 +44,7 @@ use smithay::backend::renderer::gles::{GlesRenderer, GlesTexture};
44 use smithay::output::{self, Output};44 use smithay::output::{self, Output};
45 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;45 use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
46 use smithay::utils::{Logical, Point, Scale, Serial, Size, Transform};46 use smithay::utils::{Logical, Point, Scale, Serial, Size, Transform};
47+use tile::Tile;
47 use workspace::WorkspaceId;48 use workspace::WorkspaceId;
48 49
49 pub use self::monitor::MonitorRenderElement;50 pub use self::monitor::MonitorRenderElement;
@@ -281,6 +282,15 @@ impl Default for Options {
281 }282 }
282 }283 }
283 284
285+/// Tile that was just removed from the layout.
286+pub struct RemovedTile<W: LayoutElement> {
287+ tile: Tile<W>,
288+ /// Width of the column the tile was in.
289+ width: ColumnWidth,
290+ /// Whether the column the tile was in was full-width.
291+ is_full_width: bool,
292+}
293+
284 impl Options {294 impl Options {
285 fn from_config(config: &Config) -> Self {295 fn from_config(config: &Config) -> Self {
286 let layout = &config.layout;296 let layout = &config.layout;
@@ -743,13 +753,17 @@ impl<W: LayoutElement> Layout<W> {
743 );753 );
744 }754 }
745 755
746- pub fn remove_window(&mut self, window: &W::Id, transaction: Transaction) -> Option<W> {756+ pub fn remove_window(
757+ &mut self,
758+ window: &W::Id,
759+ transaction: Transaction,
760+ ) -> Option<RemovedTile<W>> {
747 match &mut self.monitor_set {761 match &mut self.monitor_set {
748 MonitorSet::Normal { monitors, .. } => {762 MonitorSet::Normal { monitors, .. } => {
749 for mon in monitors {763 for mon in monitors {
750 for (idx, ws) in mon.workspaces.iter_mut().enumerate() {764 for (idx, ws) in mon.workspaces.iter_mut().enumerate() {
751 if ws.has_window(window) {765 if ws.has_window(window) {
752- let win = ws.remove_window(window, transaction);766+ let removed = ws.remove_tile(window, transaction);
753 767
754 // Clean up empty workspaces that are not active and not last.768 // Clean up empty workspaces that are not active and not last.
755 if !ws.has_windows()769 if !ws.has_windows()
@@ -765,7 +779,7 @@ impl<W: LayoutElement> Layout<W> {
765 }779 }
766 }780 }
767 781
768- return Some(win);782+ return Some(removed);
769 }783 }
770 }784 }
771 }785 }
@@ -773,14 +787,14 @@ impl<W: LayoutElement> Layout<W> {
773 MonitorSet::NoOutputs { workspaces, .. } => {787 MonitorSet::NoOutputs { workspaces, .. } => {
774 for (idx, ws) in workspaces.iter_mut().enumerate() {788 for (idx, ws) in workspaces.iter_mut().enumerate() {
775 if ws.has_window(window) {789 if ws.has_window(window) {
776- let win = ws.remove_window(window, transaction);790+ let removed = ws.remove_tile(window, transaction);
777 791
778 // Clean up empty workspaces.792 // Clean up empty workspaces.
779 if !ws.has_windows() && ws.name.is_none() {793 if !ws.has_windows() && ws.name.is_none() {
780 workspaces.remove(idx);794 workspaces.remove(idx);
781 }795 }
782 796
783- return Some(win);797+ return Some(removed);
784 }798 }
785 }799 }
786 }800 }
@@ -2111,24 +2125,20 @@ impl<W: LayoutElement> Layout<W> {
2111 let mon = &mut monitors[mon_idx];2125 let mon = &mut monitors[mon_idx];
2112 let ws = &mut mon.workspaces[ws_idx];2126 let ws = &mut mon.workspaces[ws_idx];
2113 let column = &ws.columns[col_idx];2127 let column = &ws.columns[col_idx];
2114- let width = column.width;
2115- let is_full_width = column.is_full_width;
2116 let activate = mon_idx == *active_monitor_idx2128 let activate = mon_idx == *active_monitor_idx
2117 && ws_idx == mon.active_workspace_idx2129 && ws_idx == mon.active_workspace_idx
2118 && col_idx == ws.active_column_idx2130 && col_idx == ws.active_column_idx
2119 && tile_idx == column.active_tile_idx;2131 && tile_idx == column.active_tile_idx;
2120 2132
2121- let window = ws2133+ let removed = ws.remove_tile_by_idx(col_idx, tile_idx, Transaction::new(), None);
2122- .remove_tile_by_idx(col_idx, tile_idx, Transaction::new(), None)
2123- .into_window();
2124 2134
2125 self.add_window_by_idx(2135 self.add_window_by_idx(
2126 new_idx,2136 new_idx,
2127 workspace_idx,2137 workspace_idx,
2128- window,2138+ removed.tile.into_window(),
2129 activate,2139 activate,
2130- width,2140+ removed.width,
2131- is_full_width,2141+ removed.is_full_width,
2132 );2142 );
2133 2143
2134 let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {2144 let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set else {
src/layout/monitor.rsmodified+34 -28
@@ -458,18 +458,20 @@ impl<W: LayoutElement> Monitor<W> {
458 }458 }
459 459
460 let column = &workspace.columns[workspace.active_column_idx];460 let column = &workspace.columns[workspace.active_column_idx];
461- let width = column.width;461+ let removed = workspace.remove_tile_by_idx(
462- let is_full_width = column.is_full_width;462+ workspace.active_column_idx,
463- let window = workspace463+ column.active_tile_idx,
464- .remove_tile_by_idx(464+ Transaction::new(),
465- workspace.active_column_idx,465+ None,
466- column.active_tile_idx,466+ );
467- Transaction::new(),
468- None,
469- )
470- .into_window();
471 467
472- self.add_window(new_idx, window, true, width, is_full_width);468+ self.add_window(
469+ new_idx,
470+ removed.tile.into_window(),
471+ true,
472+ removed.width,
473+ removed.is_full_width,
474+ );
473 }475 }
474 476
475 pub fn move_to_workspace_down(&mut self) {477 pub fn move_to_workspace_down(&mut self) {
@@ -486,18 +488,20 @@ impl<W: LayoutElement> Monitor<W> {
486 }488 }
487 489
488 let column = &workspace.columns[workspace.active_column_idx];490 let column = &workspace.columns[workspace.active_column_idx];
489- let width = column.width;491+ let removed = workspace.remove_tile_by_idx(
490- let is_full_width = column.is_full_width;492+ workspace.active_column_idx,
491- let window = workspace493+ column.active_tile_idx,
492- .remove_tile_by_idx(494+ Transaction::new(),
493- workspace.active_column_idx,495+ None,
494- column.active_tile_idx,496+ );
495- Transaction::new(),
496- None,
497- )
498- .into_window();
499 497
500- self.add_window(new_idx, window, true, width, is_full_width);498+ self.add_window(
499+ new_idx,
500+ removed.tile.into_window(),
501+ true,
502+ removed.width,
503+ removed.is_full_width,
504+ );
501 }505 }
502 506
503 pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) {507 pub fn move_to_workspace(&mut self, window: Option<&W::Id>, idx: usize) {
@@ -534,17 +538,19 @@ impl<W: LayoutElement> Monitor<W> {
534 538
535 let workspace = &mut self.workspaces[source_workspace_idx];539 let workspace = &mut self.workspaces[source_workspace_idx];
536 let column = &workspace.columns[col_idx];540 let column = &workspace.columns[col_idx];
537- let width = column.width;
538- let is_full_width = column.is_full_width;
539 let activate = source_workspace_idx == self.active_workspace_idx541 let activate = source_workspace_idx == self.active_workspace_idx
540 && col_idx == workspace.active_column_idx542 && col_idx == workspace.active_column_idx
541 && tile_idx == column.active_tile_idx;543 && tile_idx == column.active_tile_idx;
542 544
543- let window = workspace545+ let removed = workspace.remove_tile_by_idx(col_idx, tile_idx, Transaction::new(), None);
544- .remove_tile_by_idx(col_idx, tile_idx, Transaction::new(), None)
545- .into_window();
546 546
547- self.add_window(new_idx, window, activate, width, is_full_width);547+ self.add_window(
548+ new_idx,
549+ removed.tile.into_window(),
550+ activate,
551+ removed.width,
552+ removed.is_full_width,
553+ );
548 554
549 if self.workspace_switch.is_none() {555 if self.workspace_switch.is_none() {
550 self.clean_up_workspaces();556 self.clean_up_workspaces();
src/layout/workspace.rsmodified+36 -41
@@ -17,7 +17,7 @@ use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size, Transform};
17 17
18 use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};18 use super::closing_window::{ClosingWindow, ClosingWindowRenderElement};
19 use super::tile::{Tile, TileRenderElement};19 use super::tile::{Tile, TileRenderElement};
20-use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options};20+use super::{ConfigureIntent, InteractiveResizeData, LayoutElement, Options, RemovedTile};
21 use crate::animation::Animation;21 use crate::animation::Animation;
22 use crate::input::swipe_tracker::SwipeTracker;22 use crate::input::swipe_tracker::SwipeTracker;
23 use crate::niri_render_elements;23 use crate::niri_render_elements;
@@ -1124,10 +1124,10 @@ impl<W: LayoutElement> Workspace<W> {
1124 pub fn remove_tile_by_idx(1124 pub fn remove_tile_by_idx(
1125 &mut self,1125 &mut self,
1126 column_idx: usize,1126 column_idx: usize,
1127- window_idx: usize,1127+ tile_idx: usize,
1128 transaction: Transaction,1128 transaction: Transaction,
1129 anim_config: Option<niri_config::Animation>,1129 anim_config: Option<niri_config::Animation>,
1130- ) -> Tile<W> {1130+ ) -> RemovedTile<W> {
1131 let offset = self.column_x(column_idx + 1) - self.column_x(column_idx);1131 let offset = self.column_x(column_idx + 1) - self.column_x(column_idx);
1132 1132
1133 let column = &mut self.columns[column_idx];1133 let column = &mut self.columns[column_idx];
@@ -1136,13 +1136,13 @@ impl<W: LayoutElement> Workspace<W> {
1136 // Animate movement of other tiles.1136 // Animate movement of other tiles.
1137 // FIXME: tiles can move by X too, in a centered or resizing layout with one window smaller1137 // FIXME: tiles can move by X too, in a centered or resizing layout with one window smaller
1138 // than the others.1138 // than the others.
1139- let offset_y = column.tile_offset(window_idx + 1).y - column.tile_offset(window_idx).y;1139+ let offset_y = column.tile_offset(tile_idx + 1).y - column.tile_offset(tile_idx).y;
1140- for tile in &mut column.tiles[window_idx + 1..] {1140+ for tile in &mut column.tiles[tile_idx + 1..] {
1141 tile.animate_move_y_from(offset_y);1141 tile.animate_move_y_from(offset_y);
1142 }1142 }
1143 1143
1144- let tile = column.tiles.remove(window_idx);1144+ let tile = column.tiles.remove(tile_idx);
1145- column.data.remove(window_idx);1145+ column.data.remove(tile_idx);
1146 1146
1147 // If one window is left, reset its weight to 1.1147 // If one window is left, reset its weight to 1.
1148 if column.data.len() == 1 {1148 if column.data.len() == 1 {
@@ -1162,6 +1162,12 @@ impl<W: LayoutElement> Workspace<W> {
1162 }1162 }
1163 }1163 }
1164 1164
1165+ let tile = RemovedTile {
1166+ tile,
1167+ width: column.width,
1168+ is_full_width: column.is_full_width,
1169+ };
1170+
1165 let became_empty = column.tiles.is_empty();1171 let became_empty = column.tiles.is_empty();
1166 let offset = if became_empty {1172 let offset = if became_empty {
1167 offset1173 offset
@@ -1322,7 +1328,7 @@ impl<W: LayoutElement> Workspace<W> {
1322 column1328 column
1323 }1329 }
1324 1330
1325- pub fn remove_window(&mut self, window: &W::Id, transaction: Transaction) -> W {1331+ pub fn remove_tile(&mut self, window: &W::Id, transaction: Transaction) -> RemovedTile<W> {
1326 let column_idx = self1332 let column_idx = self
1327 .columns1333 .columns
1328 .iter()1334 .iter()
@@ -1330,9 +1336,8 @@ impl<W: LayoutElement> Workspace<W> {
1330 .unwrap();1336 .unwrap();
1331 let column = &self.columns[column_idx];1337 let column = &self.columns[column_idx];
1332 1338
1333- let window_idx = column.position(window).unwrap();1339+ let tile_idx = column.position(window).unwrap();
1334- self.remove_tile_by_idx(column_idx, window_idx, transaction, None)1340+ self.remove_tile_by_idx(column_idx, tile_idx, transaction, None)
1335- .into_window()
1336 }1341 }
1337 1342
1338 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {1343 pub fn update_window(&mut self, window: &W::Id, serial: Option<Serial>) {
@@ -1852,7 +1857,7 @@ impl<W: LayoutElement> Workspace<W> {
1852 }1857 }
1853 1858
1854 offset.x += self.columns[source_col_idx].render_offset().x;1859 offset.x += self.columns[source_col_idx].render_offset().x;
1855- let tile = self.remove_tile_by_idx(1860+ let RemovedTile { tile, .. } = self.remove_tile_by_idx(
1856 source_col_idx,1861 source_col_idx,
1857 0,1862 0,
1858 Transaction::new(),1863 Transaction::new(),
@@ -1868,12 +1873,9 @@ impl<W: LayoutElement> Workspace<W> {
1868 new_tile.animate_move_from(offset);1873 new_tile.animate_move_from(offset);
1869 } else {1874 } else {
1870 // Move out of column.1875 // Move out of column.
1871- let width = source_column.width;
1872- let is_full_width = source_column.is_full_width;
1873-
1874 let mut offset = Point::from((source_column.render_offset().x, 0.));1876 let mut offset = Point::from((source_column.render_offset().x, 0.));
1875 1877
1876- let tile =1878+ let removed =
1877 self.remove_tile_by_idx(source_col_idx, source_tile_idx, Transaction::new(), None);1879 self.remove_tile_by_idx(source_col_idx, source_tile_idx, Transaction::new(), None);
1878 1880
1879 // We're inserting into the source column position.1881 // We're inserting into the source column position.
@@ -1881,10 +1883,10 @@ impl<W: LayoutElement> Workspace<W> {
1881 1883
1882 self.add_tile(1884 self.add_tile(
1883 Some(target_column_idx),1885 Some(target_column_idx),
1884- tile,1886+ removed.tile,
1885 source_tile_was_active,1887 source_tile_was_active,
1886- width,1888+ removed.width,
1887- is_full_width,1889+ removed.is_full_width,
1888 Some(self.options.animations.window_movement.0),1890 Some(self.options.animations.window_movement.0),
1889 );1891 );
1890 1892
@@ -1951,7 +1953,7 @@ impl<W: LayoutElement> Workspace<W> {
1951 self.activate_prev_column_on_removal = None;1953 self.activate_prev_column_on_removal = None;
1952 }1954 }
1953 1955
1954- let tile = self.remove_tile_by_idx(1956+ let RemovedTile { tile, .. } = self.remove_tile_by_idx(
1955 source_col_idx,1957 source_col_idx,
1956 0,1958 0,
1957 Transaction::new(),1959 Transaction::new(),
@@ -1966,22 +1968,19 @@ impl<W: LayoutElement> Workspace<W> {
1966 new_tile.animate_move_from(offset);1968 new_tile.animate_move_from(offset);
1967 } else {1969 } else {
1968 // Move out of column.1970 // Move out of column.
1969- let width = source_column.width;
1970- let is_full_width = source_column.is_full_width;
1971-
1972 let prev_width = self.data[source_col_idx].width;1971 let prev_width = self.data[source_col_idx].width;
1973 1972
1974- let tile =1973+ let removed =
1975 self.remove_tile_by_idx(source_col_idx, source_tile_idx, Transaction::new(), None);1974 self.remove_tile_by_idx(source_col_idx, source_tile_idx, Transaction::new(), None);
1976 1975
1977 let target_column_idx = source_col_idx + 1;1976 let target_column_idx = source_col_idx + 1;
1978 1977
1979 self.add_tile(1978 self.add_tile(
1980 Some(target_column_idx),1979 Some(target_column_idx),
1981- tile,1980+ removed.tile,
1982 source_tile_was_active,1981 source_tile_was_active,
1983- width,1982+ removed.width,
1984- is_full_width,1983+ removed.is_full_width,
1985 Some(self.options.animations.window_movement.0),1984 Some(self.options.animations.window_movement.0),
1986 );1985 );
1987 1986
@@ -2017,8 +2016,8 @@ impl<W: LayoutElement> Workspace<W> {
2017 let mut offset = Point::from((offset, 0.));2016 let mut offset = Point::from((offset, 0.));
2018 let prev_off = self.columns[source_column_idx].tile_offset(0);2017 let prev_off = self.columns[source_column_idx].tile_offset(0);
2019 2018
2020- let tile = self.remove_tile_by_idx(source_column_idx, 0, Transaction::new(), None);2019+ let removed = self.remove_tile_by_idx(source_column_idx, 0, Transaction::new(), None);
2021- self.add_tile_to_column(target_column_idx, None, tile, false);2020+ self.add_tile_to_column(target_column_idx, None, removed.tile, false);
2022 2021
2023 let target_column = &mut self.columns[target_column_idx];2022 let target_column = &mut self.columns[target_column_idx];
2024 offset += prev_off - target_column.tile_offset(target_column.tiles.len() - 1);2023 offset += prev_off - target_column.tile_offset(target_column.tiles.len() - 1);
@@ -2045,9 +2044,7 @@ impl<W: LayoutElement> Workspace<W> {
2045 let mut offset = Point::from((source_column.render_offset().x, 0.));2044 let mut offset = Point::from((source_column.render_offset().x, 0.));
2046 let prev_off = source_column.tile_offset(source_column.active_tile_idx);2045 let prev_off = source_column.tile_offset(source_column.active_tile_idx);
2047 2046
2048- let width = source_column.width;2047+ let removed = self.remove_tile_by_idx(
2049- let is_full_width = source_column.is_full_width;
2050- let tile = self.remove_tile_by_idx(
2051 source_col_idx,2048 source_col_idx,
2052 source_column.active_tile_idx,2049 source_column.active_tile_idx,
2053 Transaction::new(),2050 Transaction::new(),
@@ -2056,10 +2053,10 @@ impl<W: LayoutElement> Workspace<W> {
2056 2053
2057 self.add_tile(2054 self.add_tile(
2058 Some(target_col_idx),2055 Some(target_col_idx),
2059- tile,2056+ removed.tile,
2060 true,2057 true,
2061- width,2058+ removed.width,
2062- is_full_width,2059+ removed.is_full_width,
2063 Some(self.options.animations.window_movement.0),2060 Some(self.options.animations.window_movement.0),
2064 );2061 );
2065 2062
@@ -2412,19 +2409,17 @@ impl<W: LayoutElement> Workspace<W> {
2412 if is_fullscreen && col.tiles.len() > 1 {2409 if is_fullscreen && col.tiles.len() > 1 {
2413 // This wasn't the only window in its column; extract it into a separate column.2410 // This wasn't the only window in its column; extract it into a separate column.
2414 let activate = self.active_column_idx == col_idx && col.active_tile_idx == tile_idx;2411 let activate = self.active_column_idx == col_idx && col.active_tile_idx == tile_idx;
2415- let width = col.width;
2416- let is_full_width = col.is_full_width;
2417 2412
2418- let tile = self.remove_tile_by_idx(col_idx, tile_idx, Transaction::new(), None);2413+ let removed = self.remove_tile_by_idx(col_idx, tile_idx, Transaction::new(), None);
2419 // Create a column manually to disable the resize animation.2414 // Create a column manually to disable the resize animation.
2420 let column = Column::new_with_tile(2415 let column = Column::new_with_tile(
2421- tile,2416+ removed.tile,
2422 self.view_size,2417 self.view_size,
2423 self.working_area,2418 self.working_area,
2424 self.scale.fractional_scale(),2419 self.scale.fractional_scale(),
2425 self.options.clone(),2420 self.options.clone(),
2426- width,2421+ removed.width,
2427- is_full_width,2422+ removed.is_full_width,
2428 false,2423 false,
2429 );2424 );
2430 self.add_column(Some(col_idx + 1), column, activate, None);2425 self.add_column(Some(col_idx + 1), column, activate, None);