2020-11-27 19:37:40 +00:00
|
|
|
/*
|
|
|
|
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"
|
2021-01-30 13:22:07 +00:00
|
|
|
#include "session.h"
|
2020-11-27 19:37:40 +00:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
|
|
|
|
KWIN_SINGLETON_FACTORY(ColorManager)
|
|
|
|
|
|
|
|
class ColorManagerPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
QVector<ColorDevice *> devices;
|
|
|
|
};
|
|
|
|
|
|
|
|
ColorManager::ColorManager(QObject *parent)
|
|
|
|
: QObject(parent)
|
|
|
|
, d(new ColorManagerPrivate)
|
|
|
|
{
|
2021-01-30 13:22:07 +00:00
|
|
|
Platform *platform = kwinApp()->platform();
|
|
|
|
Session *session = platform->session();
|
|
|
|
|
|
|
|
const QVector<AbstractOutput *> outputs = platform->enabledOutputs();
|
2021-01-30 15:10:40 +00:00
|
|
|
for (AbstractOutput *output : outputs) {
|
|
|
|
handleOutputEnabled(output);
|
|
|
|
}
|
|
|
|
|
2021-01-30 13:22:07 +00:00
|
|
|
connect(platform, &Platform::outputEnabled, this, &ColorManager::handleOutputEnabled);
|
|
|
|
connect(platform, &Platform::outputDisabled, this, &ColorManager::handleOutputDisabled);
|
|
|
|
connect(session, &Session::activeChanged, this, &ColorManager::handleSessionActiveChanged);
|
2020-11-27 19:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2020-12-20 15:27:54 +00:00
|
|
|
delete device;
|
2020-11-27 19:37:40 +00:00
|
|
|
}
|
|
|
|
|
2020-12-21 18:17:56 +00:00
|
|
|
void ColorManager::handleSessionActiveChanged(bool active)
|
|
|
|
{
|
|
|
|
if (!active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (ColorDevice *device : qAsConst(d->devices)) {
|
|
|
|
device->scheduleUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-27 19:37:40 +00:00
|
|
|
} // namespace KWin
|