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