From 8c0dfe19c29f079c06d556fbf645db8eafb713da Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 22 Oct 2015 16:29:48 -0700 Subject: Change X11 events based on `multitouch` option * If `multitouch` is enabled, touch input generates touch events. * If `multitouch` is disabled, touch input generates emulated mouse events. --- src/api/x11/input.rs | 22 +++++++++++++++++++--- src/api/x11/window.rs | 2 +- 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src/api/x11') diff --git a/src/api/x11/input.rs b/src/api/x11/input.rs index 388b651..d962e7f 100644 --- a/src/api/x11/input.rs +++ b/src/api/x11/input.rs @@ -5,6 +5,8 @@ use std::{mem, ptr}; use std::ffi::CString; use std::slice::from_raw_parts; +use WindowAttributes; + use events::Event; use super::{events, ffi}; @@ -46,11 +48,13 @@ pub struct XInputEventHandler { window: ffi::Window, ic: ffi::XIC, axis_list: Vec, - current_state: InputState + current_state: InputState, + multitouch: bool, } impl XInputEventHandler { - pub fn new(display: &Arc, window: ffi::Window, ic: ffi::XIC) -> XInputEventHandler { + pub fn new(display: &Arc, window: ffi::Window, ic: ffi::XIC, + window_attrs: &WindowAttributes) -> XInputEventHandler { // query XInput support let mut opcode: libc::c_int = 0; let mut event: libc::c_int = 0; @@ -113,7 +117,8 @@ impl XInputEventHandler { current_state: InputState { cursor_pos: (0.0, 0.0), axis_values: Vec::new() - } + }, + multitouch: window_attrs.multitouch, } } @@ -174,6 +179,10 @@ impl XInputEventHandler { match cookie.evtype { ffi::XI_ButtonPress | ffi::XI_ButtonRelease => { let event_data: &ffi::XIDeviceEvent = unsafe{mem::transmute(cookie.data)}; + if self.multitouch && (event_data.flags & ffi::XIPointerEmulated) != 0 { + // Deliver multi-touch events instead of emulated mouse events. + return None + } let state = if cookie.evtype == ffi::XI_ButtonPress { Pressed } else { @@ -205,6 +214,10 @@ impl XInputEventHandler { }, ffi::XI_Motion => { let event_data: &ffi::XIDeviceEvent = unsafe{mem::transmute(cookie.data)}; + if self.multitouch && (event_data.flags & ffi::XIPointerEmulated) != 0 { + // Deliver multi-touch events instead of emulated mouse events. + return None + } let axis_state = event_data.valuators; let mask = unsafe{ from_raw_parts(axis_state.mask, axis_state.mask_len as usize) }; let mut axis_count = 0; @@ -246,6 +259,9 @@ impl XInputEventHandler { ffi::XI_FocusIn => Some(Focused(true)), ffi::XI_FocusOut => Some(Focused(false)), ffi::XI_TouchBegin | ffi::XI_TouchUpdate | ffi::XI_TouchEnd => { + if !self.multitouch { + return None + } let event_data: &ffi::XIDeviceEvent = unsafe{mem::transmute(cookie.data)}; let phase = match cookie.evtype { ffi::XI_TouchBegin => TouchPhase::Started, diff --git a/src/api/x11/window.rs b/src/api/x11/window.rs index cf7854e..0196f67 100644 --- a/src/api/x11/window.rs +++ b/src/api/x11/window.rs @@ -562,7 +562,7 @@ impl Window { current_size: Cell::new((0, 0)), pending_events: Mutex::new(VecDeque::new()), cursor_state: Mutex::new(CursorState::Normal), - input_handler: Mutex::new(XInputEventHandler::new(display, window, ic)) + input_handler: Mutex::new(XInputEventHandler::new(display, window, ic, window_attrs)) }; // returning -- cgit v1.2.3