diff --git a/dbus/org.kde.screensaver.xml b/dbus/org.kde.screensaver.xml --- a/dbus/org.kde.screensaver.xml +++ b/dbus/org.kde.screensaver.xml @@ -5,5 +5,7 @@ + + diff --git a/interface.h b/interface.h --- a/interface.h +++ b/interface.h @@ -113,6 +113,8 @@ // DBus signals void ActiveChanged(bool state); + void AboutToLock(); + private Q_SLOTS: void slotLocked(); void slotUnlocked(); diff --git a/interface.cpp b/interface.cpp --- a/interface.cpp +++ b/interface.cpp @@ -51,6 +51,7 @@ QDBusConnection::sessionBus().registerObject(QStringLiteral("/org/freedesktop/ScreenSaver"), this); connect(m_daemon, &KSldApp::locked, this, &Interface::slotLocked); connect(m_daemon, &KSldApp::unlocked, this, &Interface::slotUnlocked); + connect(m_daemon, &KSldApp::aboutToLock, this, &Interface::AboutToLock); m_serviceWatcher->setConnection(QDBusConnection::sessionBus()); m_serviceWatcher->setWatchMode(QDBusServiceWatcher::WatchForUnregistration); diff --git a/ksldapp.h b/ksldapp.h --- a/ksldapp.h +++ b/ksldapp.h @@ -100,7 +100,7 @@ void inhibit(); void uninhibit(); - void lock(EstablishLock establishLock); + void lock(EstablishLock establishLock, int attemptCount = 0); void initialize(); bool event(QEvent *event) override; @@ -136,6 +136,7 @@ } Q_SIGNALS: + void aboutToLock(); void locked(); void unlocked(); void greeterClientConnectionChanged(); diff --git a/ksldapp.cpp b/ksldapp.cpp --- a/ksldapp.cpp +++ b/ksldapp.cpp @@ -358,7 +358,7 @@ } } -void KSldApp::lock(EstablishLock establishLock) +void KSldApp::lock(EstablishLock establishLock, int attemptCount) { if (lockState() != Unlocked) { // already locked or acquiring lock, no need to lock again @@ -371,9 +371,20 @@ return; } + if (attemptCount == 0) { + emit aboutToLock(); + } + qDebug() << "lock called"; if (!establishGrab()) { - qCritical() << "Could not establish screen lock"; + if (attemptCount < 3) { + qWarning() << "Could not establish screen lock. Trying again in 10ms"; + QTimer::singleShot(10, this, [=]() { + lock(establishLock, attemptCount+1); + }); + } else { + qCritical() << "Could not establish screen lock"; + } return; }