Skip to content

Commit

Permalink
linux: Fix raw_window_handle method for X11 and Wayland.
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Oct 21, 2024
1 parent d048d70 commit 93adafb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/gpui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 5 additions & 0 deletions crates/gpui/examples/webview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion crates/gpui/src/platform/linux/wayland/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,10 @@ fn primary_output_scale(state: &mut RefMut<WaylandWindowState>) -> i32 {

impl rwh::HasWindowHandle for WaylandWindow {
fn window_handle(&self) -> Result<rwh::WindowHandle<'_>, rwh::HandleError> {
unimplemented!()
let state = self.borrow();
let window = NonNull::new(state.surface.id().as_ptr().cast::<c_void>()).unwrap();
let handle = rwh::WaylandWindowHandle::new(window);
Ok(unsafe { rwh::WindowHandle::borrow_raw(handle.into()) })
}
}
impl rwh::HasDisplayHandle for WaylandWindow {
Expand Down
3 changes: 2 additions & 1 deletion crates/gpui/src/platform/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,8 @@ impl rwh::HasDisplayHandle for RawWindow {

impl rwh::HasWindowHandle for X11Window {
fn window_handle(&self) -> Result<rwh::WindowHandle, rwh::HandleError> {
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 {
Expand Down

0 comments on commit 93adafb

Please sign in to comment.