Work on input support for X11

This commit is contained in:
Pierre Krieger 2014-07-28 14:15:02 +02:00
parent 433c5b956e
commit c1da2b1273
4 changed files with 2068 additions and 2 deletions

View file

@ -3,7 +3,7 @@
extern crate libc;
pub use events::{Event, Element, PositionChanged, SizeChanged, Closed, CursorPositionChanged, Focused};
pub use events::{Iconified, NeedRefresh};
pub use events::{Iconified, NeedRefresh, Pressed, Released};
pub use hints::{Hints, ClientAPI, Profile};
#[cfg(windows)]

1002
src/x11/events.rs Normal file

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -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));
},
_ => ()
}