mobileshellstate: Make lockscreen state DBus calls async

This commit is contained in:
Devin Lin 2023-03-26 10:03:11 -07:00
parent 32af510193
commit cadc5db962
3 changed files with 30 additions and 10 deletions

View file

@ -118,15 +118,17 @@ Item {
Connections {
target: MobileShellState.LockscreenDBusClient
function onLockscreenActiveChanged() {
function onLockscreenLocked() {
itemContainer.zoomOut();
}
function onLockscreenUnlocked() {
// run zoom animation after login
if (!MobileShellState.LockscreenDBusClient.lockscreenActive) {
itemContainer.opacity = 0;
itemContainer.zoomScale = 0.8;
itemContainer.zoomIn();
}
}
}
Component.onCompleted: {
// determine the margins used

View file

@ -15,17 +15,17 @@ LockscreenDBusClient::LockscreenDBusClient(QObject *parent)
QStringLiteral("/ScreenSaver"),
QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("GetActive"));
const QDBusReply<bool> response = QDBusConnection::sessionBus().call(request);
m_lockscreenActive = response.isValid() ? response.value() : false;
Q_EMIT lockscreenActiveChanged();
QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(slotLockscreenActiveChanged(bool)), SLOT(dbusError(QDBusError)));
QDBusConnection::sessionBus().connect(QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("/ScreenSaver"),
QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("ActiveChanged"),
this,
SLOT(slotLockscreenActiveChanged));
SLOT(slotLockscreenActiveChanged(bool)));
}
LockscreenDBusClient *LockscreenDBusClient::self()
@ -43,6 +43,19 @@ void LockscreenDBusClient::slotLockscreenActiveChanged(bool active)
{
if (active != m_lockscreenActive) {
m_lockscreenActive = active;
Q_EMIT lockscreenActiveChanged();
// we don't want to trigger a lockscreen changing signal for the first property fetch (in constructor),
// since it's just getting the current state
if (m_firstPropertySet) {
m_lockscreenActive ? Q_EMIT lockscreenLocked() : Q_EMIT lockscreenUnlocked();
}
m_firstPropertySet = true;
}
}
void LockscreenDBusClient::dbusError(QDBusError error)
{
qDebug() << "Error fetching lockscreen state using DBus:" << error.message();
}

View file

@ -3,6 +3,7 @@
#pragma once
#include <QDBusError>
#include <QDBusServiceWatcher>
#include <QObject>
#include <QString>
@ -20,10 +21,14 @@ public:
Q_SIGNALS:
void lockscreenActiveChanged();
void lockscreenUnlocked();
void lockscreenLocked();
public Q_SLOTS:
void slotLockscreenActiveChanged(bool active);
void dbusError(QDBusError error);
private:
bool m_lockscreenActive;
bool m_lockscreenActive = false;
bool m_firstPropertySet = false;
};