64ad9a61d8
This change introduces a new component - ColorManager that is responsible for color management stuff. At the moment, it's very naive. It is useful only for updating gamma ramps. But in the future, it will be extended with more CMS-related features. The ColorManager depends on lcms2 library. This is an optional dependency. If lcms2 is not installed, the color manager won't be built. This also fixes the issue where colord and nightcolor overwrite each other's gamma ramps. With this change, the ColorManager will resolve the conflict between two.
76 lines
1.8 KiB
C++
76 lines
1.8 KiB
C++
/*
|
|
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
|
|
|
SPDX-License-Identifier: GPL-2.0-or-later
|
|
*/
|
|
|
|
#include "colormanager.h"
|
|
#include "abstract_output.h"
|
|
#include "colordevice.h"
|
|
#include "main.h"
|
|
#include "platform.h"
|
|
#include "utils.h"
|
|
|
|
namespace KWin
|
|
{
|
|
|
|
KWIN_SINGLETON_FACTORY(ColorManager)
|
|
|
|
class ColorManagerPrivate
|
|
{
|
|
public:
|
|
QVector<ColorDevice *> devices;
|
|
};
|
|
|
|
ColorManager::ColorManager(QObject *parent)
|
|
: QObject(parent)
|
|
, d(new ColorManagerPrivate)
|
|
{
|
|
connect(kwinApp()->platform(), &Platform::outputEnabled, this, &ColorManager::handleOutputEnabled);
|
|
connect(kwinApp()->platform(), &Platform::outputDisabled, this, &ColorManager::handleOutputDisabled);
|
|
}
|
|
|
|
ColorManager::~ColorManager()
|
|
{
|
|
s_self = nullptr;
|
|
}
|
|
|
|
QVector<ColorDevice *> ColorManager::devices() const
|
|
{
|
|
return d->devices;
|
|
}
|
|
|
|
ColorDevice *ColorManager::findDevice(AbstractOutput *output) const
|
|
{
|
|
auto it = std::find_if(d->devices.begin(), d->devices.end(), [&output](ColorDevice *device) {
|
|
return device->output() == output;
|
|
});
|
|
if (it != d->devices.end()) {
|
|
return *it;
|
|
}
|
|
return nullptr;
|
|
}
|
|
|
|
void ColorManager::handleOutputEnabled(AbstractOutput *output)
|
|
{
|
|
ColorDevice *device = new ColorDevice(output, this);
|
|
d->devices.append(device);
|
|
emit deviceAdded(device);
|
|
}
|
|
|
|
void ColorManager::handleOutputDisabled(AbstractOutput *output)
|
|
{
|
|
auto it = std::find_if(d->devices.begin(), d->devices.end(), [&output](ColorDevice *device) {
|
|
return device->output() == output;
|
|
});
|
|
if (it == d->devices.end()) {
|
|
qCWarning(KWIN_CORE) << "Could not find any color device for output" << output;
|
|
return;
|
|
}
|
|
ColorDevice *device = *it;
|
|
d->devices.erase(it);
|
|
emit deviceRemoved(device);
|
|
delete *it;
|
|
}
|
|
|
|
} // namespace KWin
|