summaryrefslogtreecommitdiff
path: root/platform/x11
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2018-02-24 03:04:30 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2018-04-30 19:03:38 +0200
commitde9d40a9537bafa613dc54f2200b7509ad6fa9e3 (patch)
tree746f887af7e07a5e89878500fc713cd5548409ac /platform/x11
parent3a5b25d5b489ad88c2861c9c37b56469580fbf03 (diff)
Implement universal translation of touch to mouse
Now generating mouse events from touch is optional (on by default) and it's performed by `InputDefault` instead of having each OS abstraction doing it. (*) The translation algorithm waits for a touch index to be pressed and tracks it translating its events to mouse events until it is raised, while ignoring other pointers. Furthermore, to avoid an stuck "touch mouse", since not all platforms may report touches raised when the window is unfocused, it checks if touches are still down by the time it's focused again and if so it resets the state of the emulated mouse. *: In the case of Windows, since it already provides touch-to-mouse translation by itself, "echo" mouse events are filtered out to have it working like the rest. On X11 a little hack has been needed to avoid a case of a spurious mouse motion event that is generated during touch interaction. Plus: Improve/fix tracking of current mouse position. ** Summary of changes to settings: ** - `display/window/handheld/emulate_touchscreen` becomes `input/pointing_devices/emulate_touch_from_mouse` - New setting: `input/pointing_devices/emulate_mouse_from_touch`
Diffstat (limited to 'platform/x11')
-rw-r--r--platform/x11/os_x11.cpp17
-rw-r--r--platform/x11/os_x11.h1
2 files changed, 18 insertions, 0 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp
index 1928800d8c..336068cb1e 100644
--- a/platform/x11/os_x11.cpp
+++ b/platform/x11/os_x11.cpp
@@ -1690,6 +1690,11 @@ void OS_X11::process_xevents() {
if (touch.state.has(index)) // Defensive
break;
touch.state[index] = pos;
+ if (touch.state.size() == 1) {
+ // X11 may send a motion event when a touch gesture begins, that would result
+ // in a spurious mouse motion event being sent to Godot; remember it to be able to filter it out
+ touch.mouse_pos_to_filter = pos;
+ }
input->parse_input_event(st);
} else {
if (!touch.state.has(index)) // Defensive
@@ -1896,6 +1901,18 @@ void OS_X11::process_xevents() {
// to be able to send relative motion events.
Point2i pos(event.xmotion.x, event.xmotion.y);
+ // Avoidance of spurious mouse motion (see handling of touch)
+ bool filter = false;
+ // Adding some tolerance to match better Point2i to Vector2
+ if (touch.state.size() && Vector2(pos).distance_squared_to(touch.mouse_pos_to_filter) < 2) {
+ filter = true;
+ }
+ // Invalidate to avoid filtering a possible legitimate similar event coming later
+ touch.mouse_pos_to_filter = Vector2(1e10, 1e10);
+ if (filter) {
+ break;
+ }
+
if (mouse_mode == MOUSE_MODE_CAPTURED) {
if (pos == Point2i(current_videomode.width / 2, current_videomode.height / 2)) {
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 610dba0716..0a39da77de 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -127,6 +127,7 @@ class OS_X11 : public OS_Unix {
Vector<int> devices;
XIEventMask event_mask;
Map<int, Vector2> state;
+ Vector2 mouse_pos_to_filter;
} touch;
#endif