feat: Enable creating an X11 display without connection

For pure-Rust connections, there is no XCB connection that can be passed into
the display constructor. Thus, this PR enables the display to be created without
needing an XCB or Xlib handle, by providing `None` in the constructor.

cc rust-windowing/raw-window-handle#120

Signed-off-by: John Nunley <dev@notgull.net>
This commit is contained in:
John Nunley 2023-11-01 22:26:10 -07:00 committed by GitHub
parent 3b98da7e28
commit c2ec494336
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 24 deletions

View file

@ -6,7 +6,7 @@ mod example {
DisplayHandle, RawDisplayHandle, RawWindowHandle, WindowHandle, XcbDisplayHandle,
XcbWindowHandle,
};
use std::{num::NonZeroU32, ptr::NonNull};
use std::{env, num::NonZeroU32, ptr::NonNull};
use x11rb::{
connection::Connection,
protocol::{
@ -24,7 +24,11 @@ mod example {
// x11rb doesn't use raw-window-handle yet, so just create our own.
let display_handle = XcbDisplayHandle::new(
NonNull::new(conn.get_raw_xcb_connection() as *mut _),
if env::var_os("SOFTBUFFER_NO_DISPLAY").is_some() {
None
} else {
NonNull::new(conn.get_raw_xcb_connection() as *mut _)
},
screen as _,
);