diff options
author | tomaka <pierre.krieger1708@gmail.com> | 2015-10-23 17:25:04 +0200 |
---|---|---|
committer | tomaka <pierre.krieger1708@gmail.com> | 2015-10-23 17:25:04 +0200 |
commit | 7f2c161704deb4a51a355bd7cc9b7f25451b569a (patch) | |
tree | 7a3b50482c60294e88b29d92cbb4c5827d37cdcd /src/api | |
parent | aaa9e508bdf564c5a32c8bb96d21c8357841555b (diff) | |
parent | 8c0dfe19c29f079c06d556fbf645db8eafb713da (diff) | |
download | glutin-7f2c161704deb4a51a355bd7cc9b7f25451b569a.tar.gz glutin-7f2c161704deb4a51a355bd7cc9b7f25451b569a.zip |
Merge pull request #644 from mbrubeck/mouse-emulated
Change X11 events based on `multitouch` option
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/x11/input.rs | 22 | ||||
-rw-r--r-- | src/api/x11/window.rs | 2 |
2 files changed, 20 insertions, 4 deletions
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<Axis>, - current_state: InputState + current_state: InputState, + multitouch: bool, } impl XInputEventHandler { - pub fn new(display: &Arc<XConnection>, window: ffi::Window, ic: ffi::XIC) -> XInputEventHandler { + pub fn new(display: &Arc<XConnection>, 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 |