From 1eee986973f407d7361c6804dc747e2999905853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?La=C3=A9rcio=20de=20Sousa?= Date: Thu, 5 Nov 2026 18:50:37 -0300 Subject: [PATCH] feat(bgrt-theme): log in by itself whoever unlocked the disk From omarchy-multiuser 0.12.0 on, the disk prompt's choice is no longer SDDM's automatic login: the greeter logs that person in as it comes up, with an empty password that omarchy-mu-login-once lets through once, so the desktop gets a console of its own and switching users needs no logout. The BGRT greeter, which replaces omarchy-multiuser's, makes the same try, and its copy of Password.js gains autoLoginUser(). With an older omarchy-multiuser, no PAM line takes the empty password, which then counts as a failed login at each greeter start. Co-Authored-By: Claude Opus 5.5 --- playbooks/files/omarchy-bgrt-sddm/Main.qml | 55 ++++++++++++++++++- playbooks/files/omarchy-bgrt-sddm/Password.js | 12 +++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/playbooks/files/omarchy-bgrt-sddm/Main.qml b/playbooks/files/omarchy-bgrt-sddm/Main.qml index 1a567d6..1083242 100644 --- a/playbooks/files/omarchy-bgrt-sddm/Main.qml +++ b/playbooks/files/omarchy-bgrt-sddm/Main.qml @@ -15,6 +15,11 @@ // the power actions at the bottom, by click or F key (Power.js). Without // omarchy-multiuser, on a single-user machine, that is Omarchy's stock // greeter: a password for the last user, into the uwsm session. +// +// As it comes up, it logs in by itself whoever unlocked the disk at this boot, as +// omarchy-multiuser's greeter does from 0.12.0 (omarchy-mu-login-select chooses, +// omarchy-mu-login-once lets that one login through), so that desktop gets a +// console of its own and switching users needs no logout. pragma ComponentBehavior: Bound import QtQuick 2.15 @@ -55,6 +60,10 @@ Rectangle { // even if it arrives after the next account was sent, so it is never taken for // that account's answer. property int duplicates: 0 + // The greeter's own try, as it comes up, at the login omarchy-mu-login-select + // chose (omarchy-mu-login-once), and an Enter pressed meanwhile. + property bool autoAttempt: false + property bool loginQueued: false readonly property var powerActions: Power.available(powerCaps) // All false until the daemon tells SDDM what the machine can do. readonly property var powerCaps: ({ @@ -111,6 +120,29 @@ Rectangle { unanswered.restart() } + // An empty password for SDDM's last user. omarchy-mu-login-select left a pass for + // it if the disk was unlocked with that user's password at this boot; without one, + // PAM turns it down at once, and nothing shows. + function tryAutoLogin() { + var user = Password.autoLoginUser(userModel.lastUser) + if (user === "") + return + autoAttempt = true + awaiting = true + sddm.login(user, "", root.sessionIndex) + unanswered.restart() + } + + function endAutoLogin() { + autoAttempt = false + awaiting = false + unanswered.stop() + if (loginQueued) { + loginQueued = false + queuedLogin.start() + } + } + function requestPower(action) { if (action.confirm) { pendingPower = action @@ -173,6 +205,10 @@ Rectangle { return root.awaiting = false unanswered.stop() + if (root.autoAttempt) { + root.endAutoLogin() + return + } if (root.pending !== "" && root.attempt + 1 < root.attemptUsers.length) { root.attempt++ root.resends = 0 @@ -182,6 +218,7 @@ Rectangle { root.failLogin() } function onLoginSucceeded() { + root.autoAttempt = false root.awaiting = false unanswered.stop() root.pending = "" @@ -202,6 +239,10 @@ Rectangle { id: unanswered interval: 5000 onTriggered: { + if (root.autoAttempt) { + root.endAutoLogin() + return + } if (root.pending === "") return if (root.resends >= 3) { @@ -213,6 +254,13 @@ Rectangle { } } + // As nextAttempt: SDDM drops a login sent before the last one's helper is gone. + Timer { + id: queuedLogin + interval: 300 + onTriggered: root.login() + } + Timer { id: pairWindow interval: 1000 @@ -289,6 +337,8 @@ Rectangle { if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { if (root.pending === "" && !root.awaiting) root.login() + else if (root.autoAttempt) + root.loginQueued = true event.accepted = true } } @@ -399,5 +449,8 @@ Rectangle { } Window.onActiveFocusItemChanged: Qt.callLater(restorePasswordFocus) - Component.onCompleted: password.forceActiveFocus() + Component.onCompleted: { + password.forceActiveFocus() + tryAutoLogin() + } } diff --git a/playbooks/files/omarchy-bgrt-sddm/Password.js b/playbooks/files/omarchy-bgrt-sddm/Password.js index 8bbff7d..7e5e0aa 100644 --- a/playbooks/files/omarchy-bgrt-sddm/Password.js +++ b/playbooks/files/omarchy-bgrt-sddm/Password.js @@ -1,4 +1,4 @@ -// Copied from omarchy-multiuser 0.11.0 (/usr/share/sddm/themes/omarchy-multiuser/Password.js), +// Copied from omarchy-multiuser 0.12.0 (/usr/share/sddm/themes/omarchy-multiuser/Password.js), // unchanged, so this theme works without that package installed. // // Pure helper for the login screen, which asks for a password alone. Loaded by @@ -18,6 +18,14 @@ function candidates(lastUser, names) { return list } +// The account the greeter logs in by itself as it comes up: SDDM's last user, +// which omarchy-mu-login-select sets to whoever unlocked the disk. Only a plain +// account name; anything else, nobody. +function autoLoginUser(lastUser) { + var name = String(lastUser || "") + return /^[a-z_][a-z0-9_-]{0,31}$/.test(name) ? name : "" +} + if (typeof module !== "undefined") { - module.exports = { candidates: candidates } + module.exports = { candidates: candidates, autoLoginUser: autoLoginUser } }