[plasma/plasma-login-manager] src/daemon: Move seat related tasks out of Display
David Edmundson <[email protected]>
| Newsgroups | gmane.comp.kde.cvs |
|---|---|
| Message-ID | <[email protected]> |
Git commit 26fae2b354361d986e3bdad70e318530bd7a69fc by David Edmundson.
Committed on 20/07/2026 at 12:16.
Pushed by davidedmundson into branch 'master'.
Move seat related tasks out of Display
Looking up if existing sessions exist or switching to a new session is a
operation on the seat.
This commit has no behavioural changes.
M +3 -59 src/daemon/Display.cpp
M +86 -7 src/daemon/Seat.cpp
M +6 -0 src/daemon/Seat.h
https://invent.kde.org/plasma/plasma-login-manager/-/commit/26fae2b354361d986e3bdad70e318530bd7a69fc
diff --git a/src/daemon/Display.cpp b/src/daemon/Display.cpp
index 4a63f69d..e5065ae3 100644
--- a/src/daemon/Display.cpp
+++ b/src/daemon/Display.cpp
@@ -24,7 +24,6 @@
#include "MainConfigLoader.h"
#include "Seat.h"
#include "SocketServer.h"
-#include "Utils.h"
#include <QDebug>
#include <QFile>
@@ -38,16 +37,10 @@
#include <fcntl.h>
#include <sys/ioctl.h>
-#include <QDBusConnection>
-#include <QDBusMessage>
-#include <QDBusReply>
-
#include <KConfig>
#include <KConfigGroup>
#include <KDesktopFile>
-#include "Login1Manager.h"
-#include "Login1Session.h"
#include "VirtualTerminal.h"
#include "config.h"
@@ -55,38 +48,6 @@ static int s_ttyFailures = 0;
namespace PLASMALOGIN
{
-bool isTtyInUse(const QString &desiredTty)
-{
- if (Logind::isAvailable()) {
- OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
- auto reply = manager.ListSessions();
- reply.waitForFinished();
-
- const auto info = reply.value();
- for (const SessionInfo &s : info) {
- OrgFreedesktopLogin1SessionInterface session(Logind::serviceName(), s.sessionPath.path(), QDBusConnection::systemBus());
- if (desiredTty == session.tTY() && session.state() != QLatin1String("closing")) {
- qDebug() << "tty" << desiredTty << "already in use by" << session.user().path.path() << session.state() << session.display()
- << session.desktop() << session.vTNr();
- return true;
- }
- }
- }
- return false;
-}
-
-int fetchAvailableVt()
-{
- if (!isTtyInUse(QStringLiteral("tty%1").arg(PLASMALOGIN_INITIAL_VT))) {
- return PLASMALOGIN_INITIAL_VT;
- }
- const auto vt = VirtualTerminal::currentVt();
- if (vt > 0 && !isTtyInUse(QStringLiteral("tty%1").arg(vt))) {
- return vt;
- }
- return VirtualTerminal::setUpNewVt();
-}
-
Display::Display(Seat *parent)
: QObject(parent)
, m_auth(new Auth(this))
@@ -95,7 +56,7 @@ Display::Display(Seat *parent)
, m_greeter(new Greeter(this))
{
if (seat()->canTTY()) {
- m_terminalId = fetchAvailableVt();
+ m_terminalId = seat()->availableVt();
}
qDebug("Using VT %d", m_terminalId);
@@ -317,22 +278,7 @@ bool Display::startAuth(const QString &user, const QString &password, const Sess
m_reuseSessionId = QString();
- if (Logind::isAvailable()) {
- OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
- auto reply = manager.ListSessions();
- reply.waitForFinished();
-
- const auto info = reply.value();
- for (const SessionInfo &s : reply.value()) {
- if (s.userName == user) {
- OrgFreedesktopLogin1SessionInterface session(Logind::serviceName(), s.sessionPath.path(), QDBusConnection::systemBus());
- if (session.service() == QLatin1String("plasmalogin") && session.state() == QLatin1String("online")) {
- m_reuseSessionId = s.sessionId;
- break;
- }
- }
- }
- }
+ m_reuseSessionId = seat()->reusableSessionId(user);
// save session desktop file name, we'll use it to set the
// last session later, in slotAuthenticationFinished()
@@ -387,9 +333,7 @@ void Display::slotAuthenticationFinished(const QString &user, bool success)
qDebug() << "Authentication for user " << user << " successful";
if (!m_reuseSessionId.isNull()) {
- OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
- manager.UnlockSession(m_reuseSessionId);
- manager.ActivateSession(m_reuseSessionId);
+ seat()->activateSession(m_reuseSessionId);
}
if (m_socket) {
diff --git a/src/daemon/Seat.cpp b/src/daemon/Seat.cpp
index 95387dd5..8f5a59be 100644
--- a/src/daemon/Seat.cpp
+++ b/src/daemon/Seat.cpp
@@ -26,6 +26,7 @@
#include <QTimer>
#include "Constants.h"
+#include "config.h"
#include <KConfig>
#include <KSharedConfig>
#include <QDir>
@@ -52,6 +53,90 @@ const QString &Seat::name() const
return m_name;
}
+bool Seat::isTtyInUse(const QString &tty) const
+{
+ if (!Logind::isAvailable()) {
+ return false;
+ }
+
+ OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
+ auto reply = manager.ListSessions();
+ reply.waitForFinished();
+
+ const auto info = reply.value();
+ for (const SessionInfo &sessionInfo : info) {
+ OrgFreedesktopLogin1SessionInterface session(Logind::serviceName(), sessionInfo.sessionPath.path(), QDBusConnection::systemBus());
+ if (tty == session.tTY() && session.state() != QLatin1String("closing")) {
+ qDebug() << "tty" << tty << "already in use by" << session.user().path.path() << session.state() << session.display() << session.desktop()
+ << session.vTNr();
+ return true;
+ }
+ }
+
+ return false;
+}
+
+int Seat::availableVt() const
+{
+ if (!isTtyInUse(QStringLiteral("tty%1").arg(PLASMALOGIN_INITIAL_VT))) {
+ return PLASMALOGIN_INITIAL_VT;
+ }
+
+ const auto vt = VirtualTerminal::currentVt();
+ if (vt > 0 && !isTtyInUse(QStringLiteral("tty%1").arg(vt))) {
+ return vt;
+ }
+
+ return VirtualTerminal::setUpNewVt();
+}
+
+QString Seat::reusableSessionId(const QString &user) const
+{
+ OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
+ auto reply = manager.ListSessions();
+ reply.waitForFinished();
+
+ for (const SessionInfo &sessionInfo : reply.value()) {
+ if (sessionInfo.userName != user) {
+ continue;
+ }
+
+ OrgFreedesktopLogin1SessionInterface session(Logind::serviceName(), sessionInfo.sessionPath.path(), QDBusConnection::systemBus());
+ if (session.service() == QLatin1String("plasmalogin") && session.state() == QLatin1String("online")) {
+ return sessionInfo.sessionId;
+ }
+ }
+
+ return {};
+}
+
+void Seat::activateSession(const QString &sessionId) const
+{
+ if (sessionId.isEmpty()) {
+ return;
+ }
+
+ OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
+ manager.UnlockSession(sessionId);
+ manager.ActivateSession(sessionId);
+}
+
+std::optional<int> Seat::vtForSession(const QString &sessionId) const
+{
+ if (sessionId.isEmpty()) {
+ return std::nullopt;
+ }
+
+ OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
+ if (!manager.isValid()) {
+ return std::nullopt;
+ }
+
+ auto sessionPath = manager.GetSession(sessionId);
+ OrgFreedesktopLogin1SessionInterface session(Logind::serviceName(), sessionPath.value().path(), QDBusConnection::systemBus());
+ return QStringView(session.tTY()).mid(3).toInt(); // we need to convert ttyN to N
+}
+
void Seat::createDisplay()
{
PlasmaLogin::config()->load();
@@ -115,14 +200,8 @@ void Seat::removeDisplay(Display *display)
void Seat::displayStopped()
{
Display *display = qobject_cast<Display *>(sender());
- OrgFreedesktopLogin1ManagerInterface manager(Logind::serviceName(), Logind::managerPath(), QDBusConnection::systemBus());
std::optional<int> nextVt;
- auto reusing = display->reuseSessionId();
- if (manager.isValid() && !reusing.isEmpty()) {
- auto sessionPath = manager.GetSession(reusing);
- OrgFreedesktopLogin1SessionInterface sessionIface(Logind::serviceName(), sessionPath.value().path(), QDBusConnection::systemBus());
- nextVt = QStringView(sessionIface.tTY()).mid(3).toInt(); // we need to convert ttyN to N
- }
+ nextVt = vtForSession(display->reuseSessionId());
// remove display
removeDisplay(display);
diff --git a/src/daemon/Seat.h b/src/daemon/Seat.h
index 1cc84a5a..34b52c14 100644
--- a/src/daemon/Seat.h
+++ b/src/daemon/Seat.h
@@ -20,6 +20,7 @@
#include "Display.h"
#include <QObject>
#include <QVector>
+#include <optional>
namespace PLASMALOGIN
{
@@ -36,6 +37,10 @@ public:
void createDisplay();
bool canTTY();
bool tryLockFirstLogin();
+ int availableVt() const;
+ QString reusableSessionId(const QString &user) const;
+ void activateSession(const QString &sessionId) const;
+ std::optional<int> vtForSession(const QString &sessionId) const;
public slots:
void removeDisplay(PLASMALOGIN::Display *display);
@@ -45,6 +50,7 @@ private slots:
private:
void startDisplay(PLASMALOGIN::Display *display, int tryNr = 1);
+ bool isTtyInUse(const QString &tty) const;
QString m_name;