plugins/nightcolor: expose daylight property in DBus interface
So that the applet can provide more detail about the current status, now that there is a configurable day time temperature.
This commit is contained in:
parent
04766c384a
commit
a5d1646590
5 changed files with 60 additions and 8 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -90,6 +90,13 @@
|
|||
-->
|
||||
<property name="mode" type="u" access="read"/>
|
||||
|
||||
<!--
|
||||
This property holds a value to indicate whether nightcolor is currently on day or night time.
|
||||
|
||||
True = day time, false = night time
|
||||
-->
|
||||
<property name="daylight" type="b" access="read"/>
|
||||
|
||||
<!--
|
||||
This property holds a Unix timestamp that specifies when the previous color
|
||||
temperature transition had started. Note that when Night Color operates in
|
||||
|
|
Loading…
Reference in a new issue