Changeset View
Changeset View
Standalone View
Standalone View
colorcorrection/manager.h
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | KWin - the KDE window manager | ||||
3 | This file is part of the KDE project. | ||||
4 | | ||||
5 | Copyright 2017 Roman Gilg <subdiff@gmail.com> | ||||
6 | | ||||
7 | This program is free software; you can redistribute it and/or modify | ||||
8 | it under the terms of the GNU General Public License as published by | ||||
9 | the Free Software Foundation; either version 2 of the License, or | ||||
10 | (at your option) any later version. | ||||
11 | | ||||
12 | This program is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | GNU General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU General Public License | ||||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | *********************************************************************/ | ||||
20 | #ifndef KWIN_COLORCORRECT_MANAGER_H | ||||
21 | #define KWIN_COLORCORRECT_MANAGER_H | ||||
22 | | ||||
23 | #include "constants.h" | ||||
24 | #include <kwin_export.h> | ||||
25 | | ||||
26 | #include <QObject> | ||||
27 | #include <QPair> | ||||
28 | #include <QDateTime> | ||||
29 | | ||||
30 | class QTimer; | ||||
31 | | ||||
32 | namespace KWin | ||||
33 | { | ||||
34 | | ||||
35 | class Platform; | ||||
36 | | ||||
37 | namespace ColorCorrect | ||||
38 | { | ||||
39 | | ||||
40 | typedef QPair<QDateTime,QDateTime> DateTimes; | ||||
41 | typedef QPair<QTime,QTime> Times; | ||||
42 | | ||||
43 | class ColorCorrectDBusInterface; | ||||
44 | | ||||
45 | | ||||
46 | enum NightColorMode { | ||||
47 | // timings are based on provided location data | ||||
48 | Automatic = 0, | ||||
49 | // timings are based on fixed location data | ||||
50 | Location, | ||||
51 | // fixed timings | ||||
52 | Timings | ||||
53 | }; | ||||
54 | | ||||
55 | class KWIN_EXPORT Manager : public QObject | ||||
56 | { | ||||
57 | Q_OBJECT | ||||
58 | | ||||
59 | public: | ||||
60 | Manager(QObject *parent); | ||||
61 | void init(); | ||||
62 | | ||||
63 | /** | ||||
64 | * Get current configuration | ||||
65 | * @see changeConfiguration | ||||
66 | * @since 5.12 | ||||
67 | **/ | ||||
68 | QHash<QString, QVariant> info() const; | ||||
69 | /** | ||||
70 | * Change configuration | ||||
71 | * @see info | ||||
72 | * @since 5.12 | ||||
73 | **/ | ||||
74 | bool changeConfiguration(QHash<QString, QVariant> data); | ||||
75 | void autoLocationUpdate(double latitude, double longitude); | ||||
76 | | ||||
77 | // for auto tests | ||||
78 | void reparseConfigAndReset(); | ||||
79 | | ||||
80 | public Q_SLOTS: | ||||
81 | void resetSlowUpdateStartTimer(); | ||||
82 | void quickAdjust(); | ||||
83 | | ||||
84 | Q_SIGNALS: | ||||
85 | void configChange(QHash<QString, QVariant> data); | ||||
86 | | ||||
87 | private: | ||||
88 | void readConfig(); | ||||
89 | void hardReset(); | ||||
90 | void slowUpdate(int targetTemp); | ||||
91 | void resetAllTimers(); | ||||
92 | int currentTargetTemp() const; | ||||
93 | void cancelAllTimers(); | ||||
94 | /** | ||||
95 | * Quick shift on manual change to current target Temperature | ||||
96 | **/ | ||||
97 | void resetQuickAdjustTimer(); | ||||
98 | /** | ||||
99 | * Slow shift to daytime target Temperature | ||||
100 | **/ | ||||
101 | void resetSlowUpdateTimer(); | ||||
102 | | ||||
103 | void updateSunTimings(bool force); | ||||
104 | DateTimes getSunTimings(QDate date, double latitude, double longitude, bool morning) const; | ||||
105 | bool checkAutomaticSunTimings() const; | ||||
106 | bool daylight() const; | ||||
107 | | ||||
108 | void commitGammaRamps(int temperature); | ||||
109 | | ||||
110 | ColorCorrectDBusInterface *m_iface; | ||||
111 | | ||||
112 | bool m_active; | ||||
113 | bool m_running = false; | ||||
114 | | ||||
115 | NightColorMode m_mode = NightColorMode::Automatic; | ||||
116 | | ||||
117 | // the previous and next sunrise/sunset intervals - in UTC time | ||||
118 | DateTimes m_prev = DateTimes(); | ||||
119 | DateTimes m_next = DateTimes(); | ||||
120 | | ||||
121 | // manual times from config | ||||
122 | QTime m_morning = QTime(6,0); | ||||
123 | QTime m_evening = QTime(18,0); | ||||
124 | int m_trTime = 30; // saved in minutes > 1 | ||||
125 | | ||||
126 | // auto location provided by work space | ||||
127 | double m_latAuto; | ||||
128 | double m_lngAuto; | ||||
129 | // manual location from config | ||||
130 | double m_latFixed; | ||||
131 | double m_lngFixed; | ||||
132 | | ||||
133 | QTimer *m_slowUpdateStartTimer = nullptr; | ||||
134 | QTimer *m_slowUpdateTimer = nullptr; | ||||
135 | QTimer *m_quickAdjustTimer = nullptr; | ||||
136 | | ||||
137 | int m_currentTemp = NEUTRAL_TEMPERATURE; | ||||
138 | int m_dayTargetTemp = NEUTRAL_TEMPERATURE; | ||||
139 | int m_nightTargetTemp = DEFAULT_NIGHT_TEMPERATURE; | ||||
140 | | ||||
141 | int m_failedCommitAttempts = 0; | ||||
142 | }; | ||||
143 | | ||||
144 | } | ||||
145 | } | ||||
146 | | ||||
147 | #endif // KWIN_COLORCORRECT_MANAGER_H |