From 741311b619c9738b3adb15213c442e47834a1c98 Mon Sep 17 00:00:00 2001 From: Victor Berger Date: Tue, 8 Dec 2015 23:30:17 +0100 Subject: api/wayland: core context --- src/api/wayland/context.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ src/api/wayland/mod.rs | 3 ++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/api/wayland/context.rs (limited to 'src') diff --git a/src/api/wayland/context.rs b/src/api/wayland/context.rs new file mode 100644 index 0000000..4fc743b --- /dev/null +++ b/src/api/wayland/context.rs @@ -0,0 +1,42 @@ +use wayland_client::EventIterator; +use wayland_client::wayland::get_display; +use wayland_client::wayland::compositor::WlCompositor; +use wayland_client::wayland::seat::WlSeat; +use wayland_client::wayland::shell::WlShell; +use wayland_client::wayland::shm::WlShm; +use wayland_client::wayland::subcompositor::WlSubcompositor; + +lazy_static! { + pub static ref WAYLAND_CONTEXT: Option = { + WaylandContext::init() + }; +} + +wayland_env!(InnerEnv, + compositor: WlCompositor, + seat: WlSeat, + shell: WlShell, + shm: WlShm, + subcompositor: WlSubcompositor +); + +pub struct WaylandContext { + inner: InnerEnv, + iterator: EventIterator +} + +impl WaylandContext { + fn init() -> Option { + let display = match get_display() { + Some(display) => display, + None => return None + }; + + let (inner_env, iterator) = InnerEnv::init(display); + + Some(WaylandContext { + inner: inner_env, + iterator: iterator + }) + } +} \ No newline at end of file diff --git a/src/api/wayland/mod.rs b/src/api/wayland/mod.rs index 246a9e4..f30389c 100644 --- a/src/api/wayland/mod.rs +++ b/src/api/wayland/mod.rs @@ -6,10 +6,11 @@ pub use self::window::{PollEventsIterator, WaitEventsIterator, Window, WindowPro extern crate wayland_kbd; extern crate wayland_window; +mod context; mod monitor; mod window; #[inline] pub fn is_available() -> bool { - false + context::WAYLAND_CONTEXT.is_some() } -- cgit v1.2.3