fix: avoid panic when no outputs are present

Replace `unwrap()` on the output scale query with conditional handling.
This prevents a panic when the last output is removed and the query
temporarily returns no results + add test to cover removing all outputs.
This commit is contained in:
awsms 2026-02-26 19:20:40 +01:00 committed by Supreeeme
parent ecde06ed3a
commit 10f985b84c
2 changed files with 26 additions and 15 deletions

View file

@ -701,25 +701,25 @@ impl<C: XConnection> ServerState<C> {
let mut scale;
let mut outputs = self.world.query_mut::<&OutputScaleFactor>().into_iter();
let (_, output_scale) = outputs.next().unwrap();
if let Some((_, output_scale)) = outputs.next() {
scale = output_scale.get();
scale = output_scale.get();
for (_, output_scale) in outputs {
if output_scale.get() != scale {
mixed_scale = true;
scale = scale.min(output_scale.get());
for (_, output_scale) in outputs {
if output_scale.get() != scale {
mixed_scale = true;
scale = scale.min(output_scale.get());
}
}
}
if mixed_scale {
warn!(
"Mixed output scales detected, choosing to give apps the smallest detected scale ({scale}x)"
);
}
if mixed_scale {
warn!(
"Mixed output scales detected, choosing to give apps the smallest detected scale ({scale}x)"
);
}
debug!("Using new scale {scale}");
self.new_scale = Some(scale);
debug!("Using new scale {scale}");
self.new_scale = Some(scale);
}
}
{