mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
screenbrightnessplugin: Fix behaviour if dbus service is not initialized
If the dbus service gets initialized later, ensure that the latest values are being fetched.
This commit is contained in:
parent
b9d4ff6455
commit
abfe419b3b
4 changed files with 30 additions and 28 deletions
|
|
@ -17,6 +17,7 @@ import org.kde.plasma.private.mobileshell.screenbrightnessplugin as ScreenBright
|
||||||
Item {
|
Item {
|
||||||
id: root
|
id: root
|
||||||
implicitHeight: brightnessRow.implicitHeight
|
implicitHeight: brightnessRow.implicitHeight
|
||||||
|
visible: screenBrightness.brightnessAvailable
|
||||||
|
|
||||||
ScreenBrightness.ScreenBrightnessUtil {
|
ScreenBrightness.ScreenBrightnessUtil {
|
||||||
id: screenBrightness
|
id: screenBrightness
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ target_link_libraries(screenbrightnessplugin PRIVATE
|
||||||
KF6::ConfigGui
|
KF6::ConfigGui
|
||||||
KF6::I18n
|
KF6::I18n
|
||||||
KF6::Screen
|
KF6::Screen
|
||||||
|
QCoro::DBus
|
||||||
)
|
)
|
||||||
|
|
||||||
ecm_finalize_qml_module(screenbrightnessplugin)
|
ecm_finalize_qml_module(screenbrightnessplugin)
|
||||||
|
|
|
||||||
|
|
@ -15,9 +15,6 @@ ScreenBrightnessUtil::ScreenBrightnessUtil(QObject *parent)
|
||||||
QDBusConnection::sessionBus(),
|
QDBusConnection::sessionBus(),
|
||||||
this);
|
this);
|
||||||
|
|
||||||
fetchBrightness();
|
|
||||||
fetchMaxBrightness();
|
|
||||||
|
|
||||||
connect(m_brightnessInterface,
|
connect(m_brightnessInterface,
|
||||||
&org::kde::Solid::PowerManagement::Actions::BrightnessControl::brightnessChanged,
|
&org::kde::Solid::PowerManagement::Actions::BrightnessControl::brightnessChanged,
|
||||||
this,
|
this,
|
||||||
|
|
@ -27,6 +24,9 @@ ScreenBrightnessUtil::ScreenBrightnessUtil(QObject *parent)
|
||||||
this,
|
this,
|
||||||
&ScreenBrightnessUtil::fetchMaxBrightness);
|
&ScreenBrightnessUtil::fetchMaxBrightness);
|
||||||
|
|
||||||
|
fetchBrightness();
|
||||||
|
fetchMaxBrightness();
|
||||||
|
|
||||||
// watch for brightness interface
|
// watch for brightness interface
|
||||||
m_brightnessInterfaceWatcher = new QDBusServiceWatcher(QStringLiteral("org.kde.Solid.PowerManagement.Actions.BrightnessControl"),
|
m_brightnessInterfaceWatcher = new QDBusServiceWatcher(QStringLiteral("org.kde.Solid.PowerManagement.Actions.BrightnessControl"),
|
||||||
QDBusConnection::sessionBus(),
|
QDBusConnection::sessionBus(),
|
||||||
|
|
@ -34,6 +34,8 @@ ScreenBrightnessUtil::ScreenBrightnessUtil(QObject *parent)
|
||||||
this);
|
this);
|
||||||
|
|
||||||
connect(m_brightnessInterfaceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() -> void {
|
connect(m_brightnessInterfaceWatcher, &QDBusServiceWatcher::serviceRegistered, this, [this]() -> void {
|
||||||
|
fetchBrightness();
|
||||||
|
fetchMaxBrightness();
|
||||||
Q_EMIT brightnessAvailableChanged();
|
Q_EMIT brightnessAvailableChanged();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -64,34 +66,32 @@ bool ScreenBrightnessUtil::brightnessAvailable() const
|
||||||
|
|
||||||
void ScreenBrightnessUtil::fetchBrightness()
|
void ScreenBrightnessUtil::fetchBrightness()
|
||||||
{
|
{
|
||||||
QDBusPendingReply<int> reply = m_brightnessInterface->brightness();
|
QDBusPendingReply<int> pendingReply = m_brightnessInterface->brightness();
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
const auto reply = co_await pendingReply;
|
||||||
|
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
|
|
||||||
QDBusPendingReply<int> reply = *watcher;
|
|
||||||
if (reply.isError()) {
|
if (reply.isError()) {
|
||||||
qWarning() << "Getting brightness failed:" << reply.error().name() << reply.error().message();
|
qWarning() << "Getting brightness failed:" << reply.error().name() << reply.error().message();
|
||||||
} else if (m_brightness != reply.value()) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_brightness != reply.value()) {
|
||||||
m_brightness = reply.value();
|
m_brightness = reply.value();
|
||||||
Q_EMIT brightnessChanged();
|
Q_EMIT brightnessChanged();
|
||||||
}
|
}
|
||||||
watcher->deleteLater();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenBrightnessUtil::fetchMaxBrightness()
|
void ScreenBrightnessUtil::fetchMaxBrightness()
|
||||||
{
|
{
|
||||||
QDBusPendingReply<int> reply = m_brightnessInterface->brightnessMax();
|
QDBusPendingReply<int> reply = m_brightnessInterface->brightnessMax();
|
||||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
const auto reply = co_await pendingReply;
|
||||||
|
|
||||||
connect(watcher, &QDBusPendingCallWatcher::finished, this, [this](QDBusPendingCallWatcher *watcher) {
|
|
||||||
QDBusPendingReply<int> reply = *watcher;
|
|
||||||
if (reply.isError()) {
|
if (reply.isError()) {
|
||||||
qWarning() << "Getting max brightness failed:" << reply.error().name() << reply.error().message();
|
qWarning() << "Getting max brightness failed:" << reply.error().name() << reply.error().message();
|
||||||
} else if (m_maxBrightness != reply.value()) {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_maxBrightness != reply.value()) {
|
||||||
m_maxBrightness = reply.value();
|
m_maxBrightness = reply.value();
|
||||||
Q_EMIT maxBrightnessChanged();
|
Q_EMIT maxBrightnessChanged();
|
||||||
}
|
}
|
||||||
watcher->deleteLater();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,8 @@ private Q_SLOTS:
|
||||||
void fetchMaxBrightness();
|
void fetchMaxBrightness();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_brightness;
|
int m_brightness{0};
|
||||||
int m_maxBrightness;
|
int m_maxBrightness{0};
|
||||||
|
|
||||||
org::kde::Solid::PowerManagement::Actions::BrightnessControl *m_brightnessInterface;
|
org::kde::Solid::PowerManagement::Actions::BrightnessControl *m_brightnessInterface;
|
||||||
QDBusServiceWatcher *m_brightnessInterfaceWatcher;
|
QDBusServiceWatcher *m_brightnessInterfaceWatcher;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue