[plasma/plasma-login-manager] src/daemon: daemon: Move autologin to seat

David Edmundson <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 491e323a9026b5547ff9c0a69f13825ccf238e7a by David Edmundson.
Committed on 26/07/2026 at 21:25.
Pushed by davidedmundson into branch 'master'.

daemon: Move autologin to seat

If we start multiple sessions we would only want to autologin to the
first. Therefore it's a property of the Seat not the Display.

This contains no behavioural changes, but is a stepping stone to a fix.

M  +18   -45   src/daemon/Display.cpp
M  +1    -3    src/daemon/Display.h
M  +26   -0    src/daemon/Seat.cpp

https://invent.kde.org/plasma/plasma-login-manager/-/commit/491e323a9026b5547ff9c0a69f13825ccf238e7a

diff --git a/src/daemon/Display.cpp b/src/daemon/Display.cpp
index c8d53fd6..5963e59c 100644
--- a/src/daemon/Display.cpp
+++ b/src/daemon/Display.cpp
@@ -37,10 +37,6 @@
 #include <fcntl.h>
 #include <sys/ioctl.h>
 
-#include <KConfig>
-#include <KConfigGroup>
-#include <KDesktopFile>
-
 #include "VirtualTerminal.h"
 #include "config.h"
 
@@ -87,47 +83,6 @@ Display::Display(Seat *parent)
         VirtualTerminal::jumpToVt(PLASMALOGIN_INITIAL_VT, true);
         stop();
     });
-
-    // Per-seat autologin: a seat with its own [Autologin][<seat>] subgroup is logged in as that
-    // subgroup's User running its Session, so a dedicated seat can be driven by the login manager
-    // without the greeter claiming it. The subgroup overrides the [Autologin] keys (User, Session,
-    // Relogin) for that seat; a seat with no subgroup takes the global path unchanged.
-    QString autologinUser;
-    QString autologinSession;
-    const KConfigGroup autologinGroup = PlasmaLogin::config()->config()->group(QStringLiteral("Autologin"));
-    const bool tryLockFirstLogin = seat()->tryLockFirstLogin();
-    const QString seatName = seat()->name();
-    if (autologinGroup.hasGroup(seatName)) {
-        const KConfigGroup seatGroup = autologinGroup.group(seatName);
-        if (seatGroup.readEntry("Relogin", PlasmaLogin::config()->autologinRelogin()) || tryLockFirstLogin) {
-            autologinUser = seatGroup.readEntry("User", QString());
-            autologinSession = seatGroup.readEntry("Session", QString());
-            if (autologinUser.isEmpty()) {
-                qWarning() << "Per-seat autologin: seat" << seatName << "is configured to autologin but names no User; it will be greeted.";
-            } else {
-                qInfo() << "Per-seat autologin: seat" << seatName << "configured for user" << autologinUser << "session" << autologinSession;
-            }
-        } else {
-            qDebug() << "Per-seat autologin: seat" << seatName
-                     << "has a config subgroup but Relogin is off and this is not the first login; it will be greeted.";
-        }
-    } else if (PlasmaLogin::config()->autologinRelogin() || tryLockFirstLogin) {
-        autologinUser = PlasmaLogin::config()->autologinUser();
-        autologinSession = PlasmaLogin::config()->autologinSession();
-    }
-
-    if (!autologinUser.isEmpty()) {
-        m_autologinUser = autologinUser;
-        // determine session type
-        m_autologinSession = Session::create(Session::WaylandSession, autologinSession);
-        if (!m_autologinSession.isValid()) {
-            m_autologinSession = Session::create(Session::X11Session, autologinSession);
-        }
-        if (!m_autologinSession.isValid()) {
-            qCritical() << "Unable to find autologin session entry" << autologinSession << "for user"
-                        << autologinUser << "on seat" << seatName << "— falling back to the greeter";
-        }
-    }
 }
 
 Display::~Display()
@@ -151,6 +106,24 @@ Seat *Display::seat() const
     return m_seat;
 }
 
+void Display::setAutoLogin(const QString &user, const QString &session)
+{
+    m_autologinUser = user;
+    m_autologinSession = Session();
+    if (user.isEmpty()) {
+        return;
+    }
+
+    m_autologinSession = Session::create(Session::WaylandSession, session);
+    if (!m_autologinSession.isValid()) {
+        m_autologinSession = Session::create(Session::X11Session, session);
+    }
+    if (!m_autologinSession.isValid()) {
+        qCritical() << "Unable to find autologin session entry" << session << "for user" << user << "on seat" << seat()->name()
+                    << "— falling back to the greeter";
+    }
+}
+
 bool Display::start()
 {
     if (m_started) {
diff --git a/src/daemon/Display.h b/src/daemon/Display.h
index a04b6b81..2861ece5 100644
--- a/src/daemon/Display.h
+++ b/src/daemon/Display.h
@@ -54,6 +54,7 @@ public:
     }
 
     Seat *seat() const;
+    void setAutoLogin(const QString &user, const QString &session);
 
 public slots:
     bool start();
@@ -84,9 +85,6 @@ private:
     QString m_reuseSessionId;
 
     Session m_autologinSession;
-    // The user to autologin as. Normally PlasmaLogin::config()->autologinUser(), but for a seat
-    // with its own [Autologin][<seat>] config subgroup it is that subgroup's User= (the kiosk
-    // user on a dedicated seat). Set in the constructor, consumed by start().
     QString m_autologinUser;
 
     Auth *m_auth{nullptr};
diff --git a/src/daemon/Seat.cpp b/src/daemon/Seat.cpp
index c365afad..2b22554c 100644
--- a/src/daemon/Seat.cpp
+++ b/src/daemon/Seat.cpp
@@ -151,6 +151,32 @@ void Seat::createDisplay()
     // add display to the list
     m_displays << display;
 
+    // Per-seat autologin overrides the global [Autologin] keys for a dedicated seat.
+    // Resolve it here, after the configuration has been reloaded, rather than caching it
+    // in Display's constructor.
+    QString autologinUser;
+    QString autologinSession;
+    const bool firstLogin = tryLockFirstLogin();
+    const KConfigGroup autologinGroup = PlasmaLogin::config()->config()->group(QStringLiteral("Autologin"));
+    if (autologinGroup.hasGroup(m_name)) {
+        const KConfigGroup seatGroup = autologinGroup.group(m_name);
+        if (seatGroup.readEntry("Relogin", PlasmaLogin::config()->autologinRelogin()) || firstLogin) {
+            autologinUser = seatGroup.readEntry("User", QString());
+            autologinSession = seatGroup.readEntry("Session", QString());
+            if (autologinUser.isEmpty()) {
+                qWarning() << "Per-seat autologin: seat" << m_name << "is configured to autologin but names no User; it will be greeted.";
+            } else {
+                qInfo() << "Per-seat autologin: seat" << m_name << "configured for user" << autologinUser << "session" << autologinSession;
+            }
+        } else {
+            qDebug() << "Per-seat autologin: seat" << m_name << "has a config subgroup but Relogin is off and this is not the first login; it will be greeted.";
+        }
+    } else if (PlasmaLogin::config()->autologinRelogin() || firstLogin) {
+        autologinUser = PlasmaLogin::config()->autologinUser();
+        autologinSession = PlasmaLogin::config()->autologinSession();
+    }
+    display->setAutoLogin(autologinUser, autologinSession);
+
     // start the display
     startDisplay(display);
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.