anvil: Fix crash in `maximize_request`
It's possible that a surface wants to be maximized before the window has actually been mapped yet, and therefore `outputs_for_window` returns an empty `Vec`. In that case, it's fine to use the first output available, instead.
@@ -664,7 +664,14 @@ impl<BackendData: Backend> XdgShellHandler for AnvilState<BackendData> {
.window_for_surface(surface.wl_surface(), WindowSurfaceType::TOPLEVEL)
.unwrap()
.clone();
- let output = &self.space.outputs_for_window(&window)[0];
+ let output = self.space.outputs_for_window(&window).into_iter().next();
+ let mut output = output.as_ref();
+ if output.is_none() {
+ // The window hasn't been mapped yet, use the primary output instead
+ output = self.space.outputs().next();
+ }
+ // Assumes that at least one output exists
+ let output = output.unwrap();
let geometry = self.space.output_geometry(output).unwrap();
self.space.map_window(&window, geometry.loc, None, true);
