Changeset View
Changeset View
Standalone View
Standalone View
colorcorrection/manager.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | |||||
51 | static const int QUICK_ADJUST_DURATION = 2000; | 51 | static const int QUICK_ADJUST_DURATION = 2000; | ||
52 | static const int TEMPERATURE_STEP = 50; | 52 | static const int TEMPERATURE_STEP = 50; | ||
53 | 53 | | |||
54 | static bool checkLocation(double lat, double lng) | 54 | static bool checkLocation(double lat, double lng) | ||
55 | { | 55 | { | ||
56 | return -90 <= lat && lat <= 90 && -180 <= lng && lng <= 180; | 56 | return -90 <= lat && lat <= 90 && -180 <= lng && lng <= 180; | ||
57 | } | 57 | } | ||
58 | 58 | | |||
59 | // FIXME: The internal OSD service doesn't work on X11 right now. Once the QPA | ||||
60 | // is ported away from Wayland, drop this function in favor of the internal | ||||
61 | // OSD service. | ||||
62 | static void showStatusOsd(bool enabled) | ||||
63 | { | ||||
64 | // TODO: Maybe use different icons? | ||||
65 | const QString iconName = enabled | ||||
66 | ? QStringLiteral("preferences-desktop-display-nightcolor-on") | ||||
67 | : QStringLiteral("preferences-desktop-display-nightcolor-off"); | ||||
68 | | ||||
69 | const QString text = enabled | ||||
70 | ? i18nc("Night Color was enabled", "Night Color On") | ||||
71 | : i18nc("Night Color was disabled", "Night Color Off"); | ||||
72 | | ||||
73 | QDBusMessage message = QDBusMessage::createMethodCall( | ||||
74 | QStringLiteral("org.kde.plasmashell"), | ||||
75 | QStringLiteral("/org/kde/osdService"), | ||||
76 | QStringLiteral("org.kde.osdService"), | ||||
77 | QStringLiteral("showText")); | ||||
78 | message.setArguments({ iconName, text }); | ||||
79 | | ||||
80 | QDBusConnection::sessionBus().asyncCall(message); | ||||
81 | } | ||||
82 | | ||||
59 | Manager::Manager(QObject *parent) | 83 | Manager::Manager(QObject *parent) | ||
60 | : QObject(parent) | 84 | : QObject(parent) | ||
61 | { | 85 | { | ||
62 | m_iface = new ColorCorrectDBusInterface(this); | 86 | m_iface = new ColorCorrectDBusInterface(this); | ||
63 | connect(kwinApp(), &Application::workspaceCreated, this, &Manager::init); | 87 | connect(kwinApp(), &Application::workspaceCreated, this, &Manager::init); | ||
88 | | ||||
89 | // Display a message when Night Color is (un)inhibited. | ||||
90 | connect(this, &Manager::inhibitedChanged, this, [this] { | ||||
91 | showStatusOsd(!isInhibited()); | ||||
92 | }); | ||||
64 | } | 93 | } | ||
65 | 94 | | |||
66 | void Manager::init() | 95 | void Manager::init() | ||
67 | { | 96 | { | ||
68 | Settings::instance(kwinApp()->config()); | 97 | Settings::instance(kwinApp()->config()); | ||
69 | // we may always read in the current config | 98 | // we may always read in the current config | ||
70 | readConfig(); | 99 | readConfig(); | ||
71 | 100 | | |||
▲ Show 20 Lines • Show All 68 Lines • ▼ Show 20 Line(s) | |||||
140 | { | 169 | { | ||
141 | cancelAllTimers(); | 170 | cancelAllTimers(); | ||
142 | 171 | | |||
143 | // Timings of the Sun are not used in the constant mode. | 172 | // Timings of the Sun are not used in the constant mode. | ||
144 | if (m_mode != NightColorMode::Constant) { | 173 | if (m_mode != NightColorMode::Constant) { | ||
145 | updateSunTimings(true); | 174 | updateSunTimings(true); | ||
146 | } | 175 | } | ||
147 | 176 | | |||
148 | if (kwinApp()->platform()->supportsGammaControl() && m_active) { | 177 | if (kwinApp()->platform()->supportsGammaControl() && m_active && !isInhibited()) { | ||
149 | m_running = true; | 178 | m_running = true; | ||
150 | commitGammaRamps(currentTargetTemp()); | 179 | commitGammaRamps(currentTargetTemp()); | ||
151 | } | 180 | } | ||
152 | resetAllTimers(); | 181 | resetAllTimers(); | ||
153 | } | 182 | } | ||
154 | 183 | | |||
155 | void Manager::reparseConfigAndReset() | 184 | void Manager::reparseConfigAndReset() | ||
156 | { | 185 | { | ||
157 | cancelAllTimers(); | 186 | cancelAllTimers(); | ||
158 | readConfig(); | 187 | readConfig(); | ||
159 | hardReset(); | 188 | hardReset(); | ||
160 | } | 189 | } | ||
161 | 190 | | |||
162 | // FIXME: The internal OSD service doesn't work on X11 right now. Once the QPA | 191 | void Manager::toggle() | ||
163 | // is ported away from Wayland, drop this function in favor of the internal | | |||
164 | // OSD service. | | |||
165 | static void showStatusOsd(bool enabled) | | |||
166 | { | 192 | { | ||
167 | // TODO: Maybe use different icons? | 193 | m_isInhibited = !m_isInhibited; | ||
168 | const QString iconName = enabled | 194 | m_isInhibited ? inhibit() : uninhibit(); | ||
169 | ? QStringLiteral("preferences-desktop-display-nightcolor-on") | | |||
170 | : QStringLiteral("preferences-desktop-display-nightcolor-off"); | | |||
171 | | ||||
172 | const QString text = enabled | | |||
173 | ? i18nc("Night Color was enabled", "Night Color On") | | |||
174 | : i18nc("Night Color was disabled", "Night Color Off"); | | |||
175 | | ||||
176 | QDBusMessage message = QDBusMessage::createMethodCall( | | |||
177 | QStringLiteral("org.kde.plasmashell"), | | |||
178 | QStringLiteral("/org/kde/osdService"), | | |||
179 | QStringLiteral("org.kde.osdService"), | | |||
180 | QStringLiteral("showText")); | | |||
181 | message.setArguments({ iconName, text }); | | |||
182 | | ||||
183 | QDBusConnection::sessionBus().asyncCall(message); | | |||
184 | } | 195 | } | ||
185 | 196 | | |||
186 | void Manager::toggle() | 197 | bool Manager::isInhibited() const | ||
187 | { | 198 | { | ||
188 | if (!kwinApp()->platform()->supportsGammaControl()) { | 199 | return m_inhibitRefereceCount; | ||
189 | return; | | |||
190 | } | 200 | } | ||
191 | 201 | | |||
192 | m_active = !m_active; | 202 | void Manager::inhibit() | ||
203 | { | ||||
204 | m_inhibitRefereceCount++; | ||||
193 | 205 | | |||
194 | showStatusOsd(m_active); | 206 | if (m_inhibitRefereceCount == 1) { | ||
207 | resetAllTimers(); | ||||
208 | emit inhibitedChanged(); | ||||
209 | } | ||||
210 | } | ||||
211 | | ||||
212 | void Manager::uninhibit() | ||||
213 | { | ||||
214 | m_inhibitRefereceCount--; | ||||
195 | 215 | | |||
216 | if (!m_inhibitRefereceCount) { | ||||
196 | resetAllTimers(); | 217 | resetAllTimers(); | ||
218 | emit inhibitedChanged(); | ||||
219 | } | ||||
197 | } | 220 | } | ||
198 | 221 | | |||
199 | void Manager::initShortcuts() | 222 | void Manager::initShortcuts() | ||
200 | { | 223 | { | ||
201 | QAction *toggleAction = new QAction(this); | 224 | QAction *toggleAction = new QAction(this); | ||
202 | toggleAction->setProperty("componentName", QStringLiteral(KWIN_NAME)); | 225 | toggleAction->setProperty("componentName", QStringLiteral(KWIN_NAME)); | ||
203 | toggleAction->setObjectName(i18n("Toggle Night Color")); | 226 | toggleAction->setObjectName(i18n("Toggle Night Color")); | ||
204 | toggleAction->setText(i18n("Toggle Night Color")); | 227 | toggleAction->setText(i18n("Toggle Night Color")); | ||
▲ Show 20 Lines • Show All 69 Lines • ▼ Show 20 Line(s) | 233 | { | |||
274 | m_evening = evB; | 297 | m_evening = evB; | ||
275 | m_trTime = qMax(trTime / 1000 / 60, 1); | 298 | m_trTime = qMax(trTime / 1000 / 60, 1); | ||
276 | } | 299 | } | ||
277 | 300 | | |||
278 | void Manager::resetAllTimers() | 301 | void Manager::resetAllTimers() | ||
279 | { | 302 | { | ||
280 | cancelAllTimers(); | 303 | cancelAllTimers(); | ||
281 | if (kwinApp()->platform()->supportsGammaControl()) { | 304 | if (kwinApp()->platform()->supportsGammaControl()) { | ||
282 | if (m_active) { | 305 | m_running = m_active && !isInhibited(); | ||
283 | m_running = true; | | |||
284 | } | | |||
285 | // we do this also for active being false in order to reset the temperature back to the day value | 306 | // we do this also for active being false in order to reset the temperature back to the day value | ||
286 | resetQuickAdjustTimer(); | 307 | resetQuickAdjustTimer(); | ||
287 | } else { | 308 | } else { | ||
288 | m_running = false; | 309 | m_running = false; | ||
289 | } | 310 | } | ||
290 | } | 311 | } | ||
291 | 312 | | |||
292 | void Manager::cancelAllTimers() | 313 | void Manager::cancelAllTimers() | ||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Line(s) | |||||
537 | 558 | | |||
538 | bool Manager::daylight() const | 559 | bool Manager::daylight() const | ||
539 | { | 560 | { | ||
540 | return m_prev.first.date() == m_next.first.date(); | 561 | return m_prev.first.date() == m_next.first.date(); | ||
541 | } | 562 | } | ||
542 | 563 | | |||
543 | int Manager::currentTargetTemp() const | 564 | int Manager::currentTargetTemp() const | ||
544 | { | 565 | { | ||
545 | if (!m_active) { | 566 | if (!m_running) { | ||
546 | return NEUTRAL_TEMPERATURE; | 567 | return NEUTRAL_TEMPERATURE; | ||
547 | } | 568 | } | ||
548 | 569 | | |||
549 | if (m_mode == NightColorMode::Constant) { | 570 | if (m_mode == NightColorMode::Constant) { | ||
550 | return m_nightTargetTemp; | 571 | return m_nightTargetTemp; | ||
551 | } | 572 | } | ||
552 | 573 | | |||
553 | const QDateTime todayNow = QDateTime::currentDateTime(); | 574 | const QDateTime todayNow = QDateTime::currentDateTime(); | ||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |