aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/x11/mod.rs')
-rw-r--r--src/x11/mod.rs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/x11/mod.rs b/src/x11/mod.rs
index 9f773f4..a917fc1 100644
--- a/src/x11/mod.rs
+++ b/src/x11/mod.rs
@@ -3,6 +3,7 @@ use libc;
use std::{mem, ptr};
use std::sync::atomics::AtomicBool;
+mod events;
mod ffi;
pub struct Window {
@@ -61,7 +62,9 @@ impl Window {
let mut swa: ffi::XSetWindowAttributes = unsafe { mem::zeroed() };
swa.colormap = cmap;
swa.event_mask = ffi::ExposureMask | ffi::ResizeRedirectMask |
- ffi::VisibilityChangeMask | ffi::KeyPressMask | ffi::PointerMotionMask;
+ ffi::VisibilityChangeMask | ffi::KeyPressMask | ffi::PointerMotionMask |
+ ffi::KeyPressMask | ffi::KeyReleaseMask | ffi::ButtonPressMask |
+ ffi::ButtonReleaseMask;
swa
};
@@ -174,6 +177,30 @@ impl Window {
events.push(CursorPositionChanged(event.x as uint, event.y as uint));
},
+ ffi::KeyPress | ffi::KeyRelease => {
+ use {Pressed, Released};
+ let event: &ffi::XKeyEvent = unsafe { mem::transmute(&xev) };
+
+ let keysym = unsafe { ffi::XKeycodeToKeysym(self.display, event.keycode as ffi::KeyCode, 0) };
+
+ match events::keycode_to_element(keysym as libc::c_uint) {
+ Some(elem) if xev.type_ == ffi::KeyPress => {
+ events.push(Pressed(elem));
+ },
+ Some(elem) if xev.type_ == ffi::KeyRelease => {
+ events.push(Released(elem));
+ },
+ _ => ()
+ }
+ //
+ },
+
+ ffi::ButtonPress | ffi::ButtonRelease => {
+ use {Pressed, Released};
+ let event: &ffi::XButtonEvent = unsafe { mem::transmute(&xev) };
+ //events.push(CursorPositionChanged(event.x as uint, event.y as uint));
+ },
+
_ => ()
}