From 62ed09f70f9b8f88e8e3687b85e3be70255e2e0f Mon Sep 17 00:00:00 2001 From: tsujan Date: Fri, 5 Jul 2024 21:52:37 +0330 Subject: [PATCH] Made horizontal wheel scrolling work with Custom Command (#2074) Previously, only the vertical wheel scrolling worked, which might not be ideal with a touchpad. A confession: My concern wasn't the touchpad ;) I made this patch as a workaround for a regression about Wayland, because of which, Qt's vertical and horizontal wheel events are swapped under special circumstances. However, the end result is independent of that regression. --- plugin-customcommand/custombutton.cpp | 6 ++++-- plugin-customcommand/lxqtcustomcommand.cpp | 6 +++--- plugin-customcommand/lxqtcustomcommand.h | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/plugin-customcommand/custombutton.cpp b/plugin-customcommand/custombutton.cpp index a8ae7ac5f..8dfc99790 100644 --- a/plugin-customcommand/custombutton.cpp +++ b/plugin-customcommand/custombutton.cpp @@ -76,8 +76,10 @@ CustomButton::~CustomButton() = default; void CustomButton::wheelEvent(QWheelEvent *event) { - int y = event->angleDelta().y(); - emit wheelScrolled(y); + QPoint anglePoint = event->angleDelta(); + bool horizontal(qAbs(event->angleDelta().x()) > qAbs(anglePoint.y())); + int delta = horizontal ? anglePoint.x() : anglePoint.y(); + emit wheelScrolled(delta); event->accept(); } diff --git a/plugin-customcommand/lxqtcustomcommand.cpp b/plugin-customcommand/lxqtcustomcommand.cpp index df5477de9..5fb145f91 100644 --- a/plugin-customcommand/lxqtcustomcommand.cpp +++ b/plugin-customcommand/lxqtcustomcommand.cpp @@ -214,11 +214,11 @@ void LXQtCustomCommand::updateButton() { mButton->updateWidth(); } -void LXQtCustomCommand::handleWheelScrolled(int yDelta) +void LXQtCustomCommand::handleWheelScrolled(int delta) { - if (yDelta > 0 && !mWheelUp.isEmpty()) + if (delta > 0 && !mWheelUp.isEmpty()) runDetached(mWheelUp); - else if (yDelta < 0 && !mWheelDown.isEmpty()) + else if (delta < 0 && !mWheelDown.isEmpty()) runDetached(mWheelDown); } diff --git a/plugin-customcommand/lxqtcustomcommand.h b/plugin-customcommand/lxqtcustomcommand.h index ffb5679d3..ec279f812 100644 --- a/plugin-customcommand/lxqtcustomcommand.h +++ b/plugin-customcommand/lxqtcustomcommand.h @@ -56,7 +56,7 @@ protected slots: private slots: void handleClick(); void handleFinished(int exitCode, QProcess::ExitStatus exitStatus); - void handleWheelScrolled(int yDelta); + void handleWheelScrolled(int delta); void updateButton(); void runCommand(); void runDetached(QString command);