diff --git a/window/src/os/wayland/connection.rs b/window/src/os/wayland/connection.rs index 4a823c9a6..d357b3fea 100644 --- a/window/src/os/wayland/connection.rs +++ b/window/src/os/wayland/connection.rs @@ -223,6 +223,7 @@ impl ConnectionOps for Connection { } } } + self.windows.borrow_mut().clear(); Ok(()) } diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index 221e9395f..d1b4e9aab 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -217,7 +217,7 @@ pub struct WindowInner { callbacks: Box, surface: WlSurface, seat: WlSeat, - window: toolkit::window::Window, + window: Option>, pool: MemPool, dimensions: (u32, u32), need_paint: bool, @@ -334,7 +334,7 @@ impl Window { callbacks, surface, seat, - window, + window: Some(window), pool, dimensions, need_paint: true, @@ -472,17 +472,21 @@ impl WindowInner { match evt { Event::Close => { if self.callbacks.can_close() { - println!("FIXME: I should destroy all refs to the window now"); + self.callbacks.destroy(); + self.window.take(); } } Event::Refresh => { self.do_paint().unwrap(); } Event::Configure { new_size, .. } => { + if self.window.is_none() { + return; + } if let Some((w, h)) = new_size { let factor = toolkit::surface::get_dpi_factor(&self.surface); self.surface.set_buffer_scale(factor); - self.window.resize(w, h); + self.window.as_mut().unwrap().resize(w, h); let w = w * factor as u32; let h = h * factor as u32; self.dimensions = (w, h); @@ -492,7 +496,7 @@ impl WindowInner { dpi: 96 * factor as usize, }); } - self.window.refresh(); + self.window.as_mut().unwrap().refresh(); self.do_paint().unwrap(); } } @@ -504,6 +508,11 @@ impl WindowInner { return Ok(()); } + if self.window.is_none() { + // Window has been closed; complete gracefully + return Ok(()); + } + self.pool .resize((4 * self.dimensions.0 * self.dimensions.1) as usize)?; @@ -526,7 +535,7 @@ impl WindowInner { self.damage(); self.surface.commit(); - self.window.refresh(); + self.window.as_mut().unwrap().refresh(); self.need_paint = false; Ok(()) @@ -728,15 +737,21 @@ impl WindowOps for Window { } impl WindowOpsMut for WindowInner { - fn close(&mut self) {} + fn close(&mut self) { + self.callbacks.destroy(); + self.window.take(); + } fn hide(&mut self) {} fn show(&mut self) { + if self.window.is_none() { + return; + } let conn = Connection::get().unwrap(); if !conn.environment.borrow().shell.needs_configure() { self.do_paint().unwrap(); } else { - self.window.refresh(); + self.window.as_mut().unwrap().refresh(); } } @@ -753,6 +768,8 @@ impl WindowOpsMut for WindowInner { /// Change the title for the window manager fn set_title(&mut self, title: &str) { - self.window.set_title(title.to_string()); + if let Some(window) = self.window.as_ref() { + window.set_title(title.to_string()); + } } }