Fix Anvil panic when resizing dead window

This commit is contained in:
Poly 2021-06-17 22:41:53 +02:00 committed by Victor Berger
parent f9f77288c8
commit 69543c0cfa
1 changed files with 14 additions and 3 deletions

View File

@ -162,12 +162,18 @@ struct ResizeSurfaceGrab {
impl PointerGrab for ResizeSurfaceGrab { impl PointerGrab for ResizeSurfaceGrab {
fn motion( fn motion(
&mut self, &mut self,
_handle: &mut PointerInnerHandle<'_>, handle: &mut PointerInnerHandle<'_>,
location: (f64, f64), location: (f64, f64),
_focus: Option<(wl_surface::WlSurface, (f64, f64))>, _focus: Option<(wl_surface::WlSurface, (f64, f64))>,
_serial: Serial, serial: Serial,
_time: u32, time: u32,
) { ) {
// It is impossible to get `min_size` and `max_size` of dead toplevel, so we return early.
if !self.toplevel.alive() | self.toplevel.get_surface().is_none() {
handle.unset_grab(serial, time);
return;
}
let mut dx = location.0 - self.start_data.location.0; let mut dx = location.0 - self.start_data.location.0;
let mut dy = location.1 - self.start_data.location.1; let mut dy = location.1 - self.start_data.location.1;
@ -254,6 +260,11 @@ impl PointerGrab for ResizeSurfaceGrab {
// No more buttons are pressed, release the grab. // No more buttons are pressed, release the grab.
handle.unset_grab(serial, time); handle.unset_grab(serial, time);
// If toplevel is dead, we can't resize it, so we return early.
if !self.toplevel.alive() | self.toplevel.get_surface().is_none() {
return;
}
if let SurfaceKind::Xdg(xdg) = &self.toplevel { if let SurfaceKind::Xdg(xdg) = &self.toplevel {
if xdg if xdg
.with_pending_state(|state| { .with_pending_state(|state| {