Commit 1565910c authored by Vlad Zahorodnii's avatar Vlad Zahorodnii
Browse files

[nightcolor] Expose transition timings to d-bus

Summary:
These timings can be useful for the night color applet. For example, it
could show "Next transition will start at XXX" or something like that.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D26666
parent 8e89308a
......@@ -152,6 +152,46 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
QDBusConnection::sessionBus().send(message);
});
connect(m_manager, &Manager::previousTransitionTimingsChanged, this, [this] {
QVariantMap changedProperties;
changedProperties.insert(QStringLiteral("previousTransitionDateTime"), previousTransitionDateTime());
changedProperties.insert(QStringLiteral("previousTransitionDuration"), previousTransitionDuration());
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, &Manager::scheduledTransitionTimingsChanged, this, [this] {
QVariantMap changedProperties;
changedProperties.insert(QStringLiteral("scheduledTransitionDateTime"), scheduledTransitionDateTime());
changedProperties.insert(QStringLiteral("scheduledTransitionDuration"), scheduledTransitionDuration());
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, &Manager::configChange, this, &ColorCorrectDBusInterface::nightColorConfigChanged);
new ColorCorrectAdaptor(this);
QDBusConnection::sessionBus().registerObject(QStringLiteral("/ColorCorrect"), this);
......@@ -192,6 +232,34 @@ int ColorCorrectDBusInterface::mode() const
return m_manager->mode();
}
quint64 ColorCorrectDBusInterface::previousTransitionDateTime() const
{
const QDateTime dateTime = m_manager->previousTransitionDateTime();
if (dateTime.isValid()) {
return quint64(dateTime.toSecsSinceEpoch());
}
return 0;
}
quint32 ColorCorrectDBusInterface::previousTransitionDuration() const
{
return quint32(m_manager->previousTransitionDuration());
}
quint64 ColorCorrectDBusInterface::scheduledTransitionDateTime() const
{
const QDateTime dateTime = m_manager->scheduledTransitionDateTime();
if (dateTime.isValid()) {
return quint64(dateTime.toSecsSinceEpoch());
}
return 0;
}
quint32 ColorCorrectDBusInterface::scheduledTransitionDuration() const
{
return quint32(m_manager->scheduledTransitionDuration());
}
QHash<QString, QVariant> ColorCorrectDBusInterface::nightColorInfo()
{
return m_manager->info();
......
......@@ -43,6 +43,10 @@ class ColorCorrectDBusInterface : public QObject, public QDBusContext
Q_PROPERTY(int currentTemperature READ currentTemperature)
Q_PROPERTY(int targetTemperature READ targetTemperature)
Q_PROPERTY(int mode READ mode)
Q_PROPERTY(quint64 previousTransitionDateTime READ previousTransitionDateTime)
Q_PROPERTY(quint32 previousTransitionDuration READ previousTransitionDuration)
Q_PROPERTY(quint64 scheduledTransitionDateTime READ scheduledTransitionDateTime)
Q_PROPERTY(quint32 scheduledTransitionDuration READ scheduledTransitionDuration)
public:
explicit ColorCorrectDBusInterface(Manager *parent);
......@@ -55,6 +59,10 @@ public:
int currentTemperature() const;
int targetTemperature() const;
int mode() const;
quint64 previousTransitionDateTime() const;
quint32 previousTransitionDuration() const;
quint64 scheduledTransitionDateTime() const;
quint32 scheduledTransitionDuration() const;
public Q_SLOTS:
/**
......
......@@ -135,10 +135,7 @@ void Manager::hardReset()
{
cancelAllTimers();
// Timings of the Sun are not used in the constant mode.
if (m_mode != NightColorMode::Constant) {
updateSunTimings(true);
}
updateTransitionTimings(true);
updateTargetTemperature();
if (isAvailable() && isEnabled() && !isInhibited()) {
......@@ -216,6 +213,26 @@ NightColorMode Manager::mode() const
return m_mode;
}
QDateTime Manager::previousTransitionDateTime() const
{
return m_prev.first;
}
qint64 Manager::previousTransitionDuration() const
{
return m_prev.first.msecsTo(m_prev.second);
}
QDateTime Manager::scheduledTransitionDateTime() const
{
return m_next.first;
}
qint64 Manager::scheduledTransitionDuration() const
{
return m_next.first.msecsTo(m_next.second);
}
void Manager::initShortcuts()
{
QAction *toggleAction = new QAction(this);
......@@ -320,10 +337,7 @@ void Manager::cancelAllTimers()
void Manager::resetQuickAdjustTimer()
{
// We don't use timings of the Sun in the constant mode.
if (m_mode != NightColorMode::Constant) {
updateSunTimings(false);
}
updateTransitionTimings(false);
updateTargetTemperature();
int tempDiff = qAbs(currentTargetTemp() - m_currentTemp);
......@@ -389,7 +403,7 @@ void Manager::resetSlowUpdateStartTimer()
m_slowUpdateStartTimer->setSingleShot(true);
connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &Manager::resetSlowUpdateStartTimer);
updateSunTimings(false);
updateTransitionTimings(false);
updateTargetTemperature();
const int diff = QDateTime::currentDateTime().msecsTo(m_next.first);
......@@ -469,8 +483,16 @@ void Manager::updateTargetTemperature()
emit targetTemperatureChanged();
}
void Manager::updateSunTimings(bool force)
void Manager::updateTransitionTimings(bool force)
{
if (m_mode == NightColorMode::Constant) {
m_next = DateTimes();
m_prev = DateTimes();
emit previousTransitionTimingsChanged();
emit scheduledTransitionTimingsChanged();
return;
}
const QDateTime todayNow = QDateTime::currentDateTime();
if (m_mode == NightColorMode::Timings) {
......@@ -489,6 +511,8 @@ void Manager::updateSunTimings(bool force)
m_next = DateTimes(morB.addDays(1), morE.addDays(1));
m_prev = DateTimes(eveB, eveE);
}
emit previousTransitionTimingsChanged();
emit scheduledTransitionTimingsChanged();
return;
}
......@@ -531,6 +555,9 @@ void Manager::updateSunTimings(bool force)
}
}
}
emit previousTransitionTimingsChanged();
emit scheduledTransitionTimingsChanged();
}
DateTimes Manager::getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const
......
......@@ -175,6 +175,30 @@ public:
*/
NightColorMode mode() 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
* time object is not valid.
*/
QDateTime previousTransitionDateTime() const;
/**
* Returns the duration of the previous screen color temperature transition, in milliseconds.
*/
qint64 previousTransitionDuration() const;
/**
* Returns the datetime that specifies when the next screen color temperature transition will
* start. Notice that when Night Color operates in the Constant mode, the returned date time
* object is not valid.
*/
QDateTime scheduledTransitionDateTime() const;
/**
* Returns the duration of the next screen color temperature transition, in milliseconds.
*/
qint64 scheduledTransitionDuration() const;
// for auto tests
void reparseConfigAndReset();
......@@ -215,6 +239,16 @@ Q_SIGNALS:
*/
void modeChanged();
/**
* Emitted whenever the timings of the previous color temperature transition have changed.
*/
void previousTransitionTimingsChanged();
/**
* Emitted whenever the timings of the next color temperature transition have changed.
*/
void scheduledTransitionTimingsChanged();
private:
void initShortcuts();
void readConfig();
......@@ -233,7 +267,7 @@ private:
void resetSlowUpdateTimer();
void updateTargetTemperature();
void updateSunTimings(bool force);
void updateTransitionTimings(bool force);
DateTimes getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const;
bool checkAutomaticSunTimings() const;
bool daylight() const;
......
......@@ -84,5 +84,33 @@
Valid modes: 0 - automatic, 1 - location, 2 - timings, 3 - constant.
-->
<property name="mode" type="u" 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
the constant mode, this property holds a value of 0.
-->
<property name="previousTransitionDateTime" type="t" access="read"/>
<!--
This property holds a value that specifies the duration of the previous color
temperature transition, in milliseconds. Note that when Night Color operates
in the constant mode, this property holds a value of 0.
-->
<property name="previousTransitionDuration" type="u" access="read"/>
<!--
This property holds a Unix timestamp that specifies when the next scheduled
color temperature transition will start. Note that when Night Color operates
in the constant mode, this property holds a value of 0.
-->
<property name="scheduledTransitionDateTime" type="t" access="read"/>
<!--
This property holds a value that specifies the duration of next scheduled
color transition, in milliseconds. Note that when Night Color operates in
the constant mode, this property holds a value of 0.
-->
<property name="scheduledTransitionDuration" type="u" access="read"/>
</interface>
</node>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment