From 64482e7e71991b397cc4f3f80a3c422e7c0ad9ef Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Tue, 26 Nov 2024 22:12:10 +0800 Subject: [PATCH] linux: Fix raw_window_handle method for X11 and Wayland. --- Cargo.lock | 1 + crates/gpui/Cargo.toml | 3 +++ crates/gpui/examples/webview.rs | 5 +++++ crates/gpui/src/platform/linux/wayland/window.rs | 5 ++++- crates/gpui/src/platform/linux/x11/window.rs | 3 ++- 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e334f0ee8a7e10..95dac5bb970ff8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5502,6 +5502,7 @@ dependencies = [ "foreign-types 0.5.0", "futures 0.3.31", "gpui_macros", + "gtk", "http_client", "image", "itertools 0.13.0", diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index b469a37f042dc4..ecf1ab14f23adc 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -119,6 +119,9 @@ http_client = { workspace = true, features = ["test-support"] } unicode-segmentation.workspace = true wry = "0.41.0" +[target.'cfg(target_os = "linux")'.dev-dependencies] +gtk = "0.18.0" + [build-dependencies] embed-resource = "2.4" diff --git a/crates/gpui/examples/webview.rs b/crates/gpui/examples/webview.rs index 5cc687ee12e51a..1c988cd0a55d79 100644 --- a/crates/gpui/examples/webview.rs +++ b/crates/gpui/examples/webview.rs @@ -35,6 +35,11 @@ impl Render for WebViewWindow { } fn main() { + #[cfg(target_os = "linux")] + { + gtk::init().unwrap(); + } + App::new().run(|cx: &mut AppContext| { let bounds = Bounds::centered(None, size(px(1200.0), px(800.0)), cx); let window = cx diff --git a/crates/gpui/src/platform/linux/wayland/window.rs b/crates/gpui/src/platform/linux/wayland/window.rs index 55ba4f6004d393..8611ddaff54d32 100644 --- a/crates/gpui/src/platform/linux/wayland/window.rs +++ b/crates/gpui/src/platform/linux/wayland/window.rs @@ -751,7 +751,10 @@ fn primary_output_scale(state: &mut RefMut) -> i32 { impl rwh::HasWindowHandle for WaylandWindow { fn window_handle(&self) -> Result, rwh::HandleError> { - unimplemented!() + let state = self.borrow(); + let window = NonNull::new(state.surface.id().as_ptr().cast::()).unwrap(); + let handle = rwh::WaylandWindowHandle::new(window); + Ok(unsafe { rwh::WindowHandle::borrow_raw(handle.into()) }) } } impl rwh::HasDisplayHandle for WaylandWindow { diff --git a/crates/gpui/src/platform/linux/x11/window.rs b/crates/gpui/src/platform/linux/x11/window.rs index ae9abe714691f8..c24f7648620157 100644 --- a/crates/gpui/src/platform/linux/x11/window.rs +++ b/crates/gpui/src/platform/linux/x11/window.rs @@ -306,7 +306,8 @@ impl rwh::HasDisplayHandle for RawWindow { impl rwh::HasWindowHandle for X11Window { fn window_handle(&self) -> Result { - unimplemented!() + let mut handle = rwh::XlibWindowHandle::new(self.0.x_window as u64); + Ok(unsafe { rwh::WindowHandle::borrow_raw(handle.into()) }) } } impl rwh::HasDisplayHandle for X11Window {