mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
taskswitcher: implement left/right swipe gesture
This commit is contained in:
parent
26aaa808b0
commit
fc300d1a28
2 changed files with 28 additions and 26 deletions
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue