2023-03-06 06:38:43 +00:00
|
|
|
// SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2021-12-27 06:32:24 +00:00
|
|
|
|
2023-03-19 06:46:05 +00:00
|
|
|
import QtQuick
|
|
|
|
|
import QtQuick.Layouts
|
2021-12-27 06:32:24 +00:00
|
|
|
|
2023-07-25 01:13:52 +00:00
|
|
|
import org.kde.kirigami 2.20 as Kirigami
|
2021-12-27 06:32:24 +00:00
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
2023-03-06 06:38:43 +00:00
|
|
|
|
|
|
|
|
import org.kde.kwin 3.0 as KWinComponents
|
2021-12-27 06:32:24 +00:00
|
|
|
|
2023-03-31 05:26:35 +00:00
|
|
|
MouseArea {
|
2021-12-27 06:32:24 +00:00
|
|
|
id: root
|
2023-03-06 06:38:43 +00:00
|
|
|
readonly property int count: repeater.count
|
|
|
|
|
|
2022-12-11 02:05:13 +00:00
|
|
|
required property real shellTopMargin
|
|
|
|
|
required property real shellBottomMargin
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2022-07-21 15:13:42 +00:00
|
|
|
required property var taskSwitcher
|
2021-12-27 06:32:24 +00:00
|
|
|
readonly property var taskSwitcherState: taskSwitcher.taskSwitcherState
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-04-01 03:32:56 +00:00
|
|
|
property int taskInteractingCount: 0
|
|
|
|
|
|
2022-07-21 15:13:42 +00:00
|
|
|
// account for system header and footer offset (center the preview image)
|
|
|
|
|
readonly property real taskY: {
|
2022-12-11 02:05:13 +00:00
|
|
|
let headerHeight = shellTopMargin;
|
|
|
|
|
let footerHeight = shellBottomMargin;
|
2022-07-21 15:13:42 +00:00
|
|
|
let diff = headerHeight - footerHeight;
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2022-07-21 15:13:42 +00:00
|
|
|
let baseY = (taskSwitcher.height / 2) - (taskSwitcherState.taskHeight / 2) - (taskSwitcherState.taskHeaderHeight / 2)
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-03-19 06:46:05 +00:00
|
|
|
return baseY + diff / 2 - shellTopMargin;
|
2023-03-06 06:38:43 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-01 05:10:02 +00:00
|
|
|
function getTaskAt(index) {
|
|
|
|
|
return repeater.itemAt(index);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-06 06:38:43 +00:00
|
|
|
function closeAll() {
|
|
|
|
|
for (var i = 0; i < repeater.count; i++) {
|
|
|
|
|
repeater.itemAt(i).closeApp();
|
|
|
|
|
}
|
2022-07-21 15:13:42 +00:00
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
|
|
|
|
function minimizeAll() {
|
|
|
|
|
for (var i = 0; i < repeater.count; i++) {
|
|
|
|
|
let item = repeater.itemAt(i);
|
|
|
|
|
|
|
|
|
|
// update property
|
|
|
|
|
if (!item.window.minimized) {
|
|
|
|
|
taskSwitcherState.wasInActiveTask = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// minimize window immediately if it shows up
|
|
|
|
|
item.minimizeApp();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function jumpToFirstVisibleWindow() {
|
|
|
|
|
for (var i = 0; i < repeater.count; i++) {
|
|
|
|
|
let item = repeater.itemAt(i);
|
|
|
|
|
|
|
|
|
|
if (!item.window.minimized) {
|
|
|
|
|
taskSwitcherState.goToTaskIndex(i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 23:29:14 +00:00
|
|
|
transform: Scale {
|
|
|
|
|
origin.x: root.width / 2
|
|
|
|
|
origin.y: root.height / 2
|
|
|
|
|
xScale: taskSwitcherState.currentScale
|
|
|
|
|
yScale: taskSwitcherState.currentScale
|
|
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-03-31 05:26:35 +00:00
|
|
|
onClicked: {
|
|
|
|
|
// if tapped on the background, then hide
|
|
|
|
|
if (!taskSwitcherState.currentlyBeingOpened) {
|
|
|
|
|
taskSwitcher.hide();
|
2021-12-27 15:05:05 +00:00
|
|
|
}
|
2023-03-31 05:26:35 +00:00
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-03-31 05:26:35 +00:00
|
|
|
onPressedChanged: {
|
|
|
|
|
if (!taskSwitcherState.currentlyBeingOpened && pressed) {
|
|
|
|
|
// ensure animations aren't running when finger is pressed
|
|
|
|
|
taskSwitcherState.cancelAnimations();
|
2021-12-27 06:32:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-27 06:32:24 +00:00
|
|
|
Repeater {
|
|
|
|
|
id: repeater
|
2022-02-11 18:09:19 +00:00
|
|
|
model: taskSwitcher.tasksModel
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-27 06:32:24 +00:00
|
|
|
// left margin from root edge such that the task is centered
|
2023-03-06 06:38:43 +00:00
|
|
|
readonly property real leftMargin: (root.width / 2) - (taskSwitcherState.taskWidth / 2)
|
|
|
|
|
|
2021-12-27 06:32:24 +00:00
|
|
|
delegate: Task {
|
|
|
|
|
id: task
|
|
|
|
|
readonly property int currentIndex: model.index
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-27 06:32:24 +00:00
|
|
|
// this is the x-position with respect to the list
|
|
|
|
|
property real listX: taskSwitcherState.xPositionFromTaskIndex(currentIndex);
|
2023-03-06 06:38:43 +00:00
|
|
|
Behavior on listX {
|
|
|
|
|
NumberAnimation {
|
2023-07-25 01:13:52 +00:00
|
|
|
duration: Kirigami.Units.longDuration
|
2023-03-06 06:38:43 +00:00
|
|
|
easing.type: Easing.InOutQuad
|
|
|
|
|
}
|
2021-12-27 06:32:24 +00:00
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-27 06:32:24 +00:00
|
|
|
// this is the actual displayed x-position on screen
|
|
|
|
|
x: listX + repeater.leftMargin - taskSwitcherState.xPosition
|
2022-07-21 15:13:42 +00:00
|
|
|
y: root.taskY
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-27 06:32:24 +00:00
|
|
|
// ensure current task is above others
|
|
|
|
|
z: taskSwitcherState.currentTaskIndex === currentIndex ? 1 : 0
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-28 00:01:01 +00:00
|
|
|
// only show header once task switcher is opened
|
2021-12-27 23:29:14 +00:00
|
|
|
showHeader: !taskSwitcherState.currentlyBeingOpened
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-28 00:01:01 +00:00
|
|
|
// darken effect as task gets away from the centre of the screen
|
|
|
|
|
darken: {
|
2023-05-13 15:15:52 +00:00
|
|
|
const distFromCentreProgress = Math.abs(x - repeater.leftMargin) / taskSwitcherState.taskWidth;
|
|
|
|
|
const upperBoundAdjust = Math.min(0.5, distFromCentreProgress) - 0.2;
|
2021-12-28 00:01:01 +00:00
|
|
|
return Math.max(0, upperBoundAdjust);
|
|
|
|
|
}
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2023-04-01 03:32:56 +00:00
|
|
|
// update count of tasks being interacted with, so we know whether we are in a swipe up action
|
|
|
|
|
onInteractingActiveChanged: {
|
|
|
|
|
let offset = interactingActive ? 1 : -1;
|
|
|
|
|
taskInteractingCount = Math.max(0, taskInteractingCount + offset);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 06:32:24 +00:00
|
|
|
width: taskSwitcherState.taskWidth
|
|
|
|
|
height: taskSwitcherState.taskHeight
|
|
|
|
|
previewWidth: taskSwitcherState.previewWidth
|
|
|
|
|
previewHeight: taskSwitcherState.previewHeight
|
2023-03-06 06:38:43 +00:00
|
|
|
|
2021-12-27 06:32:24 +00:00
|
|
|
taskSwitcher: root.taskSwitcher
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|