Skip to content

Commit

Permalink
Made horizontal wheel scrolling work with Custom Command (#2074)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tsujan authored Jul 5, 2024
1 parent 2bbc017 commit 62ed09f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions plugin-customcommand/custombutton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions plugin-customcommand/lxqtcustomcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion plugin-customcommand/lxqtcustomcommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 62ed09f

Please sign in to comment.