taskswitcher: improve some gesture animations

improves task quick switch and flick to homescreen gesture animations. fixes most of https://invent.kde.org/plasma/plasma-mobile/-/issues/368
This commit is contained in:
Luis Büchi 2024-07-15 14:42:45 +00:00
parent b79fe898d6
commit 452f0df68b
2 changed files with 35 additions and 5 deletions

View file

@ -171,7 +171,7 @@ FocusScope {
} }
if (shouldSwitch) { if (shouldSwitch) {
let appAtNewIndex = taskList.getTaskAt(newIndex).window; let appAtNewIndex = taskList.getTaskAt(newIndex).window;
taskSwitcherHelpers.openApp(newIndex, appAtNewIndex); taskSwitcherHelpers.openApp(newIndex, appAtNewIndex, Kirigami.Units.longDuration * 4, Easing.OutExpo);
} else { } else {
// if not switching, just open task switcher // if not switching, just open task switcher
taskSwitcherHelpers.animateGoToTaskIndex(state.currentTaskIndex); taskSwitcherHelpers.animateGoToTaskIndex(state.currentTaskIndex);

View file

@ -67,12 +67,21 @@ QtObject {
} }
} }
// scaling factor during closing of the switcher
property real closingScalingFactor: 1
// scale of the task list (based on the progress of the swipe up gesture) // scale of the task list (based on the progress of the swipe up gesture)
readonly property real currentScale: { readonly property real currentScale: {
let maxScale = 1 / scalingFactor; let maxScale = 1 / scalingFactor;
let subtract = (maxScale - 1) * Math.min(root.state.yPosition / openedYPosition, 1); let subtract = (maxScale - 1) * Math.min(root.state.yPosition / openedYPosition, 1);
let finalScale = Math.min(maxScale, maxScale - subtract); let finalScale = Math.min(maxScale, maxScale - subtract);
// if closing scaling factor is below 1 we want it to override the other scale
// to allow for a smoother closing animation
if (closingScalingFactor < 1) {
return closingScalingFactor;
}
// animate scale only if we are *not* opening from the homescreen // animate scale only if we are *not* opening from the homescreen
if (root.state.wasInActiveTask || !root.state.gestureInProgress) { if (root.state.wasInActiveTask || !root.state.gestureInProgress) {
return finalScale; return finalScale;
@ -92,6 +101,7 @@ QtObject {
openAnim.stop(); openAnim.stop();
openAppAnim.stop(); openAppAnim.stop();
closeAnim.stop(); closeAnim.stop();
closeScaleAnim.stop();
xAnim.stop(); xAnim.stop();
} }
@ -120,14 +130,17 @@ QtObject {
} }
function close() { function close() {
cancelAnimations();
closingScalingFactor = currentScale;
closeAnim.restart(); closeAnim.restart();
closeScaleAnim.restart();
} }
function openApp(index, window) { function openApp(index, window, duration = Kirigami.Units.shortDuration, horizontalEasing = Easing.OutBack) {
// cancel any opening animations ongoing // cancel any opening animations ongoing
cancelAnimations(); cancelAnimations();
animateGoToTaskIndex(index, Kirigami.Units.shortDuration); animateGoToTaskIndex(index, duration);
openAppAnim.restart(); openAppAnim.restart();
KWinComponents.Workspace.activeWindow = window KWinComponents.Workspace.activeWindow = window
} }
@ -143,9 +156,10 @@ QtObject {
} }
// go to the task index, animated // go to the task index, animated
function animateGoToTaskIndex(index, duration = Kirigami.Units.longDuration * 2) { function animateGoToTaskIndex(index, duration = Kirigami.Units.longDuration * 2, easing = Easing.OutExpo) {
xAnim.duration = duration; xAnim.duration = duration;
xAnim.to = xPositionFromTaskIndex(index); xAnim.to = xPositionFromTaskIndex(index);
xAnim.easing.type = easing;
xAnim.restart(); xAnim.restart();
} }
@ -216,18 +230,34 @@ QtObject {
} }
} }
// TODO: This animation should ideally be replaced by some
// speed tracking to track finger movement better. Until then
// InBack at least pretends to go in the finger move direction
property var closeAnim: NumberAnimation { property var closeAnim: NumberAnimation {
target: root.state target: root.state
property: "yPosition" property: "yPosition"
to: 0 to: 0
duration: Kirigami.Units.longDuration duration: Kirigami.Units.longDuration
easing.type: Easing.InOutQuad easing.type: Easing.InBack
onFinished: { onFinished: {
root.state.status = stateClass.Inactive; root.state.status = stateClass.Inactive;
taskSwitcher.instantHide(); taskSwitcher.instantHide();
} }
} }
property var closeScaleAnim: NumberAnimation {
target: root
property: "closingScalingFactor"
to: 0.1
duration: Kirigami.Units.longDuration
easing.type: Easing.InQuad
onStopped: {
closingScalingFactor = 1;
}
}
property var openAppAnim: NumberAnimation { property var openAppAnim: NumberAnimation {
target: root.state target: root.state
property: "yPosition" property: "yPosition"