diff --git a/applets/pager/package/contents/ui/main.qml b/applets/pager/package/contents/ui/main.qml --- a/applets/pager/package/contents/ui/main.qml +++ b/applets/pager/package/contents/ui/main.qml @@ -51,6 +51,8 @@ property int dragSwitchDesktopId: -1 + property int wheelDelta: 0 + anchors.fill: parent acceptedButtons: Qt.NoButton @@ -100,10 +102,30 @@ } onWheel: { - if (wheel.angleDelta.y > 0 || wheel.angleDelta.x > 0) { - pagerModel.changePage((repeater.count + pagerModel.currentPage - 2) % repeater.count); - } else { - pagerModel.changePage(pagerModel.currentPage % repeater.count); + // Magic number 120 for common "one click, see: + // http://qt-project.org/doc/qt-5/qml-qtquick-wheelevent.html#angleDelta-prop + wheelDelta += wheel.angleDelta.y || wheel.angleDelta.x; + + var increment = 0; + + while (wheelDelta >= 120) { + wheelDelta -= 120; + increment++; + } + + while (wheelDelta <= -120) { + wheelDelta += 120; + increment--; + } + + while (increment != 0) { + if (increment < 0) { + pagerModel.changePage((pagerModel.currentPage + 1) % repeater.count); + } else { + pagerModel.changePage((repeater.count + pagerModel.currentPage - 1) % repeater.count); + } + + increment += (increment < 0) ? 1 : -1; } } @@ -187,7 +209,7 @@ id: dragTimer interval: 1000 onTriggered: { - if (dragSwitchDesktopId != -1 && dragSwitchDesktopId !== pagerModel.currentPage - 1) { + if (dragSwitchDesktopId != -1 && dragSwitchDesktopId !== pagerModel.currentPage) { pagerModel.changePage(dragSwitchDesktopId); } } @@ -260,7 +282,7 @@ id: desktop property int desktopId: index - property bool active: isActivityPager ? (index == pagerModel.currentPage) : (index + 1 == pagerModel.currentPage) + property bool active: (index == pagerModel.currentPage) mainText: model.display // our ToolTip has maximumLineCount of 8 which doesn't fit but QML doesn't diff --git a/applets/pager/plugin/pagermodel.h b/applets/pager/plugin/pagermodel.h --- a/applets/pager/plugin/pagermodel.h +++ b/applets/pager/plugin/pagermodel.h @@ -101,7 +101,7 @@ Q_INVOKABLE void moveWindow(int window, double x, double y, int targetItemId, int sourceItemId, qreal widthScaleFactor, qreal heightScaleFactor); - Q_INVOKABLE void changePage(int itemId); + Q_INVOKABLE void changePage(int page); Q_INVOKABLE void drop(QMimeData *mimeData, int itemId); Q_INVOKABLE void addDesktop(); Q_INVOKABLE void removeDesktop(); diff --git a/applets/pager/plugin/pagermodel.cpp b/applets/pager/plugin/pagermodel.cpp --- a/applets/pager/plugin/pagermodel.cpp +++ b/applets/pager/plugin/pagermodel.cpp @@ -351,7 +351,7 @@ int PagerModel::currentPage() const { if (d->pagerType == VirtualDesktops) { - return d->virtualDesktopInfo->currentDesktop(); + return d->virtualDesktopInfo->currentDesktop() - 1; } else { return d->activityInfo->runningActivities().indexOf(d->activityInfo->currentActivity()); } @@ -518,34 +518,33 @@ #endif } -void PagerModel::changePage(int itemId) +void PagerModel::changePage(int page) { + #if HAVE_X11 if (!KWindowSystem::isPlatformX11()) { return; } - const int targetId = (d->pagerType == VirtualDesktops) ? itemId + 1 : itemId; - - if (currentPage() == targetId) { + if (currentPage() == page) { if (d->showDesktop) { QDBusConnection::sessionBus().asyncCall(QDBusMessage::createMethodCall(QLatin1String("org.kde.plasmashell"), QLatin1String("/PlasmaShell"), QLatin1String("org.kde.PlasmaShell"), QLatin1String("toggleDashboard"))); } } else { if (d->pagerType == VirtualDesktops) { - KWindowSystem::setCurrentDesktop(targetId); + KWindowSystem::setCurrentDesktop(page + 1); } else { const QStringList &runningActivities = d->activityInfo->runningActivities(); - - if (targetId < runningActivities.length()) { + if (page < runningActivities.length()) { KActivities::Controller activitiesController; - activitiesController.setCurrentActivity(runningActivities.at(targetId)); + activitiesController.setCurrentActivity(runningActivities.at(page)); } } } + #else Q_UNUSED(itemId) #endif