forked from quickshell/quickshell
		
	service/mpris: preserve mpris watcher and players across reload
This commit is contained in:
		
							parent
							
								
									9d5dd402b9
								
							
						
					
					
						commit
						b1f5a5eb94
					
				
					 4 changed files with 29 additions and 11 deletions
				
			
		
							
								
								
									
										2
									
								
								BUILD.md
									
										
									
									
									
								
							
							
						
						
									
										2
									
								
								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.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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; }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<MprisPlayer>* MprisQml::players() { // NOLINT
 | 
			
		||||
	return MprisWatcher::instance()->players();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
} // namespace qs::service::mpris
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<MprisPlayer>* players READ players CONSTANT);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	explicit MprisWatcher(QObject* parent = nullptr);
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] ObjectModel<MprisPlayer>* 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<MprisPlayer> readyPlayers {this};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class MprisQml: public QObject {
 | 
			
		||||
	Q_OBJECT;
 | 
			
		||||
	QML_NAMED_ELEMENT(Mpris);
 | 
			
		||||
	QML_SINGLETON;
 | 
			
		||||
	/// All connected MPRIS players.
 | 
			
		||||
	Q_PROPERTY(ObjectModel<MprisPlayer>* players READ players CONSTANT);
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	explicit MprisQml(QObject* parent = nullptr): QObject(parent) {};
 | 
			
		||||
 | 
			
		||||
	[[nodiscard]] ObjectModel<MprisPlayer>* players();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
} // namespace qs::service::mpris
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue