Add get_x11_xconnection function

This commit is contained in:
rerion 2017-01-07 14:34:38 +01:00
parent d4b8fd9f5a
commit f5812018ca
3 changed files with 20 additions and 9 deletions

View file

@ -5,6 +5,7 @@ use std::ptr;
use libc; use libc;
use Window; use Window;
use platform::Window as LinuxWindow; use platform::Window as LinuxWindow;
use platform::{UnixBackend, UNIX_BACKEND};
use WindowBuilder; use WindowBuilder;
use api::x11::XConnection; use api::x11::XConnection;
use api::x11::ffi::XVisualInfo; use api::x11::ffi::XVisualInfo;
@ -14,6 +15,13 @@ use wayland_client::protocol::wl_surface::WlSurface;
pub use api::x11; pub use api::x11;
pub fn get_x11_xconnection() -> Option<Arc<XConnection>> {
match *UNIX_BACKEND {
UnixBackend::X(ref connec) => Some(connec.clone()),
_ => None,
}
}
/// Additional methods on `Window` that are specific to Unix. /// Additional methods on `Window` that are specific to Unix.
pub trait WindowExt { pub trait WindowExt {
/// Returns a pointer to the `Window` object of xlib that is used by this window. /// 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. /// Additional methods on `WindowBuilder` that are specific to Unix.
pub trait WindowBuilderExt { pub trait WindowBuilderExt {
fn with_visual(self, visual_infos: *const XVisualInfo) -> WindowBuilder; fn with_x11_visual<T>(self, visual_infos: *const T) -> WindowBuilder;
fn with_screen(self, screen_id: i32) -> WindowBuilder; fn with_x11_screen(self, screen_id: i32) -> WindowBuilder;
} }
impl WindowBuilderExt for WindowBuilder { impl WindowBuilderExt for WindowBuilder {
#[inline] #[inline]
fn with_visual(mut self, visual_infos: *const XVisualInfo) -> WindowBuilder { fn with_x11_visual<T>(mut self, visual_infos: *const T) -> WindowBuilder {
self.platform_specific.visual_infos = Some( self.platform_specific.visual_infos = Some(
unsafe { ptr::read(visual_infos) } unsafe { ptr::read(visual_infos as *const XVisualInfo) }
); );
self self
} }
#[inline] #[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.platform_specific.screen_id = Some(screen_id);
self self
} }

View file

@ -21,14 +21,14 @@ pub struct PlatformSpecificWindowBuilderAttributes {
pub screen_id: Option<i32>, pub screen_id: Option<i32>,
} }
enum Backend { pub enum Backend {
X(Arc<XConnection>), X(Arc<XConnection>),
Wayland(Arc<wayland::WaylandContext>), Wayland(Arc<wayland::WaylandContext>),
Error(XNotSupported), Error(XNotSupported),
} }
lazy_static!( lazy_static!(
static ref BACKEND: Backend = { pub static ref BACKEND: Backend = {
if let Some(ctxt) = wayland::WaylandContext::init() { if let Some(ctxt) = wayland::WaylandContext::init() {
Backend::Wayland(Arc::new(ctxt)) Backend::Wayland(Arc::new(ctxt))
} else { } else {
@ -40,6 +40,7 @@ lazy_static!(
}; };
); );
pub enum Window { pub enum Window {
#[doc(hidden)] #[doc(hidden)]
X(x11::Window), X(x11::Window),

View file

@ -3,5 +3,7 @@
pub use self::api_dispatch::{Window, WindowProxy, MonitorId, get_available_monitors, get_primary_monitor}; 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::{WaitEventsIterator, PollEventsIterator};
pub use self::api_dispatch::PlatformSpecificWindowBuilderAttributes; 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; mod api_dispatch;