forge
Explore
Log in

Don't you dare go Hollow

Preserve column width on window actions

Browse files at this commit

ee8404b9a9e6976b58a3ca4c690dd1a848e2bc52Ivan MolodetskikhParent: 5a86b43
Fixes https://github.com/YaLTeR/niri/issues/53
src/handlers/compositor.rsmodified+7 -1
@@ -18,6 +18,7 @@ use smithay::wayland::shm::{ShmHandler, ShmState};
18 use smithay::{delegate_compositor, delegate_shm};18 use smithay::{delegate_compositor, delegate_shm};
19 19
20 use super::xdg_shell;20 use super::xdg_shell;
21+use crate::layout::ColumnWidth;
21 use crate::niri::{ClientState, State};22 use crate::niri::{ClientState, State};
22 23
23 impl CompositorHandler for State {24 impl CompositorHandler for State {
@@ -98,7 +99,12 @@ impl CompositorHandler for State {
98 let window = entry.remove();99 let window = entry.remove();
99 window.on_commit();100 window.on_commit();
100 101
101- if let Some(output) = self.niri.layout.add_window(window, true).cloned() {102+ if let Some(output) = self
103+ .niri
104+ .layout
105+ .add_window(window, true, ColumnWidth::default())
106+ .cloned()
107+ {
102 self.niri.queue_redraw(output);108 self.niri.queue_redraw(output);
103 }109 }
104 return;110 return;
src/layout.rsmodified+44 -16
@@ -248,7 +248,7 @@ impl Options {
248 248
249 /// Width of a column.249 /// Width of a column.
250 #[derive(Debug, Clone, Copy, PartialEq)]250 #[derive(Debug, Clone, Copy, PartialEq)]
251-enum ColumnWidth {251+pub enum ColumnWidth {
252 /// Proportion of the current view width.252 /// Proportion of the current view width.
253 Proportion(f64),253 Proportion(f64),
254 /// One of the proportion presets.254 /// One of the proportion presets.
@@ -610,6 +610,7 @@ impl<W: LayoutElement> Layout<W> {
610 workspace_idx: usize,610 workspace_idx: usize,
611 window: W,611 window: W,
612 activate: bool,612 activate: bool,
613+ width: ColumnWidth,
613 ) {614 ) {
614 let MonitorSet::Normal {615 let MonitorSet::Normal {
615 monitors,616 monitors,
@@ -620,7 +621,7 @@ impl<W: LayoutElement> Layout<W> {
620 panic!()621 panic!()
621 };622 };
622 623
623- monitors[monitor_idx].add_window(workspace_idx, window, activate);624+ monitors[monitor_idx].add_window(workspace_idx, window, activate, width);
624 625
625 if activate {626 if activate {
626 *active_monitor_idx = monitor_idx;627 *active_monitor_idx = monitor_idx;
@@ -630,7 +631,7 @@ impl<W: LayoutElement> Layout<W> {
630 /// Adds a new window to the layout.631 /// Adds a new window to the layout.
631 ///632 ///
632 /// Returns an output that the window was added to, if there were any outputs.633 /// Returns an output that the window was added to, if there were any outputs.
633- pub fn add_window(&mut self, window: W, activate: bool) -> Option<&Output> {634+ pub fn add_window(&mut self, window: W, activate: bool, width: ColumnWidth) -> Option<&Output> {
634 match &mut self.monitor_set {635 match &mut self.monitor_set {
635 MonitorSet::Normal {636 MonitorSet::Normal {
636 monitors,637 monitors,
@@ -638,7 +639,7 @@ impl<W: LayoutElement> Layout<W> {
638 ..639 ..
639 } => {640 } => {
640 let mon = &mut monitors[*active_monitor_idx];641 let mon = &mut monitors[*active_monitor_idx];
641- mon.add_window(mon.active_workspace_idx, window, activate);642+ mon.add_window(mon.active_workspace_idx, window, activate, width);
642 Some(&mon.output)643 Some(&mon.output)
643 }644 }
644 MonitorSet::NoOutputs { workspaces } => {645 MonitorSet::NoOutputs { workspaces } => {
@@ -648,7 +649,7 @@ impl<W: LayoutElement> Layout<W> {
648 workspaces.push(Workspace::new_no_outputs(self.options.clone()));649 workspaces.push(Workspace::new_no_outputs(self.options.clone()));
649 &mut workspaces[0]650 &mut workspaces[0]
650 };651 };
651- ws.add_window(window, activate);652+ ws.add_window(window, activate, width);
652 None653 None
653 }654 }
654 }655 }
@@ -1203,10 +1204,11 @@ impl<W: LayoutElement> Layout<W> {
1203 }1204 }
1204 let column = &ws.columns[ws.active_column_idx];1205 let column = &ws.columns[ws.active_column_idx];
1205 let window = column.windows[column.active_window_idx].clone();1206 let window = column.windows[column.active_window_idx].clone();
1207+ let width = column.width;
1206 ws.remove_window(&window);1208 ws.remove_window(&window);
1207 1209
1208 let workspace_idx = monitors[new_idx].active_workspace_idx;1210 let workspace_idx = monitors[new_idx].active_workspace_idx;
1209- self.add_window_by_idx(new_idx, workspace_idx, window, true);1211+ self.add_window_by_idx(new_idx, workspace_idx, window, true, width);
1210 }1212 }
1211 }1213 }
1212 1214
@@ -1218,6 +1220,19 @@ impl<W: LayoutElement> Layout<W> {
1218 self.remove_window(&window);1220 self.remove_window(&window);
1219 1221
1220 if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {1222 if let MonitorSet::Normal { monitors, .. } = &mut self.monitor_set {
1223+ let mut width = None;
1224+ for mon in &*monitors {
1225+ for ws in &mon.workspaces {
1226+ for col in &ws.columns {
1227+ if col.windows.contains(&window) {
1228+ width = Some(col.width);
1229+ break;
1230+ }
1231+ }
1232+ }
1233+ }
1234+ let Some(width) = width else { return };
1235+
1221 let new_idx = monitors1236 let new_idx = monitors
1222 .iter()1237 .iter()
1223 .position(|mon| &mon.output == output)1238 .position(|mon| &mon.output == output)
@@ -1225,7 +1240,7 @@ impl<W: LayoutElement> Layout<W> {
1225 1240
1226 let workspace_idx = monitors[new_idx].active_workspace_idx;1241 let workspace_idx = monitors[new_idx].active_workspace_idx;
1227 // FIXME: activate only if it was already active and focused.1242 // FIXME: activate only if it was already active and focused.
1228- self.add_window_by_idx(new_idx, workspace_idx, window, true);1243+ self.add_window_by_idx(new_idx, workspace_idx, window, true, width);
1229 }1244 }
1230 }1245 }
1231 1246
@@ -1441,10 +1456,16 @@ impl<W: LayoutElement> Monitor<W> {
1441 )));1456 )));
1442 }1457 }
1443 1458
1444- pub fn add_window(&mut self, workspace_idx: usize, window: W, activate: bool) {1459+ pub fn add_window(
1460+ &mut self,
1461+ workspace_idx: usize,
1462+ window: W,
1463+ activate: bool,
1464+ width: ColumnWidth,
1465+ ) {
1445 let workspace = &mut self.workspaces[workspace_idx];1466 let workspace = &mut self.workspaces[workspace_idx];
1446 1467
1447- workspace.add_window(window.clone(), activate);1468+ workspace.add_window(window.clone(), activate, width);
1448 1469
1449 // After adding a new window, workspace becomes this output's own.1470 // After adding a new window, workspace becomes this output's own.
1450 workspace.original_output = OutputId::new(&self.output);1471 workspace.original_output = OutputId::new(&self.output);
@@ -1523,10 +1544,11 @@ impl<W: LayoutElement> Monitor<W> {
1523 }1544 }
1524 1545
1525 let column = &mut workspace.columns[workspace.active_column_idx];1546 let column = &mut workspace.columns[workspace.active_column_idx];
1547+ let width = column.width;
1526 let window = column.windows[column.active_window_idx].clone();1548 let window = column.windows[column.active_window_idx].clone();
1527 workspace.remove_window(&window);1549 workspace.remove_window(&window);
1528 1550
1529- self.add_window(new_idx, window, true);1551+ self.add_window(new_idx, window, true, width);
1530 }1552 }
1531 1553
1532 pub fn move_to_workspace_down(&mut self) {1554 pub fn move_to_workspace_down(&mut self) {
@@ -1543,10 +1565,11 @@ impl<W: LayoutElement> Monitor<W> {
1543 }1565 }
1544 1566
1545 let column = &mut workspace.columns[workspace.active_column_idx];1567 let column = &mut workspace.columns[workspace.active_column_idx];
1568+ let width = column.width;
1546 let window = column.windows[column.active_window_idx].clone();1569 let window = column.windows[column.active_window_idx].clone();
1547 workspace.remove_window(&window);1570 workspace.remove_window(&window);
1548 1571
1549- self.add_window(new_idx, window, true);1572+ self.add_window(new_idx, window, true, width);
1550 }1573 }
1551 1574
1552 pub fn move_to_workspace(&mut self, idx: u8) {1575 pub fn move_to_workspace(&mut self, idx: u8) {
@@ -1563,10 +1586,11 @@ impl<W: LayoutElement> Monitor<W> {
1563 }1586 }
1564 1587
1565 let column = &mut workspace.columns[workspace.active_column_idx];1588 let column = &mut workspace.columns[workspace.active_column_idx];
1589+ let width = column.width;
1566 let window = column.windows[column.active_window_idx].clone();1590 let window = column.windows[column.active_window_idx].clone();
1567 workspace.remove_window(&window);1591 workspace.remove_window(&window);
1568 1592
1569- self.add_window(new_idx, window, true);1593+ self.add_window(new_idx, window, true, width);
1570 1594
1571 // Don't animate this action.1595 // Don't animate this action.
1572 self.workspace_switch = None;1596 self.workspace_switch = None;
@@ -2051,7 +2075,7 @@ impl<W: LayoutElement> Workspace<W> {
2051 x2075 x
2052 }2076 }
2053 2077
2054- fn add_window(&mut self, window: W, activate: bool) {2078+ fn add_window(&mut self, window: W, activate: bool, width: ColumnWidth) {
2055 self.enter_output_for_window(&window);2079 self.enter_output_for_window(&window);
2056 2080
2057 let was_empty = self.columns.is_empty();2081 let was_empty = self.columns.is_empty();
@@ -2067,6 +2091,7 @@ impl<W: LayoutElement> Workspace<W> {
2067 self.view_size,2091 self.view_size,
2068 self.working_area,2092 self.working_area,
2069 self.options.clone(),2093 self.options.clone(),
2094+ width,
2070 );2095 );
2071 self.columns.insert(idx, column);2096 self.columns.insert(idx, column);
2072 2097
@@ -2286,7 +2311,7 @@ impl<W: LayoutElement> Workspace<W> {
2286 let window = source_column.windows[source_column.active_window_idx].clone();2311 let window = source_column.windows[source_column.active_window_idx].clone();
2287 self.remove_window(&window);2312 self.remove_window(&window);
2288 2313
2289- self.add_window(window, true);2314+ self.add_window(window, true, ColumnWidth::default());
2290 }2315 }
2291 2316
2292 fn view_pos(&self) -> i32 {2317 fn view_pos(&self) -> i32 {
@@ -2379,6 +2404,7 @@ impl<W: LayoutElement> Workspace<W> {
2379 let window = col.windows.remove(win_idx);2404 let window = col.windows.remove(win_idx);
2380 col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1);2405 col.active_window_idx = min(col.active_window_idx, col.windows.len() - 1);
2381 col.update_window_sizes();2406 col.update_window_sizes();
2407+ let width = col.width;
2382 2408
2383 col_idx += 1;2409 col_idx += 1;
2384 self.columns.insert(2410 self.columns.insert(
@@ -2388,6 +2414,7 @@ impl<W: LayoutElement> Workspace<W> {
2388 self.view_size,2414 self.view_size,
2389 self.working_area,2415 self.working_area,
2390 self.options.clone(),2416 self.options.clone(),
2417+ width,
2391 ),2418 ),
2392 );2419 );
2393 if self.active_column_idx >= col_idx || target_window_was_focused {2420 if self.active_column_idx >= col_idx || target_window_was_focused {
@@ -2500,11 +2527,12 @@ impl<W: LayoutElement> Column<W> {
2500 view_size: Size<i32, Logical>,2527 view_size: Size<i32, Logical>,
2501 working_area: Rectangle<i32, Logical>,2528 working_area: Rectangle<i32, Logical>,
2502 options: Rc<Options>,2529 options: Rc<Options>,
2530+ width: ColumnWidth,
2503 ) -> Self {2531 ) -> Self {
2504 let mut rv = Self {2532 let mut rv = Self {
2505 windows: vec![],2533 windows: vec![],
2506 active_window_idx: 0,2534 active_window_idx: 0,
2507- width: ColumnWidth::default(),2535+ width,
2508 is_fullscreen: false,2536 is_fullscreen: false,
2509 view_size,2537 view_size,
2510 working_area,2538 working_area,
@@ -3046,7 +3074,7 @@ mod tests {
3046 }3074 }
3047 3075
3048 let win = TestWindow::new(id, bbox);3076 let win = TestWindow::new(id, bbox);
3049- layout.add_window(win, activate);3077+ layout.add_window(win, activate, ColumnWidth::default());
3050 }3078 }
3051 Op::CloseWindow(id) => {3079 Op::CloseWindow(id) => {
3052 let dummy = TestWindow::new(id, Rectangle::default());3080 let dummy = TestWindow::new(id, Rectangle::default());