Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
linux/x11: Do panic when unmapping/destroying of X11 window fails (#13262)
Thorsten Ball8524e8731940
diff --git a/crates/gpui/src/platform/linux/x11/window.rs b/crates/gpui/src/platform/linux/x11/window.rsindex 5e48faaad11..c7c8cf07083 100644--- a/crates/gpui/src/platform/linux/x11/window.rs+++ b/crates/gpui/src/platform/linux/x11/window.rs@@ -1,3 +1,5 @@+use anyhow::Context;+use crate::{platform::blade::{BladeRenderer, BladeSurfaceConfig},px, size, AnyWindowHandle, Bounds, DevicePixels, ForegroundExecutor, Modifiers, Pixels,@@ -8,7 +10,7 @@ use crate::{use blade_graphics as gpu;use raw_window_handle as rwh;-use util::ResultExt;+use util::{maybe, ResultExt};use x11rb::{connection::Connection,protocol::{@@ -422,26 +424,32 @@ impl Drop for X11Window {let mut state = self.0.state.borrow_mut();state.renderer.destroy();- self.0.xcb_connection.unmap_window(self.0.x_window).unwrap();- self.0- .xcb_connection- .destroy_window(self.0.x_window)- .unwrap();- self.0.xcb_connection.flush().unwrap();+ let destroy_x_window = maybe!({+ self.0.xcb_connection.unmap_window(self.0.x_window)?;+ self.0.xcb_connection.destroy_window(self.0.x_window)?;+ self.0.xcb_connection.flush()?;- // Mark window as destroyed so that we can filter out when X11 events- // for it still come in.- state.destroyed = true;+ anyhow::Ok(())+ })+ .context("unmapping and destroying X11 window")+ .log_err();++ if destroy_x_window.is_some() {+ // Mark window as destroyed so that we can filter out when X11 events+ // for it still come in.+ state.destroyed = true;++ let this_ptr = self.0.clone();+ let client_ptr = state.client.clone();+ state+ .executor+ .spawn(async move {+ this_ptr.close();+ client_ptr.drop_window(this_ptr.x_window);+ })+ .detach();+ }- let this_ptr = self.0.clone();- let client_ptr = state.client.clone();- state- .executor- .spawn(async move {- this_ptr.close();- client_ptr.drop_window(this_ptr.x_window);- })- .detach();drop(state);}}