From 53d1e26ff553b9eda5041929101c0ed054fc775b Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Fri, 14 Feb 2020 11:36:32 +0100 Subject: [PATCH] High resolution wheel-event support from libinput Is necessary because the support was added using a new event and a new getter. [ChangeLog][QtGui][libinput] Can now use the hires scrolling API from libinput 1.19, adding this feature to QPAs using libinput directly Task-number: QTBUG-96227 Change-Id: Ie30281de2f6391389e9e6049bc4117d3a8f63ad1 Reviewed-by: Shawn Rutledge --- src/gui/configure.cmake | 22 +++++++++++++++++++ .../input/libinput/qlibinputhandler.cpp | 4 ++++ .../input/libinput/qlibinputpointer.cpp | 16 ++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/gui/configure.cmake b/src/gui/configure.cmake index ea6752806e..a7fb77d48a 100644 --- a/src/gui/configure.cmake +++ b/src/gui/configure.cmake @@ -512,6 +512,23 @@ xcb_xkb_get_kbd_by_name_replies_key_names_value_list_sizeof(nullptr, 0, 0, 0, 0, } ") +# libinput_hires_wheel_support +qt_config_compile_test(libinput_hires_wheel_support + LABEL "libinput hires wheel support" + LIBRARIES + Libinput::Libinput + CODE +"#include +int main(void) +{ + /* BEGIN TEST: */ +libinput_event_type type = LIBINPUT_EVENT_POINTER_SCROLL_WHEEL; +libinput_event_pointer_get_scroll_value_v120(nullptr, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); + /* END TEST: */ + return 0; +} +") + # special case begin # directwrite (assumes DirectWrite2) qt_config_compile_test(directwrite @@ -678,6 +695,10 @@ qt_feature("libinput-axis-api" PRIVATE LABEL "axis API in libinput" CONDITION QT_FEATURE_libinput AND ON ) +qt_feature("libinput-hires-wheel-support" PRIVATE + LABEL "HiRes wheel support in libinput" + CONDITION QT_FEATURE_libinput AND TEST_libinput_hires_wheel_support +) qt_feature("lgmon" LABEL "lgmon" CONDITION libs.lgmon OR FIXME @@ -1223,6 +1244,7 @@ qt_configure_end_summary_section() # end of "Qt Gui" section qt_configure_add_summary_section(NAME "Features used by QPA backends") qt_configure_add_summary_entry(ARGS "evdev") qt_configure_add_summary_entry(ARGS "libinput") +qt_configure_add_summary_entry(ARGS "libinput_hires_wheel_support") qt_configure_add_summary_entry(ARGS "integrityhid") qt_configure_add_summary_entry(ARGS "mtdev") qt_configure_add_summary_entry(ARGS "tslib") diff --git a/src/platformsupport/input/libinput/qlibinputhandler.cpp b/src/platformsupport/input/libinput/qlibinputhandler.cpp index 95dfb46d16..bd7827feb8 100644 --- a/src/platformsupport/input/libinput/qlibinputhandler.cpp +++ b/src/platformsupport/input/libinput/qlibinputhandler.cpp @@ -208,7 +208,11 @@ void QLibInputHandler::processEvent(libinput_event *ev) case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE: m_pointer->processAbsMotion(libinput_event_get_pointer_event(ev)); break; +#if QT_CONFIG(libinput_hires_wheel_support) + case LIBINPUT_EVENT_POINTER_SCROLL_WHEEL: +#else case LIBINPUT_EVENT_POINTER_AXIS: +#endif m_pointer->processAxis(libinput_event_get_pointer_event(ev)); break; case LIBINPUT_EVENT_KEYBOARD_KEY: diff --git a/src/platformsupport/input/libinput/qlibinputpointer.cpp b/src/platformsupport/input/libinput/qlibinputpointer.cpp index db9e81b5df..bf26075f7c 100644 --- a/src/platformsupport/input/libinput/qlibinputpointer.cpp +++ b/src/platformsupport/input/libinput/qlibinputpointer.cpp @@ -133,16 +133,28 @@ void QLibInputPointer::processAxis(libinput_event_pointer *e) angleDelta.setX(qRound(value)); #else if (libinput_event_pointer_has_axis(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL)) { +#if QT_CONFIG(libinput_hires_wheel_support) + value = libinput_event_pointer_get_scroll_value_v120(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); +#else value = libinput_event_pointer_get_axis_value(e, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL); +#endif angleDelta.setY(qRound(value)); } if (libinput_event_pointer_has_axis(e, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL)) { +#if QT_CONFIG(libinput_hires_wheel_support) + value = libinput_event_pointer_get_scroll_value_v120(e, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); +#else value = libinput_event_pointer_get_axis_value(e, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL); +#endif angleDelta.setX(qRound(value)); } #endif - const int factor = 8; - angleDelta *= -factor; +#if QT_CONFIG(libinput_hires_wheel_support) + const int factor = -1; +#else + const int factor = -8; +#endif + angleDelta *= factor; Qt::KeyboardModifiers mods = QGuiApplicationPrivate::inputDeviceManager()->keyboardModifiers(); QWindowSystemInterface::handleWheelEvent(nullptr, m_pos, m_pos, QPoint(), angleDelta, mods); }