kwin/mobiletaskswitcher: Port swipe to dismiss to use MouseArea from DragHandler

This commit is contained in:
Devin Lin 2023-03-30 23:53:31 -07:00
parent 88d9c066af
commit c4f80992cc

View file

@ -63,28 +63,51 @@ Item {
} }
onClicked: { onClicked: {
if (!taskSwitcher.taskSwitcherState.currentlyBeingOpened) { if (!taskSwitcher.taskSwitcherState.currentlyBeingOpened && !passedDragThreshold) {
delegate.activateApp(); delegate.activateApp();
} }
} }
// drag up gesture // pixels before we start treating it as drag event
DragHandler { readonly property real dragThreshold: 5
id: dragHandler
target: parent
enabled: !taskSwitcher.taskSwitcherState.currentlyBeingOpened property real startPosition: 0
property bool hasStartPosition: false
property bool passedDragThreshold: false
yAxis.enabled: true onPositionChanged: (mouse) => {
xAxis.enabled: false // map it to the root area, so that it doesn't jitter (since this item is moving)
yAxis.maximum: 0 const yPos = control.mapToItem(delegate, mouse.x, mouse.y).y
// y > 0 - dragging down (opening the app) // reset start position
if (!hasStartPosition) {
startPosition = yPos;
hasStartPosition = true;
}
// set threshold
if (!passedDragThreshold && Math.abs(y) > dragThreshold) {
passedDragThreshold = true;
// TODO: request that FlickContainer be not interactive (so we don't change position in list while swiping up)
}
// update position
// y < 0 - dragging up (dismissing the app) // y < 0 - dragging up (dismissing the app)
onActiveChanged: { y = Math.min(0, yPos - startPosition);
}
onPressedChanged: {
yAnimator.stop(); yAnimator.stop();
if (control.movingUp && parent.y < -PlasmaCore.Units.gridUnit * 2) { // reset values
if (pressed) {
hasStartPosition = false;
passedDragThreshold = false;
}
// run animation when finger lets go
if (!pressed) {
if (control.movingUp && control.y < -PlasmaCore.Units.gridUnit * 2) {
yAnimator.to = -root.height; yAnimator.to = -root.height;
} else { } else {
yAnimator.to = 0; yAnimator.to = 0;
@ -105,7 +128,7 @@ Item {
NumberAnimation on y { NumberAnimation on y {
id: yAnimator id: yAnimator
running: !dragHandler.active running: !control.pressed
duration: PlasmaCore.Units.longDuration duration: PlasmaCore.Units.longDuration
easing.type: Easing.InOutQuad easing.type: Easing.InOutQuad
to: 0 to: 0