From 59b4d23d58f804e0d9ae05cf80da67784680d186 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Thu, 31 Jul 2014 17:33:46 +0200 Subject: Add mouse buttons press/release events for X11 --- src/x11/ffi.rs | 6 ++++++ src/x11/mod.rs | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/x11') diff --git a/src/x11/ffi.rs b/src/x11/ffi.rs index f73d408..2c94820 100644 --- a/src/x11/ffi.rs +++ b/src/x11/ffi.rs @@ -30,6 +30,12 @@ pub type XID = uint; pub static AllocNone: libc::c_int = 0; pub static AllocAll: libc::c_int = 1; +pub static Button1: libc::c_uint = 1; +pub static Button2: libc::c_uint = 2; +pub static Button3: libc::c_uint = 3; +pub static Button4: libc::c_uint = 4; +pub static Button5: libc::c_uint = 5; + pub static InputOutput: libc::c_uint = 1; pub static InputOnly: libc::c_uint = 2; diff --git a/src/x11/mod.rs b/src/x11/mod.rs index 4bd186f..c2b2044 100644 --- a/src/x11/mod.rs +++ b/src/x11/mod.rs @@ -243,8 +243,27 @@ impl Window { ffi::ButtonPress | ffi::ButtonRelease => { use {Pressed, Released}; + use events; let event: &ffi::XButtonEvent = unsafe { mem::transmute(&xev) }; - //events.push(CursorPositionChanged(event.x as uint, event.y as uint)); + + 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), + _ => 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)); + } + } }, _ => () -- cgit v1.2.3