[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/D26666master
parent
8e89308a33
commit
1565910c40
|
@ -152,6 +152,46 @@ ColorCorrectDBusInterface::ColorCorrectDBusInterface(Manager *parent)
|
||||||
QDBusConnection::sessionBus().send(message);
|
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);
|
connect(m_manager, &Manager::configChange, this, &ColorCorrectDBusInterface::nightColorConfigChanged);
|
||||||
new ColorCorrectAdaptor(this);
|
new ColorCorrectAdaptor(this);
|
||||||
QDBusConnection::sessionBus().registerObject(QStringLiteral("/ColorCorrect"), this);
|
QDBusConnection::sessionBus().registerObject(QStringLiteral("/ColorCorrect"), this);
|
||||||
|
@ -192,6 +232,34 @@ int ColorCorrectDBusInterface::mode() const
|
||||||
return m_manager->mode();
|
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()
|
QHash<QString, QVariant> ColorCorrectDBusInterface::nightColorInfo()
|
||||||
{
|
{
|
||||||
return m_manager->info();
|
return m_manager->info();
|
||||||
|
|
|
@ -43,6 +43,10 @@ class ColorCorrectDBusInterface : public QObject, public QDBusContext
|
||||||
Q_PROPERTY(int currentTemperature READ currentTemperature)
|
Q_PROPERTY(int currentTemperature READ currentTemperature)
|
||||||
Q_PROPERTY(int targetTemperature READ targetTemperature)
|
Q_PROPERTY(int targetTemperature READ targetTemperature)
|
||||||
Q_PROPERTY(int mode READ mode)
|
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:
|
public:
|
||||||
explicit ColorCorrectDBusInterface(Manager *parent);
|
explicit ColorCorrectDBusInterface(Manager *parent);
|
||||||
|
@ -55,6 +59,10 @@ public:
|
||||||
int currentTemperature() const;
|
int currentTemperature() const;
|
||||||
int targetTemperature() const;
|
int targetTemperature() const;
|
||||||
int mode() const;
|
int mode() const;
|
||||||
|
quint64 previousTransitionDateTime() const;
|
||||||
|
quint32 previousTransitionDuration() const;
|
||||||
|
quint64 scheduledTransitionDateTime() const;
|
||||||
|
quint32 scheduledTransitionDuration() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -135,10 +135,7 @@ void Manager::hardReset()
|
||||||
{
|
{
|
||||||
cancelAllTimers();
|
cancelAllTimers();
|
||||||
|
|
||||||
// Timings of the Sun are not used in the constant mode.
|
updateTransitionTimings(true);
|
||||||
if (m_mode != NightColorMode::Constant) {
|
|
||||||
updateSunTimings(true);
|
|
||||||
}
|
|
||||||
updateTargetTemperature();
|
updateTargetTemperature();
|
||||||
|
|
||||||
if (isAvailable() && isEnabled() && !isInhibited()) {
|
if (isAvailable() && isEnabled() && !isInhibited()) {
|
||||||
|
@ -216,6 +213,26 @@ NightColorMode Manager::mode() const
|
||||||
return m_mode;
|
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()
|
void Manager::initShortcuts()
|
||||||
{
|
{
|
||||||
QAction *toggleAction = new QAction(this);
|
QAction *toggleAction = new QAction(this);
|
||||||
|
@ -320,10 +337,7 @@ void Manager::cancelAllTimers()
|
||||||
|
|
||||||
void Manager::resetQuickAdjustTimer()
|
void Manager::resetQuickAdjustTimer()
|
||||||
{
|
{
|
||||||
// We don't use timings of the Sun in the constant mode.
|
updateTransitionTimings(false);
|
||||||
if (m_mode != NightColorMode::Constant) {
|
|
||||||
updateSunTimings(false);
|
|
||||||
}
|
|
||||||
updateTargetTemperature();
|
updateTargetTemperature();
|
||||||
|
|
||||||
int tempDiff = qAbs(currentTargetTemp() - m_currentTemp);
|
int tempDiff = qAbs(currentTargetTemp() - m_currentTemp);
|
||||||
|
@ -389,7 +403,7 @@ void Manager::resetSlowUpdateStartTimer()
|
||||||
m_slowUpdateStartTimer->setSingleShot(true);
|
m_slowUpdateStartTimer->setSingleShot(true);
|
||||||
connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &Manager::resetSlowUpdateStartTimer);
|
connect(m_slowUpdateStartTimer, &QTimer::timeout, this, &Manager::resetSlowUpdateStartTimer);
|
||||||
|
|
||||||
updateSunTimings(false);
|
updateTransitionTimings(false);
|
||||||
updateTargetTemperature();
|
updateTargetTemperature();
|
||||||
|
|
||||||
const int diff = QDateTime::currentDateTime().msecsTo(m_next.first);
|
const int diff = QDateTime::currentDateTime().msecsTo(m_next.first);
|
||||||
|
@ -469,8 +483,16 @@ void Manager::updateTargetTemperature()
|
||||||
emit targetTemperatureChanged();
|
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();
|
const QDateTime todayNow = QDateTime::currentDateTime();
|
||||||
|
|
||||||
if (m_mode == NightColorMode::Timings) {
|
if (m_mode == NightColorMode::Timings) {
|
||||||
|
@ -489,6 +511,8 @@ void Manager::updateSunTimings(bool force)
|
||||||
m_next = DateTimes(morB.addDays(1), morE.addDays(1));
|
m_next = DateTimes(morB.addDays(1), morE.addDays(1));
|
||||||
m_prev = DateTimes(eveB, eveE);
|
m_prev = DateTimes(eveB, eveE);
|
||||||
}
|
}
|
||||||
|
emit previousTransitionTimingsChanged();
|
||||||
|
emit scheduledTransitionTimingsChanged();
|
||||||
return;
|
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
|
DateTimes Manager::getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const
|
||||||
|
|
|
@ -175,6 +175,30 @@ public:
|
||||||
*/
|
*/
|
||||||
NightColorMode mode() const;
|
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
|
// for auto tests
|
||||||
void reparseConfigAndReset();
|
void reparseConfigAndReset();
|
||||||
|
|
||||||
|
@ -215,6 +239,16 @@ Q_SIGNALS:
|
||||||
*/
|
*/
|
||||||
void modeChanged();
|
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:
|
private:
|
||||||
void initShortcuts();
|
void initShortcuts();
|
||||||
void readConfig();
|
void readConfig();
|
||||||
|
@ -233,7 +267,7 @@ private:
|
||||||
void resetSlowUpdateTimer();
|
void resetSlowUpdateTimer();
|
||||||
|
|
||||||
void updateTargetTemperature();
|
void updateTargetTemperature();
|
||||||
void updateSunTimings(bool force);
|
void updateTransitionTimings(bool force);
|
||||||
DateTimes getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const;
|
DateTimes getSunTimings(const QDateTime &dateTime, double latitude, double longitude, bool morning) const;
|
||||||
bool checkAutomaticSunTimings() const;
|
bool checkAutomaticSunTimings() const;
|
||||||
bool daylight() const;
|
bool daylight() const;
|
||||||
|
|
|
@ -84,5 +84,33 @@
|
||||||
Valid modes: 0 - automatic, 1 - location, 2 - timings, 3 - constant.
|
Valid modes: 0 - automatic, 1 - location, 2 - timings, 3 - constant.
|
||||||
-->
|
-->
|
||||||
<property name="mode" type="u" access="read"/>
|
<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>
|
</interface>
|
||||||
</node>
|
</node>
|
||||||
|
|
Loading…
Reference in New Issue