diff --git a/tabbox/tabboxhandler.h b/tabbox/tabboxhandler.h --- a/tabbox/tabboxhandler.h +++ b/tabbox/tabboxhandler.h @@ -334,6 +334,8 @@ */ QModelIndex first() const; + bool eventFilter(QObject *watcher, QEvent *event) override; + Q_SIGNALS: /** * This signal is fired when the TabBoxConfig changes diff --git a/tabbox/tabboxhandler.cpp b/tabbox/tabboxhandler.cpp --- a/tabbox/tabboxhandler.cpp +++ b/tabbox/tabboxhandler.cpp @@ -92,6 +92,7 @@ */ bool isShown; TabBoxClient *lastRaisedClient, *lastRaisedClientSucc; + int wheelAngleDelta = 0; private: QObject *createSwitcherItem(bool desktopMode); @@ -336,6 +337,10 @@ // everything is prepared, so let's make the whole thing visible item->setVisible(true); } + if (QWindow *w = window()) { + wheelAngleDelta = 0; + w->installEventFilter(q); + } #endif } @@ -607,6 +612,35 @@ return model->index(0, 0); } +bool TabBoxHandler::eventFilter(QObject *watched, QEvent *e) +{ + if (watched == d->window()) { + if (e->type() == QEvent::Wheel) { + QWheelEvent *event = static_cast(e); + // On x11 the delta for vertical scrolling might also be on X for whatever reason + const int delta = event->angleDelta().y() != 0 ? event->angleDelta().y() : event->angleDelta().x(); + d->wheelAngleDelta += delta; + while (d->wheelAngleDelta <= -120) { + d->wheelAngleDelta += 120; + const QModelIndex index = nextPrev(true); + if (index.isValid()) { + setCurrentIndex(index); + } + } + while (d->wheelAngleDelta >= 120) { + d->wheelAngleDelta -= 120; + const QModelIndex index = nextPrev(false); + if (index.isValid()) { + setCurrentIndex(index); + } + } + return true; + } + } + // pass on + return QObject::eventFilter(watched, e); +} + TabBoxHandler* tabBox = nullptr; TabBoxClient::TabBoxClient()