aboutsummaryrefslogtreecommitdiff
path: root/src/safe_x11
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-11-22 20:02:10 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-11-22 20:02:10 -0300
commit83b7d0cb4f30c95ce6f27d2c0944727d75eb6e5e (patch)
tree255c9e3f5e0703676382fda1157bdb5daf14bc62 /src/safe_x11
parent47fc031feeddc955e6c7c43410613c75e3370e96 (diff)
downloaddotwm-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')
-rw-r--r--src/safe_x11/Makefile7
-rw-r--r--src/safe_x11/event.rs33
-rw-r--r--src/safe_x11/mod.rs24
-rw-r--r--src/safe_x11/safex11.c32
-rw-r--r--src/safe_x11/safex11.h7
5 files changed, 23 insertions, 80 deletions
diff --git a/src/safe_x11/Makefile b/src/safe_x11/Makefile
deleted file mode 100644
index 4ea8a63..0000000
--- a/src/safe_x11/Makefile
+++ /dev/null
@@ -1,7 +0,0 @@
-all:
- $(CC) -c -fPIC safex11.c -o safex11.o -lX11
- $(CC) -shared -o libsafex11.so safex11.o -lX11
-
-clean:
- rm safex11.o
- rm *.so*
diff --git a/src/safe_x11/event.rs b/src/safe_x11/event.rs
deleted file mode 100644
index 8a4bc32..0000000
--- a/src/safe_x11/event.rs
+++ /dev/null
@@ -1,33 +0,0 @@
-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();
- select_next_event(display, fd, &mut last_event) as i32;
- last_event
- }
-}
-
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
diff --git a/src/safe_x11/safex11.c b/src/safe_x11/safex11.c
deleted file mode 100644
index e4f87d8..0000000
--- a/src/safe_x11/safex11.c
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "safex11.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <X11/Xutil.h>
-
-int select_next_event(Display *display, int x11_fd, XEvent *retval)
-{
- fd_set in_fds;
- struct timeval tv;
- XEvent ev;
- /* check if there're some events on the queue first of all. */
- if(XPending(display) > 0)
- goto EVENT_QUEUED;
-
- FD_ZERO(&in_fds);
- FD_SET(x11_fd, &in_fds);
-
- /* one second */
- tv.tv_usec = 0;
- tv.tv_sec = 1;
-
- /* Wait for X Event or a Timer */
- if(select(x11_fd+1, &in_fds, 0, 0, &tv))
- goto EVENT_QUEUED;
-
- return 0;
-
-EVENT_QUEUED:
- XNextEvent(display, &ev);
- *retval = ev;
- return 1;
-}
diff --git a/src/safe_x11/safex11.h b/src/safe_x11/safex11.h
deleted file mode 100644
index bbf4e80..0000000
--- a/src/safe_x11/safex11.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef _WM_EVENT_H_
-#define _WM_EVENT_H_
-#include <X11/Xlib.h>
-
-int select_next_event(Display *display, int x11_fd, XEvent *retval);
-
-#endif