From f8bafef294aa0010646199f32238d3efb35102af Mon Sep 17 00:00:00 2001 From: Roman Gilg Date: Sun, 15 Mar 2020 22:40:56 +0100 Subject: [PATCH] Adapt to new KScreenLocker API Summary: KScreenLocker only anymore takes an FD when it tries to lock. The connection is created and kept internally in KWin. At the moment we do not do any further checks on the lock but directly hand over an FD whenever KScreenLocker is about to lock. Reviewers: #kwin, davidedmundson Reviewed By: #kwin, davidedmundson Subscribers: davidedmundson, apol, kwin Tags: #kwin Differential Revision: https://phabricator.kde.org/D28085 --- wayland_server.cpp | 49 +++++++++++++++++++++++++++++++++++++++------- wayland_server.h | 1 + 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/wayland_server.cpp b/wayland_server.cpp index 0814396a00..a84abcce17 100644 --- a/wayland_server.cpp +++ b/wayland_server.cpp @@ -505,20 +505,43 @@ void WaylandServer::initWorkspace() void WaylandServer::initScreenLocker() { - ScreenLocker::KSldApp::self(); - ScreenLocker::KSldApp::self()->setWaylandDisplay(m_display); + auto *screenLockerApp = ScreenLocker::KSldApp::self(); + ScreenLocker::KSldApp::self()->setGreeterEnvironment(kwinApp()->processStartupEnvironment()); ScreenLocker::KSldApp::self()->initialize(); - connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::greeterClientConnectionChanged, this, - [this] () { - m_screenLockerClientConnection = ScreenLocker::KSldApp::self()->greeterClientConnection(); + connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::aboutToLock, this, + [this, screenLockerApp] () { + if (m_screenLockerClientConnection) { + // Already sent data to KScreenLocker. + return; + } + int clientFd = createScreenLockerConnection(); + if (clientFd < 0) { + return; + } + ScreenLocker::KSldApp::self()->setWaylandFd(clientFd); + + for (auto *seat : m_display->seats()) { + connect(seat, &KWayland::Server::SeatInterface::timestampChanged, + screenLockerApp, &ScreenLocker::KSldApp::userActivity); + } } ); connect(ScreenLocker::KSldApp::self(), &ScreenLocker::KSldApp::unlocked, this, - [this] () { - m_screenLockerClientConnection = nullptr; + [this, screenLockerApp] () { + if (m_screenLockerClientConnection) { + m_screenLockerClientConnection->destroy(); + delete m_screenLockerClientConnection; + m_screenLockerClientConnection = nullptr; + } + + for (auto *seat : m_display->seats()) { + disconnect(seat, &KWayland::Server::SeatInterface::timestampChanged, + screenLockerApp, &ScreenLocker::KSldApp::userActivity); + } + ScreenLocker::KSldApp::self()->setWaylandFd(-1); } ); @@ -541,6 +564,18 @@ WaylandServer::SocketPairConnection WaylandServer::createConnection() return ret; } +int WaylandServer::createScreenLockerConnection() +{ + const auto socket = createConnection(); + if (!socket.connection) { + return -1; + } + m_screenLockerClientConnection = socket.connection; + connect(m_screenLockerClientConnection, &KWayland::Server::ClientConnection::disconnected, + this, [this] { m_screenLockerClientConnection = nullptr; }); + return socket.fd; +} + int WaylandServer::createXWaylandConnection() { const auto socket = createConnection(); diff --git a/wayland_server.h b/wayland_server.h index d90e0119e3..b2f1c77c5d 100644 --- a/wayland_server.h +++ b/wayland_server.h @@ -242,6 +242,7 @@ Q_SIGNALS: void foreignTransientChanged(KWayland::Server::SurfaceInterface *child); private: + int createScreenLockerConnection(); void shellClientShown(Toplevel *t); quint16 createClientId(KWayland::Server::ClientConnection *c); void destroyInternalConnection();