Changeset View
Changeset View
Standalone View
Standalone View
colorcorrection/manager.cpp
Show First 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | |||||
65 | 65 | | |||
66 | void Manager::init() | 66 | void Manager::init() | ||
67 | { | 67 | { | ||
68 | Settings::instance(kwinApp()->config()); | 68 | Settings::instance(kwinApp()->config()); | ||
69 | // we may always read in the current config | 69 | // we may always read in the current config | ||
70 | readConfig(); | 70 | readConfig(); | ||
71 | 71 | | |||
72 | if (!kwinApp()->platform()->supportsGammaControl()) { | 72 | if (!kwinApp()->platform()->supportsGammaControl()) { | ||
73 | // at least update the sun timings to make the values accessible via dbus | | |||
74 | updateSunTimings(true); | | |||
75 | return; | 73 | return; | ||
76 | } | 74 | } | ||
77 | 75 | | |||
78 | connect(Screens::self(), &Screens::countChanged, this, &Manager::hardReset); | 76 | connect(Screens::self(), &Screens::countChanged, this, &Manager::hardReset); | ||
79 | 77 | | |||
80 | connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, this, | 78 | connect(LogindIntegration::self(), &LogindIntegration::sessionActiveChanged, this, | ||
81 | [this](bool active) { | 79 | [this](bool active) { | ||
82 | if (active) { | 80 | if (active) { | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
136 | #endif | 134 | #endif | ||
137 | 135 | | |||
138 | hardReset(); | 136 | hardReset(); | ||
139 | } | 137 | } | ||
140 | 138 | | |||
141 | void Manager::hardReset() | 139 | void Manager::hardReset() | ||
142 | { | 140 | { | ||
143 | cancelAllTimers(); | 141 | cancelAllTimers(); | ||
142 | | ||||
143 | // Timings of the Sun are not used in the constant mode. | ||||
144 | if (m_mode != NightColorMode::Constant) { | ||||
144 | updateSunTimings(true); | 145 | updateSunTimings(true); | ||
146 | } | ||||
147 | | ||||
145 | if (kwinApp()->platform()->supportsGammaControl() && m_active) { | 148 | if (kwinApp()->platform()->supportsGammaControl() && m_active) { | ||
146 | m_running = true; | 149 | m_running = true; | ||
147 | commitGammaRamps(currentTargetTemp()); | 150 | commitGammaRamps(currentTargetTemp()); | ||
148 | } | 151 | } | ||
149 | resetAllTimers(); | 152 | resetAllTimers(); | ||
150 | } | 153 | } | ||
151 | 154 | | |||
152 | void Manager::reparseConfigAndReset() | 155 | void Manager::reparseConfigAndReset() | ||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | |||||
206 | void Manager::readConfig() | 209 | void Manager::readConfig() | ||
207 | { | 210 | { | ||
208 | Settings *s = Settings::self(); | 211 | Settings *s = Settings::self(); | ||
209 | s->load(); | 212 | s->load(); | ||
210 | 213 | | |||
211 | m_active = s->active(); | 214 | m_active = s->active(); | ||
212 | 215 | | |||
213 | NightColorMode mode = s->mode(); | 216 | NightColorMode mode = s->mode(); | ||
214 | if (mode == NightColorMode::Location || mode == NightColorMode::Timings) { | 217 | switch (s->mode()) { | ||
218 | case NightColorMode::Automatic: | ||||
219 | case NightColorMode::Location: | ||||
220 | case NightColorMode::Timings: | ||||
221 | case NightColorMode::Constant: | ||||
215 | m_mode = mode; | 222 | m_mode = mode; | ||
216 | } else { | 223 | break; | ||
217 | // also fallback for invalid setting values | 224 | default: | ||
225 | // Fallback for invalid setting values. | ||||
218 | m_mode = NightColorMode::Automatic; | 226 | m_mode = NightColorMode::Automatic; | ||
227 | break; | ||||
219 | } | 228 | } | ||
220 | 229 | | |||
221 | m_nightTargetTemp = qBound(MIN_TEMPERATURE, s->nightTemperature(), NEUTRAL_TEMPERATURE); | 230 | m_nightTargetTemp = qBound(MIN_TEMPERATURE, s->nightTemperature(), NEUTRAL_TEMPERATURE); | ||
222 | 231 | | |||
223 | double lat, lng; | 232 | double lat, lng; | ||
224 | auto correctReadin = [&lat, &lng]() { | 233 | auto correctReadin = [&lat, &lng]() { | ||
225 | if (!checkLocation(lat, lng)) { | 234 | if (!checkLocation(lat, lng)) { | ||
226 | // out of domain | 235 | // out of domain | ||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Line(s) | 293 | { | |||
288 | 297 | | |||
289 | m_slowUpdateStartTimer = nullptr; | 298 | m_slowUpdateStartTimer = nullptr; | ||
290 | m_slowUpdateTimer = nullptr; | 299 | m_slowUpdateTimer = nullptr; | ||
291 | m_quickAdjustTimer = nullptr; | 300 | m_quickAdjustTimer = nullptr; | ||
292 | } | 301 | } | ||
293 | 302 | | |||
294 | void Manager::resetQuickAdjustTimer() | 303 | void Manager::resetQuickAdjustTimer() | ||
295 | { | 304 | { | ||
305 | // We don't use timings of the Sun in the constant mode. | ||||
306 | if (m_mode != NightColorMode::Constant) { | ||||
296 | updateSunTimings(false); | 307 | updateSunTimings(false); | ||
308 | } | ||||
297 | 309 | | |||
298 | int tempDiff = qAbs(currentTargetTemp() - m_currentTemp); | 310 | int tempDiff = qAbs(currentTargetTemp() - m_currentTemp); | ||
299 | // allow tolerance of one TEMPERATURE_STEP to compensate if a slow update is coincidental | 311 | // allow tolerance of one TEMPERATURE_STEP to compensate if a slow update is coincidental | ||
300 | if (tempDiff > TEMPERATURE_STEP) { | 312 | if (tempDiff > TEMPERATURE_STEP) { | ||
301 | cancelAllTimers(); | 313 | cancelAllTimers(); | ||
302 | m_quickAdjustTimer = new QTimer(this); | 314 | m_quickAdjustTimer = new QTimer(this); | ||
303 | m_quickAdjustTimer->setSingleShot(false); | 315 | m_quickAdjustTimer->setSingleShot(false); | ||
304 | connect(m_quickAdjustTimer, &QTimer::timeout, this, &Manager::quickAdjust); | 316 | connect(m_quickAdjustTimer, &QTimer::timeout, this, &Manager::quickAdjust); | ||
Show All 37 Lines | 353 | { | |||
342 | delete m_slowUpdateStartTimer; | 354 | delete m_slowUpdateStartTimer; | ||
343 | m_slowUpdateStartTimer = nullptr; | 355 | m_slowUpdateStartTimer = nullptr; | ||
344 | 356 | | |||
345 | if (!m_running || m_quickAdjustTimer) { | 357 | if (!m_running || m_quickAdjustTimer) { | ||
346 | // only reenable the slow update start timer when quick adjust is not active anymore | 358 | // only reenable the slow update start timer when quick adjust is not active anymore | ||
347 | return; | 359 | return; | ||
348 | } | 360 | } | ||
349 | 361 | | |||
362 | // There is no need for starting the slow update timer. Screen color temperature | ||||
363 | // will be constant all the time now. | ||||
364 | if (m_mode == NightColorMode::Constant) { | ||||
365 | return; | ||||
366 | } | ||||
367 | | ||||
350 | // set up the next slow update | 368 | // set up the next slow update | ||
351 | m_slowUpdateStartTimer = new QTimer(this); | 369 | m_slowUpdateStartTimer = new QTimer(this); | ||
352 | m_slowUpdateStartTimer->setSingleShot(true); | 370 | m_slowUpdateStartTimer->setSingleShot(true); | ||
353 | connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &Manager::resetSlowUpdateStartTimer); | 371 | connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &Manager::resetSlowUpdateStartTimer); | ||
354 | 372 | | |||
355 | updateSunTimings(false); | 373 | updateSunTimings(false); | ||
356 | int diff; | 374 | int diff; | ||
357 | if (m_mode == NightColorMode::Timings) { | 375 | if (m_mode == NightColorMode::Timings) { | ||
▲ Show 20 Lines • Show All 173 Lines • ▼ Show 20 Line(s) | |||||
531 | } | 549 | } | ||
532 | 550 | | |||
533 | int Manager::currentTargetTemp() const | 551 | int Manager::currentTargetTemp() const | ||
534 | { | 552 | { | ||
535 | if (!m_active) { | 553 | if (!m_active) { | ||
536 | return NEUTRAL_TEMPERATURE; | 554 | return NEUTRAL_TEMPERATURE; | ||
537 | } | 555 | } | ||
538 | 556 | | |||
557 | if (m_mode == NightColorMode::Constant) { | ||||
558 | return m_nightTargetTemp; | ||||
559 | } | ||||
560 | | ||||
539 | QDateTime todayNow = QDateTime::currentDateTimeUtc(); | 561 | QDateTime todayNow = QDateTime::currentDateTimeUtc(); | ||
540 | 562 | | |||
541 | auto f = [this, todayNow](int target1, int target2) { | 563 | auto f = [this, todayNow](int target1, int target2) { | ||
542 | if (todayNow <= m_prev.second) { | 564 | if (todayNow <= m_prev.second) { | ||
543 | double residueQuota = todayNow.msecsTo(m_prev.second) / (double)m_prev.first.msecsTo(m_prev.second); | 565 | double residueQuota = todayNow.msecsTo(m_prev.second) / (double)m_prev.first.msecsTo(m_prev.second); | ||
544 | 566 | | |||
545 | double ret = (int)((1. - residueQuota) * (double)target2 + residueQuota * (double)target1); | 567 | double ret = (int)((1. - residueQuota) * (double)target2 + residueQuota * (double)target1); | ||
546 | // remove single digits | 568 | // remove single digits | ||
▲ Show 20 Lines • Show All 128 Lines • ▼ Show 20 Line(s) | 672 | { | |||
675 | } | 697 | } | ||
676 | 698 | | |||
677 | iter1 = data.constFind("Mode"); | 699 | iter1 = data.constFind("Mode"); | ||
678 | if (iter1 != data.constEnd()) { | 700 | if (iter1 != data.constEnd()) { | ||
679 | if (!iter1.value().canConvert<int>()) { | 701 | if (!iter1.value().canConvert<int>()) { | ||
680 | return false; | 702 | return false; | ||
681 | } | 703 | } | ||
682 | int mo = iter1.value().toInt(); | 704 | int mo = iter1.value().toInt(); | ||
683 | if (mo < 0 || 2 < mo) { | 705 | if (mo < 0 || 3 < mo) { | ||
684 | return false; | 706 | return false; | ||
685 | } | 707 | } | ||
686 | NightColorMode moM; | 708 | NightColorMode moM; | ||
687 | switch (mo) { | 709 | switch (mo) { | ||
688 | case 0: | 710 | case 0: | ||
689 | moM = NightColorMode::Automatic; | 711 | moM = NightColorMode::Automatic; | ||
690 | break; | 712 | break; | ||
691 | case 1: | 713 | case 1: | ||
692 | moM = NightColorMode::Location; | 714 | moM = NightColorMode::Location; | ||
693 | break; | 715 | break; | ||
694 | case 2: | 716 | case 2: | ||
695 | moM = NightColorMode::Timings; | 717 | moM = NightColorMode::Timings; | ||
718 | break; | ||||
719 | case 3: | ||||
720 | moM = NightColorMode::Constant; | ||||
721 | break; | ||||
696 | } | 722 | } | ||
697 | modeUpdate = m_mode != moM; | 723 | modeUpdate = m_mode != moM; | ||
698 | mode = moM; | 724 | mode = moM; | ||
699 | } | 725 | } | ||
700 | 726 | | |||
701 | iter1 = data.constFind("NightTemperature"); | 727 | iter1 = data.constFind("NightTemperature"); | ||
702 | if (iter1 != data.constEnd()) { | 728 | if (iter1 != data.constEnd()) { | ||
703 | if (!iter1.value().canConvert<int>()) { | 729 | if (!iter1.value().canConvert<int>()) { | ||
▲ Show 20 Lines • Show All 129 Lines • Show Last 20 Lines |