diff options
Diffstat (limited to 'platform/x11/os_x11.cpp')
-rw-r--r-- | platform/x11/os_x11.cpp | 80 |
1 files changed, 73 insertions, 7 deletions
diff --git a/platform/x11/os_x11.cpp b/platform/x11/os_x11.cpp index 39160ee720..c695d657e7 100644 --- a/platform/x11/os_x11.cpp +++ b/platform/x11/os_x11.cpp @@ -83,6 +83,12 @@ #define XINPUT_CLIENT_VERSION_MAJOR 2 #define XINPUT_CLIENT_VERSION_MINOR 2 +#define VALUATOR_ABSX 0 +#define VALUATOR_ABSY 1 +#define VALUATOR_PRESSURE 2 +#define VALUATOR_TILTX 3 +#define VALUATOR_TILTY 4 + static const double abs_resolution_mult = 10000.0; static const double abs_resolution_range_mult = 10.0; @@ -665,6 +671,15 @@ bool OS_X11::refresh_device_info() { int range_min_y = 0; int range_max_x = 0; int range_max_y = 0; + int pressure_resolution = 0; + int pressure_min = 0; + int pressure_max = 0; + int tilt_resolution_x = 0; + int tilt_resolution_y = 0; + int tilt_range_min_x = 0; + int tilt_range_min_y = 0; + int tilt_range_max_x = 0; + int tilt_range_max_y = 0; for (int j = 0; j < dev->num_classes; j++) { #ifdef TOUCH_ENABLED if (dev->classes[j]->type == XITouchClass && ((XITouchClassInfo *)dev->classes[j])->mode == XIDirectTouch) { @@ -674,16 +689,28 @@ bool OS_X11::refresh_device_info() { if (dev->classes[j]->type == XIValuatorClass) { XIValuatorClassInfo *class_info = (XIValuatorClassInfo *)dev->classes[j]; - if (class_info->number == 0 && class_info->mode == XIModeAbsolute) { + if (class_info->number == VALUATOR_ABSX && class_info->mode == XIModeAbsolute) { resolution_x = class_info->resolution; range_min_x = class_info->min; range_max_x = class_info->max; absolute_mode = true; - } else if (class_info->number == 1 && class_info->mode == XIModeAbsolute) { + } else if (class_info->number == VALUATOR_ABSY && class_info->mode == XIModeAbsolute) { resolution_y = class_info->resolution; range_min_y = class_info->min; range_max_y = class_info->max; absolute_mode = true; + } else if (class_info->number == VALUATOR_PRESSURE && class_info->mode == XIModeAbsolute) { + pressure_resolution = class_info->resolution; + pressure_min = class_info->min; + pressure_max = class_info->max; + } else if (class_info->number == VALUATOR_TILTX && class_info->mode == XIModeAbsolute) { + tilt_resolution_x = class_info->resolution; + tilt_range_min_x = class_info->min; + tilt_range_max_x = class_info->max; + } else if (class_info->number == VALUATOR_TILTY && class_info->mode == XIModeAbsolute) { + tilt_resolution_y = class_info->resolution; + tilt_range_min_y = class_info->min; + tilt_range_max_y = class_info->max; } } } @@ -703,6 +730,18 @@ bool OS_X11::refresh_device_info() { xi.absolute_devices[dev->deviceid] = Vector2(abs_resolution_mult / resolution_x, abs_resolution_mult / resolution_y); print_verbose("XInput: Absolute pointing device: " + String(dev->name)); } + + if (pressure_resolution <= 0) { + pressure_resolution = (pressure_max - pressure_min); + } + if (tilt_resolution_x <= 0) { + tilt_resolution_x = (tilt_range_max_x - tilt_range_min_x); + } + if (tilt_resolution_y <= 0) { + tilt_resolution_y = (tilt_range_max_y - tilt_range_min_y); + } + xi.pressure = 0; + xi.pen_devices[dev->deviceid] = Vector3(pressure_resolution, tilt_resolution_x, tilt_resolution_y); } XIFreeDeviceInfo(info); @@ -1767,7 +1806,8 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { XKeyEvent xkeyevent_no_mod = *xkeyevent; xkeyevent_no_mod.state &= ~ShiftMask; xkeyevent_no_mod.state &= ~ControlMask; - XLookupString(&xkeyevent_no_mod, str, 256, &keysym_keycode, NULL); + XLookupString(xkeyevent, str, 256, &keysym_unicode, NULL); + XLookupString(&xkeyevent_no_mod, NULL, 0, &keysym_keycode, NULL); // Meanwhile, XLookupString returns keysyms useful for unicode. @@ -1777,8 +1817,6 @@ void OS_X11::handle_key_event(XKeyEvent *p_event, bool p_echo) { xmblen = 8; } - keysym_unicode = keysym_keycode; - if (xkeyevent->type == KeyPress && xic) { Status status; @@ -2096,14 +2134,39 @@ void OS_X11::process_xevents() { double rel_x = 0.0; double rel_y = 0.0; + double pressure = 0.0; + double tilt_x = 0.0; + double tilt_y = 0.0; - if (XIMaskIsSet(raw_event->valuators.mask, 0)) { + if (XIMaskIsSet(raw_event->valuators.mask, VALUATOR_ABSX)) { rel_x = *values; values++; } - if (XIMaskIsSet(raw_event->valuators.mask, 1)) { + if (XIMaskIsSet(raw_event->valuators.mask, VALUATOR_ABSY)) { rel_y = *values; + values++; + } + + if (XIMaskIsSet(raw_event->valuators.mask, VALUATOR_PRESSURE)) { + pressure = *values; + values++; + } + + if (XIMaskIsSet(raw_event->valuators.mask, VALUATOR_TILTX)) { + tilt_x = *values; + values++; + } + + if (XIMaskIsSet(raw_event->valuators.mask, VALUATOR_TILTY)) { + tilt_y = *values; + } + + Map<int, Vector3>::Element *pen_info = xi.pen_devices.find(device_id); + if (pen_info) { + Vector3 mult = pen_info->value(); + if (mult.x != 0.0) xi.pressure = pressure / mult.x; + if ((mult.y != 0.0) && (mult.z != 0.0)) xi.tilt = Vector2(tilt_x / mult.y, tilt_y / mult.z); } // https://bugs.freedesktop.org/show_bug.cgi?id=71609 @@ -2418,6 +2481,9 @@ void OS_X11::process_xevents() { Ref<InputEventMouseMotion> mm; mm.instance(); + mm->set_pressure(xi.pressure); + mm->set_tilt(xi.tilt); + // Make the absolute position integral so it doesn't look _too_ weird :) Point2i posi(pos); |