From 608185be4e0cc32ad925074185b5821af8aa2da9 Mon Sep 17 00:00:00 2001 From: Gary Tierney Date: Thu, 5 Mar 2026 01:40:07 +0000 Subject: [PATCH] fix: Implement raw-window-handle traits for X11Window (#50768) I'm embedding a 3D viewport inside GPUI by creating a child window with its own surface that fits the bounds of a GPUI element, and I need access to the raw window handle of the current window to manage it. Right now on X11 this is stubbed as unimplemented and results in a panic. I've copied most of the same implementation from the associated `RawWindow` into `X11Window`. Small clip of a Bevy app embedded inside GPUI with a popover that draws above the 3d surface to show testing was done: [Screencast_20260304_182657.webm](https://github.com/user-attachments/assets/829f9197-1613-41a7-af83-d377f3154751) Before you mark this PR as ready for review, make sure that you have: - [x] Added a solid test coverage and/or screenshots from doing manual testing - [ ] Done a self-review taking into account security and performance aspects - [ ] Aligned any UI changes with the [UI checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) Release Notes: - Added implementations of `rwh::HasDisplayHandle` and `rwh::HasWindowHandle` for `X11Window` --- crates/gpui_linux/src/linux/x11/window.rs | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/crates/gpui_linux/src/linux/x11/window.rs b/crates/gpui_linux/src/linux/x11/window.rs index f2199ac65e425a8daa04755115264231dd869837..a7cdc67ecd908becd22f799767f482754527fa51 100644 --- a/crates/gpui_linux/src/linux/x11/window.rs +++ b/crates/gpui_linux/src/linux/x11/window.rs @@ -319,12 +319,28 @@ impl rwh::HasDisplayHandle for RawWindow { impl rwh::HasWindowHandle for X11Window { fn window_handle(&self) -> Result, rwh::HandleError> { - unimplemented!() + let Some(non_zero) = NonZeroU32::new(self.0.x_window) else { + return Err(rwh::HandleError::Unavailable); + }; + let handle = rwh::XcbWindowHandle::new(non_zero); + Ok(unsafe { rwh::WindowHandle::borrow_raw(handle.into()) }) } } + impl rwh::HasDisplayHandle for X11Window { fn display_handle(&self) -> Result, rwh::HandleError> { - unimplemented!() + let connection = + as_raw_xcb_connection::AsRawXcbConnection::as_raw_xcb_connection(&*self.0.xcb) + as *mut _; + let Some(non_zero) = NonNull::new(connection) else { + return Err(rwh::HandleError::Unavailable); + }; + let screen_id = { + let state = self.0.state.borrow(); + u32::from(state.display.id()) as i32 + }; + let handle = rwh::XcbDisplayHandle::new(Some(non_zero), screen_id); + Ok(unsafe { rwh::DisplayHandle::borrow_raw(handle.into()) }) } }