shift-shell/components/mobileshell/qml/taskswitcher/TaskSwitcher.qml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

210 lines
6.3 KiB
QML
Raw Normal View History

2015-06-18 23:31:26 +00:00
/*
2021-03-01 20:03:25 +00:00
* SPDX-FileCopyrightText: 2015 Marco Martin <notmart@gmail.com>
* SPDX-FileCopyrightText: 2021-2022 Devin Lin <devin@kde.org>
2015-06-18 23:31:26 +00:00
*
* SPDX-License-Identifier: GPL-2.0-or-later
2015-06-18 23:31:26 +00:00
*/
import QtQuick 2.15
import QtQuick.Controls 2.15 as QQC2
2015-06-18 23:31:26 +00:00
import QtQuick.Layouts 1.1
import QtQuick.Window 2.15
import org.kde.taskmanager 0.1 as TaskManager
2015-06-24 20:47:07 +00:00
import org.kde.plasma.core 2.1 as PlasmaCore
2019-10-11 10:06:12 +00:00
import org.kde.plasma.components 3.0 as PlasmaComponents
2019-09-18 13:31:04 +00:00
import org.kde.plasma.private.nanoshell 2.0 as NanoShell
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
2015-06-18 23:31:26 +00:00
import "../components" as Components
/**
* Component that provides a task switcher.
*/
Item {
id: root
2015-06-18 23:31:26 +00:00
visible: false
opacity: 0
2021-10-18 03:50:59 +00:00
// state object
property var taskSwitcherState: TaskSwitcherState {
taskSwitcher: root
}
/**
* The task manager model to use for the tasks switcher.
*/
property TaskManager.TasksModel tasksModel
/**
* The number of tasks in the given task manager model.
*/
readonly property int tasksCount: tasksModel.count
2015-06-18 23:31:26 +00:00
/**
* The screen model to be used for moving windows between screens.
*/
property var displaysModel: MobileShell.DisplaysModel {}
/**
* Whether the window is active.
*/
property bool windowActive: Window.active
onWindowActiveChanged: {
// if a window has popped up in front, close the task switcher
if (visible && !windowActive) {
hide();
}
}
// update API property
onVisibleChanged: MobileShell.HomeScreenControls.taskSwitcherVisible = visible;
// keep track of task list events
property int oldTasksCount: tasksCount
onTasksCountChanged: {
if (tasksCount == 0) {
hide();
} else if (tasksCount < oldTasksCount && taskSwitcherState.currentTaskIndex >= tasksCount - 1) {
// if the user is on the last task, and it is closed, scroll left
taskSwitcherState.animateGoToTaskIndex(tasksCount - 1, PlasmaCore.Units.longDuration);
}
2021-10-18 03:50:59 +00:00
oldTasksCount = tasksCount;
2020-07-31 10:06:46 +00:00
}
2015-06-18 23:31:26 +00:00
2021-10-18 18:47:17 +00:00
//BEGIN functions
2021-10-18 18:47:17 +00:00
function show(animation) {
// reset values
taskSwitcherState.cancelAnimations();
taskSwitcherState.yPosition = 0;
taskSwitcherState.xPosition = 0;
taskSwitcherState.wasInActiveTask = tasksModel.activeTask.row >= 0;
taskSwitcherState.currentlyBeingOpened = true;
2021-10-18 18:47:17 +00:00
2021-10-18 03:50:59 +00:00
// skip to first active task
if (taskSwitcherState.wasInActiveTask) {
taskSwitcherState.goToTaskIndex(tasksModel.activeTask.row);
}
2021-10-18 03:50:59 +00:00
// show task switcher, hide all running apps
visible = true;
opacity = 1;
minimizeAll();
2021-10-18 18:47:17 +00:00
// fully open the panel (if this is a button press, not gesture)
2021-10-18 18:47:17 +00:00
if (animation) {
taskSwitcherState.open();
2021-10-18 18:47:17 +00:00
}
2015-06-18 23:31:26 +00:00
}
function instantHide() {
opacity = 0;
visible = false;
2015-06-18 23:31:26 +00:00
}
function hide() {
closeAnim.restart();
2021-10-18 18:47:17 +00:00
}
// scroll to delegate index, and activate it
function activateWindow(id) {
taskSwitcherState.openApp(id);
2021-10-18 18:47:17 +00:00
}
function setSingleActiveWindow(id) {
if (id < 0) {
return;
}
var newActiveIdx = tasksModel.index(id, 0)
var newActiveGeo = tasksModel.data(newActiveIdx, TaskManager.AbstractTasksModel.ScreenGeometry)
for (var i = 0 ; i < tasksModel.count; i++) {
var idx = tasksModel.index(i, 0)
if (i == id) {
tasksModel.requestActivate(idx);
// ensure the window is in maximized state
if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMaximized)) {
tasksModel.requestToggleMaximized(idx);
}
} else if (!tasksModel.data(idx, TaskManager.AbstractTasksModel.IsMinimized)) {
var geo = tasksModel.data(idx, TaskManager.AbstractTasksModel.ScreenGeometry)
// only minimize the other windows in the same screen
if (geo === newActiveGeo) {
tasksModel.requestToggleMinimized(idx);
}
}
}
2021-10-18 03:50:59 +00:00
instantHide();
}
function minimizeAll() {
MobileShell.WindowUtil.unsetAllMinimizedGeometries(root);
MobileShell.WindowUtil.minimizeAll();
}
2021-10-18 18:47:17 +00:00
//END functions
NumberAnimation on opacity {
id: closeAnim
2021-10-18 18:47:17 +00:00
to: 0
duration: PlasmaCore.Units.shortDuration
easing.type: Easing.InOutQuad
2021-10-18 18:47:17 +00:00
onFinished: {
root.visible = false;
}
}
// background colour
Rectangle {
id: backgroundRect
anchors.fill: parent
color: {
// animate background colour only if we are *not* opening from the homescreen
if (taskSwitcherState.wasInActiveTask || !taskSwitcherState.currentlyBeingOpened) {
return Qt.rgba(0, 0, 0, 0.6);
} else {
return Qt.rgba(0, 0, 0, 0.6 * Math.min(1, taskSwitcherState.yPosition / taskSwitcherState.openedYPosition));
2021-10-18 18:47:17 +00:00
}
}
}
2021-10-18 03:50:59 +00:00
2021-10-31 19:21:02 +00:00
Item {
id: container
2021-10-18 03:50:59 +00:00
2021-10-31 19:21:02 +00:00
// provide shell margins
anchors.fill: parent
anchors.leftMargin: MobileShell.Shell.leftMargin
anchors.rightMargin: MobileShell.Shell.rightMargin
anchors.bottomMargin: MobileShell.Shell.bottomMargin
anchors.topMargin: MobileShell.Shell.topMargin
2021-10-18 03:50:59 +00:00
FlickContainer {
id: flickable
anchors.fill: parent
taskSwitcherState: root.taskSwitcherState
2021-10-31 04:11:10 +00:00
// the item is effectively anchored to the flickable bounds
TaskList {
taskSwitcher: root
opacity: {
// animate opacity only if we are *not* opening from the homescreen
if (taskSwitcherState.wasInActiveTask || !taskSwitcherState.currentlyBeingOpened) {
return 1;
} else {
Math.min(1, taskSwitcherState.yPosition / taskSwitcherState.openedYPosition);
}
}
x: flickable.contentX
width: flickable.width
height: flickable.height
2021-10-31 04:11:10 +00:00
}
2020-02-04 19:10:01 +00:00
}
2015-06-18 23:31:26 +00:00
}
}