KWin
Loading...
Searching...
No Matches
nightcolormanager.h
Go to the documentation of this file.
1/*
2 KWin - the KDE window manager
3 This file is part of the KDE project.
4
5 SPDX-FileCopyrightText: 2017 Roman Gilg <subdiff@gmail.com>
6
7 SPDX-License-Identifier: GPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "constants.h"
13#include "plugin.h"
14
15#include <QDateTime>
16#include <QObject>
17#include <QPair>
18
19#include <KConfigWatcher>
20
21class QTimer;
22
23namespace KWin
24{
25
26class ClockSkewNotifier;
27class NightColorDBusInterface;
28
29typedef QPair<QDateTime, QDateTime> DateTimes;
30typedef QPair<QTime, QTime> Times;
31
59
76class KWIN_EXPORT NightColorManager : public Plugin
77{
78 Q_OBJECT
79
80public:
81 explicit NightColorManager();
82 ~NightColorManager() override;
83
84 void autoLocationUpdate(double latitude, double longitude);
85
102 void toggle();
103
107 bool isInhibited() const;
108
115 void inhibit();
116
120 void uninhibit();
121
125 bool isEnabled() const;
126
130 bool isRunning() const;
131
135 int currentTemperature() const;
136
140 int targetTemperature() const;
141
145 NightColorMode mode() const;
146
150 bool daylight() const;
151
157 QDateTime previousTransitionDateTime() const;
158
162 qint64 previousTransitionDuration() const;
163
169 QDateTime scheduledTransitionDateTime() const;
170
174 qint64 scheduledTransitionDuration() const;
175
176 // for auto tests
177 void reconfigure();
178 static NightColorManager *self();
179
183 void preview(uint previewTemp);
184
189 void stopPreview();
190
191public Q_SLOTS:
192 void resetSlowUpdateStartTimer();
193 void quickAdjust(int targetTemp);
194
195Q_SIGNALS:
200
205
210
215
220
225
230
235
240
241private:
242 void readConfig();
243 void hardReset();
244 void slowUpdate(int targetTemp);
245 void resetAllTimers();
246 int currentTargetTemp() const;
247 void cancelAllTimers();
251 void resetQuickAdjustTimer(int targetTemp);
255 void resetSlowUpdateTimer();
256
257 void updateTargetTemperature();
258 void updateTransitionTimings(bool force);
259 DateTimes getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const;
260 bool checkAutomaticSunTimings() const;
261
262 void commitGammaRamps(int temperature);
263
264 void setEnabled(bool enabled);
265 void setRunning(bool running);
266 void setCurrentTemperature(int temperature);
267 void setMode(NightColorMode mode);
268 void setDaylight(bool daylight);
269
271 ClockSkewNotifier *m_skewNotifier;
272
273 // Specifies whether Night Color is enabled.
274 bool m_active = false;
275
276 // Specifies whether Night Color is currently running.
277 bool m_running = false;
278
279 // Specifies whether Night Color is inhibited globally.
280 bool m_isGloballyInhibited = false;
281
282 NightColorMode m_mode = NightColorMode::Automatic;
283
284 // the previous and next sunrise/sunset intervals - in UTC time
285 DateTimes m_prev = DateTimes();
286 DateTimes m_next = DateTimes();
287
288 // whether it is currently day or night
289 bool m_daylight = true;
290
291 // manual times from config
292 QTime m_morning = QTime(6, 0);
293 QTime m_evening = QTime(18, 0);
294 int m_trTime = 30; // saved in minutes > 1
295
296 // auto location provided by work space
297 double m_latAuto;
298 double m_lngAuto;
299 // manual location from config
300 double m_latFixed;
301 double m_lngFixed;
302
303 std::unique_ptr<QTimer> m_slowUpdateStartTimer;
304 std::unique_ptr<QTimer> m_slowUpdateTimer;
305 std::unique_ptr<QTimer> m_quickAdjustTimer;
306 std::unique_ptr<QTimer> m_previewTimer;
307
308 int m_currentTemp = DEFAULT_DAY_TEMPERATURE;
309 int m_targetTemperature = DEFAULT_DAY_TEMPERATURE;
310 int m_dayTargetTemp = DEFAULT_DAY_TEMPERATURE;
311 int m_nightTargetTemp = DEFAULT_NIGHT_TEMPERATURE;
312
313 int m_inhibitReferenceCount = 0;
314 KConfigWatcher::Ptr m_configWatcher;
315};
316
317} // namespace KWin
void scheduledTransitionTimingsChanged()
void previousTransitionTimingsChanged()
QPair< QTime, QTime > Times
QPair< QDateTime, QDateTime > DateTimes