diff options
author | Matias Linares <matiaslina@openmailbox.org> | 2015-11-22 20:02:10 -0300 |
---|---|---|
committer | Matias Linares <matiaslina@openmailbox.org> | 2015-11-22 20:02:10 -0300 |
commit | 83b7d0cb4f30c95ce6f27d2c0944727d75eb6e5e (patch) | |
tree | 255c9e3f5e0703676382fda1157bdb5daf14bc62 /src/safe_x11/mod.rs | |
parent | 47fc031feeddc955e6c7c43410613c75e3370e96 (diff) | |
download | dotwm-83b7d0cb4f30c95ce6f27d2c0944727d75eb6e5e.tar.gz |
Death to the threads.
All the socket stuff is done syncing it with select calls so we can
get either a X11 event or a Socket event.
Also cleanup the C mess, it's done all in rust now :).
Diffstat (limited to 'src/safe_x11/mod.rs')
-rw-r--r-- | src/safe_x11/mod.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/safe_x11/mod.rs b/src/safe_x11/mod.rs index 06c7b3c..0283966 100644 --- a/src/safe_x11/mod.rs +++ b/src/safe_x11/mod.rs @@ -6,11 +6,15 @@ use x11::xlib; use x11::xlib::{ Display, + XConnectionNumber, Screen, Cursor, XDefaultRootWindow, XQueryTree, + XEvent, + XNextEvent, + // Windows Window, }; @@ -23,9 +27,9 @@ use std::error; use std::mem::uninitialized; use std::slice; use std::fmt; +use libc::c_int; pub mod window; -pub mod event; #[derive(Debug)] pub struct XSafeError<'a> { @@ -89,6 +93,24 @@ pub fn close_display(display: *mut Display) { unsafe { xlib::XCloseDisplay(display); } } +/// 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) -> XEvent { + unsafe { + let mut last_event: XEvent = uninitialized(); + XNextEvent(display, &mut last_event); + last_event + } +} + + /// Grab pointer buttons. /// /// # Example |