forge
Explore
Log in

Don't you dare go Hollow

Support multiple open-on-output fallbacks for named workspaces (#4618)

Browse files at this commit

9a35d3774a7ff1acdce07fde05bdc94dfa5a0258UnverifiedArtem Timofeev and Ivan MolodetskikhParent: 7449fe8
* feat(config): support multiple open-on-output fallbacks

* Change open-on-output to be separate lines

---------
docs/wiki/Configuration:-Named-Workspaces.mdmodified+13 -0
@@ -46,6 +46,19 @@ Before, it could only use the connector name.
4646 This means that named workspaces "stick" to their original output in more cases, reflecting their more permanent nature.
4747 Explicitly moving a named workspace to a different monitor will still update its original output.
4848
49+<sup>Since: next release</sup> You can now write multiple `open-on-output` lines.
50+If the first output is not connected, the workspace will open on the second output, and so on.
51+
52+```kdl
53+workspace "browser" {
54+ open-on-output "DP-9"
55+ open-on-output "DP-4"
56+}
57+```
58+
59+The output order is reevaluated whenever outputs connect or disconnect.
60+Connecting a higher-priority output will move the workspace there.
61+
4962 ### Layout config overrides
5063
5164 <sup>Since: 25.11</sup>
niri-config/src/lib.rsmodified+6 -4
@@ -963,6 +963,7 @@ mod tests {
963963
964964 workspace "workspace-1" {
965965 open-on-output "eDP-1"
966+ open-on-output "DP-1"
966967 }
967968 workspace "workspace-2"
968969 workspace "workspace-3"
@@ -2312,23 +2313,24 @@ mod tests {
23122313 name: WorkspaceName(
23132314 "workspace-1",
23142315 ),
2315- open_on_output: Some(
2316+ open_on_output: [
23162317 "eDP-1",
2317- ),
2318+ "DP-1",
2319+ ],
23182320 layout: None,
23192321 },
23202322 Workspace {
23212323 name: WorkspaceName(
23222324 "workspace-2",
23232325 ),
2324- open_on_output: None,
2326+ open_on_output: [],
23252327 layout: None,
23262328 },
23272329 Workspace {
23282330 name: WorkspaceName(
23292331 "workspace-3",
23302332 ),
2331- open_on_output: None,
2333+ open_on_output: [],
23322334 layout: None,
23332335 },
23342336 ],
niri-config/src/workspace.rsmodified+2 -2
@@ -6,8 +6,8 @@ use crate::LayoutPart;
66 pub struct Workspace {
77 #[knuffel(argument)]
88 pub name: WorkspaceName,
9- #[knuffel(child, unwrap(argument))]
10- pub open_on_output: Option<String>,
9+ #[knuffel(children(name = "open-on-output"), unwrap(argument))]
10+ pub open_on_output: Vec<String>,
1111 #[knuffel(child)]
1212 pub layout: Option<WorkspaceLayoutPart>,
1313 }
src/layout/mod.rsmodified+78 -67
@@ -19,10 +19,10 @@
1919 //! 2. Connecting an output must not change the layout for any workspaces that were never on that
2020 //! output.
2121 //!
22-//! Therefore, we implement the following logic: every workspace keeps track of which output it
23-//! originated on—its *original output*. When an output disconnects, its workspaces are appended to
24-//! the (potentially new) primary output, but remember their original output. Then, if the original
25-//! output connects again, all workspaces originally from there move back to that output.
22+//! Therefore, we implement the following logic: every workspace keeps track of its ordered
23+//! original output candidates. When an output disconnects, its workspaces move to the first
24+//! connected candidate or the (potentially new) primary output. When a higher-priority candidate
25+//! connects, matching workspaces move to it.
2626 //!
2727 //! In order to avoid surprising behavior, if the user creates or moves any new windows onto a
2828 //! workspace, it forgets its original output, and its current output becomes its original output.
@@ -764,21 +764,31 @@ impl<W: LayoutElement> Layout<W> {
764764 primary_idx,
765765 active_monitor_idx,
766766 } => {
767- let primary = &mut monitors[primary_idx];
767+ let new_output_idx = monitors.len();
768+ let mut workspaces = vec![];
769+ for source_idx in 0..monitors.len() {
770+ let mut stopped_ws_switch = false;
768771
769- let mut stopped_primary_ws_switch = false;
772+ for i in (0..monitors[source_idx].workspaces.len()).rev() {
773+ let preferred = monitors[source_idx].workspaces[i].find_preferred_output(
774+ monitors
775+ .iter()
776+ .map(|monitor| &monitor.output)
777+ .chain(std::iter::once(&output)),
778+ ) == Some(new_output_idx);
779+ if !preferred {
780+ continue;
781+ }
770782
771- let mut workspaces = vec![];
772- for i in (0..primary.workspaces.len()).rev() {
773- if primary.workspaces[i].original_output.matches(&output) {
774- let ws = primary.workspaces.remove(i);
783+ let source = &mut monitors[source_idx];
784+ let ws = source.workspaces.remove(i);
775785
776786 // FIXME: this can be coded in a way that the workspace switch won't be
777787 // affected if the removed workspace is invisible. But this is good enough
778788 // for now.
779- if primary.workspace_switch.is_some() {
780- primary.workspace_switch = None;
781- stopped_primary_ws_switch = true;
789+ if source.workspace_switch.is_some() {
790+ source.workspace_switch = None;
791+ stopped_ws_switch = true;
782792 }
783793
784794 // The user could've closed a window while remaining on this workspace, on
@@ -788,7 +798,7 @@ impl<W: LayoutElement> Layout<W> {
788798 workspaces.push(ws);
789799 }
790800
791- if i <= primary.active_workspace_idx
801+ if i <= source.active_workspace_idx
792802 // Generally when moving the currently active workspace, we want to
793803 // fall back to the workspace above, so as not to end up on the last
794804 // empty workspace. However, with empty workspace above first, when
@@ -799,27 +809,27 @@ impl<W: LayoutElement> Layout<W> {
799809 // workspaces set up across multiple monitors. Without this check, the
800810 // first monitor to connect can end up with the first empty workspace
801811 // focused instead of the first named workspace.
802- && !(primary.options.layout.empty_workspace_above_first
803- && primary.active_workspace_idx == 1)
812+ && !(source.options.layout.empty_workspace_above_first
813+ && source.active_workspace_idx == 1)
804814 {
805- primary.active_workspace_idx =
806- primary.active_workspace_idx.saturating_sub(1);
815+ source.active_workspace_idx =
816+ source.active_workspace_idx.saturating_sub(1);
807817 }
808818 }
809- }
810819
811- // If we stopped a workspace switch, then we might need to clean up workspaces.
812- // Also if empty_workspace_above_first is set and there are only 2 workspaces left,
813- // both will be empty and one of them needs to be removed. clean_up_workspaces
814- // takes care of this.
820+ let source = &mut monitors[source_idx];
815821
816- if stopped_primary_ws_switch
817- || (primary.options.layout.empty_workspace_above_first
818- && primary.workspaces.len() == 2)
819- {
820- primary.clean_up_workspaces();
822+ // If we stopped a workspace switch, then we might need to clean up workspaces.
823+ // Also if empty_workspace_above_first is set and there are only 2 workspaces
824+ // left, both will be empty and one of them needs to be removed.
825+ // clean_up_workspaces takes care of this.
826+ if stopped_ws_switch
827+ || (source.options.layout.empty_workspace_above_first
828+ && source.workspaces.len() == 2)
829+ {
830+ source.clean_up_workspaces();
831+ }
821832 }
822-
823833 workspaces.reverse();
824834
825835 let ws_id_to_activate = self.last_active_workspace_id.remove(&output.name());
@@ -907,8 +917,18 @@ impl<W: LayoutElement> Layout<W> {
907917 active_monitor_idx = active_monitor_idx.saturating_sub(1);
908918 }
909919
910- let primary = &mut monitors[primary_idx];
911- primary.append_workspaces(workspaces);
920+ for target_idx in 0..monitors.len() {
921+ let target_workspaces = workspaces
922+ .extract_if(.., |ws| {
923+ ws.find_preferred_output(
924+ monitors.iter().map(|monitor| &monitor.output),
925+ )
926+ .unwrap_or(primary_idx)
927+ == target_idx
928+ })
929+ .collect();
930+ monitors[target_idx].append_workspaces(target_workspaces);
931+ }
912932
913933 MonitorSet::Normal {
914934 monitors,
@@ -2538,34 +2558,22 @@ impl<W: LayoutElement> Layout<W> {
25382558
25392559 monitor.verify_invariants();
25402560
2541- if idx == primary_idx {
2542- for ws in &monitor.workspaces {
2543- if ws.original_output.matches(&monitor.output) {
2544- // This is the primary monitor's own workspace.
2545- continue;
2546- }
2547-
2548- let own_monitor_exists = monitors
2549- .iter()
2550- .any(|m| ws.original_output.matches(&m.output));
2551- assert!(
2552- !own_monitor_exists,
2553- "primary monitor cannot have workspaces for which their own monitor exists"
2561+ for workspace in &monitor.workspaces {
2562+ let preferred =
2563+ workspace.find_preferred_output(monitors.iter().map(|monitor| &monitor.output));
2564+ let Some(preferred_idx) = preferred else {
2565+ assert_eq!(
2566+ idx, primary_idx,
2567+ "workspace without a connected output candidate must be on the primary monitor"
25542568 );
2555- }
2556- } else {
2557- assert!(
2558- monitor
2559- .workspaces
2560- .iter()
2561- .any(|workspace| workspace.original_output.matches(&monitor.output)),
2562- "secondary monitor must not have any non-own workspaces"
2569+ continue;
2570+ };
2571+ assert_eq!(
2572+ idx, preferred_idx,
2573+ "workspace must be on its preferred connected output"
25632574 );
25642575 }
25652576
2566- // FIXME: verify that primary doesn't have any workspaces for which their own monitor
2567- // exists.
2568-
25692577 for workspace in &monitor.workspaces {
25702578 assert!(
25712579 seen_workspace_id.insert(workspace.id()),
@@ -2937,16 +2945,19 @@ impl<W: LayoutElement> Layout<W> {
29372945 primary_idx,
29382946 active_monitor_idx,
29392947 } => {
2940- let mon_idx = ws_config
2941- .open_on_output
2942- .as_deref()
2943- .map(|name| {
2944- monitors
2945- .iter_mut()
2946- .position(|monitor| output_matches_name(&monitor.output, name))
2947- .unwrap_or(*primary_idx)
2948- })
2949- .unwrap_or(*active_monitor_idx);
2948+ let mon_idx = if ws_config.open_on_output.is_empty() {
2949+ *active_monitor_idx
2950+ } else {
2951+ ws_config
2952+ .open_on_output
2953+ .iter()
2954+ .find_map(|name| {
2955+ monitors
2956+ .iter()
2957+ .position(|monitor| output_matches_name(&monitor.output, name))
2958+ })
2959+ .unwrap_or(*primary_idx)
2960+ };
29502961 let mon = &mut monitors[mon_idx];
29512962
29522963 let ws = Workspace::new_with_config(
@@ -3490,7 +3501,7 @@ impl<W: LayoutElement> Layout<W> {
34903501 // Do not do anything if the output is already correct
34913502 if current_idx == target_idx {
34923503 // Just update the original output since this is an explicit movement action.
3493- current.workspaces[old_idx].original_output = OutputId::new(&current.output);
3504+ current.workspaces[old_idx].original_outputs = vec![OutputId::new(&current.output)];
34943505
34953506 return false;
34963507 }
@@ -3501,7 +3512,7 @@ impl<W: LayoutElement> Layout<W> {
35013512 current_idx == *active_monitor_idx && old_idx == current.active_workspace_idx;
35023513
35033514 let mut ws = current.remove_workspace_by_idx(old_idx);
3504- ws.original_output = OutputId::new(new_output);
3515+ ws.original_outputs = vec![OutputId::new(new_output)];
35053516
35063517 let target = &mut monitors[target_idx];
35073518 target.insert_workspace(ws, target.active_workspace_idx + 1, activate);
src/layout/monitor.rsmodified+3 -3
@@ -557,7 +557,7 @@ impl<W: LayoutElement> Monitor<W> {
557557
558558 // After adding a new window, workspace becomes this output's own.
559559 if workspace.name().is_none() {
560- workspace.original_output = OutputId::new(&self.output);
560+ workspace.original_outputs = vec![OutputId::new(&self.output)];
561561 }
562562
563563 if workspace_idx == self.workspaces.len() - 1 {
@@ -602,7 +602,7 @@ impl<W: LayoutElement> Monitor<W> {
602602
603603 // After adding a new window, workspace becomes this output's own.
604604 if workspace.name().is_none() {
605- workspace.original_output = OutputId::new(&self.output);
605+ workspace.original_outputs = vec![OutputId::new(&self.output)];
606606 }
607607
608608 if workspace_idx == self.workspaces.len() - 1 {
@@ -636,7 +636,7 @@ impl<W: LayoutElement> Monitor<W> {
636636
637637 // After adding a new window, workspace becomes this output's own.
638638 if workspace.name().is_none() {
639- workspace.original_output = OutputId::new(&self.output);
639+ workspace.original_outputs = vec![OutputId::new(&self.output)];
640640 }
641641
642642 // Since we're adding window to an existing column, the workspace isn't empty, and
src/layout/tests.rsmodified+130 -11
@@ -426,8 +426,8 @@ enum Op {
426426 AddNamedWorkspace {
427427 #[proptest(strategy = "1..=5usize")]
428428 ws_name: usize,
429- #[proptest(strategy = "prop::option::of(1..=5usize)")]
430- output_name: Option<usize>,
429+ #[proptest(strategy = "proptest::collection::vec(1..=5usize, 0..=3)")]
430+ output_names: Vec<usize>,
431431 #[proptest(strategy = "prop::option::of(arbitrary_layout_part().prop_map(Box::new))")]
432432 layout_config: Option<Box<niri_config::LayoutPart>>,
433433 },
@@ -854,12 +854,15 @@ impl Op {
854854 }
855855 Op::AddNamedWorkspace {
856856 ws_name,
857- output_name,
857+ output_names,
858858 layout_config,
859859 } => {
860860 layout.ensure_named_workspace(&WorkspaceConfig {
861861 name: WorkspaceName(format!("ws{ws_name}")),
862- open_on_output: output_name.map(|name| format!("output{name}")),
862+ open_on_output: output_names
863+ .into_iter()
864+ .map(|name| format!("output{name}"))
865+ .collect(),
863866 layout: layout_config.map(|x| niri_config::WorkspaceLayoutPart(*x)),
864867 });
865868 }
@@ -1644,6 +1647,122 @@ fn check_ops(ops: impl IntoIterator<Item = Op>) -> Layout<TestWindow> {
16441647 layout
16451648 }
16461649
1650+fn workspace_output_name(layout: &Layout<TestWindow>, ws_name: usize) -> &str {
1651+ layout
1652+ .workspaces()
1653+ .find(|(_, _, workspace)| workspace.name() == Some(&format!("ws{ws_name}")))
1654+ .and_then(|(monitor, _, _)| monitor)
1655+ .unwrap()
1656+ .output_name()
1657+}
1658+
1659+#[test]
1660+fn workspace_output_fallback_promotes_preferred_in_reverse_connection_order() {
1661+ // output3 is not a candidate, so it stays the primary monitor throughout; every assertion
1662+ // below can only hold because of the candidate list.
1663+ let mut layout = Layout::default();
1664+ check_ops_on_layout(
1665+ &mut layout,
1666+ [
1667+ Op::AddOutput(3),
1668+ Op::AddNamedWorkspace {
1669+ ws_name: 1,
1670+ output_names: vec![1, 2],
1671+ layout_config: None,
1672+ },
1673+ ],
1674+ );
1675+ assert_eq!(workspace_output_name(&layout, 1), "output3");
1676+
1677+ // The second candidate connects first; the workspace must leave the primary monitor.
1678+ check_ops_on_layout(&mut layout, [Op::AddOutput(2)]);
1679+ assert_eq!(workspace_output_name(&layout, 1), "output2");
1680+
1681+ // The first candidate connects last; it still wins.
1682+ check_ops_on_layout(&mut layout, [Op::AddOutput(1)]);
1683+ assert_eq!(workspace_output_name(&layout, 1), "output1");
1684+}
1685+
1686+#[test]
1687+fn workspace_output_preferred_removal_uses_fallback() {
1688+ let mut layout = Layout::default();
1689+ check_ops_on_layout(
1690+ &mut layout,
1691+ [
1692+ Op::AddOutput(3),
1693+ Op::AddNamedWorkspace {
1694+ ws_name: 1,
1695+ output_names: vec![1, 2],
1696+ layout_config: None,
1697+ },
1698+ Op::AddOutput(1),
1699+ Op::AddOutput(2),
1700+ ],
1701+ );
1702+ assert_eq!(workspace_output_name(&layout, 1), "output1");
1703+
1704+ // The preferred candidate disconnects: the next candidate wins over the primary monitor.
1705+ check_ops_on_layout(&mut layout, [Op::RemoveOutput(1)]);
1706+ assert_eq!(workspace_output_name(&layout, 1), "output2");
1707+
1708+ // No candidate left: fall back to the primary monitor.
1709+ check_ops_on_layout(&mut layout, [Op::RemoveOutput(2)]);
1710+ assert_eq!(workspace_output_name(&layout, 1), "output3");
1711+}
1712+
1713+#[test]
1714+fn workspace_output_without_match_stays_on_default_output() {
1715+ let mut layout = Layout::default();
1716+ check_ops_on_layout(
1717+ &mut layout,
1718+ [
1719+ Op::AddOutput(3),
1720+ Op::AddNamedWorkspace {
1721+ ws_name: 1,
1722+ output_names: vec![1, 2],
1723+ layout_config: None,
1724+ },
1725+ ],
1726+ );
1727+ assert_eq!(workspace_output_name(&layout, 1), "output3");
1728+
1729+ // An output that is not in the candidate list must not take the workspace.
1730+ check_ops_on_layout(&mut layout, [Op::AddOutput(4)]);
1731+ assert_eq!(workspace_output_name(&layout, 1), "output3");
1732+}
1733+
1734+#[test]
1735+fn explicit_workspace_move_overrides_output_candidates() {
1736+ let mut layout = Layout::default();
1737+ check_ops_on_layout(
1738+ &mut layout,
1739+ [
1740+ Op::AddOutput(3),
1741+ Op::AddNamedWorkspace {
1742+ ws_name: 1,
1743+ output_names: vec![1, 2],
1744+ layout_config: None,
1745+ },
1746+ Op::AddOutput(2),
1747+ ],
1748+ );
1749+ assert_eq!(workspace_output_name(&layout, 1), "output2");
1750+
1751+ // After an explicit move, the candidate list no longer applies, even when the preferred
1752+ // candidate connects afterwards.
1753+ check_ops_on_layout(
1754+ &mut layout,
1755+ [
1756+ Op::MoveWorkspaceToMonitor {
1757+ ws_name: Some(1),
1758+ output_id: 3,
1759+ },
1760+ Op::AddOutput(1),
1761+ ],
1762+ );
1763+ assert_eq!(workspace_output_name(&layout, 1), "output3");
1764+}
1765+
16471766 #[track_caller]
16481767 fn check_ops_with_options(
16491768 options: Options,
@@ -1673,7 +1792,7 @@ fn operations_dont_panic() {
16731792 Op::FocusOutput(2),
16741793 Op::AddNamedWorkspace {
16751794 ws_name: 1,
1676- output_name: Some(1),
1795+ output_names: vec![1],
16771796 layout_config: None,
16781797 },
16791798 Op::UnnameWorkspace { ws_name: 1 },
@@ -1824,7 +1943,7 @@ fn operations_from_starting_state_dont_panic() {
18241943 Op::FocusOutput(2),
18251944 Op::AddNamedWorkspace {
18261945 ws_name: 1,
1827- output_name: Some(1),
1946+ output_names: vec![1],
18281947 layout_config: None,
18291948 },
18301949 Op::UnnameWorkspace { ws_name: 1 },
@@ -2363,12 +2482,12 @@ fn removing_all_outputs_preserves_empty_named_workspaces() {
23632482 Op::AddOutput(1),
23642483 Op::AddNamedWorkspace {
23652484 ws_name: 1,
2366- output_name: None,
2485+ output_names: vec![],
23672486 layout_config: None,
23682487 },
23692488 Op::AddNamedWorkspace {
23702489 ws_name: 2,
2371- output_name: None,
2490+ output_names: vec![],
23722491 layout_config: None,
23732492 },
23742493 Op::RemoveOutput(1),
@@ -2731,7 +2850,7 @@ fn named_workspace_to_output() {
27312850 let ops = [
27322851 Op::AddNamedWorkspace {
27332852 ws_name: 1,
2734- output_name: None,
2853+ output_names: vec![],
27352854 layout_config: None,
27362855 },
27372856 Op::AddOutput(1),
@@ -2747,7 +2866,7 @@ fn named_workspace_to_output_ewaf() {
27472866 let ops = [
27482867 Op::AddNamedWorkspace {
27492868 ws_name: 1,
2750- output_name: Some(2),
2869+ output_names: vec![2],
27512870 layout_config: None,
27522871 },
27532872 Op::AddOutput(1),
@@ -2981,7 +3100,7 @@ fn interactive_move_from_workspace_with_layout_config() {
29813100 let ops = [
29823101 Op::AddNamedWorkspace {
29833102 ws_name: 1,
2984- output_name: Some(2),
3103+ output_names: vec![2],
29853104 layout_config: Some(Box::new(niri_config::LayoutPart {
29863105 border: Some(niri_config::BorderRule {
29873106 on: true,
src/layout/workspace.rsmodified+47 -19
@@ -54,11 +54,11 @@ pub struct Workspace<W: LayoutElement> {
5454 /// Whether the floating layout is active instead of the scrolling layout.
5555 floating_is_active: FloatingActive,
5656
57- /// The original output of this workspace.
57+ /// The original outputs of this workspace, in preference order.
5858 ///
5959 /// Most of the time this will be the workspace's current output, however, after an output
60- /// disconnection, it may remain pointing to the disconnected output.
61- pub(super) original_output: OutputId,
60+ /// disconnection, they may remain pointing to disconnected outputs.
61+ pub(super) original_outputs: Vec<OutputId>,
6262
6363 /// Current output of this workspace.
6464 output: Option<Output>,
@@ -114,7 +114,7 @@ pub struct Workspace<W: LayoutElement> {
114114 id: WorkspaceId,
115115 }
116116
117-#[derive(Debug, Clone)]
117+#[derive(Debug, Clone, PartialEq, Eq)]
118118 pub struct OutputId(String);
119119
120120 impl OutputId {
@@ -217,11 +217,15 @@ impl<W: LayoutElement> Workspace<W> {
217217 clock: Clock,
218218 base_options: Rc<Options>,
219219 ) -> Self {
220- let original_output = config
220+ let mut original_outputs: Vec<OutputId> = config
221221 .as_ref()
222- .and_then(|c| c.open_on_output.clone())
223- .map(OutputId)
224- .unwrap_or(OutputId::new(&output));
222+ .map(|c| c.open_on_output.iter().cloned().map(OutputId).collect())
223+ .unwrap_or_default();
224+ if original_outputs.is_empty() {
225+ original_outputs.push(OutputId::new(&output));
226+ } else {
227+ Self::normalize_original_outputs(&mut original_outputs, &output);
228+ }
225229
226230 let layout_config = config.as_mut().and_then(|c| c.layout.take().map(|x| x.0));
227231
@@ -258,7 +262,7 @@ impl<W: LayoutElement> Workspace<W> {
258262 scrolling,
259263 floating,
260264 floating_is_active: FloatingActive::No,
261- original_output,
265+ original_outputs,
262266 scale,
263267 transform: output.current_transform(),
264268 view_size,
@@ -280,12 +284,10 @@ impl<W: LayoutElement> Workspace<W> {
280284 clock: Clock,
281285 base_options: Rc<Options>,
282286 ) -> Self {
283- let original_output = OutputId(
284- config
285- .as_ref()
286- .and_then(|c| c.open_on_output.clone())
287- .unwrap_or_default(),
288- );
287+ let original_outputs = config
288+ .as_ref()
289+ .map(|c| c.open_on_output.iter().cloned().map(OutputId).collect())
290+ .unwrap_or_default();
289291
290292 let layout_config = config.as_mut().and_then(|c| c.layout.take().map(|x| x.0));
291293
@@ -325,7 +327,7 @@ impl<W: LayoutElement> Workspace<W> {
325327 output: None,
326328 scale,
327329 transform: Transform::Normal,
328- original_output,
330+ original_outputs,
329331 view_size,
330332 working_area,
331333 shadow: Shadow::new(shadow_config),
@@ -474,6 +476,15 @@ impl<W: LayoutElement> Workspace<W> {
474476 self.output.as_ref()
475477 }
476478
479+ pub(super) fn find_preferred_output<'a>(
480+ &self,
481+ outputs: impl Iterator<Item = &'a Output> + Clone,
482+ ) -> Option<usize> {
483+ self.original_outputs
484+ .iter()
485+ .find_map(|id| outputs.clone().position(|output| id.matches(output)))
486+ }
487+
477488 pub fn active_window(&self) -> Option<&W> {
478489 if self.floating_is_active.get() {
479490 self.floating.active_window()
@@ -508,9 +519,11 @@ impl<W: LayoutElement> Workspace<W> {
508519 self.output = output;
509520
510521 if let Some(output) = &self.output {
511- // Normalize original output: possibly replace connector with make/model/serial.
512- if self.original_output.matches(output) {
513- self.original_output = OutputId::new(output);
522+ if self.original_outputs.is_empty() {
523+ self.original_outputs.push(OutputId::new(output));
524+ } else {
525+ // Normalize original outputs: possibly replace connectors with make/model/serial.
526+ Self::normalize_original_outputs(&mut self.original_outputs, output);
514527 }
515528
516529 self.update_output_size();
@@ -521,6 +534,21 @@ impl<W: LayoutElement> Workspace<W> {
521534 }
522535 }
523536
537+ fn normalize_original_outputs(outputs: &mut Vec<OutputId>, output: &Output) {
538+ for id in &mut *outputs {
539+ if id.matches(output) {
540+ *id = OutputId::new(output);
541+ }
542+ }
543+
544+ // Connector and make/model/serial candidates may resolve to the same output.
545+ for idx in (0..outputs.len()).rev() {
546+ if outputs[..idx].contains(&outputs[idx]) {
547+ outputs.remove(idx);
548+ }
549+ }
550+ }
551+
524552 fn enter_output_for_window(&self, window: &W) {
525553 if let Some(output) = &self.output {
526554 window.set_preferred_scale_transform(self.scale, self.transform);