From 69543c0cfa496bccf9e263430a48be945883e5e8 Mon Sep 17 00:00:00 2001 From: Poly Date: Thu, 17 Jun 2021 22:41:53 +0200 Subject: [PATCH] Fix Anvil panic when resizing dead window --- anvil/src/shell.rs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/anvil/src/shell.rs b/anvil/src/shell.rs index d94488d..3899537 100644 --- a/anvil/src/shell.rs +++ b/anvil/src/shell.rs @@ -162,12 +162,18 @@ struct ResizeSurfaceGrab { impl PointerGrab for ResizeSurfaceGrab { fn motion( &mut self, - _handle: &mut PointerInnerHandle<'_>, + handle: &mut PointerInnerHandle<'_>, location: (f64, f64), _focus: Option<(wl_surface::WlSurface, (f64, f64))>, - _serial: Serial, - _time: u32, + serial: Serial, + 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 dy = location.1 - self.start_data.location.1; @@ -254,6 +260,11 @@ impl PointerGrab for ResizeSurfaceGrab { // No more buttons are pressed, release the grab. 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 xdg .with_pending_state(|state| {