summaryrefslogtreecommitdiffstats
path: root/platform/x11/os_x11.h
diff options
context:
space:
mode:
authorCosmic Chip Socket <34800072+cosmicchipsocket@users.noreply.github.com>2018-08-17 18:59:26 -0400
committerRémi Verschelde <rverschelde@gmail.com>2018-12-14 23:51:20 +0100
commitcf124b1415c4718325514ec32794fb0587885e3b (patch)
tree871970d65029ba383f5a9d3b66054a748ab6a11f /platform/x11/os_x11.h
parent5f32fc82087404ac2c803770dc9d1e3711fc14fd (diff)
downloadredot-engine-cf124b1415c4718325514ec32794fb0587885e3b.tar.gz
Use XInput2 RawMotion to generate MouseMotion events
The current system for capturing the mouse and generating motion events on X11 has issues with inaccurate and lopsided input. This is because both XQueryPointer and XWarpPointer work in terms of integer coordinates when the underlying X11 input driver may be tracking the mouse using subpixel coordinates. When warping the pointer, the fractional part of the pointer position is discarded. To work around this issue, the fix uses raw motion events from XInput 2. These events report relative motion and are not affected by pointer warping. Additionally, this means Godot is able to detect motion at a higher resolution under X11. Because this is raw mouse input, it is not affected by the user's pointer speed and acceleration settings. This is the same system as SDL2 uses for its relative motion. Multitouch input on X requires XInput 2.2. Raw motion events require XInput 2.0. Since 2.0 is old enough, this is now the minimum requirement to use Godot on X.
Diffstat (limited to 'platform/x11/os_x11.h')
-rw-r--r--platform/x11/os_x11.h24
1 files changed, 15 insertions, 9 deletions
diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h
index 68a1e51376..4e73c5beec 100644
--- a/platform/x11/os_x11.h
+++ b/platform/x11/os_x11.h
@@ -48,11 +48,9 @@
#include <X11/Xcursor/Xcursor.h>
#include <X11/Xlib.h>
+#include <X11/extensions/XInput2.h>
#include <X11/extensions/Xrandr.h>
#include <X11/keysym.h>
-#ifdef TOUCH_ENABLED
-#include <X11/extensions/XInput2.h>
-#endif
// Hints for X11 fullscreen
typedef struct {
@@ -121,24 +119,32 @@ class OS_X11 : public OS_Unix {
bool im_active;
Vector2 im_position;
- Point2i last_mouse_pos;
+ Point2 last_mouse_pos;
bool last_mouse_pos_valid;
Point2i last_click_pos;
uint64_t last_click_ms;
int last_click_button_index;
uint32_t last_button_state;
-#ifdef TOUCH_ENABLED
+
struct {
int opcode;
- Vector<int> devices;
- XIEventMask event_mask;
+ Vector<int> touch_devices;
+ Map<int, Vector2> absolute_devices;
+ XIEventMask all_event_mask;
+ XIEventMask all_master_event_mask;
Map<int, Vector2> state;
Vector2 mouse_pos_to_filter;
- } touch;
-#endif
+ Vector2 relative_motion;
+ Vector2 raw_pos;
+ Vector2 old_raw_pos;
+ ::Time last_relative_time;
+ } xi;
+
+ bool refresh_device_info();
unsigned int get_mouse_button_state(unsigned int p_x11_button, int p_x11_type);
void get_key_modifier_state(unsigned int p_x11_state, Ref<InputEventWithModifiers> state);
+ void flush_mouse_motion();
MouseMode mouse_mode;
Point2i center;