From 8a577f9a571146b8015747eba4b84ba10d0abae5 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Mon, 12 Jun 2023 19:58:17 -0400 Subject: [PATCH] homescreens: Update API usage to match changes for Plasmoid & Containment --- .../mobileshell/qml/homescreen/HomeScreen.qml | 57 ++++---- .../folio/package/contents/ui/main.qml | 136 +++++++++--------- .../halcyon/package/contents/ui/main.qml | 105 +++++++------- 3 files changed, 152 insertions(+), 146 deletions(-) diff --git a/components/mobileshell/qml/homescreen/HomeScreen.qml b/components/mobileshell/qml/homescreen/HomeScreen.qml index 834fa22c..ef9ec380 100644 --- a/components/mobileshell/qml/homescreen/HomeScreen.qml +++ b/components/mobileshell/qml/homescreen/HomeScreen.qml @@ -1,7 +1,5 @@ -/* - * SPDX-FileCopyrightText: 2021 Devin Lin - * SPDX-License-Identifier: LGPL-2.0-or-later - */ +// SPDX-FileCopyrightText: 2021-2023 Devin Lin +// SPDX-License-Identifier: LGPL-2.0-or-later import QtQuick import QtQuick.Window @@ -20,6 +18,7 @@ import "../components" as Components * The base homescreen component, implementing features that simplify * homescreen implementation. */ + Item { id: root @@ -27,17 +26,17 @@ Item { * Emitted when an action is triggered to open the homescreen. */ signal homeTriggered() - + /** * Emitted when resetting the homescreen position is requested. */ signal resetHomeScreenPosition() - + /** * Emitted when moving the homescreen position is requested. */ signal requestRelativeScroll(var pos) - + /** * The visual item that is the homescreen. */ @@ -48,7 +47,7 @@ Item { * window. */ readonly property bool overlayShown: startupFeedback.visible - + /** * Margins for the homescreen, taking panels into account. */ @@ -58,15 +57,15 @@ Item { property real rightMargin function evaluateMargins() { - topMargin = plasmoid.availableScreenRect.y + topMargin = Plasmoid.availableScreenRect.y // add a specific check for the nav panel for now, since the gesture mode still technically has height - bottomMargin = ShellSettings.Settings.navigationPanelEnabled ? root.height - (plasmoid.availableScreenRect.y + plasmoid.availableScreenRect.height) : 0; - leftMargin = plasmoid.availableScreenRect.x - rightMargin = root.width - (plasmoid.availableScreenRect.x + plasmoid.availableScreenRect.width) + bottomMargin = ShellSettings.Settings.navigationPanelEnabled ? root.height - (Plasmoid.availableScreenRect.y + Plasmoid.availableScreenRect.height) : 0; + leftMargin = Plasmoid.availableScreenRect.x + rightMargin = root.width - (Plasmoid.availableScreenRect.x + Plasmoid.availableScreenRect.width) } Connections { - target: plasmoid + target: Plasmoid // avoid binding loops with root.height and root.width changing along with the availableScreenRect function onAvailableScreenRectChanged() { @@ -78,12 +77,12 @@ Item { Connections { target: MobileShellState.ShellDBusClient - + function onOpenHomeScreenRequested() { if (WindowPlugin.WindowMaximizedTracker.showingWindow) { itemContainer.zoomIn(); } - + resetHomeScreenPosition(); WindowPlugin.WindowUtil.unsetAllMinimizedGeometries(root); @@ -91,15 +90,15 @@ Item { root.homeTriggered(); } - + function onResetHomeScreenPositionRequested() { root.resetHomeScreenPosition(); } - + function onOpenAppLaunchAnimationRequested(splashIcon, title, x, y, sourceIconSize) { startupFeedback.open(splashIcon, title, x, y, sourceIconSize); } - + function onCloseAppLaunchAnimationRequested() { startupFeedback.close(); } @@ -133,18 +132,18 @@ Item { // determine the margins used evaluateMargins(); } - + // homescreen visual component Components.BaseItem { id: itemContainer anchors.fill: parent - + // animations opacity: 0 property real zoomScale: 1 - + readonly property real zoomScaleOut: 0.8 - + function zoomIn() { // don't use check animationsEnabled here, so we ensure the scale and opacity is always 1 when disabled scaleAnim.to = 1; @@ -166,13 +165,13 @@ Item { zoomScale = zoomScaleOut; opacity = 0; } - + NumberAnimation on opacity { id: opacityAnim duration: 300 running: false } - + NumberAnimation on zoomScale { id: scaleAnim duration: 600 @@ -196,15 +195,15 @@ Item { itemContainer.evaluateAnimChange(); } } - - transform: Scale { - origin.x: itemContainer.width / 2; - origin.y: itemContainer.height / 2; + + transform: Scale { + origin.x: itemContainer.width / 2; + origin.y: itemContainer.height / 2; xScale: itemContainer.zoomScale yScale: itemContainer.zoomScale } } - + // start app animation component Components.StartupFeedback { id: startupFeedback diff --git a/containments/homescreens/folio/package/contents/ui/main.qml b/containments/homescreens/folio/package/contents/ui/main.qml index bc019509..be4d6f8b 100644 --- a/containments/homescreens/folio/package/contents/ui/main.qml +++ b/containments/homescreens/folio/package/contents/ui/main.qml @@ -18,28 +18,16 @@ import org.kde.plasma.private.mobileshell.state 1.0 as MobileShellState import org.kde.private.mobile.homescreen.folio 1.0 as Folio import org.kde.plasma.private.mobileshell.windowplugin as WindowPlugin -MobileShell.HomeScreen { - id: root - width: 640 - height: 480 - onResetHomeScreenPosition: { - homescreen.homeScreenState.animateGoToPageIndex(0, PlasmaCore.Units.longDuration); - homescreen.homeScreenState.closeAppDrawer(); - } - - onHomeTriggered: { - searchWidget.close(); - } - - property bool componentComplete: false - +ContainmentItem { + id: root + Component.onCompleted: { // ensure the gestures work immediately on load forceActiveFocus(); } - - Plasmoid.onActivated: { + + Plasmoid.onActivated: { // there's a couple of steps: // - minimize windows (only if we are in an app) // - open app drawer @@ -54,70 +42,84 @@ MobileShell.HomeScreen { || MobileShellState.ShellDBusClient.isActionDrawerOpen || searchWidget.isOpen ) { - + // Always close the search widget as well if (searchWidget.isOpen) { searchWidget.close(); } - - } else if (homescreen.homeScreenState.currentView === HomeScreenState.PageView) { - homescreen.homeScreenState.openAppDrawer(); + + } else if (folioHomeScreen.homeScreenState.currentView === HomeScreenState.PageView) { + folioHomeScreen.homeScreenState.openAppDrawer(); } else { - homescreen.homeScreenState.closeAppDrawer(); + folioHomeScreen.homeScreenState.closeAppDrawer(); } } - - contentItem: Item { - // homescreen component - HomeScreen { - id: homescreen - anchors.fill: parent - topMargin: root.topMargin - bottomMargin: root.bottomMargin - leftMargin: root.leftMargin - rightMargin: root.rightMargin + MobileShell.HomeScreen { + id: homeScreen - opacity: (1 - searchWidget.openFactor) + onResetHomeScreenPosition: { + folioHomeScreen.homeScreenState.animateGoToPageIndex(0, PlasmaCore.Units.longDuration); + folioHomeScreen.homeScreenState.closeAppDrawer(); + } - // make the homescreen not interactable when task switcher or startup feedback is on - interactive: !root.overlayShown + onHomeTriggered: { + searchWidget.close(); } - - // search component - MobileShell.KRunnerWidget { - id: searchWidget - anchors.fill: parent - - visible: openFactor > 0 - topMargin: root.topMargin - bottomMargin: root.bottomMargin - leftMargin: root.leftMargin - rightMargin: root.rightMargin + property bool componentComplete: false + + contentItem: Item { + // homescreen component + HomeScreen { + id: folioHomeScreen + anchors.fill: parent + + topMargin: homeScreen.topMargin + bottomMargin: homeScreen.bottomMargin + leftMargin: homeScreen.leftMargin + rightMargin: homeScreen.rightMargin + + opacity: (1 - searchWidget.openFactor) + + // make the homescreen not interactable when task switcher or startup feedback is on + interactive: !homeScreen.overlayShown + } + + // search component + MobileShell.KRunnerWidget { + id: searchWidget + anchors.fill: parent + + visible: openFactor > 0 + + topMargin: homeScreen.topMargin + bottomMargin: homeScreen.bottomMargin + leftMargin: homeScreen.leftMargin + rightMargin: homeScreen.rightMargin + } } - } - - Connections { - target: homescreen.homeScreenState - - function onSwipeDownGestureBegin() { - searchWidget.startGesture(); + + Connections { + target: folioHomeScreen.homeScreenState + + function onSwipeDownGestureBegin() { + searchWidget.startGesture(); + } + function onSwipeDownGestureEnd() { + searchWidget.endGesture(); + } + function onSwipeDownGestureOffset(offset) { + searchWidget.updateGestureOffset(-offset); + } } - function onSwipeDownGestureEnd() { - searchWidget.endGesture(); - } - function onSwipeDownGestureOffset(offset) { - searchWidget.updateGestureOffset(-offset); - } - } - - // listen to app launch errors - Connections { - target: Folio.ApplicationListModel - function onLaunchError(msg) { - MobileShellState.ShellDBusClient.closeAppLaunchAnimation() + + // listen to app launch errors + Connections { + target: Folio.ApplicationListModel + function onLaunchError(msg) { + MobileShellState.ShellDBusClient.closeAppLaunchAnimation() + } } } } - diff --git a/containments/homescreens/halcyon/package/contents/ui/main.qml b/containments/homescreens/halcyon/package/contents/ui/main.qml index 9c5ce41a..2e37afee 100644 --- a/containments/homescreens/halcyon/package/contents/ui/main.qml +++ b/containments/homescreens/halcyon/package/contents/ui/main.qml @@ -14,33 +14,15 @@ import org.kde.plasma.private.mobileshell.state as MobileShellState import org.kde.private.mobile.homescreen.halcyon as Halcyon import org.kde.plasma.private.mobileshell.windowplugin as WindowPlugin -MobileShell.HomeScreen { +ContainmentItem { id: root - - onResetHomeScreenPosition: { - homescreen.triggerHomescreen(); - } - - onHomeTriggered: { - search.close(); - } Component.onCompleted: { Halcyon.ApplicationListModel.loadApplications(); - Halcyon.PinnedModel.applet = plasmoid.nativeInterface; + Halcyon.PinnedModel.applet = Plasmoid.nativeInterface; forceActiveFocus(); } - Rectangle { - id: darkenBackground - color: root.overlayShown ? 'transparent' : (homescreen.page == 1 ? Qt.rgba(0, 0, 0, 0.7) : Qt.rgba(0, 0, 0, 0.2)) - anchors.fill: parent - z: -1 - Behavior on color { - ColorAnimation { duration: PlasmaCore.Units.longDuration } - } - } - Plasmoid.onActivated: { // there's a couple of steps: // - minimize windows (only if we are in an app) @@ -58,45 +40,68 @@ MobileShell.HomeScreen { search.close(); } - homescreen.page = 0; + halcyonHomeScreen.page = 0; WindowPlugin.WindowUtil.isShowingDesktop = true; - } else if (homescreen.page == 0) { - homescreen.page = 1; + } else if (halcyonHomeScreen.page == 0) { + halcyonHomeScreen.page = 1; } else { WindowPlugin.WindowUtil.isShowingDesktop = false; - homescreen.page = 0; + halcyonHomeScreen.page = 0; } } - - // homescreen component - contentItem: Item { - HomeScreen { - id: homescreen - anchors.fill: parent - - topMargin: root.topMargin - bottomMargin: root.bottomMargin - leftMargin: root.leftMargin - rightMargin: root.rightMargin - // make the homescreen not interactable when task switcher or startup feedback is on - interactive: !root.overlayShown - searchWidget: search + Rectangle { + id: darkenBackground + color: homeScreen.overlayShown ? 'transparent' : (halcyonHomeScreen.page == 1 ? Qt.rgba(0, 0, 0, 0.7) : Qt.rgba(0, 0, 0, 0.2)) + anchors.fill: parent + z: -1 + Behavior on color { + ColorAnimation { duration: PlasmaCore.Units.longDuration } } - - // search component - MobileShell.KRunnerWidget { - id: search - anchors.fill: parent - visible: openFactor > 0 + } - onActionTriggered: search.close() - - topMargin: root.topMargin - bottomMargin: root.bottomMargin - leftMargin: root.leftMargin - rightMargin: root.rightMargin + MobileShell.HomeScreen { + id: homeScreen + anchors.fill: parent + + onResetHomeScreenPosition: { + halcyonHomeScreen.triggerHomescreen(); + } + + onHomeTriggered: { + search.close(); + } + + // homescreen component + contentItem: Item { + HomeScreen { + id: halcyonHomeScreen + anchors.fill: parent + + topMargin: homeScreen.topMargin + bottomMargin: homeScreen.bottomMargin + leftMargin: homeScreen.leftMargin + rightMargin: homeScreen.rightMargin + + // make the homescreen not interactable when task switcher or startup feedback is on + interactive: !homeScreen.overlayShown + searchWidget: search + } + + // search component + MobileShell.KRunnerWidget { + id: search + anchors.fill: parent + visible: openFactor > 0 + + onActionTriggered: search.close() + + topMargin: homeScreen.topMargin + bottomMargin: homeScreen.bottomMargin + leftMargin: homeScreen.leftMargin + rightMargin: homeScreen.rightMargin + } } } }