Preserve column width when toggling off full width
Browse files at this commite397f773bd56405da2829fb1aeb6e6747837da90Parent: 37de77d2 changed files +70 -27
- src/handlers/compositor.rs +6 -1
- src/layout.rs +64 -26
src/handlers/compositor.rsmodified+6 -1
| @@ -98,7 +98,12 @@ impl CompositorHandler for State { | |||
| 98 | let window = entry.remove(); | 98 | let window = entry.remove(); |
| 99 | window.on_commit(); | 99 | window.on_commit(); |
| 100 | 100 | ||
| 101 | - if let Some(output) = self.niri.layout.add_window(window, true, None).cloned() { | 101 | + if let Some(output) = self |
| 102 | + .niri | ||
| 103 | + .layout | ||
| 104 | + .add_window(window, true, None, false) | ||
| 105 | + .cloned() | ||
| 106 | + { | ||
| 102 | self.niri.queue_redraw(output); | 107 | self.niri.queue_redraw(output); |
| 103 | } | 108 | } |
| 104 | return; | 109 | return; |
src/layout.rsmodified+64 -26
| @@ -317,8 +317,14 @@ struct Column<W: LayoutElement> { | |||
| 317 | active_window_idx: usize, | 317 | active_window_idx: usize, |
| 318 | 318 | ||
| 319 | /// Desired width of this column. | 319 | /// Desired width of this column. |
| 320 | + /// | ||
| 321 | + /// If the column is full-width or full-screened, this is the width that should be restored | ||
| 322 | + /// upon unfullscreening and untoggling full-width. | ||
| 320 | width: ColumnWidth, | 323 | width: ColumnWidth, |
| 321 | 324 | ||
| 325 | + /// Whether this column is full-width. | ||
| 326 | + is_full_width: bool, | ||
| 327 | + | ||
| 322 | /// Whether this column contains a single full-screened window. | 328 | /// Whether this column contains a single full-screened window. |
| 323 | is_fullscreen: bool, | 329 | is_fullscreen: bool, |
| 324 | 330 | ||
| @@ -642,6 +648,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 642 | window: W, | 648 | window: W, |
| 643 | activate: bool, | 649 | activate: bool, |
| 644 | width: ColumnWidth, | 650 | width: ColumnWidth, |
| 651 | + is_full_width: bool, | ||
| 645 | ) { | 652 | ) { |
| 646 | let MonitorSet::Normal { | 653 | let MonitorSet::Normal { |
| 647 | monitors, | 654 | monitors, |
| @@ -652,7 +659,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 652 | panic!() | 659 | panic!() |
| 653 | }; | 660 | }; |
| 654 | 661 | ||
| 655 | - monitors[monitor_idx].add_window(workspace_idx, window, activate, width); | 662 | + monitors[monitor_idx].add_window(workspace_idx, window, activate, width, is_full_width); |
| 656 | 663 | ||
| 657 | if activate { | 664 | if activate { |
| 658 | *active_monitor_idx = monitor_idx; | 665 | *active_monitor_idx = monitor_idx; |
| @@ -667,6 +674,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 667 | window: W, | 674 | window: W, |
| 668 | activate: bool, | 675 | activate: bool, |
| 669 | width: Option<ColumnWidth>, | 676 | width: Option<ColumnWidth>, |
| 677 | + is_full_width: bool, | ||
| 670 | ) -> Option<&Output> { | 678 | ) -> Option<&Output> { |
| 671 | let width = width | 679 | let width = width |
| 672 | .or(self.options.default_width) | 680 | .or(self.options.default_width) |
| @@ -679,7 +687,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 679 | .. | 687 | .. |
| 680 | } => { | 688 | } => { |
| 681 | let mon = &mut monitors[*active_monitor_idx]; | 689 | let mon = &mut monitors[*active_monitor_idx]; |
| 682 | - mon.add_window(mon.active_workspace_idx, window, activate, width); | 690 | + mon.add_window( |
| 691 | + mon.active_workspace_idx, | ||
| 692 | + window, | ||
| 693 | + activate, | ||
| 694 | + width, | ||
| 695 | + is_full_width, | ||
| 696 | + ); | ||
| 683 | Some(&mon.output) | 697 | Some(&mon.output) |
| 684 | } | 698 | } |
| 685 | MonitorSet::NoOutputs { workspaces } => { | 699 | MonitorSet::NoOutputs { workspaces } => { |
| @@ -689,7 +703,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 689 | workspaces.push(Workspace::new_no_outputs(self.options.clone())); | 703 | workspaces.push(Workspace::new_no_outputs(self.options.clone())); |
| 690 | &mut workspaces[0] | 704 | &mut workspaces[0] |
| 691 | }; | 705 | }; |
| 692 | - ws.add_window(window, activate, width); | 706 | + ws.add_window(window, activate, width, is_full_width); |
| 693 | None | 707 | None |
| 694 | } | 708 | } |
| 695 | } | 709 | } |
| @@ -1266,10 +1280,11 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1266 | let column = &ws.columns[ws.active_column_idx]; | 1280 | let column = &ws.columns[ws.active_column_idx]; |
| 1267 | let window = column.windows[column.active_window_idx].clone(); | 1281 | let window = column.windows[column.active_window_idx].clone(); |
| 1268 | let width = column.width; | 1282 | let width = column.width; |
| 1283 | + let is_full_width = column.is_full_width; | ||
| 1269 | ws.remove_window(&window); | 1284 | ws.remove_window(&window); |
| 1270 | 1285 | ||
| 1271 | let workspace_idx = monitors[new_idx].active_workspace_idx; | 1286 | let workspace_idx = monitors[new_idx].active_workspace_idx; |
| 1272 | - self.add_window_by_idx(new_idx, workspace_idx, window, true, width); | 1287 | + self.add_window_by_idx(new_idx, workspace_idx, window, true, width, is_full_width); |
| 1273 | } | 1288 | } |
| 1274 | } | 1289 | } |
| 1275 | 1290 | ||
| @@ -1282,11 +1297,13 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1282 | 1297 | ||
| 1283 | if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { | 1298 | if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set { |
| 1284 | let mut width = None; | 1299 | let mut width = None; |
| 1300 | + let mut is_full_width = false; | ||
| 1285 | for mon in &*monitors { | 1301 | for mon in &*monitors { |
| 1286 | for ws in &mon.workspaces { | 1302 | for ws in &mon.workspaces { |
| 1287 | for col in &ws.columns { | 1303 | for col in &ws.columns { |
| 1288 | if col.windows.contains(&window) { | 1304 | if col.windows.contains(&window) { |
| 1289 | width = Some(col.width); | 1305 | width = Some(col.width); |
| 1306 | + is_full_width = col.is_full_width; | ||
| 1290 | break; | 1307 | break; |
| 1291 | } | 1308 | } |
| 1292 | } | 1309 | } |
| @@ -1301,7 +1318,7 @@ impl<W: LayoutElement> Layout<W> { | |||
| 1301 | 1318 | ||
| 1302 | let workspace_idx = monitors[new_idx].active_workspace_idx; | 1319 | let workspace_idx = monitors[new_idx].active_workspace_idx; |
| 1303 | // FIXME: activate only if it was already active and focused. | 1320 | // FIXME: activate only if it was already active and focused. |
| 1304 | - self.add_window_by_idx(new_idx, workspace_idx, window, true, width); | 1321 | + self.add_window_by_idx(new_idx, workspace_idx, window, true, width, is_full_width); |
| 1305 | } | 1322 | } |
| 1306 | } | 1323 | } |
| 1307 | 1324 | ||
| @@ -1523,10 +1540,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1523 | window: W, | 1540 | window: W, |
| 1524 | activate: bool, | 1541 | activate: bool, |
| 1525 | width: ColumnWidth, | 1542 | width: ColumnWidth, |
| 1543 | + is_full_width: bool, | ||
| 1526 | ) { | 1544 | ) { |
| 1527 | let workspace = &mut self.workspaces[workspace_idx]; | 1545 | let workspace = &mut self.workspaces[workspace_idx]; |
| 1528 | 1546 | ||
| 1529 | - workspace.add_window(window.clone(), activate, width); | 1547 | + workspace.add_window(window.clone(), activate, width, is_full_width); |
| 1530 | 1548 | ||
| 1531 | // After adding a new window, workspace becomes this output's own. | 1549 | // After adding a new window, workspace becomes this output's own. |
| 1532 | workspace.original_output = OutputId::new(&self.output); | 1550 | workspace.original_output = OutputId::new(&self.output); |
| @@ -1606,10 +1624,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1606 | 1624 | ||
| 1607 | let column = &mut workspace.columns[workspace.active_column_idx]; | 1625 | let column = &mut workspace.columns[workspace.active_column_idx]; |
| 1608 | let width = column.width; | 1626 | let width = column.width; |
| 1627 | + let is_full_width = column.is_full_width; | ||
| 1609 | let window = column.windows[column.active_window_idx].clone(); | 1628 | let window = column.windows[column.active_window_idx].clone(); |
| 1610 | workspace.remove_window(&window); | 1629 | workspace.remove_window(&window); |
| 1611 | 1630 | ||
| 1612 | - self.add_window(new_idx, window, true, width); | 1631 | + self.add_window(new_idx, window, true, width, is_full_width); |
| 1613 | } | 1632 | } |
| 1614 | 1633 | ||
| 1615 | pub fn move_to_workspace_down(&mut self) { | 1634 | pub fn move_to_workspace_down(&mut self) { |
| @@ -1627,10 +1646,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1627 | 1646 | ||
| 1628 | let column = &mut workspace.columns[workspace.active_column_idx]; | 1647 | let column = &mut workspace.columns[workspace.active_column_idx]; |
| 1629 | let width = column.width; | 1648 | let width = column.width; |
| 1649 | + let is_full_width = column.is_full_width; | ||
| 1630 | let window = column.windows[column.active_window_idx].clone(); | 1650 | let window = column.windows[column.active_window_idx].clone(); |
| 1631 | workspace.remove_window(&window); | 1651 | workspace.remove_window(&window); |
| 1632 | 1652 | ||
| 1633 | - self.add_window(new_idx, window, true, width); | 1653 | + self.add_window(new_idx, window, true, width, is_full_width); |
| 1634 | } | 1654 | } |
| 1635 | 1655 | ||
| 1636 | pub fn move_to_workspace(&mut self, idx: u8) { | 1656 | pub fn move_to_workspace(&mut self, idx: u8) { |
| @@ -1648,10 +1668,11 @@ impl<W: LayoutElement> Monitor<W> { | |||
| 1648 | 1668 | ||
| 1649 | let column = &mut workspace.columns[workspace.active_column_idx]; | 1669 | let column = &mut workspace.columns[workspace.active_column_idx]; |
| 1650 | let width = column.width; | 1670 | let width = column.width; |
| 1671 | + let is_full_width = column.is_full_width; | ||
| 1651 | let window = column.windows[column.active_window_idx].clone(); | 1672 | let window = column.windows[column.active_window_idx].clone(); |
| 1652 | workspace.remove_window(&window); | 1673 | workspace.remove_window(&window); |
| 1653 | 1674 | ||
| 1654 | - self.add_window(new_idx, window, true, width); | 1675 | + self.add_window(new_idx, window, true, width, is_full_width); |
| 1655 | 1676 | ||
| 1656 | // Don't animate this action. | 1677 | // Don't animate this action. |
| 1657 | self.workspace_switch = None; | 1678 | self.workspace_switch = None; |
| @@ -2155,7 +2176,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2155 | x | 2176 | x |
| 2156 | } | 2177 | } |
| 2157 | 2178 | ||
| 2158 | - fn add_window(&mut self, window: W, activate: bool, width: ColumnWidth) { | 2179 | + fn add_window(&mut self, window: W, activate: bool, width: ColumnWidth, is_full_width: bool) { |
| 2159 | self.enter_output_for_window(&window); | 2180 | self.enter_output_for_window(&window); |
| 2160 | 2181 | ||
| 2161 | let was_empty = self.columns.is_empty(); | 2182 | let was_empty = self.columns.is_empty(); |
| @@ -2172,6 +2193,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2172 | self.working_area, | 2193 | self.working_area, |
| 2173 | self.options.clone(), | 2194 | self.options.clone(), |
| 2174 | width, | 2195 | width, |
| 2196 | + is_full_width, | ||
| 2175 | ); | 2197 | ); |
| 2176 | self.columns.insert(idx, column); | 2198 | self.columns.insert(idx, column); |
| 2177 | 2199 | ||
| @@ -2390,10 +2412,11 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2390 | } | 2412 | } |
| 2391 | 2413 | ||
| 2392 | let width = source_column.width; | 2414 | let width = source_column.width; |
| 2415 | + let is_full_width = source_column.is_full_width; | ||
| 2393 | let window = source_column.windows[source_column.active_window_idx].clone(); | 2416 | let window = source_column.windows[source_column.active_window_idx].clone(); |
| 2394 | self.remove_window(&window); | 2417 | self.remove_window(&window); |
| 2395 | 2418 | ||
| 2396 | - self.add_window(window, true, width); | 2419 | + self.add_window(window, true, width, is_full_width); |
| 2397 | } | 2420 | } |
| 2398 | 2421 | ||
| 2399 | fn view_pos(&self) -> i32 { | 2422 | fn view_pos(&self) -> i32 { |
| @@ -2496,6 +2519,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2496 | col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1); | 2519 | col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1); |
| 2497 | col.update_window_sizes(); | 2520 | col.update_window_sizes(); |
| 2498 | let width = col.width; | 2521 | let width = col.width; |
| 2522 | + let is_full_width = col.is_full_width; | ||
| 2499 | 2523 | ||
| 2500 | col_idx += 1; | 2524 | col_idx += 1; |
| 2501 | self.columns.insert( | 2525 | self.columns.insert( |
| @@ -2506,6 +2530,7 @@ impl<W: LayoutElement> Workspace<W> { | |||
| 2506 | self.working_area, | 2530 | self.working_area, |
| 2507 | self.options.clone(), | 2531 | self.options.clone(), |
| 2508 | width, | 2532 | width, |
| 2533 | + is_full_width, | ||
| 2509 | ), | 2534 | ), |
| 2510 | ); | 2535 | ); |
| 2511 | if self.active_column_idx >= col_idx || target_window_was_focused { | 2536 | if self.active_column_idx >= col_idx || target_window_was_focused { |
| @@ -2632,12 +2657,14 @@ impl<W: LayoutElement> Column<W> { | |||
| 2632 | working_area: Rectangle<i32, Logical>, | 2657 | working_area: Rectangle<i32, Logical>, |
| 2633 | options: Rc<Options>, | 2658 | options: Rc<Options>, |
| 2634 | width: ColumnWidth, | 2659 | width: ColumnWidth, |
| 2660 | + is_full_width: bool, | ||
| 2635 | ) -> Self { | 2661 | ) -> Self { |
| 2636 | let mut rv = Self { | 2662 | let mut rv = Self { |
| 2637 | windows: vec![], | 2663 | windows: vec![], |
| 2638 | heights: vec![], | 2664 | heights: vec![], |
| 2639 | active_window_idx: 0, | 2665 | active_window_idx: 0, |
| 2640 | width, | 2666 | width, |
| 2667 | + is_full_width, | ||
| 2641 | is_fullscreen: false, | 2668 | is_fullscreen: false, |
| 2642 | view_size, | 2669 | view_size, |
| 2643 | working_area, | 2670 | working_area, |
| @@ -2683,6 +2710,7 @@ impl<W: LayoutElement> Column<W> { | |||
| 2683 | 2710 | ||
| 2684 | fn set_width(&mut self, width: ColumnWidth) { | 2711 | fn set_width(&mut self, width: ColumnWidth) { |
| 2685 | self.width = width; | 2712 | self.width = width; |
| 2713 | + self.is_full_width = false; | ||
| 2686 | self.update_window_sizes(); | 2714 | self.update_window_sizes(); |
| 2687 | } | 2715 | } |
| 2688 | 2716 | ||
| @@ -2738,7 +2766,13 @@ impl<W: LayoutElement> Column<W> { | |||
| 2738 | .unwrap_or(i32::MAX); | 2766 | .unwrap_or(i32::MAX); |
| 2739 | let max_width = max(max_width, min_width); | 2767 | let max_width = max(max_width, min_width); |
| 2740 | 2768 | ||
| 2741 | - let width = self.width.resolve(&self.options, self.working_area.size.w); | 2769 | + let width = if self.is_full_width { |
| 2770 | + ColumnWidth::Proportion(1.) | ||
| 2771 | + } else { | ||
| 2772 | + self.width | ||
| 2773 | + }; | ||
| 2774 | + | ||
| 2775 | + let width = width.resolve(&self.options, self.working_area.size.w); | ||
| 2742 | let width = max(min(width, max_width), min_width); | 2776 | let width = max(min(width, max_width), min_width); |
| 2743 | 2777 | ||
| 2744 | // Compute the window heights. | 2778 | // Compute the window heights. |
| @@ -2896,7 +2930,13 @@ impl<W: LayoutElement> Column<W> { | |||
| 2896 | } | 2930 | } |
| 2897 | 2931 | ||
| 2898 | fn toggle_width(&mut self) { | 2932 | fn toggle_width(&mut self) { |
| 2899 | - let idx = match self.width { | 2933 | + let width = if self.is_full_width { |
| 2934 | + ColumnWidth::Proportion(1.) | ||
| 2935 | + } else { | ||
| 2936 | + self.width | ||
| 2937 | + }; | ||
| 2938 | + | ||
| 2939 | + let idx = match width { | ||
| 2900 | ColumnWidth::Preset(idx) => (idx + 1) % self.options.preset_widths.len(), | 2940 | ColumnWidth::Preset(idx) => (idx + 1) % self.options.preset_widths.len(), |
| 2901 | _ => { | 2941 | _ => { |
| 2902 | let current = self.width(); | 2942 | let current = self.width(); |
| @@ -2914,22 +2954,20 @@ impl<W: LayoutElement> Column<W> { | |||
| 2914 | } | 2954 | } |
| 2915 | 2955 | ||
| 2916 | fn toggle_full_width(&mut self) { | 2956 | fn toggle_full_width(&mut self) { |
| 2917 | - let width = match self.width { | 2957 | + self.is_full_width = !self.is_full_width; |
| 2918 | - ColumnWidth::Proportion(x) if x == 1. => { | 2958 | + self.update_window_sizes(); |
| 2919 | - // FIXME: would be good to restore to previous width here. | ||
| 2920 | - self.options | ||
| 2921 | - .default_width | ||
| 2922 | - .unwrap_or(ColumnWidth::Proportion(0.5)) | ||
| 2923 | - } | ||
| 2924 | - _ => ColumnWidth::Proportion(1.), | ||
| 2925 | - }; | ||
| 2926 | - self.set_width(width); | ||
| 2927 | } | 2959 | } |
| 2928 | 2960 | ||
| 2929 | fn set_column_width(&mut self, change: SizeChange) { | 2961 | fn set_column_width(&mut self, change: SizeChange) { |
| 2930 | - let current_px = self.width.resolve(&self.options, self.working_area.size.w); | 2962 | + let width = if self.is_full_width { |
| 2963 | + ColumnWidth::Proportion(1.) | ||
| 2964 | + } else { | ||
| 2965 | + self.width | ||
| 2966 | + }; | ||
| 2967 | + | ||
| 2968 | + let current_px = width.resolve(&self.options, self.working_area.size.w); | ||
| 2931 | 2969 | ||
| 2932 | - let current = match self.width { | 2970 | + let current = match width { |
| 2933 | ColumnWidth::Preset(idx) => self.options.preset_widths[idx], | 2971 | ColumnWidth::Preset(idx) => self.options.preset_widths[idx], |
| 2934 | current => current, | 2972 | current => current, |
| 2935 | }; | 2973 | }; |
| @@ -3326,7 +3364,7 @@ mod tests { | |||
| 3326 | } | 3364 | } |
| 3327 | 3365 | ||
| 3328 | let win = TestWindow::new(id, bbox); | 3366 | let win = TestWindow::new(id, bbox); |
| 3329 | - layout.add_window(win, activate, None); | 3367 | + layout.add_window(win, activate, None, false); |
| 3330 | } | 3368 | } |
| 3331 | Op::CloseWindow(id) => { | 3369 | Op::CloseWindow(id) => { |
| 3332 | let dummy = TestWindow::new(id, Rectangle::default()); | 3370 | let dummy = TestWindow::new(id, Rectangle::default()); |