From fc300d1a28f46445315773ba183963c15303199e Mon Sep 17 00:00:00 2001 From: Yari Polla Date: Tue, 3 May 2022 01:38:42 +0200 Subject: [PATCH] taskswitcher: implement left/right swipe gesture --- .../navigationpanel/NavigationGestureArea.qml | 32 +++++++++---------- .../qml/taskswitcher/TaskSwitcherState.qml | 22 +++++++------ 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/components/mobileshell/qml/navigationpanel/NavigationGestureArea.qml b/components/mobileshell/qml/navigationpanel/NavigationGestureArea.qml index 094d771f..c72093ac 100644 --- a/components/mobileshell/qml/navigationpanel/NavigationGestureArea.qml +++ b/components/mobileshell/qml/navigationpanel/NavigationGestureArea.qml @@ -21,11 +21,10 @@ Item { id: root property var taskSwitcher - + MouseArea { id: mouseArea anchors.fill: parent - drag.filterChildren: true // drag gesture property int oldMouseY: 0 @@ -33,37 +32,36 @@ Item { property int oldMouseX: 0 property int startMouseX: 0 property bool opening: false + + enabled: !taskSwitcher.visible onPressed: { - startMouseX = oldMouseX = mouse.y; + startMouseX = oldMouseX = mouse.x; startMouseY = oldMouseY = mouse.y; } - - onPositionChanged: { - if (!opening && Math.abs(startMouseY - oldMouseY) < root.height) { - oldMouseY = mouse.y; - return; - } else if (mouseArea.pressed) { - opening = true; - } - if (root.taskSwitcher.visible) { + onPositionChanged: { + if (root.taskSwitcher.visible || taskSwitcher.taskSwitcherState.currentlyBeingOpened) { // update task switcher drag let offsetY = (mouse.y - oldMouseY) * 0.5; // we want to make the gesture take a longer swipe than it being pixel perfect let offsetX = (mouse.x - oldMouseX) * 0.7; // we want to make the gesture not too hard to swipe, but not too easy taskSwitcher.taskSwitcherState.yPosition = Math.max(0, taskSwitcher.taskSwitcherState.yPosition - offsetY); - taskSwitcher.taskSwitcherState.xPosition -= offsetX; + taskSwitcher.taskSwitcherState.xPosition = taskSwitcher.taskSwitcherState.xPosition - offsetX; } - if (!root.taskSwitcher.visible && Math.abs(startMouseY - mouse.y) > PlasmaCore.Units.gridUnit && taskSwitcher.tasksCount) { - // start task switcher gesture + if (!root.taskSwitcher.visible && Math.abs(startMouseX - mouse.x) > PlasmaCore.Units.gridUnit && taskSwitcher.tasksCount && taskSwitcher.tasksModel.activeTask.row >= 0){ + // start switch task gesture + taskSwitcher.taskSwitcherState.scrollingTasks = true; + root.taskSwitcher.show(false); + } else if (!root.taskSwitcher.visible && Math.abs(startMouseY - mouse.y) > PlasmaCore.Units.gridUnit && taskSwitcher.tasksCount) { + // start task switcher opening gesture root.taskSwitcher.show(false); } - + oldMouseY = mouse.y; oldMouseX = mouse.x; } - + onReleased: { if (taskSwitcher.taskSwitcherState.currentlyBeingOpened) { taskSwitcher.taskSwitcherState.updateState(); diff --git a/components/mobileshell/qml/taskswitcher/TaskSwitcherState.qml b/components/mobileshell/qml/taskswitcher/TaskSwitcherState.qml index 242567f0..0f5229a8 100644 --- a/components/mobileshell/qml/taskswitcher/TaskSwitcherState.qml +++ b/components/mobileshell/qml/taskswitcher/TaskSwitcherState.qml @@ -62,6 +62,9 @@ QtObject { // whether we are in a swipe up gesture to open the task switcher property bool currentlyBeingOpened: false + // whether we are in a swipe left/right gesture to walk through tasks + property bool scrollingTasks: false + readonly property int currentTaskIndex: { let candidateIndex = Math.round(-xPosition / (taskSpacing + taskWidth)); return Math.max(0, Math.min(taskSwitcher.tasksCount - 1, candidateIndex)); @@ -107,10 +110,10 @@ QtObject { let finalScale = Math.max(0, Math.min(maxScale, maxScale - subtract)); // animate scale only if we are *not* opening from the homescreen - if (wasInActiveTask || !currentlyBeingOpened) { + if ((wasInActiveTask || !currentlyBeingOpened) && !scrollingTasks) { return finalScale; } - return 1; + return scrollingTasks ? maxScale : 1; } // ~~ signals and functions ~~ @@ -159,7 +162,7 @@ QtObject { cancelAnimations(); // update vertical state - if (movingUp || root.yPosition >= openedYPosition) { + if ((movingUp || root.yPosition >= openedYPosition) && !scrollingTasks) { // open task switcher and stay openAnim.restart(); } else { @@ -197,20 +200,20 @@ QtObject { easing.type: Easing.OutBack } - property var openAnim: NumberAnimation { + property var openAnim: NumberAnimation { target: root property: "yPosition" - to: openedYPosition + to: openedYPosition duration: MobileShell.MobileShellSettings.animationsEnabled ? 300 : 0 - easing.type: Easing.OutBack + easing.type: Easing.OutBack onFinished: { root.currentlyBeingOpened = false; } } - + property var closeAnim: NumberAnimation { - target: root + target: root property: "yPosition" to: 0 duration: MobileShell.MobileShellSettings.animationsEnabled ? PlasmaCore.Units.longDuration : 0 @@ -218,8 +221,9 @@ QtObject { onFinished: { root.currentlyBeingOpened = false; + scrollingTasks = false; taskSwitcher.instantHide(); - + if (root.wasInActiveTask) { taskSwitcher.setSingleActiveWindow(root.currentTaskIndex); }