aboutsummaryrefslogtreecommitdiffstats
path: root/src/x11
diff options
context:
space:
mode:
authorTomaka17 <pierre.krieger1708@gmail.com>2014-08-13 17:04:57 +0200
committerTomaka17 <pierre.krieger1708@gmail.com>2014-08-13 17:23:03 +0200
commitae65b423ddf2be0bb7981eba81366a93c686724f (patch)
treeebf9c4b9a38c5a06ce324d010ad3e6e4297f5d65 /src/x11
parent3aab801f291c513f5b662589097fa5d5653d8ffe (diff)
downloadglutin-ae65b423ddf2be0bb7981eba81366a93c686724f.tar.gz
glutin-ae65b423ddf2be0bb7981eba81366a93c686724f.zip
Implement new events system
Diffstat (limited to 'src/x11')
-rw-r--r--src/x11/events.rs4
-rw-r--r--src/x11/mod.rs60
2 files changed, 31 insertions, 33 deletions
diff --git a/src/x11/events.rs b/src/x11/events.rs
index 78d310c..d5b559a 100644
--- a/src/x11/events.rs
+++ b/src/x11/events.rs
@@ -1,8 +1,8 @@
use {events, libc};
use super::ffi;
-use Element;
+use VirtualKeyCode;
-pub fn keycode_to_element(scancode: libc::c_uint) -> Option<Element> {
+pub fn keycode_to_element(scancode: libc::c_uint) -> Option<VirtualKeyCode> {
Some(match scancode {
//ffi::XK_BackSpace => events::Backspace,
ffi::XK_Tab => events::Tab,
diff --git a/src/x11/mod.rs b/src/x11/mod.rs
index 3286b99..455f43c 100644
--- a/src/x11/mod.rs
+++ b/src/x11/mod.rs
@@ -331,13 +331,13 @@ impl Window {
},
ffi::MotionNotify => {
- use CursorPositionChanged;
+ use MouseMoved;
let event: &ffi::XMotionEvent = unsafe { mem::transmute(&xev) };
- events.push(CursorPositionChanged(event.x as uint, event.y as uint));
+ events.push(MouseMoved((event.x as int, event.y as int)));
},
ffi::KeyPress | ffi::KeyRelease => {
- use {Pressed, Released, ReceivedCharacter};
+ use {KeyboardInput, Pressed, Released, ReceivedCharacter, KeyModifiers};
let event: &mut ffi::XKeyEvent = unsafe { mem::transmute(&xev) };
if event.type_ == ffi::KeyPress {
@@ -345,7 +345,7 @@ impl Window {
unsafe { ffi::XFilterEvent(mem::transmute(raw_ev), self.window) };
}
- let keysym = unsafe { ffi::XKeycodeToKeysym(self.display, event.keycode as ffi::KeyCode, 0) };
+ let state = if xev.type_ == ffi::KeyPress { Pressed } else { Released };
let written = unsafe {
use std::str;
@@ -356,48 +356,46 @@ impl Window {
mem::transmute(buffer.as_mut_ptr()),
buffer.len() as libc::c_int, ptr::mut_null(), ptr::mut_null());
- str::from_utf8(buffer.as_slice().slice_to(count as uint)).unwrap_or("").to_string()
+ str::from_utf8(buffer.as_slice().slice_to(count as uint))
+ .unwrap_or("").to_string()
};
for chr in written.as_slice().chars() {
events.push(ReceivedCharacter(chr));
}
- 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));
- },
- _ => ()
- }
+ let keysym = unsafe {
+ ffi::XKeycodeToKeysym(self.display, event.keycode as ffi::KeyCode, 0)
+ };
+
+ let vkey = events::keycode_to_element(keysym as libc::c_uint);
+
+ events.push(KeyboardInput(state, event.keycode as u8,
+ vkey, KeyModifiers::empty()));
//
},
ffi::ButtonPress | ffi::ButtonRelease => {
- use {Pressed, Released};
- use events;
+ use {MouseInput, Pressed, Released};
+ use {LeftMouseButton, RightMouseButton, MiddleMouseButton, OtherMouseButton};
let event: &ffi::XButtonEvent = unsafe { mem::transmute(&xev) };
- let elem = match event.button {
- ffi::Button1 => Some(events::Button1),
- ffi::Button2 => Some(events::Button2),
- ffi::Button3 => Some(events::Button3),
- ffi::Button4 => Some(events::Button4),
- ffi::Button5 => Some(events::Button5),
+ let state = if xev.type_ == ffi::ButtonPress { Pressed } else { Released };
+
+ let button = match event.button {
+ ffi::Button1 => Some(LeftMouseButton),
+ ffi::Button2 => Some(MiddleMouseButton),
+ ffi::Button3 => Some(RightMouseButton),
+ ffi::Button4 => Some(OtherMouseButton(4)),
+ ffi::Button5 => Some(OtherMouseButton(5)),
_ => None
};
- if elem.is_some() {
- let elem = elem.unwrap();
-
- if xev.type_ == ffi::ButtonPress {
- events.push(Pressed(elem));
- } else if xev.type_ == ffi::ButtonRelease {
- events.push(Released(elem));
- }
- }
+ match button {
+ Some(button) =>
+ events.push(MouseInput(state, button)),
+ None => ()
+ };
},
_ => ()