summaryrefslogtreecommitdiff
path: root/src/safe_x11/event.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-11-22 02:58:41 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-11-22 02:58:41 -0300
commit5da38341bc54f24c8cad41f1b63405d8cc955fe7 (patch)
treedebe4dda2dd02cc23ed64b54df768a0f584938d2 /src/safe_x11/event.rs
parenta21473f60c6cfad6335db3b0b45cdff23f8b3a89 (diff)
downloaddotwm-5da38341bc54f24c8cad41f1b63405d8cc955fe7.tar.gz
next_xevent don't block anymore!
Now the next_xevent (from the safex11) will not block forever. So we can listen the socket without doing some thread stuff.
Diffstat (limited to 'src/safe_x11/event.rs')
-rw-r--r--src/safe_x11/event.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/safe_x11/event.rs b/src/safe_x11/event.rs
new file mode 100644
index 0000000..2519bad
--- /dev/null
+++ b/src/safe_x11/event.rs
@@ -0,0 +1,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
+ }
+}
+