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 libc;
use x11::xlib as x;

use X11Error;

/// An x11 Event
pub struct Event {
    inner: *mut x::XAnyEvent,
    kind: EventKind,
}

/// Type of event
pub enum EventKind {
    /// A mouse button was pressed
    ButtonPress,

    /// A mouse button was released
    ButtonRelease,

    /// None event
    None,
}

impl Event {
    /// Returns the EventKind of this event
    pub fn kind(&self) -> &EventKind {
        &self.kind
    }

    pub(super) fn from_raw(event: *mut x::XAnyEvent) -> Result<Self, X11Error> {
        Ok(Event {
            inner: event,
            kind: EventKind::None,
        })
    }
}

impl Drop for Event {
    fn drop(&mut self) {
        unsafe { libc::free(self.inner as *mut libc::c_void) };
    }
}