kscreensaver: implement locking and unlocking on session manager signals

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-04-25 17:23:17 +03:00
parent 907b24be0b
commit bbd16d2bcf
2 changed files with 42 additions and 2 deletions

View file

@ -22,13 +22,17 @@
#include <kdebug.h>
#include <kidletime.h>
static const uint ChangeScreenSettings = 4;
#include <sys/types.h>
#include <unistd.h>
// TODO: fallback to ConsoleKit
KScreenSaver::KScreenSaver(QObject *parent)
: QObject(parent),
m_objectsregistered(false),
m_serviceregistered(false),
m_xscreensaver(nullptr)
m_xscreensaver(nullptr),
m_login1("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", QDBusConnection::systemBus())
{
(void)new ScreenSaverAdaptor(this);
@ -68,6 +72,25 @@ KScreenSaver::KScreenSaver(QObject *parent)
QString::fromLatin1("xscreensaver-command"),
QStringList() << QString::fromLatin1("-watch")
);
if (m_login1.isValid()) {
QDBusReply<QDBusObjectPath> reply = m_login1.call("GetSessionByPID", uint(::getpid()));
if (reply.isValid()) {
connection = QDBusConnection::systemBus();
const QString login1sessionpath = reply.value().path();
// qDebug() << Q_FUNC_INFO << login1sessionpath;
connection.connect(
"org.freedesktop.login1", login1sessionpath, "org.freedesktop.login1.Session", "Lock",
this, SLOT(slotLock())
);
connection.connect(
"org.freedesktop.login1", login1sessionpath, "org.freedesktop.login1.Session", "Unlock",
this, SLOT(slotUnlock())
);
} else {
kWarning() << "Invalid GetSessionByPID reply";
}
}
}
KScreenSaver::~KScreenSaver()
@ -211,4 +234,16 @@ void KScreenSaver::slotXScreenSaverError()
kWarning() << xscreensaverdata;
}
void KScreenSaver::slotLock()
{
// qDebug() << Q_FUNC_INFO;
Lock();
}
void KScreenSaver::slotUnlock()
{
// qDebug() << Q_FUNC_INFO;
SetActive(false);
}
#include "moc_kscreensaver.cpp"

View file

@ -22,6 +22,7 @@
#include <QObject>
#include <QProcess>
#include <QElapsedTimer>
#include <QDBusInterface>
class KScreenSaver : public QObject
{
@ -50,12 +51,16 @@ private Q_SLOTS:
void slotXScreenSaverOutput();
void slotXScreenSaverError();
void slotLock();
void slotUnlock();
private:
bool m_objectsregistered;
bool m_serviceregistered;
QProcess* m_xscreensaver;
QElapsedTimer m_activetimer;
QList<uint> m_inhibitions;
QDBusInterface m_login1;
};
#endif // KSCREENSAVER_H