@@ -18,7 +18,7 @@ use std::marker::PhantomData;
18
18
use std:: os:: raw:: c_void;
19
19
use std:: ptr;
20
20
use std:: sync:: { Arc , Once } ;
21
- use x11 :: xlib:: { Display , XCloseDisplay , XInitThreads , XLockDisplay , XOpenDisplay , XUnlockDisplay } ;
21
+ use x11_dl :: xlib:: { Display , Xlib } ;
22
22
23
23
static X_THREADS_INIT : Once = Once :: new ( ) ;
24
24
@@ -31,6 +31,7 @@ pub struct Connection {
31
31
unsafe impl Send for Connection { }
32
32
33
33
pub ( crate ) struct NativeConnectionWrapper {
34
+ pub ( crate ) xlib : Xlib ,
34
35
pub ( crate ) egl_display : EGLDisplay ,
35
36
x11_display : * mut Display ,
36
37
x11_display_is_owned : bool ,
@@ -54,7 +55,7 @@ impl Drop for NativeConnectionWrapper {
54
55
fn drop ( & mut self ) {
55
56
unsafe {
56
57
if self . x11_display_is_owned {
57
- XCloseDisplay ( self . x11_display ) ;
58
+ ( self . xlib . XCloseDisplay ) ( self . x11_display ) ;
58
59
}
59
60
self . x11_display = ptr:: null_mut ( ) ;
60
61
}
@@ -66,11 +67,13 @@ impl Connection {
66
67
#[ inline]
67
68
pub fn new ( ) -> Result < Connection , Error > {
68
69
unsafe {
70
+ let xlib = Xlib :: open ( ) . map_err ( |_| Error :: ConnectionFailed ) ?;
71
+
69
72
X_THREADS_INIT . call_once ( || {
70
- XInitThreads ( ) ;
73
+ ( xlib . XInitThreads ) ( ) ;
71
74
} ) ;
72
75
73
- let x11_display = XOpenDisplay ( ptr:: null ( ) ) ;
76
+ let x11_display = ( xlib . XOpenDisplay ) ( ptr:: null ( ) ) ;
74
77
if x11_display. is_null ( ) {
75
78
return Err ( Error :: ConnectionFailed ) ;
76
79
}
@@ -79,6 +82,7 @@ impl Connection {
79
82
80
83
Ok ( Connection {
81
84
native_connection : Arc :: new ( NativeConnectionWrapper {
85
+ xlib,
82
86
x11_display,
83
87
x11_display_is_owned : true ,
84
88
egl_display,
@@ -102,8 +106,10 @@ impl Connection {
102
106
pub unsafe fn from_native_connection (
103
107
native_connection : NativeConnection ,
104
108
) -> Result < Connection , Error > {
109
+ let xlib = Xlib :: open ( ) . map_err ( |_| Error :: ConnectionFailed ) ?;
105
110
Ok ( Connection {
106
111
native_connection : Arc :: new ( NativeConnectionWrapper {
112
+ xlib,
107
113
egl_display : native_connection. egl_display ,
108
114
x11_display : native_connection. x11_display ,
109
115
x11_display_is_owned : false ,
@@ -112,10 +118,12 @@ impl Connection {
112
118
}
113
119
114
120
fn from_x11_display ( x11_display : * mut Display , is_owned : bool ) -> Result < Connection , Error > {
121
+ let xlib = Xlib :: open ( ) . map_err ( |_| Error :: ConnectionFailed ) ?;
115
122
unsafe {
116
123
let egl_display = create_egl_display ( x11_display) ;
117
124
Ok ( Connection {
118
125
native_connection : Arc :: new ( NativeConnectionWrapper {
126
+ xlib,
119
127
egl_display,
120
128
x11_display,
121
129
x11_display_is_owned : is_owned,
@@ -271,8 +279,10 @@ impl NativeConnectionWrapper {
271
279
pub ( crate ) fn lock_display ( & self ) -> DisplayGuard {
272
280
unsafe {
273
281
let display = self . x11_display ;
274
- XLockDisplay ( display) ;
282
+ let xlib = & self . xlib ;
283
+ ( xlib. XLockDisplay ) ( display) ;
275
284
DisplayGuard {
285
+ xlib,
276
286
display,
277
287
phantom : PhantomData ,
278
288
}
@@ -281,14 +291,15 @@ impl NativeConnectionWrapper {
281
291
}
282
292
283
293
pub ( crate ) struct DisplayGuard < ' a > {
294
+ xlib : & ' a Xlib ,
284
295
display : * mut Display ,
285
296
phantom : PhantomData < & ' a ( ) > ,
286
297
}
287
298
288
299
impl < ' a > Drop for DisplayGuard < ' a > {
289
300
fn drop ( & mut self ) {
290
301
unsafe {
291
- XUnlockDisplay ( self . display ) ;
302
+ ( self . xlib . XUnlockDisplay ) ( self . display ) ;
292
303
}
293
304
}
294
305
}
0 commit comments