-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcolormanager.cpp
91 lines (78 loc) · 2.17 KB
/
colormanager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
SPDX-FileCopyrightText: 2020 Vlad Zahorodnii <[email protected]>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "colormanager.h"
#include "abstract_output.h"
#include "colordevice.h"
#include "logind.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);
connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged,
this, &ColorManager::handleSessionActiveChanged);
}
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 device;
}
void ColorManager::handleSessionActiveChanged(bool active)
{
if (!active) {
return;
}
for (ColorDevice *device : qAsConst(d->devices)) {
device->scheduleUpdate();
}
}
} // namespace KWin