From 52b4ee3338c185787ee9a0f03c5befd117c0de3a Mon Sep 17 00:00:00 2001 From: Xaver Hugl Date: Wed, 18 Jan 2023 13:59:52 +0100 Subject: [PATCH] input: don't trigger titlebar actions on every event with a touchpad Instead, accumulate the values and only trigger an action when the user has scrolled far enough BUG: 444737 --- src/input.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/input.cpp b/src/input.cpp index 0a3f0b9255..b4c5b411d5 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -1345,6 +1345,28 @@ private: QPointF m_lastLocalTouchPos; }; +class MouseWheelAccumulator +{ +public: + float accumulate(WheelEvent *event) + { + m_scrollV120 += event->deltaV120(); + m_scrollDistance += event->delta(); + if (std::abs(m_scrollV120) >= 120 || (!event->deltaV120() && std::abs(m_scrollDistance) >= 15)) { + float ret = m_scrollDistance; + m_scrollV120 = 0; + m_scrollDistance = 0; + return ret; + } else { + return 0; + } + } + +private: + float m_scrollDistance = 0; + int m_scrollV120 = 0; +}; + class DecorationEventFilter : public InputEventFilter { public: @@ -1400,7 +1422,6 @@ public: } const QPointF localPos = event->globalPosition() - decoration->window()->pos(); const Qt::Orientation orientation = (event->angleDelta().x() != 0) ? Qt::Horizontal : Qt::Vertical; - const int delta = event->angleDelta().x() != 0 ? event->angleDelta().x() : event->angleDelta().y(); QWheelEvent e(localPos, event->globalPosition(), QPoint(), event->angleDelta(), event->buttons(), @@ -1413,8 +1434,10 @@ public: return true; } if ((orientation == Qt::Vertical) && decoration->window()->titlebarPositionUnderMouse()) { - decoration->window()->performMouseCommand(options->operationTitlebarMouseWheel(delta * -1), - event->globalPosition()); + if (float delta = m_accumulator.accumulate(event)) { + decoration->window()->performMouseCommand(options->operationTitlebarMouseWheel(delta * -1), + event->globalPosition()); + } } return true; } @@ -1554,6 +1577,7 @@ public: private: QPointF m_lastGlobalTouchPos; QPointF m_lastLocalTouchPos; + MouseWheelAccumulator m_accumulator; }; #if KWIN_BUILD_TABBOX