config: sort outputs by connector for deterministic fallback layout

When no saved configuration matches the current output set, positions
were assigned in hotplug/registration order. On hotplug races (e.g.
reconnecting monitors through a KVM switch) outputs can appear in
arbitrary order, producing a swapped left/right layout that then gets
persisted to outputs.ron, poisoning all future reconnects.

Sort outputs by connector name before generating fallback positions so
the layout is deterministic regardless of arrival order.

AI disclosure: implemented with the assistance of an LLM coding agent,
directed, reviewed, and tested by the author.

Signed-off-by: apassert <249084898+apassert@users.noreply.github.com>
This commit is contained in:
apassert 2026-09-02 21:09:51 +02:00 • committed by Victoria Brekenfeld
parent 7d1daab7bc
commit a55785993e

View file

@ -541,7 +541,13 @@ impl Config {
primary.config_mut().xwayland_primary = true;
}
}
for output in outputs.iter().filter(|o| o.mirroring().is_none()) {
// sort by connector name for a deterministic layout independent of hotplug order
let mut sorted_outputs = outputs
.iter()
.filter(|o| o.mirroring().is_none())
.collect::<Vec<_>>();
sorted_outputs.sort_by_key(|o| o.name());
for output in sorted_outputs {
{
let mut config = output.config_mut();
config.position = (w, 0);