Use winits XConnection when creating x11 window
@@ -9,6 +9,8 @@ use std::sync::{Arc};
use winit;
use winit::os::unix::WindowExt;
use winit::os::unix::WindowBuilderExt;
+use winit::os::unix::get_x11_xconnection;
+use winit::NativeMonitorId;
use Api;
use ContextError;
@@ -112,17 +114,13 @@ impl Window {
opengl: &GlAttributes<&Window>,
winit_builder: winit::WindowBuilder,
) -> Result<(Window, winit::Window), CreationError> {
- use api::glx::ffi::Xlib;
- use winit::NativeMonitorId;
-
- let xlib = Xlib::open().unwrap();
- let display = unsafe { (xlib.XOpenDisplay)(ptr::null()) };
+ let display = get_x11_xconnection().unwrap();
let screen_id = match winit_builder.window.monitor {
Some(ref m) => match m.get_native_identifier() {
NativeMonitorId::Numeric(monitor) => monitor as i32,
_ => panic!(),
},
- _ => unsafe { (xlib.XDefaultScreen)(display) },
+ _ => unsafe { (display.xlib.XDefaultScreen)(display.display) },
};
// start the context building process
@@ -140,10 +138,10 @@ impl Window {
if let Some(ref glx) = backend.glx {
Prototype::Glx(try!(GlxContext::new(
glx.clone(),
- &xlib,
+ &display.xlib,
pf_reqs,
&builder_clone_opengl_glx,
- display,
+ display.display,
screen_id,
)))
} else if let Some(ref egl) = backend.egl {
@@ -151,7 +149,7 @@ impl Window {
egl.clone(),
pf_reqs,
&builder_clone_opengl_egl,
- egl::NativeDisplay::X11(Some(display as *const _)),
+ egl::NativeDisplay::X11(Some(display.display as *const _)),
)))
} else {
return Err(CreationError::NotSupported);
@@ -163,7 +161,7 @@ impl Window {
egl.clone(),
pf_reqs,
&builder_clone_opengl_egl,
- egl::NativeDisplay::X11(Some(display as *const _)),
+ egl::NativeDisplay::X11(Some(display.display as *const _)),
)))
} else {
return Err(CreationError::NotSupported);
@@ -183,24 +181,23 @@ impl Window {
template.visualid = p.get_native_visual_id() as ffi::VisualID;
let mut num_visuals = 0;
- let vi = (xlib.XGetVisualInfo)(display, ffi::VisualIDMask,
+ let vi = (display.xlib.XGetVisualInfo)(display.display, ffi::VisualIDMask,
&mut template, &mut num_visuals);
- // display.check_errors().expect("Failed to call XGetVisualInfo");
+ display.check_errors().expect("Failed to call XGetVisualInfo");
assert!(!vi.is_null());
assert!(num_visuals == 1);
let vi_copy = ptr::read(vi as *const _);
- (xlib.XFree)(vi as *mut _);
+ (display.xlib.XFree)(vi as *mut _);
vi_copy
}
},
};
let winit_window = winit_builder
- .with_visual(&visual_infos as *const _)
- .with_screen(screen_id)
+ .with_x11_visual(&visual_infos as *const _)
+ .with_x11_screen(screen_id)
.build().unwrap();
- let display = winit_window.get_xlib_xconnection().unwrap();
let xlib_window = winit_window.get_xlib_window().unwrap();
// finish creating the OpenGL context
