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,8 +701,7 @@ 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();
for (_, output_scale) in outputs {
@ -721,6 +720,7 @@ impl<C: XConnection> ServerState<C> {
debug!("Using new scale {scale}");
self.new_scale = Some(scale);
}
}
{
if let Some(FocusData {

View file

@ -1773,6 +1773,17 @@ fn output_offset_remove_output() {
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]
fn output_offset_surface_positioning() {
let (mut f, comp) = TestFixture::new_with_compositor();