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,13 +118,15 @@ Item {
Connections { Connections {
target: MobileShellState.LockscreenDBusClient target: MobileShellState.LockscreenDBusClient
function onLockscreenActiveChanged() { function onLockscreenLocked() {
itemContainer.zoomOut();
}
function onLockscreenUnlocked() {
// run zoom animation after login // run zoom animation after login
if (!MobileShellState.LockscreenDBusClient.lockscreenActive) { itemContainer.opacity = 0;
itemContainer.opacity = 0; itemContainer.zoomScale = 0.8;
itemContainer.zoomScale = 0.8; itemContainer.zoomIn();
itemContainer.zoomIn();
}
} }
} }

View file

@ -15,17 +15,17 @@ LockscreenDBusClient::LockscreenDBusClient(QObject *parent)
QStringLiteral("/ScreenSaver"), QStringLiteral("/ScreenSaver"),
QStringLiteral("org.freedesktop.ScreenSaver"), QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("GetActive")); QStringLiteral("GetActive"));
const QDBusReply<bool> response = QDBusConnection::sessionBus().call(request); const QDBusReply<bool> response = QDBusConnection::sessionBus().call(request);
m_lockscreenActive = response.isValid() ? response.value() : false; QDBusConnection::sessionBus().callWithCallback(request, this, SLOT(slotLockscreenActiveChanged(bool)), SLOT(dbusError(QDBusError)));
Q_EMIT lockscreenActiveChanged();
QDBusConnection::sessionBus().connect(QStringLiteral("org.freedesktop.ScreenSaver"), QDBusConnection::sessionBus().connect(QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("/ScreenSaver"), QStringLiteral("/ScreenSaver"),
QStringLiteral("org.freedesktop.ScreenSaver"), QStringLiteral("org.freedesktop.ScreenSaver"),
QStringLiteral("ActiveChanged"), QStringLiteral("ActiveChanged"),
this, this,
SLOT(slotLockscreenActiveChanged)); SLOT(slotLockscreenActiveChanged(bool)));
} }
LockscreenDBusClient *LockscreenDBusClient::self() LockscreenDBusClient *LockscreenDBusClient::self()
@ -43,6 +43,19 @@ void LockscreenDBusClient::slotLockscreenActiveChanged(bool active)
{ {
if (active != m_lockscreenActive) { if (active != m_lockscreenActive) {
m_lockscreenActive = active; m_lockscreenActive = active;
Q_EMIT lockscreenActiveChanged(); 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 #pragma once
#include <QDBusError>
#include <QDBusServiceWatcher> #include <QDBusServiceWatcher>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
@ -20,10 +21,14 @@ public:
Q_SIGNALS: Q_SIGNALS:
void lockscreenActiveChanged(); void lockscreenActiveChanged();
void lockscreenUnlocked();
void lockscreenLocked();
public Q_SLOTS: public Q_SLOTS:
void slotLockscreenActiveChanged(bool active); void slotLockscreenActiveChanged(bool active);
void dbusError(QDBusError error);
private: private:
bool m_lockscreenActive; bool m_lockscreenActive = false;
bool m_firstPropertySet = false;
}; };