2015-02-25 18:26:04 +00:00
|
|
|
/*
|
2021-03-01 20:03:25 +00:00
|
|
|
* SPDX-FileCopyrightText: 2019 Marco Martin <mart@kde.org>
|
2021-12-25 01:17:08 +00:00
|
|
|
* SPDX-FileCopyrightText: 2021 Devin Lin <devin@kde.org>
|
2015-02-25 18:26:04 +00:00
|
|
|
*
|
2021-03-01 20:03:25 +00:00
|
|
|
* SPDX-License-Identifier: LGPL-2.0-or-later
|
2015-02-25 18:26:04 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-12-25 01:17:08 +00:00
|
|
|
import QtQuick 2.15
|
|
|
|
|
import QtQuick.Window 2.15
|
2015-02-25 18:38:34 +00:00
|
|
|
import QtQuick.Layouts 1.1
|
2015-02-25 18:26:04 +00:00
|
|
|
|
2021-12-25 03:31:33 +00:00
|
|
|
import org.kde.taskmanager 0.1 as TaskManager
|
2015-02-25 18:26:04 +00:00
|
|
|
import org.kde.plasma.plasmoid 2.0
|
|
|
|
|
import org.kde.plasma.core 2.0 as PlasmaCore
|
2019-09-04 16:39:31 +00:00
|
|
|
import org.kde.plasma.components 3.0 as PlasmaComponents
|
2015-02-25 18:26:04 +00:00
|
|
|
|
2021-03-18 14:07:33 +00:00
|
|
|
import org.kde.plasma.private.mobilehomescreencomponents 0.1 as HomeScreenComponents
|
2020-07-22 15:17:10 +00:00
|
|
|
import org.kde.plasma.private.mobileshell 1.0 as MobileShell
|
|
|
|
|
|
2021-03-18 17:34:37 +00:00
|
|
|
FocusScope {
|
2015-02-25 18:26:04 +00:00
|
|
|
id: root
|
2019-09-04 16:39:31 +00:00
|
|
|
width: 640
|
|
|
|
|
height: 480
|
2015-02-25 18:26:04 +00:00
|
|
|
|
2015-06-20 23:08:46 +00:00
|
|
|
//BEGIN functions
|
2015-07-09 11:29:26 +00:00
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
function recalculateMaxFavoriteCount() {
|
|
|
|
|
if (!componentComplete) {
|
|
|
|
|
return;
|
2015-10-15 13:26:23 +00:00
|
|
|
}
|
2021-12-31 00:49:08 +00:00
|
|
|
HomeScreenComponents.ApplicationListModel.maxFavoriteCount = Math.max(4, Math.floor(Math.min(width, height) / homescreen.homeScreenContents.favoriteStrip.cellWidth));
|
2015-06-20 23:08:46 +00:00
|
|
|
}
|
2021-12-25 03:31:33 +00:00
|
|
|
|
|
|
|
|
function triggerHomeScreen() {
|
|
|
|
|
MobileShell.HomeScreenControls.resetHomeScreenPosition();
|
|
|
|
|
taskSwitcher.visible = false; // will trigger homescreen open
|
2022-01-03 05:25:33 +00:00
|
|
|
searchWidget.close();
|
|
|
|
|
taskSwitcher.minimizeAll();
|
2021-12-25 03:31:33 +00:00
|
|
|
}
|
2021-02-15 10:44:48 +00:00
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
//END functions
|
2015-06-20 23:08:46 +00:00
|
|
|
|
2021-10-29 01:54:52 +00:00
|
|
|
//BEGIN API implementation
|
2021-10-29 00:11:01 +00:00
|
|
|
Connections {
|
|
|
|
|
target: MobileShell.HomeScreenControls
|
|
|
|
|
|
|
|
|
|
property real lastRequestedPosition: 0
|
2021-12-25 01:17:08 +00:00
|
|
|
|
2021-12-25 03:31:33 +00:00
|
|
|
function onOpenHomeScreen() {
|
|
|
|
|
root.triggerHomeScreen();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 00:11:01 +00:00
|
|
|
function onResetHomeScreenPosition() {
|
2021-12-31 02:11:21 +00:00
|
|
|
homescreen.homeScreenState.animateGoToPageIndex(0, PlasmaCore.Units.longDuration);
|
2021-12-31 00:49:08 +00:00
|
|
|
homescreen.homeScreenState.closeAppDrawer();
|
2021-10-29 00:11:01 +00:00
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
|
2021-10-29 00:11:01 +00:00
|
|
|
function onSnapHomeScreenPosition() {
|
|
|
|
|
if (lastRequestedPosition < 0) {
|
2021-12-31 00:49:08 +00:00
|
|
|
homescreen.homeScreenState.openAppDrawer();
|
2021-10-29 00:11:01 +00:00
|
|
|
} else {
|
2021-12-31 00:49:08 +00:00
|
|
|
homescreen.homeScreenState.closeAppDrawer();
|
2021-10-29 00:11:01 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
|
2021-10-29 00:11:01 +00:00
|
|
|
function onRequestRelativeScroll(pos) {
|
2021-12-31 00:49:08 +00:00
|
|
|
// TODO
|
|
|
|
|
//homescreen.appDrawer.offset -= pos.y;
|
|
|
|
|
//lastRequestedPosition = pos.y;
|
2021-10-29 00:11:01 +00:00
|
|
|
}
|
2021-12-29 05:08:32 +00:00
|
|
|
|
2022-03-20 18:24:44 +00:00
|
|
|
function onOpenAppLaunchAnimation(splashIcon, title, x, y, sourceIconSize) {
|
2021-12-29 05:08:32 +00:00
|
|
|
startupFeedback.open(splashIcon, title, x, y, sourceIconSize);
|
|
|
|
|
}
|
2022-03-20 18:24:44 +00:00
|
|
|
|
|
|
|
|
function onCloseAppLaunchAnimation() {
|
|
|
|
|
startupFeedback.close();
|
|
|
|
|
}
|
2021-10-18 03:50:59 +00:00
|
|
|
}
|
2021-12-25 01:17:08 +00:00
|
|
|
|
|
|
|
|
Plasmoid.onScreenChanged: {
|
|
|
|
|
if (plasmoid.screen == 0) {
|
2021-12-25 03:31:33 +00:00
|
|
|
MobileShell.HomeScreenControls.taskSwitcher = taskSwitcher;
|
|
|
|
|
MobileShell.HomeScreenControls.homeScreenWindow = root.Window.window;
|
2021-12-25 01:17:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Window.onWindowChanged: {
|
|
|
|
|
if (plasmoid.screen == 0) {
|
2021-12-25 03:31:33 +00:00
|
|
|
MobileShell.HomeScreenControls.homeScreenWindow = root.Window.window;
|
2021-12-25 01:17:08 +00:00
|
|
|
}
|
|
|
|
|
}
|
2021-10-18 03:50:59 +00:00
|
|
|
|
2021-10-29 01:54:52 +00:00
|
|
|
//END API implementation
|
2021-10-29 00:11:01 +00:00
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
property bool componentComplete: false
|
|
|
|
|
onWidthChanged: recalculateMaxFavoriteCount()
|
2021-12-25 01:17:08 +00:00
|
|
|
onHeightChanged: recalculateMaxFavoriteCount()
|
2021-10-29 00:11:01 +00:00
|
|
|
|
2019-09-04 16:39:31 +00:00
|
|
|
Component.onCompleted: {
|
2021-03-18 14:07:33 +00:00
|
|
|
// ApplicationListModel doesn't have a plasmoid as is not the one that should be doing writing
|
|
|
|
|
HomeScreenComponents.ApplicationListModel.loadApplications();
|
|
|
|
|
HomeScreenComponents.FavoritesModel.applet = plasmoid;
|
|
|
|
|
HomeScreenComponents.FavoritesModel.loadApplications();
|
|
|
|
|
|
2021-10-29 00:11:01 +00:00
|
|
|
// set API variables
|
2020-07-22 15:17:10 +00:00
|
|
|
if (plasmoid.screen == 0) {
|
2021-12-25 03:31:33 +00:00
|
|
|
MobileShell.HomeScreenControls.taskSwitcher = taskSwitcher;
|
2021-10-29 00:11:01 +00:00
|
|
|
MobileShell.HomeScreenControls.homeScreenWindow = root.Window.window;
|
2020-07-22 15:17:10 +00:00
|
|
|
}
|
2019-09-04 16:39:31 +00:00
|
|
|
componentComplete = true;
|
|
|
|
|
recalculateMaxFavoriteCount()
|
2021-10-18 18:56:37 +00:00
|
|
|
|
|
|
|
|
// ensure the gestures work immediately on load
|
|
|
|
|
forceActiveFocus();
|
2015-03-05 12:37:39 +00:00
|
|
|
}
|
2021-10-18 18:56:37 +00:00
|
|
|
|
2021-10-16 03:17:32 +00:00
|
|
|
Plasmoid.onActivated: {
|
|
|
|
|
console.log("Triggered!", plasmoid.nativeInterface.showingDesktop)
|
2021-12-31 00:49:08 +00:00
|
|
|
|
|
|
|
|
// there's a couple of steps:
|
|
|
|
|
// - minimize windows
|
|
|
|
|
// - open app drawer
|
|
|
|
|
// - restore windows
|
|
|
|
|
if (!plasmoid.nativeInterface.showingDesktop) {
|
|
|
|
|
plasmoid.nativeInterface.showingDesktop = true;
|
|
|
|
|
} else if (homescreen.homeScreenState.currentView === MobileShell.HomeScreenState.PageView) {
|
|
|
|
|
homescreen.homeScreenState.openAppDrawer()
|
|
|
|
|
} else {
|
|
|
|
|
plasmoid.nativeInterface.showingDesktop = false
|
|
|
|
|
homescreen.homeScreenState.closeAppDrawer()
|
|
|
|
|
}
|
2019-09-04 16:39:31 +00:00
|
|
|
}
|
2021-10-18 18:56:37 +00:00
|
|
|
|
2022-01-03 05:25:33 +00:00
|
|
|
// control the opacity of both the search and homescreen components
|
|
|
|
|
property real homeScreenOpacity: 1
|
|
|
|
|
NumberAnimation on homeScreenOpacity {
|
|
|
|
|
id: opacityAnimation
|
|
|
|
|
duration: PlasmaCore.Units.longDuration
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-25 03:31:33 +00:00
|
|
|
// homescreen component
|
2021-12-31 00:49:08 +00:00
|
|
|
HomeScreenComponents.HomeScreen {
|
2021-12-25 01:17:08 +00:00
|
|
|
id: homescreen
|
2021-10-18 18:56:37 +00:00
|
|
|
anchors.fill: parent
|
2022-01-03 05:25:33 +00:00
|
|
|
opacity: root.homeScreenOpacity * (1 - searchWidget.openFactor)
|
2021-12-31 00:49:08 +00:00
|
|
|
|
|
|
|
|
// make the homescreen not interactable when task switcher or startup feedback is on
|
|
|
|
|
interactive: !taskSwitcher.visible && !startupFeedback.visible
|
2022-01-03 05:25:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// search component
|
|
|
|
|
MobileShell.KRunnerWidget {
|
|
|
|
|
id: searchWidget
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
opacity: root.homeScreenOpacity
|
|
|
|
|
visible: openFactor > 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Connections {
|
|
|
|
|
target: homescreen.homeScreenState
|
|
|
|
|
|
|
|
|
|
function onSwipeDownGestureBegin() {
|
|
|
|
|
searchWidget.startGesture();
|
|
|
|
|
}
|
|
|
|
|
function onSwipeDownGestureEnd() {
|
|
|
|
|
searchWidget.endGesture();
|
|
|
|
|
}
|
|
|
|
|
function onSwipeDownGestureOffset(offset) {
|
|
|
|
|
searchWidget.updateGestureOffset(-offset);
|
2021-12-25 01:17:08 +00:00
|
|
|
}
|
2021-10-18 18:56:37 +00:00
|
|
|
}
|
2021-12-25 03:31:33 +00:00
|
|
|
|
|
|
|
|
// task switcher component
|
|
|
|
|
|
|
|
|
|
TaskManager.VirtualDesktopInfo {
|
|
|
|
|
id: virtualDesktopInfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskManager.ActivityInfo {
|
|
|
|
|
id: activityInfo
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MobileShell.TaskSwitcher {
|
|
|
|
|
id: taskSwitcher
|
2022-02-11 18:09:19 +00:00
|
|
|
|
|
|
|
|
tasksModel: TaskManager.TasksModel {
|
|
|
|
|
groupMode: TaskManager.TasksModel.GroupDisabled
|
|
|
|
|
|
|
|
|
|
screenGeometry: plasmoid.screenGeometry
|
2022-03-12 22:17:12 +00:00
|
|
|
sortMode: TaskManager.TasksModel.SortAlpha
|
2022-02-11 18:09:19 +00:00
|
|
|
|
|
|
|
|
virtualDesktop: virtualDesktopInfo.currentDesktop
|
|
|
|
|
activity: activityInfo.currentActivity
|
|
|
|
|
}
|
2021-12-25 03:31:33 +00:00
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
// hide homescreen elements to make use of wallpaper
|
|
|
|
|
onVisibleChanged: {
|
|
|
|
|
if (visible) {
|
2021-12-29 05:08:32 +00:00
|
|
|
startupFeedback.visible = false;
|
|
|
|
|
|
2021-12-25 03:31:33 +00:00
|
|
|
// only animate if going from homescreen
|
|
|
|
|
if (taskSwitcher.wasInActiveTask) {
|
|
|
|
|
opacityAnimation.to = 0;
|
|
|
|
|
opacityAnimation.restart();
|
|
|
|
|
} else {
|
2022-01-03 05:25:33 +00:00
|
|
|
root.homeScreenOpacity = 0;
|
2021-12-25 03:31:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
opacityAnimation.to = 1;
|
|
|
|
|
opacityAnimation.restart();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-12-29 05:08:32 +00:00
|
|
|
|
2022-02-11 18:09:19 +00:00
|
|
|
// start app animation component
|
2021-12-29 05:08:32 +00:00
|
|
|
MobileShell.StartupFeedback {
|
|
|
|
|
id: startupFeedback
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
}
|
2015-06-20 21:45:19 +00:00
|
|
|
}
|
2019-09-04 16:39:31 +00:00
|
|
|
|