From b1f5a5eb94badd180f182cd2bc1fb9687cb2f672 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Sun, 2 Jun 2024 16:18:45 -0700 Subject: [PATCH] service/mpris: preserve mpris watcher and players across reload --- BUILD.md | 2 +- src/core/proxywindow.cpp | 4 +--- src/services/mpris/watcher.cpp | 11 ++++++++++- src/services/mpris/watcher.hpp | 23 +++++++++++++++++------ 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/BUILD.md b/BUILD.md index 92589ccc..c9909598 100644 --- a/BUILD.md +++ b/BUILD.md @@ -43,7 +43,7 @@ To disable: `-DSOCKETS=OFF` ### Wayland This feature enables wayland support. Subfeatures exist for each particular wayland integration. -WARNING: Wayland integration relies on featurs that are not part of the public Qt API and which +WARNING: Wayland integration relies on features that are not part of the public Qt API and which may break in minor releases. Updating quickshell's dependencies without ensuring without ensuring that the current Qt version is supported WILL result in quickshell failing to build or misbehaving at runtime. diff --git a/src/core/proxywindow.cpp b/src/core/proxywindow.cpp index c2961c24..4eef5f38 100644 --- a/src/core/proxywindow.cpp +++ b/src/core/proxywindow.cpp @@ -156,9 +156,7 @@ void ProxyWindowBase::completeWindow() { emit this->screenChanged(); } -bool ProxyWindowBase::deleteOnInvisible() const { - return false; -} +bool ProxyWindowBase::deleteOnInvisible() const { return false; } QQuickWindow* ProxyWindowBase::backingWindow() const { return this->window; } QQuickItem* ProxyWindowBase::contentItem() const { return this->mContentItem; } diff --git a/src/services/mpris/watcher.cpp b/src/services/mpris/watcher.cpp index 8c67a4d6..8a788933 100644 --- a/src/services/mpris/watcher.cpp +++ b/src/services/mpris/watcher.cpp @@ -16,7 +16,7 @@ namespace qs::service::mpris { Q_LOGGING_CATEGORY(logMprisWatcher, "quickshell.service.mpris.watcher", QtWarningMsg); -MprisWatcher::MprisWatcher(QObject* parent): QObject(parent) { +MprisWatcher::MprisWatcher() { qCDebug(logMprisWatcher) << "Starting MprisWatcher"; auto bus = QDBusConnection::sessionBus(); @@ -102,4 +102,13 @@ void MprisWatcher::registerPlayer(const QString& address) { qCDebug(logMprisWatcher) << "Registered MprisPlayer" << address; } +MprisWatcher* MprisWatcher::instance() { + static MprisWatcher* instance = new MprisWatcher(); // NOLINT + return instance; +} + +ObjectModel* MprisQml::players() { // NOLINT + return MprisWatcher::instance()->players(); +} + } // namespace qs::service::mpris diff --git a/src/services/mpris/watcher.hpp b/src/services/mpris/watcher.hpp index 91275c7e..d60471cc 100644 --- a/src/services/mpris/watcher.hpp +++ b/src/services/mpris/watcher.hpp @@ -18,16 +18,12 @@ namespace qs::service::mpris { ///! Provides access to MprisPlayers. class MprisWatcher: public QObject { Q_OBJECT; - QML_NAMED_ELEMENT(Mpris); - QML_SINGLETON; - /// All connected MPRIS players. - Q_PROPERTY(ObjectModel* players READ players CONSTANT); public: - explicit MprisWatcher(QObject* parent = nullptr); - [[nodiscard]] ObjectModel* players(); + static MprisWatcher* instance(); + private slots: void onServiceRegistered(const QString& service); void onServiceUnregistered(const QString& service); @@ -35,6 +31,8 @@ private slots: void onPlayerDestroyed(QObject* object); private: + explicit MprisWatcher(); + void registerExisting(); void registerPlayer(const QString& address); @@ -43,4 +41,17 @@ private: ObjectModel readyPlayers {this}; }; +class MprisQml: public QObject { + Q_OBJECT; + QML_NAMED_ELEMENT(Mpris); + QML_SINGLETON; + /// All connected MPRIS players. + Q_PROPERTY(ObjectModel* players READ players CONSTANT); + +public: + explicit MprisQml(QObject* parent = nullptr): QObject(parent) {}; + + [[nodiscard]] ObjectModel* players(); +}; + } // namespace qs::service::mpris