aboutsummaryrefslogtreecommitdiff
path: root/src/safe_x11/event.rs
blob: 2519bad6392bac7f8fdfe04eb1808d0c264a16ae (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
use x11::xlib::{
    XConnectionNumber,
    Display,
    XEvent,
};

use std::mem::uninitialized;

use libc::c_int;

#[link(name = "safex11")]
extern {
    /// Get an XEvent if there're one on the queue or wait a little before continue.
    fn select_next_event(display: *mut Display, x11_fd: c_int, ev: *mut XEvent) -> c_int;
}

/// Get the file descriptor for the XServer
pub fn x11_fd(display: *mut Display) -> c_int {
    unsafe { XConnectionNumber(display) }
}

/// Get the next event from the xserver. This call will not block forever
/// (like XNextEvent), instead it will wait for a certain time (1 second
/// for now, but it can change) so we're not blocking the socket interface
/// on the main thread.
pub fn next_xevent(display: *mut Display, fd: c_int) -> XEvent {
    unsafe {
        let mut last_event: XEvent = uninitialized();
        let retval = select_next_event(display, fd, &mut last_event) as i32;
        last_event
    }
}