aboutsummaryrefslogtreecommitdiffstats
path: root/src/api
diff options
context:
space:
mode:
authorMatt Brubeck <mbrubeck@limpet.net>2015-10-22 16:29:48 -0700
committerMatt Brubeck <mbrubeck@limpet.net>2015-10-23 08:01:03 -0700
commit8c0dfe19c29f079c06d556fbf645db8eafb713da (patch)
tree18f09ed58dbfd81a8ab5613754a4425f2d067fb0 /src/api
parent6cefaa12be09c76bd0320a22a513e9bc99ea6337 (diff)
downloadglutin-8c0dfe19c29f079c06d556fbf645db8eafb713da.tar.gz
glutin-8c0dfe19c29f079c06d556fbf645db8eafb713da.zip
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.
Diffstat (limited to 'src/api')
-rw-r--r--src/api/x11/input.rs22
-rw-r--r--src/api/x11/window.rs2
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