Re-initialize colord integration when colord daemon is restarted

We need to re-create all colord devices in case colord daemon is reloaded.
This commit is contained in:
Vlad Zahorodnii 2020-11-26 20:29:10 +02:00
parent 3a7bce693e
commit 83003f0ccc
2 changed files with 36 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include "platform.h"
#include <QDBusPendingCallWatcher>
#include <QDBusServiceWatcher>
namespace KWin
{
@ -21,6 +22,22 @@ ColordIntegration::ColordIntegration(QObject *parent)
{
qDBusRegisterMetaType<CdStringMap>();
auto watcher = new QDBusServiceWatcher(QStringLiteral("org.freedesktop.ColorManager"),
QDBusConnection::systemBus(),
QDBusServiceWatcher::WatchForRegistration |
QDBusServiceWatcher::WatchForUnregistration, this);
connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &ColordIntegration::initialize);
connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &ColordIntegration::teardown);
QDBusConnectionInterface *interface = QDBusConnection::systemBus().interface();
if (interface->isServiceRegistered(QStringLiteral("org.freedesktop.ColorManager"))) {
initialize();
}
}
void ColordIntegration::initialize()
{
const Platform *platform = kwinApp()->platform();
m_colordInterface = new CdInterface(QStringLiteral("org.freedesktop.ColorManager"),
@ -36,6 +53,22 @@ ColordIntegration::ColordIntegration(QObject *parent)
connect(platform, &Platform::outputRemoved, this, &ColordIntegration::handleOutputRemoved);
}
void ColordIntegration::teardown()
{
const Platform *platform = kwinApp()->platform();
const QVector<AbstractOutput *> outputs = platform->outputs();
for (AbstractOutput *output : outputs) {
handleOutputRemoved(output);
}
delete m_colordInterface;
m_colordInterface = nullptr;
disconnect(platform, &Platform::outputAdded, this, &ColordIntegration::handleOutputAdded);
disconnect(platform, &Platform::outputRemoved, this, &ColordIntegration::handleOutputRemoved);
}
void ColordIntegration::handleOutputAdded(AbstractOutput *output)
{
ColordDevice *device = new ColordDevice(output, this);

View file

@ -30,6 +30,9 @@ private Q_SLOTS:
void handleOutputRemoved(AbstractOutput *output);
private:
void initialize();
void teardown();
QHash<AbstractOutput *, ColordDevice *> m_outputToDevice;
CdInterface *m_colordInterface;
};