m: Use tiny-xlib instead of x11-dl

My new tiny-xlib crate takes up a fraction of the space that the x11-dl crate uses, supports
feature-based static linking and involves less of Xlib's ridiculous surface.
This commit is contained in:
John Nunley 2023-07-02 15:08:01 -07:00 committed by GitHub
parent 6c78268502
commit 3404953bdb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 14 deletions

View file

@ -41,7 +41,7 @@ jobs:
- { target: i686-pc-windows-gnu, os: windows-latest, host: -i686-pc-windows-gnu }
- { target: i686-unknown-linux-gnu, os: ubuntu-latest, }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: --no-default-features, features: x11 }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: --no-default-features, features: "x11,x11-dlopen" }
- { target: x86_64-unknown-linux-gnu, os: ubuntu-latest, options: --no-default-features, features: "wayland,wayland-dlopen" }
- { target: x86_64-unknown-redox, os: ubuntu-latest, }
- { target: x86_64-unknown-freebsd, os: ubuntu-latest, }

View file

@ -17,24 +17,26 @@ name = "buffer_mut"
harness = false
[features]
default = ["x11", "wayland", "wayland-dlopen"]
default = ["x11", "x11-dlopen", "wayland", "wayland-dlopen"]
wayland = ["wayland-backend", "wayland-client", "memmap2", "nix", "fastrand"]
wayland-dlopen = ["wayland-sys/dlopen"]
x11 = ["bytemuck", "nix", "x11rb", "x11-dl"]
x11 = ["as-raw-xcb-connection", "bytemuck", "nix", "tiny-xlib", "x11rb"]
x11-dlopen = ["tiny-xlib/dlopen", "x11rb/dl-libxcb"]
[dependencies]
log = "0.4.17"
raw-window-handle = "0.5.0"
[target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox"))))'.dependencies]
as-raw-xcb-connection = { version = "1.0.0", optional = true }
bytemuck = { version = "1.12.3", optional = true }
memmap2 = { version = "0.6.1", optional = true }
nix = { version = "0.26.1", optional = true }
tiny-xlib = { version = "0.2.1", optional = true }
wayland-backend = { version = "0.1.0", features = ["client_system"], optional = true }
wayland-client = { version = "0.30.0", optional = true }
wayland-sys = "0.30.0"
x11-dl = { version = "2.19.1", optional = true }
x11rb = { version = "0.12.0", features = ["allow-unsafe-code", "dl-libxcb", "shm"], optional = true }
x11rb = { version = "0.12.0", features = ["allow-unsafe-code", "shm"], optional = true }
[target.'cfg(all(unix, not(any(target_vendor = "apple", target_os = "android", target_os = "redox", target_os = "linux", target_os = "freebsd"))))'.dependencies]
fastrand = { version = "1.8.0", optional = true }

View file

@ -17,9 +17,7 @@ use std::{
slice,
};
use x11_dl::xlib::Display;
use x11_dl::xlib_xcb::Xlib_xcb;
use as_raw_xcb_connection::AsRawXcbConnection;
use x11rb::connection::{Connection, SequenceNumber};
use x11rb::cookie::Cookie;
use x11rb::errors::{ConnectionError, ReplyError, ReplyOrIdError};
@ -39,9 +37,6 @@ impl X11DisplayImpl {
pub(crate) unsafe fn from_xlib(
display_handle: XlibDisplayHandle,
) -> Result<X11DisplayImpl, SoftBufferError> {
// Try to open the XlibXCB shared library.
let lib_xcb = Xlib_xcb::open().swbuf_err("Failed to open XlibXCB shared library")?;
// Validate the display handle to ensure we can use it.
if display_handle.display.is_null() {
return Err(SoftBufferError::IncompleteDisplayHandle);
@ -49,12 +44,14 @@ impl X11DisplayImpl {
// Get the underlying XCB connection.
// SAFETY: The user has asserted that the display handle is valid.
let connection =
unsafe { (lib_xcb.XGetXCBConnection)(display_handle.display as *mut Display) };
let connection = unsafe {
let display = tiny_xlib::Display::from_ptr(display_handle.display);
display.as_raw_xcb_connection()
};
// Construct the equivalent XCB display and window handles.
let mut xcb_display_handle = XcbDisplayHandle::empty();
xcb_display_handle.connection = connection;
xcb_display_handle.connection = connection.cast();
xcb_display_handle.screen = display_handle.screen;
// SAFETY: If the user passed in valid Xlib handles, then these are valid XCB handles.