Skip to content

Commit 5ae293f

Browse files
committed
Update to raw-window-handle 0.6
There has been a breaking API change in raw-window-handle. The traits HasRawDisplayHandle and HasRawWindowHandle have been deprecated in favor of the new HasDisplayHandle and HasWindowHandle traits. Instead of a raw handle, a handle containing a lifetime is handed out via these traits. Internally, we still use the raw API and convert to the new handles. Signed-off-by: Uli Schlachter <psychon@znc.in>
1 parent 1fd59d2 commit 5ae293f

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

x11rb/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ x11rb-protocol = { version = "0.13.2", default-features = false, features = ["st
2222
libc = { version = "0.2", optional = true }
2323
libloading = { version = "0.8.0", optional = true }
2424
once_cell = { version = "1.19", optional = true }
25-
raw-window-handle = { version = "0.5.0", optional = true }
25+
raw-window-handle = { version = "0.6.0", optional = true }
2626
as-raw-xcb-connection = { version = "1.0", optional = true }
2727
tracing = { version = "0.1", optional = true, default-features = false }
2828
rustix = { version = "1.0", default-features = false, features = ["std", "event", "fs", "net", "system"] }

x11rb/src/xcb_ffi/mod.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ use std::sync::{atomic::Ordering, Mutex};
1212

1313
use libc::c_void;
1414

15+
#[cfg(feature = "raw-window-handle")]
16+
use raw_window_handle::{
17+
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, WindowHandle, XcbDisplayHandle,
18+
XcbWindowHandle,
19+
};
20+
1521
use crate::connection::{
1622
compute_length_field, Connection, ReplyOrError, RequestConnection, RequestKind,
1723
};
@@ -634,26 +640,26 @@ impl AsFd for XCBConnection {
634640
}
635641

636642
#[cfg(feature = "raw-window-handle")]
637-
unsafe impl raw_window_handle::HasRawDisplayHandle for XCBConnection {
643+
impl HasDisplayHandle for XCBConnection {
638644
#[inline]
639-
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
640-
let mut handle = raw_window_handle::XcbDisplayHandle::empty();
641-
handle.connection = self.get_raw_xcb_connection();
645+
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
646+
// We do not have/know a screen, but people want this trait implemented anyway. We guess.
647+
let screen = 0;
648+
let connection = std::ptr::NonNull::new(self.get_raw_xcb_connection());
649+
let handle = XcbDisplayHandle::new(connection, screen);
642650

643-
raw_window_handle::RawDisplayHandle::Xcb(handle)
651+
unsafe { Ok(DisplayHandle::borrow_raw(handle.into())) }
644652
}
645653
}
646654

647655
#[cfg(feature = "raw-window-handle")]
648-
unsafe impl raw_window_handle::HasRawWindowHandle
649-
for crate::protocol::xproto::WindowWrapper<XCBConnection>
650-
{
656+
impl HasWindowHandle for crate::protocol::xproto::WindowWrapper<XCBConnection> {
651657
#[inline]
652-
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
653-
let mut handle = raw_window_handle::XcbWindowHandle::empty();
654-
handle.window = self.window();
658+
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
659+
let window = std::num::NonZeroU32::new(self.window()).ok_or(HandleError::NotSupported)?;
660+
let handle = XcbWindowHandle::new(window);
655661

656-
raw_window_handle::RawWindowHandle::Xcb(handle)
662+
unsafe { Ok(WindowHandle::borrow_raw(handle.into())) }
657663
}
658664
}
659665

0 commit comments

Comments
 (0)