From 310b44f35be8146623d8e5fbbe380ae14f30de72 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Tue, 12 May 2015 22:47:34 +0200 Subject: Make platform::linux generic over X11 and Wayland. --- src/api/glx/mod.rs | 11 ++++++++--- src/api/wayland/mod.rs | 4 ++++ src/api/x11/mod.rs | 12 +++++++----- 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'src/api') diff --git a/src/api/glx/mod.rs b/src/api/glx/mod.rs index 9cda90e..3c0c8a0 100644 --- a/src/api/glx/mod.rs +++ b/src/api/glx/mod.rs @@ -14,6 +14,8 @@ use std::{mem, ptr}; use api::x11::ffi; +use platform::Window as PlatformWindow; + pub struct Context { glx: ffi::glx::Glx, display: *mut ffi::Display, @@ -80,9 +82,12 @@ impl Context { }); let share = if let Some(win) = builder.sharing { - match win.x.context { - ::api::x11::Context::Glx(ref c) => c.context, - _ => panic!("Cannot share contexts between different APIs") + match win { + &PlatformWindow::X(ref win) => match win.x.context { + ::api::x11::Context::Glx(ref c) => c.context, + _ => panic!("Cannot share contexts between different APIs") + }, + _ => panic!("Cannot use glx on a non-X11 window.") } } else { ptr::null() diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index f70d62e..4fd0357 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -147,6 +147,10 @@ lazy_static! { }; } +pub fn is_available() -> bool { + WAYLAND_CONTEXT.is_some() +} + pub struct Window { shell_surface: ShellSurface, pending_events: Arc>>, diff --git a/src/api/x11/mod.rs b/src/api/x11/mod.rs index 0dcf85b..30adadc 100644 --- a/src/api/x11/mod.rs +++ b/src/api/x11/mod.rs @@ -21,6 +21,8 @@ use api::dlopen; use api::glx::Context as GlxContext; use api::egl::Context as EglContext; +use platform::MonitorID as PlatformMonitorID; + pub use self::monitor::{MonitorID, get_available_monitors, get_primary_monitor}; mod events; @@ -310,9 +312,9 @@ pub struct Window { impl Window { pub fn new(builder: BuilderAttribs) -> Result { - let xlib = ffi::Xlib::open().unwrap(); // FIXME: gracious handling - let xcursor = ffi::Xcursor::open().unwrap(); // FIXME: gracious handling - let xf86vmode = ffi::Xf86vmode::open().unwrap(); // FIXME: gracious handling + let xlib = try!(ffi::Xlib::open().map_err(|_| CreationError::NotSupported)); + let xcursor = try!(ffi::Xcursor::open().map_err(|_| CreationError::NotSupported)); + let xf86vmode = try!(ffi::Xf86vmode::open().map_err(|_| CreationError::NotSupported)); let glx = { let mut libglx = unsafe { dlopen::dlopen(b"libGL.so.1\0".as_ptr() as *const _, dlopen::RTLD_NOW) }; @@ -342,8 +344,8 @@ impl Window { }; let screen_id = match builder.monitor { - Some(MonitorID(monitor)) => monitor as i32, - None => unsafe { (xlib.XDefaultScreen)(display) }, + Some(PlatformMonitorID::X(MonitorID(monitor))) => monitor as i32, + _ => unsafe { (xlib.XDefaultScreen)(display) }, }; // getting the FBConfig -- cgit v1.2.3