forge
Explore
Log in

Don't you dare go Hollow

layout: Update workspace original output on moving even if same monitor

Browse files at this commit

1c749f578c44daa044bce30c2d3f22eb45970e4bIvan MolodetskikhParent: 3a887a6
Moving is an explicit action that puts the workspace on a specific monitor. It
makes sense to update the original output even if the workspace already happens
to be on the target monitor.
src/layout/mod.rsmodified+62 -1
@@ -3046,6 +3046,9 @@ impl<W: LayoutElement> Layout<W> {
3046 3046
3047 // Do not do anything if the output is already correct3047 // Do not do anything if the output is already correct
3048 if &current.output == output {3048 if &current.output == output {
3049+ // Just update the original output since this is an explicit movement action.
3050+ current.active_workspace().original_output = OutputId::new(output);
3051+
3049 return false;3052 return false;
3050 }3053 }
3051 3054
@@ -3119,11 +3122,16 @@ impl<W: LayoutElement> Layout<W> {
3119 .position(|mon| mon.output == new_output)3122 .position(|mon| mon.output == new_output)
3120 .unwrap();3123 .unwrap();
3121 3124
3125+ let current = &mut monitors[current_idx];
3126+
3127+ // Do not do anything if the output is already correct
3122 if current_idx == target_idx {3128 if current_idx == target_idx {
3129+ // Just update the original output since this is an explicit movement action.
3130+ current.workspaces[old_idx].original_output = OutputId::new(&current.output);
3131+
3123 return false;3132 return false;
3124 }3133 }
3125 3134
3126- let current = &mut monitors[current_idx];
3127 let current_active_ws_idx = current.active_workspace_idx;3135 let current_active_ws_idx = current.active_workspace_idx;
3128 3136
3129 if old_idx == current.workspaces.len() - 1 {3137 if old_idx == current.workspaces.len() - 1 {
@@ -6065,6 +6073,59 @@ mod tests {
6065 check_ops(&ops);6073 check_ops(&ops);
6066 }6074 }
6067 6075
6076+ #[test]
6077+ fn workspaces_update_original_output_on_moving_to_same_output() {
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+ Op::MoveWorkspaceToOutput(2),
6088+ Op::AddOutput(1),
6089+ ];
6090+
6091+ let layout = check_ops(&ops);
6092+ let (mon, _, ws) = layout
6093+ .workspaces()
6094+ .find(|(_, _, ws)| ws.name().is_some())
6095+ .unwrap();
6096+ assert!(ws.name().is_some()); // Sanity check.
6097+ let mon = mon.unwrap();
6098+ assert_eq!(mon.output_name(), "output2");
6099+ }
6100+
6101+ #[test]
6102+ fn workspaces_update_original_output_on_moving_to_same_monitor() {
6103+ let ops = [
6104+ Op::AddOutput(1),
6105+ Op::SetWorkspaceName {
6106+ new_ws_name: 1,
6107+ ws_name: None,
6108+ },
6109+ Op::AddOutput(2),
6110+ Op::RemoveOutput(1),
6111+ Op::FocusWorkspaceUp,
6112+ Op::MoveWorkspaceToMonitor {
6113+ ws_name: Some(1),
6114+ output_id: 2,
6115+ },
6116+ Op::AddOutput(1),
6117+ ];
6118+
6119+ let layout = check_ops(&ops);
6120+ let (mon, _, ws) = layout
6121+ .workspaces()
6122+ .find(|(_, _, ws)| ws.name().is_some())
6123+ .unwrap();
6124+ assert!(ws.name().is_some()); // Sanity check.
6125+ let mon = mon.unwrap();
6126+ assert_eq!(mon.output_name(), "output2");
6127+ }
6128+
6068 #[test]6129 #[test]
6069 fn large_negative_height_change() {6130 fn large_negative_height_change() {
6070 let ops = [6131 let ops = [