diff --git a/autotests/integration/colorcorrect_nightcolor_test.cpp b/autotests/integration/colorcorrect_nightcolor_test.cpp --- a/autotests/integration/colorcorrect_nightcolor_test.cpp +++ b/autotests/integration/colorcorrect_nightcolor_test.cpp @@ -83,9 +83,10 @@ QTest::newRow("activeMode0") << "true" << 0 << 4500 << 45.5 << 35.1 << "0600" << "1800" << 30 << true; QTest::newRow("activeMode1") << "true" << 1 << 2500 << -10.5 << -8. << "0020" << "2000" << 60 << true; + QTest::newRow("activeMode2") << "true" << 3 << 3500 << 45.5 << 35.1 << "0600" << "1800" << 60 << true; QTest::newRow("notActiveMode2") << "false" << 2 << 5000 << 90. << -180. << "0600" << "1800" << 1 << true; - QTest::newRow("wrongData1") << "fa" << 3 << 7000 << 91. << -181. << "060" << "800" << 999999 << false; - QTest::newRow("wrongData2") << "fa" << 3 << 7000 << 91. << -181. << "060" << "800" << -2 << false; + QTest::newRow("wrongData1") << "fa" << 4 << 7000 << 91. << -181. << "060" << "800" << 999999 << false; + QTest::newRow("wrongData2") << "fa" << 4 << 7000 << 91. << -181. << "060" << "800" << -2 << false; } void ColorCorrectNightColorTest::testConfigRead() @@ -183,7 +184,8 @@ QTest::newRow("data0") << true << 0 << 4500 << 45.5 << 35.1 << QTime(6,0,0) << QTime(18,0,0) << 30 << true; QTest::newRow("data1") << true << 1 << 2500 << -10.5 << -8. << QTime(0,2,0) << QTime(20,0,0) << 60 << true; QTest::newRow("data2") << false << 2 << 5000 << 90. << -180. << QTime(6,0,0) << QTime(19,1,1) << 1 << true; - QTest::newRow("wrongData0") << true << 3 << 4500 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; + QTest::newRow("data3") << false << 3 << 2000 << 90. << -180. << QTime(6,0,0) << QTime(18,0,0) << 1 << true; + QTest::newRow("wrongData0") << true << 4 << 4500 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; QTest::newRow("wrongData1") << true << 0 << 500 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; QTest::newRow("wrongData2") << true << 0 << 7000 << 0. << 0. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; QTest::newRow("wrongData3") << true << 0 << 4500 << 91. << -181. << QTime(6,0,0) << QTime(18,0,0) << 30 << false; diff --git a/colorcorrection/colorcorrect_settings.kcfg b/colorcorrection/colorcorrect_settings.kcfg --- a/colorcorrection/colorcorrect_settings.kcfg +++ b/colorcorrection/colorcorrect_settings.kcfg @@ -19,6 +19,7 @@ + NightColorMode::Automatic diff --git a/colorcorrection/manager.h b/colorcorrection/manager.h --- a/colorcorrection/manager.h +++ b/colorcorrection/manager.h @@ -42,16 +42,50 @@ class ColorCorrectDBusInterface; - +/** + * This enum type is used to specify operation mode of the night color manager. + **/ enum NightColorMode { - // timings are based on provided location data - Automatic = 0, - // timings are based on fixed location data + /** + * Color temperature is computed based on the current position of the Sun. + * + * Location of the user is provided by Plasma. + **/ + Automatic, + /** + * Color temperature is computed based on the current position of the Sun. + * + * Location of the user is provided by themselves. + **/ Location, - // fixed timings - Timings + /** + * Color temperature is computed based on the current time. + * + * Sunrise and sunset times have to be specified by the user. + **/ + Timings, + /** + * Color temperature is constant thoughout the day. + **/ + Constant, }; +/** + * The night color manager is a blue light filter similar to Redshift. + * + * There are four modes this manager can operate in: Automatic, Location, Timings, + * and Constant. Both Automatic and Location modes derive screen color temperature + * from the current position of the Sun, the only difference between two is how + * coordinates of the user are specified. If the user located near either one of + * Earth's poles, we can't compute correct position of the Sun, that's why we need + * Timings and Constant mode. + * + * With the Timings mode, screen color temperature is compused based on the clock + * time. The user needs to specify timings of the sunset and sunrise as well the + * transition time. + * + * With the Constant mode, screen color temperature is always constant. + **/ class KWIN_EXPORT Manager : public QObject { Q_OBJECT diff --git a/colorcorrection/manager.cpp b/colorcorrection/manager.cpp --- a/colorcorrection/manager.cpp +++ b/colorcorrection/manager.cpp @@ -66,8 +66,6 @@ readConfig(); if (!kwinApp()->platform()->supportsGammaControl()) { - // at least update the sun timings to make the values accessible via dbus - updateSunTimings(true); return; } @@ -137,7 +135,12 @@ void Manager::hardReset() { cancelAllTimers(); - updateSunTimings(true); + + // Timings of the Sun are not used in the constant mode. + if (m_mode != NightColorMode::Constant) { + updateSunTimings(true); + } + if (kwinApp()->platform()->supportsGammaControl() && m_active) { m_running = true; commitGammaRamps(currentTargetTemp()); @@ -160,11 +163,17 @@ m_active = s->active(); NightColorMode mode = s->mode(); - if (mode == NightColorMode::Location || mode == NightColorMode::Timings) { + switch (s->mode()) { + case NightColorMode::Automatic: + case NightColorMode::Location: + case NightColorMode::Timings: + case NightColorMode::Constant: m_mode = mode; - } else { - // also fallback for invalid setting values + break; + default: + // Fallback for invalid setting values. m_mode = NightColorMode::Automatic; + break; } m_nightTargetTemp = qBound(MIN_TEMPERATURE, s->nightTemperature(), NEUTRAL_TEMPERATURE); @@ -242,7 +251,10 @@ void Manager::resetQuickAdjustTimer() { - updateSunTimings(false); + // We don't use timings of the Sun in the constant mode. + if (m_mode != NightColorMode::Constant) { + updateSunTimings(false); + } int tempDiff = qAbs(currentTargetTemp() - m_currentTemp); // allow tolerance of one TEMPERATURE_STEP to compensate if a slow update is coincidental @@ -296,6 +308,12 @@ return; } + // There is no need for starting the slow update timer. Screen color temperature + // will be constant all the time now. + if (m_mode == NightColorMode::Constant) { + return; + } + // set up the next slow update m_slowUpdateStartTimer = new QTimer(this); m_slowUpdateStartTimer->setSingleShot(true); @@ -485,6 +503,10 @@ return NEUTRAL_TEMPERATURE; } + if (m_mode == NightColorMode::Constant) { + return m_nightTargetTemp; + } + QDateTime todayNow = QDateTime::currentDateTimeUtc(); auto f = [this, todayNow](int target1, int target2) { @@ -629,7 +651,7 @@ return false; } int mo = iter1.value().toInt(); - if (mo < 0 || 2 < mo) { + if (mo < 0 || 3 < mo) { return false; } NightColorMode moM; @@ -642,6 +664,10 @@ break; case 2: moM = NightColorMode::Timings; + break; + case 3: + moM = NightColorMode::Constant; + break; } modeUpdate = m_mode != moM; mode = moM;