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 scale;
let mut outputs = self.world.query_mut::<&OutputScaleFactor>().into_iter(); 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 {
for (_, output_scale) in outputs { mixed_scale = true;
if output_scale.get() != scale { scale = scale.min(output_scale.get());
mixed_scale = true; }
scale = scale.min(output_scale.get());
} }
}
if mixed_scale { if mixed_scale {
warn!( warn!(
"Mixed output scales detected, choosing to give apps the smallest detected scale ({scale}x)" "Mixed output scales detected, choosing to give apps the smallest detected scale ({scale}x)"
); );
} }
debug!("Using new scale {scale}"); debug!("Using new scale {scale}");
self.new_scale = Some(scale); self.new_scale = Some(scale);
}
} }
{ {

View file

@ -1773,6 +1773,17 @@ fn output_offset_remove_output() {
check_output_position_event(&output_main_c, (0, 0)); check_output_position_event(&output_main_c, (0, 0));
} }
#[test]
fn remove_all_outputs() {
let (mut f, _) = TestFixture::new_with_compositor();
let (_, output) = f.new_output(0, 0);
f.run();
f.remove_output(output);
f.run();
}
#[test] #[test]
fn output_offset_surface_positioning() { fn output_offset_surface_positioning() {
let (mut f, comp) = TestFixture::new_with_compositor(); let (mut f, comp) = TestFixture::new_with_compositor();