summaryrefslogtreecommitdiff
path: root/src/event.rs
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@openmailbox.org>2015-11-08 23:02:00 -0300
committerMatias Linares <matiaslina@openmailbox.org>2015-11-08 23:02:00 -0300
commitacf4a04b7452b6dd2e69064b4f85144b8445bbe9 (patch)
treeaef2d5caab26bab04b300ef232ca75578716fa7f /src/event.rs
downloaddotwm-acf4a04b7452b6dd2e69064b4f85144b8445bbe9.tar.gz
Initial commit
This initial commit has the following: * We can spawn a terminal. * Given a new window, we can move it around the screen, but only the window that was created, all the other windows disappear on the void, so.. :( and that's it
Diffstat (limited to 'src/event.rs')
-rw-r--r--src/event.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/event.rs b/src/event.rs
new file mode 100644
index 0000000..e15ee18
--- /dev/null
+++ b/src/event.rs
@@ -0,0 +1,69 @@
+use x11::xlib::{
+ XEvent,
+ XKeyEvent,
+ XButtonEvent,
+ XMotionEvent,
+ XCrossingEvent,
+ XCreateWindowEvent,
+ XDestroyWindowEvent,
+ XConfigureEvent,
+};
+
+use x11::xlib;
+use x11::xlib::Display;
+use std::fmt;
+
+use safe_x11::next_xevent;
+
+pub enum Event {
+ Key(XKeyEvent, bool),
+ Button(XButtonEvent, bool),
+ Drag(XMotionEvent),
+ Enter(XCrossingEvent),
+ Leave(XCrossingEvent),
+ Generic(XEvent),
+ Create(XCreateWindowEvent),
+ Destroy(XDestroyWindowEvent),
+ Configure(XConfigureEvent),
+ NoEvent
+}
+
+impl fmt::Debug for Event {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ let s = match self {
+ &Event::Key(ev, pressed) => format!("Key({}, {})", XEvent::from(ev).get_type(), pressed),
+ &Event::Button(ev, pressed) => format!("Button({}, {})", XEvent::from(ev).get_type(), pressed),
+ &Event::Drag(ev) => format!("Drag({})", XEvent::from(ev).get_type()),
+ &Event::Generic(ev) => format!("Generic({})", XEvent::from(ev).get_type()),
+ &Event::Enter(ev) => format!("Enter({})", XEvent::from(ev).get_type()),
+ &Event::Leave(ev) => format!("Enter({})", XEvent::from(ev).get_type()),
+ &Event::Create(ev) => format!("Create({})", XEvent::from(ev).get_type()),
+ &Event::Destroy(ev) => format!("Destroy({})", XEvent::from(ev).get_type()),
+ &Event::Configure(ev) => format!("Configure({})", XEvent::from(ev).get_type()),
+ &Event::NoEvent => format!("NoEvent"),
+ };
+
+ write!(f, "{}", s)
+ }
+}
+
+pub fn next_event(display: *mut Display) -> Event {
+ let ev = next_xevent(display);
+
+ match ev.get_type() {
+ 2 => Event::Key(xlib::XKeyEvent::from(ev), true),
+ 3 => Event::Key(xlib::XKeyEvent::from(ev), false),
+ 4 => Event::Button(xlib::XButtonEvent::from(ev), true),
+ 5 => Event::Button(xlib::XButtonEvent::from(ev), false),
+ 6 => Event::Drag(XMotionEvent::from(ev)),
+ 7 => Event::Enter(XCrossingEvent::from(ev)),
+ 8 => Event::Leave(XCrossingEvent::from(ev)),
+ 16 => Event::Create(XCreateWindowEvent::from(ev)),
+ 17 => Event::Destroy(XDestroyWindowEvent::from(ev)),
+ 22 => Event::Configure(XConfigureEvent::from(ev)),
+ e => {
+ println!("Unknown event {}", e);
+ Event::NoEvent
+ },
+ }
+}