forge
Explore
Log in

Don't you dare go Hollow

layout: Do not update original output for named workspaces upon adding windows

Browse files at this commit

1d3820a064f1f3b686eb6e8a1aab155681a96457Ivan MolodetskikhParent: 1c749f5
The way named workspaces are generally used makes them more "attached" to their
original output.

For example, you have a two-monitor setup with named workspaces on both. When
you disconnect the monitor to go somewhere and work for a while, then return,
you probably want your named workspaces to return to where they were on your
second monitor.

This is in contrast to unnamed workspaces which are more transient and should
more easily follow you wherever you're working.
src/layout/mod.rsmodified+30 -0
@@ -6073,6 +6073,36 @@ mod tests {
6073 check_ops(&ops);6073 check_ops(&ops);
6074 }6074 }
6075 6075
6076+ #[test]
6077+ fn named_workspaces_dont_update_original_output_on_adding_window() {
6078+ let ops = [
6079+ Op::AddOutput(1),
6080+ Op::SetWorkspaceName {
6081+ new_ws_name: 1,
6082+ ws_name: None,
6083+ },
6084+ Op::AddOutput(2),
6085+ Op::RemoveOutput(1),
6086+ Op::FocusWorkspaceUp,
6087+ // Adding a window updates the original output for unnamed workspaces.
6088+ Op::AddWindow {
6089+ params: TestWindowParams::new(1),
6090+ },
6091+ // Connecting the previous output should move the named workspace back since its
6092+ // original output wasn't updated.
6093+ Op::AddOutput(1),
6094+ ];
6095+
6096+ let layout = check_ops(&ops);
6097+ let (mon, _, ws) = layout
6098+ .workspaces()
6099+ .find(|(_, _, ws)| ws.name().is_some())
6100+ .unwrap();
6101+ assert!(ws.name().is_some()); // Sanity check.
6102+ let mon = mon.unwrap();
6103+ assert_eq!(mon.output_name(), "output1");
6104+ }
6105+
6076 #[test]6106 #[test]
6077 fn workspaces_update_original_output_on_moving_to_same_output() {6107 fn workspaces_update_original_output_on_moving_to_same_output() {
6078 let ops = [6108 let ops = [
src/layout/monitor.rsmodified+9 -3
@@ -259,7 +259,9 @@ impl<W: LayoutElement> Monitor<W> {
259 workspace.add_column(column, activate);259 workspace.add_column(column, activate);
260 260
261 // After adding a new window, workspace becomes this output's own.261 // After adding a new window, workspace becomes this output's own.
262- workspace.original_output = OutputId::new(&self.output);262+ if workspace.name().is_none() {
263+ workspace.original_output = OutputId::new(&self.output);
264+ }
263 265
264 if workspace_idx == self.workspaces.len() - 1 {266 if workspace_idx == self.workspaces.len() - 1 {
265 self.add_workspace_bottom();267 self.add_workspace_bottom();
@@ -311,7 +313,9 @@ impl<W: LayoutElement> Monitor<W> {
311 workspace.add_tile(tile, target, activate, width, is_full_width, is_floating);313 workspace.add_tile(tile, target, activate, width, is_full_width, is_floating);
312 314
313 // After adding a new window, workspace becomes this output's own.315 // After adding a new window, workspace becomes this output's own.
314- workspace.original_output = OutputId::new(&self.output);316+ if workspace.name().is_none() {
317+ workspace.original_output = OutputId::new(&self.output);
318+ }
315 319
316 if workspace_idx == self.workspaces.len() - 1 {320 if workspace_idx == self.workspaces.len() - 1 {
317 // Insert a new empty workspace.321 // Insert a new empty workspace.
@@ -341,7 +345,9 @@ impl<W: LayoutElement> Monitor<W> {
341 workspace.add_tile_to_column(column_idx, tile_idx, tile, activate);345 workspace.add_tile_to_column(column_idx, tile_idx, tile, activate);
342 346
343 // After adding a new window, workspace becomes this output's own.347 // After adding a new window, workspace becomes this output's own.
344- workspace.original_output = OutputId::new(&self.output);348+ if workspace.name().is_none() {
349+ workspace.original_output = OutputId::new(&self.output);
350+ }
345 351
346 // Since we're adding window to an existing column, the workspace isn't empty, and352 // Since we're adding window to an existing column, the workspace isn't empty, and
347 // therefore cannot be the last one, so we never need to insert a new empty workspace.353 // therefore cannot be the last one, so we never need to insert a new empty workspace.
wiki/Configuration:-Named-Workspaces.mdmodified+4 -0
@@ -41,3 +41,7 @@ There's no way to give a name to an already existing workspace, but you can simp
41 Before, it could only use the connector name.41 Before, it could only use the connector name.
42 42
43 <sup>Since: 25.01</sup> You can use `set-workspace-name` and `unset-workspace-name` actions to change workspace names dynamically.43 <sup>Since: 25.01</sup> You can use `set-workspace-name` and `unset-workspace-name` actions to change workspace names dynamically.
44+
45+<sup>Since: next release</sup> Named workspaces no longer update/forget their original output when opening a new window on them (unnamed workspaces will keep doing that).
46+This means that named workspaces "stick" to their original output in more cases, reflecting their more permanent nature.
47+Explicitly moving a named workspace to a different monitor will still update its original output.