From f25840bfc2b89d61aa47bf79a86825574a0f3441 Mon Sep 17 00:00:00 2001 From: Devin Lin Date: Sun, 19 Mar 2023 18:32:19 -0700 Subject: [PATCH] mobileshellstate: Move to DBus API instead of trying to use shared QML context This also allows us to trigger behaviour from other processes that import mobileshell --- .../quicksettings/QuickSettingsDelegate.qml | 4 +- .../qml/components/StartupFeedback.qml | 8 +- .../mobileshell/qml/homescreen/HomeScreen.qml | 34 +----- .../mobileshell/qml/volumeosd/VolumeOSD.qml | 2 +- .../mediacontrols/MediaControlsWidget.qml | 2 +- components/mobileshellstate/CMakeLists.txt | 16 +++ .../mobileshellstateplugin.cpp | 10 +- .../qml/HomeScreenControls.qml | 26 ---- components/mobileshellstate/qml/Shell.qml | 47 -------- .../mobileshellstate/qml/TopPanelControls.qml | 26 ---- components/mobileshellstate/resources.qrc | 3 - .../mobileshellstate/shelldbusclient.cpp | 112 ++++++++++++++++++ components/mobileshellstate/shelldbusclient.h | 60 ++++++++++ .../mobileshellstate/shelldbusobject.cpp | 70 +++++++++++ components/mobileshellstate/shelldbusobject.h | 46 +++++++ .../package/contents/ui/HomeDelegate.qml | 6 - .../package/contents/ui/LauncherRepeater.qml | 2 +- .../ui/appdrawer/GridViewAppDrawer.qml | 2 +- .../ui/appdrawer/ListViewAppDrawer.qml | 2 +- .../folio/package/contents/ui/main.qml | 20 ++-- .../contents/ui/FavoritesAppDelegate.qml | 2 +- .../package/contents/ui/GridAppList.qml | 2 +- .../halcyon/package/contents/ui/main.qml | 11 +- .../panel/package/contents/ui/main.qml | 54 ++++----- .../contents/ui/NavigationPanelComponent.qml | 4 +- .../donotdisturb/contents/ui/main.qml | 11 +- .../record/package/contents/ui/main.qml | 2 +- .../screenshot/package/contents/ui/main.qml | 11 +- shell/contents/views/Desktop.qml | 8 +- 29 files changed, 381 insertions(+), 222 deletions(-) delete mode 100644 components/mobileshellstate/qml/HomeScreenControls.qml delete mode 100644 components/mobileshellstate/qml/Shell.qml delete mode 100644 components/mobileshellstate/qml/TopPanelControls.qml create mode 100644 components/mobileshellstate/shelldbusclient.cpp create mode 100644 components/mobileshellstate/shelldbusclient.h create mode 100644 components/mobileshellstate/shelldbusobject.cpp create mode 100644 components/mobileshellstate/shelldbusobject.h diff --git a/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsDelegate.qml b/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsDelegate.qml index 5167d44c..195297ca 100644 --- a/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsDelegate.qml +++ b/components/mobileshell/qml/actiondrawer/quicksettings/QuickSettingsDelegate.qml @@ -66,7 +66,7 @@ Components.BaseItem { root.toggleFunction(); } else if (root.settingsCommand && !root.restrictedPermissions) { closeRequested(); - MobileShellState.Shell.openAppLaunchAnimation( + MobileShellState.ShellDBusClient.openAppLaunchAnimation( root.icon, root.text, iconItem.Kirigami.ScenePosition.x + iconItem.width/2, @@ -79,7 +79,7 @@ Components.BaseItem { function delegatePressAndHold() { if (root.settingsCommand && !root.restrictedPermissions) { closeRequested(); - MobileShellState.Shell.openAppLaunchAnimation( + MobileShellState.ShellDBusClient.openAppLaunchAnimation( root.icon, root.text, iconItem.Kirigami.ScenePosition.x + iconItem.width/2, diff --git a/components/mobileshell/qml/components/StartupFeedback.qml b/components/mobileshell/qml/components/StartupFeedback.qml index f9bd60c9..43ce3ccf 100644 --- a/components/mobileshell/qml/components/StartupFeedback.qml +++ b/components/mobileshell/qml/components/StartupFeedback.qml @@ -57,8 +57,8 @@ MouseArea { // use mousearea to ensure clicks don't go behind // close when homescreen requested Connections { - target: MobileShellState.HomeScreenControls - function onOpenHomeScreen() { + target: MobileShellState.ShellDBusClient + function onOpenHomeScreenRequested() { root.close(); } } @@ -129,7 +129,7 @@ MouseArea { // use mousearea to ensure clicks don't go behind ScriptAction { script: { // close the app drawer after it isn't visible - MobileShellState.HomeScreenControls.resetHomeScreenPosition(); + MobileShellState.ShellDBusClient.resetHomeScreenPosition(); } } } @@ -161,7 +161,7 @@ MouseArea { // use mousearea to ensure clicks don't go behind ScriptAction { script: { // close the app drawer after it isn't visible - MobileShellState.HomeScreenControls.resetHomeScreenPosition(); + MobileShellState.ShellDBusClient.resetHomeScreenPosition(); } } } diff --git a/components/mobileshell/qml/homescreen/HomeScreen.qml b/components/mobileshell/qml/homescreen/HomeScreen.qml index 40c461ab..f9c70f43 100644 --- a/components/mobileshell/qml/homescreen/HomeScreen.qml +++ b/components/mobileshell/qml/homescreen/HomeScreen.qml @@ -77,14 +77,14 @@ Item { //BEGIN API implementation Connections { - target: MobileShellState.HomeScreenControls + target: MobileShellState.ShellDBusClient - function onOpenHomeScreen() { + function onOpenHomeScreenRequested() { if (WindowPlugin.WindowMaximizedTracker.showingWindow) { itemContainer.zoomIn(); } - MobileShellState.HomeScreenControls.resetHomeScreenPosition(); + resetHomeScreenPosition(); WindowPlugin.WindowUtil.unsetAllMinimizedGeometries(root); WindowPlugin.WindowUtil.minimizeAll(); @@ -92,46 +92,24 @@ Item { root.homeTriggered(); } - function onResetHomeScreenPosition() { + function onResetHomeScreenPositionRequested() { root.resetHomeScreenPosition(); } - function onRequestRelativeScroll(pos) { - // TODO - //homescreen.appDrawer.offset -= pos.y; - //lastRequestedPosition = pos.y; - } - - function onOpenAppLaunchAnimation(splashIcon, title, x, y, sourceIconSize) { + function onOpenAppLaunchAnimationRequested(splashIcon, title, x, y, sourceIconSize) { startupFeedback.open(splashIcon, title, x, y, sourceIconSize); } - function onCloseAppLaunchAnimation() { + function onCloseAppLaunchAnimationRequested() { startupFeedback.close(); } } - - Plasmoid.onScreenChanged: { - if (plasmoid.screen == 0) { - MobileShellState.HomeScreenControls.homeScreenWindow = root.Window.window; - } - } - Window.onWindowChanged: { - if (plasmoid.screen == 0) { - MobileShellState.HomeScreenControls.homeScreenWindow = root.Window.window; - } - } //END API implementation Component.onCompleted: { // determine the margins used evaluateMargins(); - - // set API variables - if (plasmoid.screen == 0) { - MobileShellState.HomeScreenControls.homeScreenWindow = root.Window.window; - } } // homescreen visual component diff --git a/components/mobileshell/qml/volumeosd/VolumeOSD.qml b/components/mobileshell/qml/volumeosd/VolumeOSD.qml index b6c65601..289b54e9 100644 --- a/components/mobileshell/qml/volumeosd/VolumeOSD.qml +++ b/components/mobileshell/qml/volumeosd/VolumeOSD.qml @@ -179,7 +179,7 @@ Window { onClicked: { let coords = mapToItem(flickable, 0, 0); - MobileShellState.Shell.openAppLaunchAnimation("audio-volume-high", i18n("Audio Settings"), coords.x, coords.y, PlasmaCore.Units.iconSizes.medium); + MobileShellState.ShellDBusClient.openAppLaunchAnimation("audio-volume-high", i18n("Audio Settings"), coords.x, coords.y, PlasmaCore.Units.iconSizes.medium); MobileShell.ShellUtil.executeCommand("plasma-open-settings kcm_pulseaudio"); } } diff --git a/components/mobileshell/qml/widgets/mediacontrols/MediaControlsWidget.qml b/components/mobileshell/qml/widgets/mediacontrols/MediaControlsWidget.qml index 14931927..e2e916b8 100644 --- a/components/mobileshell/qml/widgets/mediacontrols/MediaControlsWidget.qml +++ b/components/mobileshell/qml/widgets/mediacontrols/MediaControlsWidget.qml @@ -75,7 +75,7 @@ Item { onClicked: { Components.AppLaunch.launchOrActivateApp(modelData.desktopEntry + ".desktop"); - MobileShellState.Shell.closeActionDrawer(); + MobileShellState.ShellDBusClient.closeActionDrawer(); } Components.BaseItem { diff --git a/components/mobileshellstate/CMakeLists.txt b/components/mobileshellstate/CMakeLists.txt index f2908436..7a749cc4 100644 --- a/components/mobileshellstate/CMakeLists.txt +++ b/components/mobileshellstate/CMakeLists.txt @@ -6,7 +6,22 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/..) set(mobileshellstateplugin_SRCS mobileshellstateplugin.cpp + shelldbusobject.cpp + shelldbusclient.cpp ) + +qt_generate_dbus_interface( + ${CMAKE_CURRENT_SOURCE_DIR}/shelldbusobject.h + org.kde.plasmashell.Mobile.xml + OPTIONS -s -m -P +) + +qt_add_dbus_adaptor(mobileshellstateplugin_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasmashell.Mobile.xml + ${CMAKE_CURRENT_SOURCE_DIR}/shelldbusobject.h ShellDBusObject) +qt_add_dbus_interface(mobileshellstateplugin_SRCS ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasmashell.Mobile.xml plasmashellmobileinterface) + +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.kde.plasmashell.Mobile.xml DESTINATION ${KDE_INSTALL_DBUSINTERFACEDIR}) + qt_add_resources(RESOURCES resources.qrc) add_library(mobileshellstateplugin SHARED ${mobileshellstateplugin_SRCS} ${RESOURCES}) @@ -18,6 +33,7 @@ target_link_libraries(mobileshellstateplugin Qt::Qml Qt::Gui Qt::Quick + Qt::DBus KF6::Plasma KF6::I18n KF6::Notifications diff --git a/components/mobileshellstate/mobileshellstateplugin.cpp b/components/mobileshellstate/mobileshellstateplugin.cpp index 8c9b9304..3b5c51e0 100644 --- a/components/mobileshellstate/mobileshellstateplugin.cpp +++ b/components/mobileshellstate/mobileshellstateplugin.cpp @@ -2,6 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "mobileshellstateplugin.h" +#include "shelldbusclient.h" +#include "shelldbusobject.h" #include #include @@ -15,9 +17,11 @@ void MobileShellStatePlugin::registerTypes(const char *uri) { Q_ASSERT(QLatin1String(uri) == QLatin1String("org.kde.plasma.private.mobileshell.state")); + qmlRegisterType(uri, 1, 0, "ShellDBusObject"); + qmlRegisterSingletonType(uri, 1, 0, "ShellDBusClient", [](QQmlEngine *, QJSEngine *) -> QObject * { + return ShellDBusClient::self(); + }); + // / qmlRegisterSingletonType(resolvePath("AudioProvider.qml"), uri, 1, 0, "AudioProvider"); - qmlRegisterSingletonType(resolvePath("HomeScreenControls.qml"), uri, 1, 0, "HomeScreenControls"); - qmlRegisterSingletonType(resolvePath("Shell.qml"), uri, 1, 0, "Shell"); - qmlRegisterSingletonType(resolvePath("TopPanelControls.qml"), uri, 1, 0, "TopPanelControls"); } diff --git a/components/mobileshellstate/qml/HomeScreenControls.qml b/components/mobileshellstate/qml/HomeScreenControls.qml deleted file mode 100644 index cf68a416..00000000 --- a/components/mobileshellstate/qml/HomeScreenControls.qml +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-FileCopyrightText: 2020 Marco Martin -// SPDX-FileCopyrightText: 2021 Devin Lin -// SPDX-License-Identifier: GPL-2.0-or-later - -import QtQuick 2.12 -import QtQuick.Window 2.2 - -pragma Singleton - -/** - * Provides access to the homescreen plasmoid containment within the shell. - */ -QtObject { - id: root - - signal openHomeScreen() - signal resetHomeScreenPosition() - signal requestRelativeScroll(point pos) - - signal openAppLaunchAnimation(string splashIcon, string title, real x, real y, real sourceIconSize) - signal closeAppLaunchAnimation() - - property var taskSwitcher - property QtObject homeScreenWindow - property bool taskSwitcherVisible: false -} diff --git a/components/mobileshellstate/qml/Shell.qml b/components/mobileshellstate/qml/Shell.qml deleted file mode 100644 index cd35efaf..00000000 --- a/components/mobileshellstate/qml/Shell.qml +++ /dev/null @@ -1,47 +0,0 @@ -// SPDX-FileCopyrightText: 2022 Devin Lin -// SPDX-License-Identifier: GPL-2.0-or-later - -import QtQuick 2.15 -import QtQuick.Window 2.15 - -pragma Singleton - -/** - * Provides access to common functions within the shell. Only available within the plasmashell process. - */ -QtObject { - id: delegate - - /** - * Whether the action drawer is currently open. - */ - readonly property bool actionDrawerVisible: TopPanelControls.actionDrawerVisible - - /** - * Open the app launch screen with animation parameters. - */ - function openAppLaunchAnimation(splashIcon: string, title: string, x: real, y: real, sourceIconSize: real) { - HomeScreenControls.openAppLaunchAnimation(splashIcon, title, x, y, sourceIconSize); - } - - /** - * Close the app launch screen. - */ - function closeAppLaunchAnimation() { - HomeScreenControls.closeAppLaunchAnimation(); - } - - /** - * Open the action drawer. - */ - function openActionDrawer() { - TopPanelControls.openActionDrawer(); - } - - /** - * Close the action drawer, if it is open. - */ - function closeActionDrawer() { - TopPanelControls.closeActionDrawer(); - } -} diff --git a/components/mobileshellstate/qml/TopPanelControls.qml b/components/mobileshellstate/qml/TopPanelControls.qml deleted file mode 100644 index 6a140644..00000000 --- a/components/mobileshellstate/qml/TopPanelControls.qml +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2021 Devin Lin - * - * SPDX-License-Identifier: GPL-2.0-or-later - */ - -import QtQuick 2.12 -import org.kde.plasma.core 2.0 as PlasmaCore - -pragma Singleton - -/** - * Provides access to the panel plasmoid containment within the shell. - */ -QtObject { - id: root - - signal startSwipe() - signal endSwipe() - signal requestRelativeScroll(real offsetY) - signal closeActionDrawer() - signal openActionDrawer() - property bool inSwipe: false - property bool actionDrawerVisible: false - property var notificationsWidget: null // updated in panel containment -} diff --git a/components/mobileshellstate/resources.qrc b/components/mobileshellstate/resources.qrc index 728f27b2..7653d82f 100644 --- a/components/mobileshellstate/resources.qrc +++ b/components/mobileshellstate/resources.qrc @@ -4,9 +4,6 @@ --> - qml/HomeScreenControls.qml - qml/Shell.qml - qml/TopPanelControls.qml qml/AudioProvider.qml diff --git a/components/mobileshellstate/shelldbusclient.cpp b/components/mobileshellstate/shelldbusclient.cpp new file mode 100644 index 00000000..5f07dfb2 --- /dev/null +++ b/components/mobileshellstate/shelldbusclient.cpp @@ -0,0 +1,112 @@ +// SPDX-FileCopyrightText: 2023 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "shelldbusclient.h" + +#include + +ShellDBusClient::ShellDBusClient(QObject *parent) + : QObject{parent} + , m_interface{new OrgKdePlasmashellInterface{QStringLiteral("org.kde.plasmashell"), QStringLiteral("/Mobile"), QDBusConnection::sessionBus(), this}} + , m_connected{false} +{ + m_watcher = new QDBusServiceWatcher(QStringLiteral("org.kde.plasmashell"), QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + + if (m_interface->isValid()) { + connectSignals(); + } + + connect(m_watcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() -> void { + m_connected = true; + if (m_interface->isValid()) { + connectSignals(); + } + }); + + connect(m_watcher, &QDBusServiceWatcher::serviceUnregistered, this, [this]() -> void { + m_connected = false; + }); +} + +ShellDBusClient *ShellDBusClient::self() +{ + static ShellDBusClient *instance = new ShellDBusClient; + return instance; +} + +void ShellDBusClient::connectSignals() +{ + connect(m_interface, &OrgKdePlasmashellInterface::isActionDrawerOpenChanged, this, &ShellDBusClient::updateIsActionDrawerOpen); + connect(m_interface, &OrgKdePlasmashellInterface::doNotDisturbChanged, this, &ShellDBusClient::updateDoNotDisturb); + connect(m_interface, &OrgKdePlasmashellInterface::openActionDrawerRequested, this, &ShellDBusClient::openActionDrawerRequested); + connect(m_interface, &OrgKdePlasmashellInterface::closeActionDrawerRequested, this, &ShellDBusClient::closeActionDrawerRequested); + connect(m_interface, &OrgKdePlasmashellInterface::openAppLaunchAnimationRequested, this, &ShellDBusClient::openAppLaunchAnimationRequested); + connect(m_interface, &OrgKdePlasmashellInterface::closeAppLaunchAnimationRequested, this, &ShellDBusClient::closeAppLaunchAnimationRequested); + connect(m_interface, &OrgKdePlasmashellInterface::openHomeScreenRequested, this, &ShellDBusClient::openHomeScreenRequested); + connect(m_interface, &OrgKdePlasmashellInterface::resetHomeScreenPositionRequested, this, &ShellDBusClient::resetHomeScreenPositionRequested); + + updateIsActionDrawerOpen(); + updateDoNotDisturb(); +} + +bool ShellDBusClient::doNotDisturb() +{ + return m_doNotDisturb; +} + +void ShellDBusClient::setDoNotDisturb(bool value) +{ + m_interface->setDoNotDisturb(value); +} + +bool ShellDBusClient::isActionDrawerOpen() +{ + return m_isActionDrawerOpen; +} + +void ShellDBusClient::setIsActionDrawerOpen(bool value) +{ + m_interface->setIsActionDrawerOpen(value); +} + +void ShellDBusClient::openActionDrawer() +{ + m_interface->openActionDrawer(); +} + +void ShellDBusClient::closeActionDrawer() +{ + m_interface->closeActionDrawer(); +} + +void ShellDBusClient::openAppLaunchAnimation(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize) +{ + m_interface->openAppLaunchAnimation(splashIcon, title, x, y, sourceIconSize); +} + +void ShellDBusClient::closeAppLaunchAnimation() +{ + m_interface->closeAppLaunchAnimation(); +} + +void ShellDBusClient::openHomeScreen() +{ + m_interface->openHomeScreen(); +} + +void ShellDBusClient::resetHomeScreenPosition() +{ + m_interface->resetHomeScreenPosition(); +} + +void ShellDBusClient::updateDoNotDisturb() +{ + m_doNotDisturb = m_interface->doNotDisturb(); + Q_EMIT doNotDisturbChanged(); +} + +void ShellDBusClient::updateIsActionDrawerOpen() +{ + m_isActionDrawerOpen = m_interface->isActionDrawerOpen(); + Q_EMIT isActionDrawerOpenChanged(); +} diff --git a/components/mobileshellstate/shelldbusclient.h b/components/mobileshellstate/shelldbusclient.h new file mode 100644 index 00000000..ff1422d2 --- /dev/null +++ b/components/mobileshellstate/shelldbusclient.h @@ -0,0 +1,60 @@ +// SPDX-FileCopyrightText: 2023 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "plasmashellmobileinterface.h" + +#include +#include +#include + +class ShellDBusClient : public QObject +{ + Q_OBJECT + Q_PROPERTY(bool doNotDisturb READ doNotDisturb WRITE setDoNotDisturb NOTIFY doNotDisturbChanged); + Q_PROPERTY(bool isActionDrawerOpen READ isActionDrawerOpen WRITE setIsActionDrawerOpen NOTIFY isActionDrawerOpenChanged); + +public: + explicit ShellDBusClient(QObject *parent = nullptr); + static ShellDBusClient *self(); + + bool doNotDisturb(); + void setDoNotDisturb(bool value); + + bool isActionDrawerOpen(); + void setIsActionDrawerOpen(bool value); + + Q_INVOKABLE void openActionDrawer(); + Q_INVOKABLE void closeActionDrawer(); + + Q_INVOKABLE void openAppLaunchAnimation(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize); + Q_INVOKABLE void closeAppLaunchAnimation(); + + Q_INVOKABLE void openHomeScreen(); + Q_INVOKABLE void resetHomeScreenPosition(); + +Q_SIGNALS: + void isActionDrawerOpenChanged(); + void doNotDisturbChanged(); + void openActionDrawerRequested(); + void closeActionDrawerRequested(); + void openAppLaunchAnimationRequested(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize); + void closeAppLaunchAnimationRequested(); + void openHomeScreenRequested(); + void resetHomeScreenPositionRequested(); + +private Q_SLOTS: + void updateDoNotDisturb(); + void updateIsActionDrawerOpen(); + +private: + void connectSignals(); + + OrgKdePlasmashellInterface *m_interface; + QDBusServiceWatcher *m_watcher; + + bool m_doNotDisturb; + bool m_isActionDrawerOpen; + bool m_connected; +}; diff --git a/components/mobileshellstate/shelldbusobject.cpp b/components/mobileshellstate/shelldbusobject.cpp new file mode 100644 index 00000000..289799dd --- /dev/null +++ b/components/mobileshellstate/shelldbusobject.cpp @@ -0,0 +1,70 @@ +// SPDX-FileCopyrightText: 2023 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "shelldbusobject.h" +#include "mobileadaptor.h" + +#include + +ShellDBusObject::ShellDBusObject(QObject *parent) + : QObject{parent} +{ + new PlasmashellAdaptor{this}; + QDBusConnection::sessionBus().registerObject(QStringLiteral("/Mobile"), this); +} + +bool ShellDBusObject::doNotDisturb() +{ + return m_doNotDisturb; +} + +void ShellDBusObject::setDoNotDisturb(bool value) +{ + if (value != m_doNotDisturb) { + m_doNotDisturb = value; + Q_EMIT doNotDisturbChanged(); + } +} + +bool ShellDBusObject::isActionDrawerOpen() +{ + return m_isActionDrawerOpen; +} + +void ShellDBusObject::setIsActionDrawerOpen(bool value) +{ + if (value != m_isActionDrawerOpen) { + m_isActionDrawerOpen = value; + Q_EMIT isActionDrawerOpenChanged(); + } +} + +void ShellDBusObject::openActionDrawer() +{ + Q_EMIT openActionDrawerRequested(); +} + +void ShellDBusObject::closeActionDrawer() +{ + Q_EMIT closeActionDrawerRequested(); +} + +void ShellDBusObject::openAppLaunchAnimation(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize) +{ + Q_EMIT openAppLaunchAnimationRequested(splashIcon, title, x, y, sourceIconSize); +} + +void ShellDBusObject::closeAppLaunchAnimation() +{ + Q_EMIT closeAppLaunchAnimationRequested(); +} + +void ShellDBusObject::openHomeScreen() +{ + Q_EMIT openHomeScreenRequested(); +} + +void ShellDBusObject::resetHomeScreenPosition() +{ + Q_EMIT resetHomeScreenPositionRequested(); +} diff --git a/components/mobileshellstate/shelldbusobject.h b/components/mobileshellstate/shelldbusobject.h new file mode 100644 index 00000000..a4cc2489 --- /dev/null +++ b/components/mobileshellstate/shelldbusobject.h @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2023 Devin Lin +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include +#include + +class ShellDBusObject : public QObject +{ + Q_OBJECT + Q_CLASSINFO("D-Bus Interface", "org.kde.plasmashell") + +public: + ShellDBusObject(QObject *parent = nullptr); + +Q_SIGNALS: + Q_SCRIPTABLE void doNotDisturbChanged(); + Q_SCRIPTABLE void isActionDrawerOpenChanged(); + Q_SCRIPTABLE void openActionDrawerRequested(); + Q_SCRIPTABLE void closeActionDrawerRequested(); + Q_SCRIPTABLE void openAppLaunchAnimationRequested(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize); + Q_SCRIPTABLE void closeAppLaunchAnimationRequested(); + Q_SCRIPTABLE void openHomeScreenRequested(); + Q_SCRIPTABLE void resetHomeScreenPositionRequested(); + +public Q_SLOTS: + Q_SCRIPTABLE bool doNotDisturb(); + Q_SCRIPTABLE void setDoNotDisturb(bool value); + + Q_SCRIPTABLE bool isActionDrawerOpen(); + Q_SCRIPTABLE void setIsActionDrawerOpen(bool value); + + Q_SCRIPTABLE void openActionDrawer(); + Q_SCRIPTABLE void closeActionDrawer(); + + Q_SCRIPTABLE void openAppLaunchAnimation(QString splashIcon, QString title, qreal x, qreal y, qreal sourceIconSize); + Q_SCRIPTABLE void closeAppLaunchAnimation(); + + Q_SCRIPTABLE void openHomeScreen(); + Q_SCRIPTABLE void resetHomeScreenPosition(); + +private: + bool m_doNotDisturb = false; + bool m_isActionDrawerOpen = false; +}; diff --git a/containments/homescreens/folio/package/contents/ui/HomeDelegate.qml b/containments/homescreens/folio/package/contents/ui/HomeDelegate.qml index e5f334cd..d7e77ecd 100644 --- a/containments/homescreens/folio/package/contents/ui/HomeDelegate.qml +++ b/containments/homescreens/folio/package/contents/ui/HomeDelegate.qml @@ -86,12 +86,6 @@ ContainmentLayoutManager.ItemContainer { syncDelegateGeometry() } } - Connections { - target: MobileShellState.Shell - function onTaskSwitcherVisibleChanged() { - syncDelegateGeometry(); - } - } Connections { target: appletsLayout function onAppletsLayoutInteracted() { diff --git a/containments/homescreens/folio/package/contents/ui/LauncherRepeater.qml b/containments/homescreens/folio/package/contents/ui/LauncherRepeater.qml index 223ea813..e4f0b9f8 100644 --- a/containments/homescreens/folio/package/contents/ui/LauncherRepeater.qml +++ b/containments/homescreens/folio/package/contents/ui/LauncherRepeater.qml @@ -106,7 +106,7 @@ Repeater { onLaunch: (x, y, icon, title) => { if (icon !== "") { - MobileShellState.Shell.openAppLaunchAnimation( + MobileShellState.ShellDBusClient.openAppLaunchAnimation( icon, title, delegate.iconItem.Kirigami.ScenePosition.x + delegate.iconItem.width/2, diff --git a/containments/homescreens/folio/package/contents/ui/appdrawer/GridViewAppDrawer.qml b/containments/homescreens/folio/package/contents/ui/appdrawer/GridViewAppDrawer.qml index 1c8e7400..d80bdab0 100644 --- a/containments/homescreens/folio/package/contents/ui/appdrawer/GridViewAppDrawer.qml +++ b/containments/homescreens/folio/package/contents/ui/appdrawer/GridViewAppDrawer.qml @@ -69,7 +69,7 @@ AbstractAppDrawer { } onLaunch: (x, y, icon, title, storageId) => { if (icon !== "") { - MobileShellState.Shell.openAppLaunchAnimation( + MobileShellState.ShellDBusClient.openAppLaunchAnimation( icon, title, delegate.iconItem.Kirigami.ScenePosition.x + delegate.iconItem.width/2, diff --git a/containments/homescreens/folio/package/contents/ui/appdrawer/ListViewAppDrawer.qml b/containments/homescreens/folio/package/contents/ui/appdrawer/ListViewAppDrawer.qml index ce07ae4f..b14eb58e 100644 --- a/containments/homescreens/folio/package/contents/ui/appdrawer/ListViewAppDrawer.qml +++ b/containments/homescreens/folio/package/contents/ui/appdrawer/ListViewAppDrawer.qml @@ -55,7 +55,7 @@ AbstractAppDrawer { } onLaunch: (x, y, icon, title, storageId) => { if (icon !== "") { - MobileShell.HomeScreenControls.openAppLaunchAnimation( + MobileShellState.ShellDBusClient.openAppLaunchAnimation( icon, title, delegate.iconItem.Kirigami.ScenePosition.x + delegate.iconItem.width/2, diff --git a/containments/homescreens/folio/package/contents/ui/main.qml b/containments/homescreens/folio/package/contents/ui/main.qml index 700f0e7a..c7cac778 100644 --- a/containments/homescreens/folio/package/contents/ui/main.qml +++ b/containments/homescreens/folio/package/contents/ui/main.qml @@ -44,14 +44,16 @@ MobileShell.HomeScreen { // - minimize windows (only if we are in an app) // - open app drawer // - close app drawer and, if necessary, restore windows + + // Always close action drawer + if (MobileShellState.ShellDBusClient.isActionDrawerOpen) { + MobileShellState.ShellDBusClient.closeActionDrawer(); + } + if (!WindowPlugin.WindowUtil.isShowingDesktop && WindowPlugin.WindowMaximizedTracker.showingWindow - || MobileShellState.Shell.actionDrawerVisible + || MobileShellState.ShellDBusClient.isActionDrawerOpen || searchWidget.isOpen ) { - // Always close action drawer - if (MobileShellState.Shell.actionDrawerVisible) { - MobileShellState.Shell.closeActionDrawer(); - } // Always close the search widget as well if (searchWidget.isOpen) { @@ -93,14 +95,6 @@ MobileShell.HomeScreen { bottomMargin: root.bottomMargin leftMargin: root.leftMargin rightMargin: root.rightMargin - - // close search component when task switcher is shown or hidden - Connections { - target: MobileShellState.HomeScreenControls.taskSwitcher - function onVisibleChanged() { - searchWidget.close(); - } - } } } diff --git a/containments/homescreens/halcyon/package/contents/ui/FavoritesAppDelegate.qml b/containments/homescreens/halcyon/package/contents/ui/FavoritesAppDelegate.qml index c909b371..303a164f 100644 --- a/containments/homescreens/halcyon/package/contents/ui/FavoritesAppDelegate.qml +++ b/containments/homescreens/halcyon/package/contents/ui/FavoritesAppDelegate.qml @@ -80,7 +80,7 @@ Item { function launchAppWithAnim(x: int, y: int, source, title: string, storageId: string) { if (source !== "") { - MobileShellState.Shell.openAppLaunchAnimation( + MobileShellState.ShellDBusClient.openAppLaunchAnimation( source, title, iconLoader.Kirigami.ScenePosition.x + iconLoader.width/2, diff --git a/containments/homescreens/halcyon/package/contents/ui/GridAppList.qml b/containments/homescreens/halcyon/package/contents/ui/GridAppList.qml index 2b148f85..e43832df 100644 --- a/containments/homescreens/halcyon/package/contents/ui/GridAppList.qml +++ b/containments/homescreens/halcyon/package/contents/ui/GridAppList.qml @@ -90,7 +90,7 @@ MobileShell.GridView { onLaunch: (x, y, icon, title, storageId) => { if (icon !== "") { - MobileShellState.Shell.openAppLaunchAnimation( + MobileShellState.ShellDBusClient.openAppLaunchAnimation( icon, title, delegate.iconItem.Kirigami.ScenePosition.x + delegate.iconItem.width/2, diff --git a/containments/homescreens/halcyon/package/contents/ui/main.qml b/containments/homescreens/halcyon/package/contents/ui/main.qml index b6d8db85..9c5ce41a 100644 --- a/containments/homescreens/halcyon/package/contents/ui/main.qml +++ b/containments/homescreens/halcyon/package/contents/ui/main.qml @@ -46,12 +46,13 @@ MobileShell.HomeScreen { // - minimize windows (only if we are in an app) // - open app drawer // - close app drawer and, if necessary, restore windows - if (!WindowPlugin.WindowUtil.isShowingDesktop && WindowPlugin.WindowMaximizedTracker.showingWindow || search.isOpen) { - // Always close action drawer - if (MobileShellState.Shell.actionDrawerVisible) { - MobileShellState.Shell.closeActionDrawer(); - } + // Always close action drawer + if (MobileShellState.ShellDBusClient.isActionDrawerOpen) { + MobileShellState.ShellDBusClient.closeActionDrawer(); + } + + if (!WindowPlugin.WindowUtil.isShowingDesktop && WindowPlugin.WindowMaximizedTracker.showingWindow || search.isOpen) { // Always close the search widget as well if (search.isOpen) { search.close(); diff --git a/containments/panel/package/contents/ui/main.qml b/containments/panel/package/contents/ui/main.qml index 978adda5..0da73d59 100644 --- a/containments/panel/package/contents/ui/main.qml +++ b/containments/panel/package/contents/ui/main.qml @@ -44,43 +44,31 @@ Item { //BEGIN API implementation - Binding { - target: MobileShellState.TopPanelControls - property: "inSwipe" - value: drawer.actionDrawer.dragging - } - Binding { - target: MobileShellState.TopPanelControls - property: "actionDrawerVisible" - value: drawer.visible - } - - Binding { - target: MobileShellState.TopPanelControls - property: "notificationsWidget" - value: drawer.actionDrawer.notificationsWidget - } - Connections { - target: MobileShellState.TopPanelControls - - function onStartSwipe() { - swipeArea.startSwipe(); - } - function onEndSwipe() { - swipeArea.endSwipe(); - } - function onRequestRelativeScroll(offsetY) { - swipeArea.updateOffset(offsetY); - } - function onCloseActionDrawer() { - drawer.actionDrawer.close(); - } - function onOpenActionDrawer() { + target: MobileShellState.ShellDBusClient + + function onOpenActionDrawerRequested() { drawer.actionDrawer.open(); } + + function onCloseActionDrawerRequested() { + console.log('action drawer close'); + drawer.actionDrawer.close(); + } + + function onDoNotDisturbChanged() { + if (drawer.actionDrawer.notificationsWidget.doNotDisturbModeEnabled !== MobileShellState.ShellDBusClient.doNotDisturb) { + drawer.actionDrawer.notificationsWidget.toggleDoNotDisturbMode(); + } + } } - + + Binding { + target: MobileShellState.ShellDBusClient + property: "isActionDrawerOpen" + value: drawer.visible + } + //END API implementation Component.onCompleted: { diff --git a/containments/taskpanel/package/contents/ui/NavigationPanelComponent.qml b/containments/taskpanel/package/contents/ui/NavigationPanelComponent.qml index ec0b8dd6..c728b993 100644 --- a/containments/taskpanel/package/contents/ui/NavigationPanelComponent.qml +++ b/containments/taskpanel/package/contents/ui/NavigationPanelComponent.qml @@ -73,7 +73,7 @@ MobileShell.NavigationPanel { iconSizeFactor: 1 onTriggered: { - MobileShellState.HomeScreenControls.openHomeScreen(); + MobileShellState.ShellDBusClient.openHomeScreen(); } } @@ -95,7 +95,7 @@ MobileShell.NavigationPanel { if (tasksModel.activeTask !== 0) { tasksModel.requestClose(tasksModel.activeTask); } - MobileShellState.Shell.closeAppLaunchAnimation(); + MobileShellState.ShellDBusClient.closeAppLaunchAnimation(); } } } diff --git a/quicksettings/donotdisturb/contents/ui/main.qml b/quicksettings/donotdisturb/contents/ui/main.qml index c545c822..bfa8e30d 100644 --- a/quicksettings/donotdisturb/contents/ui/main.qml +++ b/quicksettings/donotdisturb/contents/ui/main.qml @@ -4,20 +4,17 @@ * SPDX-License-Identifier: LGPL-2.0-or-later */ -import org.kde.plasma.core 2.0 as PlasmaCore -import org.kde.plasma.private.mobileshell.state 1.0 as MobileShellState +import QtQuick +import org.kde.plasma.private.mobileshell.state as MobileShellState import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS QS.QuickSetting { text: i18n("Do Not Disturb") icon: enabled ? "notifications-disabled" : "notifications" status: "" - enabled: MobileShellState.TopPanelControls.notificationsWidget && MobileShellState.TopPanelControls.notificationsWidget.doNotDisturbModeEnabled - available: MobileShellState.TopPanelControls.notificationsWidget + enabled: MobileShellState.ShellDBusClient.doNotDisturb function toggle() { - if (MobileShellState.TopPanelControls.notificationsWidget) { - MobileShellState.TopPanelControls.notificationsWidget.toggleDoNotDisturbMode(); - } + MobileShellState.ShellDBusClient.doNotDisturb = !MobileShellState.ShellDBusClient.doNotDisturb; } } diff --git a/quicksettings/record/package/contents/ui/main.qml b/quicksettings/record/package/contents/ui/main.qml index 60529dbd..adec4ec4 100644 --- a/quicksettings/record/package/contents/ui/main.qml +++ b/quicksettings/record/package/contents/ui/main.qml @@ -39,7 +39,7 @@ QS.QuickSetting { } enabled = !enabled - MobileShellState.Shell.closeActionDrawer(); + MobileShellState.ShellDBusClient.closeActionDrawer(); } PWRec.PipeWireRecord { diff --git a/quicksettings/screenshot/package/contents/ui/main.qml b/quicksettings/screenshot/package/contents/ui/main.qml index c82529d6..7ce58171 100644 --- a/quicksettings/screenshot/package/contents/ui/main.qml +++ b/quicksettings/screenshot/package/contents/ui/main.qml @@ -4,8 +4,8 @@ import QtQuick 2.15 import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS -import org.kde.plasma.private.mobileshell.state 1.0 as MobileShellState -import org.kde.plasma.quicksetting.screenshot 1.0 +import org.kde.plasma.private.mobileshell.state as MobileShellState +import org.kde.plasma.quicksetting.screenshot QS.QuickSetting { text: i18n("Screenshot") @@ -17,12 +17,13 @@ QS.QuickSetting { function toggle() { screenshotRequested = true; - MobileShellState.Shell.closeActionDrawer(); + MobileShellState.ShellDBusClient.closeActionDrawer(); } Connections { - target: MobileShellState.Shell - function onActionDrawerVisibleChanged(visible) { + target: MobileShellState.ShellDBusClient + + function onIsActionDrawerOpenChanged(visible) { if (!visible && screenshotRequested) { screenshotRequested = false; timer.restart(); diff --git a/shell/contents/views/Desktop.qml b/shell/contents/views/Desktop.qml index 54d768fb..51c02f58 100644 --- a/shell/contents/views/Desktop.qml +++ b/shell/contents/views/Desktop.qml @@ -11,6 +11,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore import org.kde.plasma.shell 2.0 as Shell import org.kde.kquickcontrolsaddons 2.0 import org.kde.kirigami 2.20 as Kirigami +import org.kde.plasma.private.mobileshell.state as MobileShellState Rectangle { id: root @@ -61,10 +62,9 @@ Rectangle { containment.anchors.fill = root; } - Component.onCompleted: { - // desktop.windowType = Shell.Desktop.Desktop; - } - + // Load shell dbus object + MobileShellState.ShellDBusObject {} + // This is taken from plasma-desktop's shell package, try to keep it in sync Loader { id: wallpaperColors