Skip to content

Commit 0c1861e

Browse files
authored
Switch to x11-dl (#333)
Everything else in servo uses x11-dl and this allows building on systems without X11 libraries installed.
1 parent f7688b4 commit 0c1861e

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sm-angle-default = ["sm-angle"]
2626
sm-no-wgl = ["sm-angle-default"]
2727
sm-test = []
2828
sm-wayland-default = []
29-
sm-x11 = ["x11"]
29+
sm-x11 = ["x11-dl"]
3030
sm-raw-window-handle-generic = []
3131
sm-raw-window-handle-05 = ["dep:rwh_05"]
3232
sm-raw-window-handle-06 = ["dep:rwh_06"]
@@ -69,9 +69,8 @@ objc = "0.2"
6969
version = "0.30"
7070
features = ["client", "dlopen", "egl"]
7171

72-
[target.'cfg(all(unix, not(any(target_os = "macos", target_os = "android", target_env = "ohos"))))'.dependencies.x11]
72+
[target.'cfg(all(unix, not(any(target_os = "macos", target_os = "android", target_env = "ohos"))))'.dependencies.x11-dl]
7373
version = "2.3.0"
74-
features = ["xlib"]
7574
optional = true
7675

7776
# Ensure that we have a static libEGL.lib present for linking with EGL bindings.

src/platform/unix/x11/connection.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::marker::PhantomData;
1818
use std::os::raw::c_void;
1919
use std::ptr;
2020
use std::sync::{Arc, Once};
21-
use x11::xlib::{Display, XCloseDisplay, XInitThreads, XLockDisplay, XOpenDisplay, XUnlockDisplay};
21+
use x11_dl::xlib::{Display, Xlib};
2222

2323
static X_THREADS_INIT: Once = Once::new();
2424

@@ -31,6 +31,7 @@ pub struct Connection {
3131
unsafe impl Send for Connection {}
3232

3333
pub(crate) struct NativeConnectionWrapper {
34+
pub(crate) xlib: Xlib,
3435
pub(crate) egl_display: EGLDisplay,
3536
x11_display: *mut Display,
3637
x11_display_is_owned: bool,
@@ -54,7 +55,7 @@ impl Drop for NativeConnectionWrapper {
5455
fn drop(&mut self) {
5556
unsafe {
5657
if self.x11_display_is_owned {
57-
XCloseDisplay(self.x11_display);
58+
(self.xlib.XCloseDisplay)(self.x11_display);
5859
}
5960
self.x11_display = ptr::null_mut();
6061
}
@@ -66,11 +67,13 @@ impl Connection {
6667
#[inline]
6768
pub fn new() -> Result<Connection, Error> {
6869
unsafe {
70+
let xlib = Xlib::open().map_err(|_| Error::ConnectionFailed)?;
71+
6972
X_THREADS_INIT.call_once(|| {
70-
XInitThreads();
73+
(xlib.XInitThreads)();
7174
});
7275

73-
let x11_display = XOpenDisplay(ptr::null());
76+
let x11_display = (xlib.XOpenDisplay)(ptr::null());
7477
if x11_display.is_null() {
7578
return Err(Error::ConnectionFailed);
7679
}
@@ -79,6 +82,7 @@ impl Connection {
7982

8083
Ok(Connection {
8184
native_connection: Arc::new(NativeConnectionWrapper {
85+
xlib,
8286
x11_display,
8387
x11_display_is_owned: true,
8488
egl_display,
@@ -102,8 +106,10 @@ impl Connection {
102106
pub unsafe fn from_native_connection(
103107
native_connection: NativeConnection,
104108
) -> Result<Connection, Error> {
109+
let xlib = Xlib::open().map_err(|_| Error::ConnectionFailed)?;
105110
Ok(Connection {
106111
native_connection: Arc::new(NativeConnectionWrapper {
112+
xlib,
107113
egl_display: native_connection.egl_display,
108114
x11_display: native_connection.x11_display,
109115
x11_display_is_owned: false,
@@ -112,10 +118,12 @@ impl Connection {
112118
}
113119

114120
fn from_x11_display(x11_display: *mut Display, is_owned: bool) -> Result<Connection, Error> {
121+
let xlib = Xlib::open().map_err(|_| Error::ConnectionFailed)?;
115122
unsafe {
116123
let egl_display = create_egl_display(x11_display);
117124
Ok(Connection {
118125
native_connection: Arc::new(NativeConnectionWrapper {
126+
xlib,
119127
egl_display,
120128
x11_display,
121129
x11_display_is_owned: is_owned,
@@ -271,8 +279,10 @@ impl NativeConnectionWrapper {
271279
pub(crate) fn lock_display(&self) -> DisplayGuard {
272280
unsafe {
273281
let display = self.x11_display;
274-
XLockDisplay(display);
282+
let xlib = &self.xlib;
283+
(xlib.XLockDisplay)(display);
275284
DisplayGuard {
285+
xlib,
276286
display,
277287
phantom: PhantomData,
278288
}
@@ -281,14 +291,15 @@ impl NativeConnectionWrapper {
281291
}
282292

283293
pub(crate) struct DisplayGuard<'a> {
294+
xlib: &'a Xlib,
284295
display: *mut Display,
285296
phantom: PhantomData<&'a ()>,
286297
}
287298

288299
impl<'a> Drop for DisplayGuard<'a> {
289300
fn drop(&mut self) {
290301
unsafe {
291-
XUnlockDisplay(self.display);
302+
(self.xlib.XUnlockDisplay)(self.display);
292303
}
293304
}
294305
}

src/platform/unix/x11/surface.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use euclid::default::Size2D;
1515
use glow::Texture;
1616
use std::marker::PhantomData;
1717
use std::os::raw::c_void;
18-
use x11::xlib::{Window, XGetGeometry};
18+
use x11_dl::xlib::Window;
1919

2020
// FIXME(pcwalton): Is this right, or should it be `TEXTURE_EXTERNAL_OES`?
2121
const SURFACE_GL_TEXTURE_TARGET: u32 = gl::TEXTURE_2D;
@@ -113,7 +113,7 @@ impl Device {
113113
let display_guard = self.native_connection.lock_display();
114114
let (mut root_window, mut x, mut y, mut width, mut height) = (0, 0, 0, 0, 0);
115115
let (mut border_width, mut depth) = (0, 0);
116-
XGetGeometry(
116+
(self.native_connection.xlib.XGetGeometry)(
117117
display_guard.display(),
118118
x11_window,
119119
&mut root_window,

0 commit comments

Comments
 (0)