diff --git a/src/plugins/nightcolor/nightcolordbusinterface.cpp b/src/plugins/nightcolor/nightcolordbusinterface.cpp
index 4bf9919c7f..ea9ad6e9c9 100644
--- a/src/plugins/nightcolor/nightcolordbusinterface.cpp
+++ b/src/plugins/nightcolor/nightcolordbusinterface.cpp
@@ -134,6 +134,24 @@ NightColorDBusInterface::NightColorDBusInterface(NightColorManager *parent)
QDBusConnection::sessionBus().send(message);
});
+ connect(m_manager, &NightColorManager::daylightChanged, this, [this] {
+ QVariantMap changedProperties;
+ changedProperties.insert(QStringLiteral("mode"), uint(m_manager->daylight()));
+
+ QDBusMessage message = QDBusMessage::createSignal(
+ QStringLiteral("/ColorCorrect"),
+ QStringLiteral("org.freedesktop.DBus.Properties"),
+ QStringLiteral("PropertiesChanged"));
+
+ message.setArguments({
+ QStringLiteral("org.kde.kwin.ColorCorrect"),
+ changedProperties,
+ QStringList(), // invalidated_properties
+ });
+
+ QDBusConnection::sessionBus().send(message);
+ });
+
connect(m_manager, &NightColorManager::previousTransitionTimingsChanged, this, [this] {
QVariantMap changedProperties;
changedProperties.insert(QStringLiteral("previousTransitionDateTime"), previousTransitionDateTime());
@@ -217,6 +235,11 @@ int NightColorDBusInterface::mode() const
return m_manager->mode();
}
+bool NightColorDBusInterface::daylight() const
+{
+ return m_manager->daylight();
+}
+
quint64 NightColorDBusInterface::previousTransitionDateTime() const
{
const QDateTime dateTime = m_manager->previousTransitionDateTime();
diff --git a/src/plugins/nightcolor/nightcolordbusinterface.h b/src/plugins/nightcolor/nightcolordbusinterface.h
index 8dd06ec24e..76c7f42fc9 100644
--- a/src/plugins/nightcolor/nightcolordbusinterface.h
+++ b/src/plugins/nightcolor/nightcolordbusinterface.h
@@ -28,6 +28,7 @@ class NightColorDBusInterface : public QObject, public QDBusContext
Q_PROPERTY(int currentTemperature READ currentTemperature)
Q_PROPERTY(int targetTemperature READ targetTemperature)
Q_PROPERTY(int mode READ mode)
+ Q_PROPERTY(bool daylight READ daylight)
Q_PROPERTY(quint64 previousTransitionDateTime READ previousTransitionDateTime)
Q_PROPERTY(quint32 previousTransitionDuration READ previousTransitionDuration)
Q_PROPERTY(quint64 scheduledTransitionDateTime READ scheduledTransitionDateTime)
@@ -44,6 +45,7 @@ public:
int currentTemperature() const;
int targetTemperature() const;
int mode() const;
+ bool daylight() const;
quint64 previousTransitionDateTime() const;
quint32 previousTransitionDuration() const;
quint64 scheduledTransitionDateTime() const;
diff --git a/src/plugins/nightcolor/nightcolormanager.cpp b/src/plugins/nightcolor/nightcolormanager.cpp
index 270b187070..0707286f9a 100644
--- a/src/plugins/nightcolor/nightcolormanager.cpp
+++ b/src/plugins/nightcolor/nightcolormanager.cpp
@@ -491,6 +491,7 @@ void NightColorManager::updateTransitionTimings(bool force)
const auto oldNext = m_next;
if (m_mode == NightColorMode::Constant) {
+ setDaylight(false);
m_next = DateTimes();
m_prev = DateTimes();
} else if (m_mode == NightColorMode::Timings) {
@@ -502,11 +503,11 @@ void NightColorManager::updateTransitionTimings(bool force)
const QDateTime nextEveE = nextEveB.addSecs(m_trTime * 60);
if (nextEveB < nextMorB) {
- m_daylight = true;
+ setDaylight(true);
m_next = DateTimes(nextEveB, nextEveE);
m_prev = DateTimes(nextMorB.addDays(-1), nextMorE.addDays(-1));
} else {
- m_daylight = false;
+ setDaylight(false);
m_next = DateTimes(nextMorB, nextMorE);
m_prev = DateTimes(nextEveB.addDays(-1), nextEveE.addDays(-1));
}
@@ -526,12 +527,12 @@ void NightColorManager::updateTransitionTimings(bool force)
// first try by only switching the timings
if (m_prev.first.date() == m_next.first.date()) {
// next is evening
- m_daylight = true;
+ setDaylight(true);
m_prev = m_next;
m_next = getSunTimings(todayNow, lat, lng, false);
} else {
// next is morning
- m_daylight = false;
+ setDaylight(false);
m_prev = m_next;
m_next = getSunTimings(todayNow.addDays(1), lat, lng, true);
}
@@ -541,17 +542,17 @@ void NightColorManager::updateTransitionTimings(bool force)
// in case this fails, reset them
DateTimes morning = getSunTimings(todayNow, lat, lng, true);
if (todayNow < morning.first) {
- m_daylight = false;
+ setDaylight(false);
m_prev = getSunTimings(todayNow.addDays(-1), lat, lng, false);
m_next = morning;
} else {
DateTimes evening = getSunTimings(todayNow, lat, lng, false);
if (todayNow < evening.first) {
- m_daylight = true;
+ setDaylight(true);
m_prev = morning;
m_next = evening;
} else {
- m_daylight = false;
+ setDaylight(false);
m_prev = evening;
m_next = getSunTimings(todayNow.addDays(1), lat, lng, true);
}
@@ -709,6 +710,15 @@ void NightColorManager::setMode(NightColorMode mode)
Q_EMIT modeChanged();
}
+void NightColorManager::setDaylight(bool daylight)
+{
+ if (m_daylight == daylight) {
+ return;
+ }
+ m_daylight = daylight;
+ Q_EMIT daylightChanged();
+}
+
} // namespace KWin
#include "moc_nightcolormanager.cpp"
diff --git a/src/plugins/nightcolor/nightcolormanager.h b/src/plugins/nightcolor/nightcolormanager.h
index 93a253f583..e942fcf729 100644
--- a/src/plugins/nightcolor/nightcolormanager.h
+++ b/src/plugins/nightcolor/nightcolormanager.h
@@ -144,6 +144,11 @@ public:
*/
NightColorMode mode() const;
+ /**
+ * Returns whether Night Color is currently on day time.
+ */
+ bool daylight() const;
+
/**
* Returns the datetime that specifies when the previous screen color temperature transition
* had started. Notice that when Night Color operates in the Constant mode, the returned date
@@ -218,6 +223,11 @@ Q_SIGNALS:
*/
void modeChanged();
+ /**
+ * Emitted whenver night color has switched between day and night time.
+ */
+ void daylightChanged();
+
/**
* Emitted whenever the timings of the previous color temperature transition have changed.
*/
@@ -248,7 +258,6 @@ private:
void updateTransitionTimings(bool force);
DateTimes getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const;
bool checkAutomaticSunTimings() const;
- bool daylight() const;
void commitGammaRamps(int temperature);
@@ -256,6 +265,7 @@ private:
void setRunning(bool running);
void setCurrentTemperature(int temperature);
void setMode(NightColorMode mode);
+ void setDaylight(bool daylight);
NightColorDBusInterface *m_iface;
ClockSkewNotifier *m_skewNotifier;
diff --git a/src/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml b/src/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml
index 2bf263d193..1f9bfe0e9d 100644
--- a/src/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml
+++ b/src/plugins/nightcolor/org.kde.kwin.ColorCorrect.xml
@@ -90,6 +90,13 @@
-->
+
+
+