f037a69f1c
This change introduces basic colord integration in wayland session. It is implemented as a binary plugin. If an output is connected, the plugin will create the corresponding colord device using the D-Bus API and start monitoring the device for changes. When a colord devices changes, the plugin will read the VCGT tag of the current ICC color profile and apply it.
82 lines
2.5 KiB
C++
82 lines
2.5 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "colordintegration.h"
|
|
#include "abstract_output.h"
|
|
#include "colorddevice.h"
|
|
#include "colordlogging.h"
|
|
#include "main.h"
|
|
#include "platform.h"
|
|
|
|
#include <QDBusPendingCallWatcher>
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
ColordIntegration::ColordIntegration(QObject *parent)
|
|
: Plugin(parent)
|
|
{
|
|
qDBusRegisterMetaType<CdStringMap>();
|
|
|
|
const Platform *platform = kwinApp()->platform();
|
|
|
|
m_colordInterface = new CdInterface(QStringLiteral("org.freedesktop.ColorManager"),
|
|
QStringLiteral("/org/freedesktop/ColorManager"),
|
|
QDBusConnection::systemBus(), this);
|
|
|
|
const QVector<AbstractOutput *> outputs = platform->outputs();
|
|
for (AbstractOutput *output : outputs) {
|
|
handleOutputAdded(output);
|
|
}
|
|
|
|
connect(platform, &Platform::outputAdded, this, &ColordIntegration::handleOutputAdded);
|
|
connect(platform, &Platform::outputRemoved, this, &ColordIntegration::handleOutputRemoved);
|
|
}
|
|
|
|
void ColordIntegration::handleOutputAdded(AbstractOutput *output)
|
|
{
|
|
ColordDevice *device = new ColordDevice(output, this);
|
|
|
|
CdStringMap properties;
|
|
properties.insert(QStringLiteral("Kind"), QStringLiteral("display"));
|
|
properties.insert(QStringLiteral("Colorspace"), QStringLiteral("RGB"));
|
|
|
|
QDBusPendingReply<QDBusObjectPath> reply =
|
|
m_colordInterface->CreateDevice(output->name(), QStringLiteral("temp"), properties);
|
|
|
|
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
|
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this, device, watcher]() {
|
|
watcher->deleteLater();
|
|
|
|
const QDBusPendingReply<QDBusObjectPath> reply = *watcher;
|
|
if (reply.isError()) {
|
|
qCDebug(KWIN_COLORD) << "Failed to add a colord device:" << reply.error();
|
|
delete device;
|
|
return;
|
|
}
|
|
|
|
const QDBusObjectPath objectPath = reply.value();
|
|
if (!device->output()) {
|
|
m_colordInterface->DeleteDevice(objectPath);
|
|
delete device;
|
|
return;
|
|
}
|
|
|
|
device->initialize(objectPath);
|
|
m_outputToDevice.insert(device->output(), device);
|
|
});
|
|
}
|
|
|
|
void ColordIntegration::handleOutputRemoved(AbstractOutput *output)
|
|
{
|
|
ColordDevice *device = m_outputToDevice.take(output);
|
|
if (device) {
|
|
m_colordInterface->DeleteDevice(device->objectPath());
|
|
delete device;
|
|
}
|
|
}
|
|
|
|
} // namespace KWin
|