diff options
author | Matt Brubeck <mbrubeck@limpet.net> | 2015-08-18 13:24:11 -0700 |
---|---|---|
committer | Matt Brubeck <mbrubeck@limpet.net> | 2015-08-18 15:17:25 -0700 |
commit | 93ce9c24f5308a77b1f13de1eacde13333d1d0ea (patch) | |
tree | a0f3cd0ca8a5ed6e8b57e0e4b648955988b1cee5 | |
parent | a4e2f82ba77d22116eaee5601fb6ee5c6356c143 (diff) | |
download | glutin-93ce9c24f5308a77b1f13de1eacde13333d1d0ea.tar.gz glutin-93ce9c24f5308a77b1f13de1eacde13333d1d0ea.zip |
Handle touch events on X11
-rw-r--r-- | src/api/x11/input.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/src/api/x11/input.rs b/src/api/x11/input.rs index 34ba33a..7387ab0 100644 --- a/src/api/x11/input.rs +++ b/src/api/x11/input.rs @@ -75,7 +75,7 @@ impl XInputEventHandler { // Button clicks and mouse events are handled via XInput // events. Key presses are still handled via plain core // X11 events. - let mut mask: [libc::c_uchar; 2] = [0, 0]; + let mut mask: [libc::c_uchar; 3] = [0; 3]; let mut input_event_mask = ffi::XIEventMask { deviceid: ffi::XIAllMasterDevices, mask_len: mask.len() as i32, @@ -88,7 +88,10 @@ impl XInputEventHandler { ffi::XI_Enter, ffi::XI_Leave, ffi::XI_FocusIn, - ffi::XI_FocusOut + ffi::XI_FocusOut, + ffi::XI_TouchBegin, + ffi::XI_TouchUpdate, + ffi::XI_TouchEnd, ]; for event in events { ffi::XISetMask(&mut mask, *event); @@ -165,6 +168,7 @@ impl XInputEventHandler { use events::ElementState::{Pressed, Released}; use events::MouseButton::{Left, Right, Middle}; use events::MouseScrollDelta::{PixelDelta, LineDelta}; + use events::{Touch, TouchPhase}; match cookie.evtype { ffi::XI_ButtonPress | ffi::XI_ButtonRelease => { @@ -240,6 +244,20 @@ impl XInputEventHandler { ffi::XI_Leave => None, ffi::XI_FocusIn => Some(Focused(true)), ffi::XI_FocusOut => Some(Focused(false)), + ffi::XI_TouchBegin | ffi::XI_TouchUpdate | ffi::XI_TouchEnd => { + let event_data: &ffi::XIDeviceEvent = unsafe{mem::transmute(cookie.data)}; + let phase = match cookie.evtype { + ffi::XI_TouchBegin => TouchPhase::Started, + ffi::XI_TouchUpdate => TouchPhase::Moved, + ffi::XI_TouchEnd => TouchPhase::Ended, + _ => unreachable!() + }; + Some(Event::Touch(Touch { + phase: phase, + location: (event_data.event_x, event_data.event_y), + id: event_data.detail as u64, + })) + } _ => None } } |