Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x11rb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ x11rb-protocol = { version = "0.13.2", default-features = false, features = ["st
libc = { version = "0.2", optional = true }
libloading = { version = "0.8.0", optional = true }
once_cell = { version = "1.19", optional = true }
raw-window-handle = { version = "0.5.0", optional = true }
raw-window-handle = { version = "0.6.0", optional = true }
as-raw-xcb-connection = { version = "1.0", optional = true }
tracing = { version = "0.1", optional = true, default-features = false }
rustix = { version = "1.0", default-features = false, features = ["std", "event", "fs", "net", "system"] }
Expand Down
30 changes: 18 additions & 12 deletions x11rb/src/xcb_ffi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use std::sync::{atomic::Ordering, Mutex};

use libc::c_void;

#[cfg(feature = "raw-window-handle")]
use raw_window_handle::{
DisplayHandle, HandleError, HasDisplayHandle, HasWindowHandle, WindowHandle, XcbDisplayHandle,
XcbWindowHandle,
};

use crate::connection::{
compute_length_field, Connection, ReplyOrError, RequestConnection, RequestKind,
};
Expand Down Expand Up @@ -634,26 +640,26 @@ impl AsFd for XCBConnection {
}

#[cfg(feature = "raw-window-handle")]
unsafe impl raw_window_handle::HasRawDisplayHandle for XCBConnection {
impl HasDisplayHandle for XCBConnection {
#[inline]
fn raw_display_handle(&self) -> raw_window_handle::RawDisplayHandle {
let mut handle = raw_window_handle::XcbDisplayHandle::empty();
handle.connection = self.get_raw_xcb_connection();
fn display_handle(&self) -> Result<DisplayHandle<'_>, HandleError> {
// We do not have/know a screen, but people want this trait implemented anyway. We guess.
let screen = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how correct how correct this is. I believe we should have something like:

struct XCBConnectionAndScreen<T: AsRef<XCBConnection>> {
    connection: T,
    screen: usize,
}


impl<T: AsRef<XCBConnection>> HasDisplayHandle for XCBConnectionAndScreen<T> {
    ...
}

Copy link
Owner Author

@psychon psychon Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I do not know that either. But for this PR: It is as correct as the old implementation. Previously, the screen = 0 was just hidden in a call to XcbDisplayHandle::empty(): https://docs.rs/raw-window-handle/0.5.2/src/raw_window_handle/unix.rs.html#191-196

Edit:

I believe we should have something like:

If you want, I can add a struct like that, but I would do that separately and not together with the version bump.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In #772 (comment) a similar question was answered with:

The raw-window-handle spec says that it is up to the consumer of the handle to fill these fields in if they need them.

I'm not quite sure what this refers to... 🤷

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I do not know that either. But for this PR: It is as correct as the old implementation. Previously, the screen = 0 was just hidden in a call to XcbDisplayHandle::empty(): https://docs.rs/raw-window-handle/0.5.2/src/raw_window_handle/unix.rs.html#191-196

Then I guess we can leave this as-is

let connection = std::ptr::NonNull::new(self.get_raw_xcb_connection());
let handle = XcbDisplayHandle::new(connection, screen);

raw_window_handle::RawDisplayHandle::Xcb(handle)
unsafe { Ok(DisplayHandle::borrow_raw(handle.into())) }
}
}

#[cfg(feature = "raw-window-handle")]
unsafe impl raw_window_handle::HasRawWindowHandle
for crate::protocol::xproto::WindowWrapper<XCBConnection>
{
impl HasWindowHandle for crate::protocol::xproto::WindowWrapper<XCBConnection> {
#[inline]
fn raw_window_handle(&self) -> raw_window_handle::RawWindowHandle {
let mut handle = raw_window_handle::XcbWindowHandle::empty();
handle.window = self.window();
fn window_handle(&self) -> Result<WindowHandle<'_>, HandleError> {
let window = std::num::NonZeroU32::new(self.window()).ok_or(HandleError::NotSupported)?;
let handle = XcbWindowHandle::new(window);

raw_window_handle::RawWindowHandle::Xcb(handle)
unsafe { Ok(WindowHandle::borrow_raw(handle.into())) }
}
}

Expand Down