Skip to content

Commit e42687e

Browse files
authored
Implement HasRawWindowHandle for X11 (#1667)
1 parent a281a81 commit e42687e

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

druid-shell/src/platform/x11/window.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use x11rb::wrapper::ConnectionExt as _;
3939
use x11rb::xcb_ffi::XCBConnection;
4040

4141
#[cfg(feature = "raw-win-handle")]
42-
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
42+
use raw_window_handle::{unix::XcbHandle, HasRawWindowHandle, RawWindowHandle};
4343

4444
use crate::common_util::IdleCallback;
4545
use crate::dialog::FileDialogOptions;
@@ -1589,7 +1589,19 @@ impl WindowHandle {
15891589
#[cfg(feature = "raw-win-handle")]
15901590
unsafe impl HasRawWindowHandle for WindowHandle {
15911591
fn raw_window_handle(&self) -> RawWindowHandle {
1592-
error!("HasRawWindowHandle trait not implemented for x11.");
1593-
RawWindowHandle::Xcb(XcbHandle::empty())
1592+
let mut handle = XcbHandle {
1593+
window: self.id,
1594+
..XcbHandle::empty()
1595+
};
1596+
1597+
if let Some(window) = self.window.upgrade() {
1598+
handle.connection = window.app.connection().get_raw_xcb_connection();
1599+
} else {
1600+
// Documentation for HasRawWindowHandle encourages filling in all fields possible,
1601+
// leaving those empty that cannot be derived.
1602+
error!("Failed to get XCBConnection, returning incomplete handle");
1603+
}
1604+
1605+
RawWindowHandle::Xcb(handle)
15941606
}
15951607
}

0 commit comments

Comments
 (0)