aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/wayland/context.rs
blob: 4fc743bc308d93249c5af0e9aee1bfd77be75d63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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> = {
        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<WaylandContext> {
        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
        })
    }
}