From f5812018ca0fe92292e5a3db9db2da12facac9bd Mon Sep 17 00:00:00 2001 From: rerion Date: Sat, 7 Jan 2017 14:34:38 +0100 Subject: [PATCH] Add get_x11_xconnection function --- src/os/unix.rs | 20 ++++++++++++++------ src/platform/linux/api_dispatch.rs | 7 ++++--- src/platform/linux/mod.rs | 2 ++ 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/os/unix.rs b/src/os/unix.rs index f983925f..6561174b 100644 --- a/src/os/unix.rs +++ b/src/os/unix.rs @@ -5,6 +5,7 @@ use std::ptr; use libc; use Window; use platform::Window as LinuxWindow; +use platform::{UnixBackend, UNIX_BACKEND}; use WindowBuilder; use api::x11::XConnection; use api::x11::ffi::XVisualInfo; @@ -14,6 +15,13 @@ use wayland_client::protocol::wl_surface::WlSurface; pub use api::x11; +pub fn get_x11_xconnection() -> Option> { + match *UNIX_BACKEND { + UnixBackend::X(ref connec) => Some(connec.clone()), + _ => None, + } +} + /// Additional methods on `Window` that are specific to Unix. pub trait WindowExt { /// Returns a pointer to the `Window` object of xlib that is used by this window. @@ -144,21 +152,21 @@ impl WindowExt for Window { /// Additional methods on `WindowBuilder` that are specific to Unix. pub trait WindowBuilderExt { - fn with_visual(self, visual_infos: *const XVisualInfo) -> WindowBuilder; - fn with_screen(self, screen_id: i32) -> WindowBuilder; + fn with_x11_visual(self, visual_infos: *const T) -> WindowBuilder; + fn with_x11_screen(self, screen_id: i32) -> WindowBuilder; } impl WindowBuilderExt for WindowBuilder { #[inline] - fn with_visual(mut self, visual_infos: *const XVisualInfo) -> WindowBuilder { + fn with_x11_visual(mut self, visual_infos: *const T) -> WindowBuilder { self.platform_specific.visual_infos = Some( - unsafe { ptr::read(visual_infos) } - ); + unsafe { ptr::read(visual_infos as *const XVisualInfo) } + ); self } #[inline] - fn with_screen(mut self, screen_id: i32) -> WindowBuilder { + fn with_x11_screen(mut self, screen_id: i32) -> WindowBuilder { self.platform_specific.screen_id = Some(screen_id); self } diff --git a/src/platform/linux/api_dispatch.rs b/src/platform/linux/api_dispatch.rs index 66deb688..03f799ce 100644 --- a/src/platform/linux/api_dispatch.rs +++ b/src/platform/linux/api_dispatch.rs @@ -21,14 +21,14 @@ pub struct PlatformSpecificWindowBuilderAttributes { pub screen_id: Option, } -enum Backend { +pub enum Backend { X(Arc), Wayland(Arc), Error(XNotSupported), -} +} lazy_static!( - static ref BACKEND: Backend = { + pub static ref BACKEND: Backend = { if let Some(ctxt) = wayland::WaylandContext::init() { Backend::Wayland(Arc::new(ctxt)) } else { @@ -40,6 +40,7 @@ lazy_static!( }; ); + pub enum Window { #[doc(hidden)] X(x11::Window), diff --git a/src/platform/linux/mod.rs b/src/platform/linux/mod.rs index 2664d31b..05c7bfff 100644 --- a/src/platform/linux/mod.rs +++ b/src/platform/linux/mod.rs @@ -3,5 +3,7 @@ pub use self::api_dispatch::{Window, WindowProxy, MonitorId, get_available_monitors, get_primary_monitor}; pub use self::api_dispatch::{WaitEventsIterator, PollEventsIterator}; pub use self::api_dispatch::PlatformSpecificWindowBuilderAttributes; +pub use self::api_dispatch::Backend as UnixBackend; +pub use self::api_dispatch::BACKEND as UNIX_BACKEND; mod api_dispatch;