summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Hein <hein@kde.org>2017-01-31 06:15:52 (GMT)
committerEike Hein <hein@kde.org>2017-02-01 10:47:37 (GMT)
commitfff65ad696f4dc34391a0e9eb4b9ef0ed09a9c42 (patch)
treef9b7e37d187ddf962be3ee8ddb8fbba418014dff
parent771e57f3b2c19f4e6f867c01c2457ec87531b4cf (diff)
Revamp (Activity) Pager wheel handling
Summary: Fixes the mouse wheel not working to switch activities by refactoring the code so currentPage() always behaves the same and accounting for virt desktops starting at 1 only where it actually counts, then fixing an off-by-one along the way. BUG:375769 Also introduces the wheel event handling logic used in Task Manager and many other UIs to avoid reacting overly sensitively to gesture scroll events from trackpads. Reviewers: #plasma Subscribers: plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D4360
-rw-r--r--applets/pager/package/contents/ui/main.qml34
-rw-r--r--applets/pager/plugin/pagermodel.cpp17
-rw-r--r--applets/pager/plugin/pagermodel.h2
3 files changed, 37 insertions, 16 deletions
diff --git a/applets/pager/package/contents/ui/main.qml b/applets/pager/package/contents/ui/main.qml
index 255ee36..2a9af6a 100644
--- a/applets/pager/package/contents/ui/main.qml
+++ b/applets/pager/package/contents/ui/main.qml
@@ -51,6 +51,8 @@ MouseArea {
property int dragSwitchDesktopId: -1
+ property int wheelDelta: 0
+
anchors.fill: parent
acceptedButtons: Qt.NoButton
@@ -100,10 +102,30 @@ MouseArea {
}
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 @@ MouseArea {
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 @@ MouseArea {
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.cpp b/applets/pager/plugin/pagermodel.cpp
index 9906e3f..a0d44a7 100644
--- a/applets/pager/plugin/pagermodel.cpp
+++ b/applets/pager/plugin/pagermodel.cpp
@@ -351,7 +351,7 @@ void PagerModel::setScreenGeometry(const QRect &geometry)
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,16 +518,15 @@ void PagerModel::moveWindow(int window, double x, double y, int targetItemId, in
#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"),
@@ -536,16 +535,16 @@ void PagerModel::changePage(int itemId)
}
} 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
diff --git a/applets/pager/plugin/pagermodel.h b/applets/pager/plugin/pagermodel.h
index 2841e90..4782266 100644
--- a/applets/pager/plugin/pagermodel.h
+++ b/applets/pager/plugin/pagermodel.h
@@ -101,7 +101,7 @@ public:
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();