shift-shell/shell/contents/lockscreen/FlickContainer.qml
Devin Lin 3adcd1d51c swipearea: Add support for touchpad
This adds support for touchpad scrolling in various shell components, such as the lockscreen, homescreen and action drawer.

Currently TODO because it appears to be very buggy when there is a control underneath that also accepts touchpad input (ex. flickable). The touchpad scroll start appears to get called by Qt, but not the end event, so I am unable to "let go" of the flick. Not sure if it's a wayland issue.

This also appears to not work in the nested KWin session, not sure if it's because of libinput or something
2024-08-01 01:53:52 +00:00

98 lines
2.3 KiB
QML

// SPDX-FileCopyrightText: 2021-2024 Devin Lin <devin@kde.org>
// SPDX-License-Identifier: LGPL-2.0-or-later
import QtQuick 2.15
import QtQuick.Layouts 1.15
import org.kde.kirigami 2.20 as Kirigami
import org.kde.plasma.private.mobileshell as MobileShell
MobileShell.SwipeArea {
id: root
required property real keypadHeight
property real animationDuration
readonly property real openFactor: position / keypadHeight
property real position: 0
property bool movingUp: false
property real __oldPosition: position
signal opened()
mode: MobileShell.SwipeArea.VerticalOnly
function cancelAnimations() {
positionAnim.stop();
}
function goToOpenPosition() {
positionAnim.to = keypadHeight;
positionAnim.restart();
}
function goToClosePosition() {
positionAnim.to = 0;
positionAnim.restart();
}
function updateState() {
// don't update state if at end
if (position <= 0 || position >= keypadHeight) return;
if (movingUp) {
goToOpenPosition();
} else {
goToClosePosition();
}
}
NumberAnimation on position {
id: positionAnim
duration: root.animationDuration
easing.type: Easing.OutExpo
onFinished: {
if (root.position === keypadHeight) {
root.opened();
}
}
}
onPositionChanged: {
movingUp = __oldPosition <= position;
__oldPosition = position;
// Limit position to between 0 and keypadHeight
if (position > keypadHeight) {
position = keypadHeight;
} else if (position < 0) {
position = 0;
}
}
function __startSwipe() {
cancelAnimations();
}
function __endSwipe() {
if (!positionAnim.running) {
updateState();
}
}
function __moveSwipe(totalDeltaX, totalDeltaY, deltaX, deltaY) {
position = Math.max(0, Math.min(keypadHeight, position - deltaY));
}
onSwipeStarted: __startSwipe()
onSwipeEnded: __endSwipe()
onSwipeMove: __moveSwipe(totalDeltaX, totalDeltaY, deltaX, deltaY)
onTouchpadScrollStarted: __startSwipe()
onTouchpadScrollEnded: __endSwipe()
onTouchpadScrollMove: __moveSwipe(totalDeltaX, totalDeltaY, deltaX, deltaY)
}