Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 54 additions & 1 deletion playbooks/files/omarchy-bgrt-sddm/Main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: ({
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -182,6 +218,7 @@ Rectangle {
root.failLogin()
}
function onLoginSucceeded() {
root.autoAttempt = false
root.awaiting = false
unanswered.stop()
root.pending = ""
Expand All @@ -202,6 +239,10 @@ Rectangle {
id: unanswered
interval: 5000
onTriggered: {
if (root.autoAttempt) {
root.endAutoLogin()
return
}
if (root.pending === "")
return
if (root.resends >= 3) {
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -399,5 +449,8 @@ Rectangle {
}
Window.onActiveFocusItemChanged: Qt.callLater(restorePasswordFocus)

Component.onCompleted: password.forceActiveFocus()
Component.onCompleted: {
password.forceActiveFocus()
tryAutoLogin()
}
}
12 changes: 10 additions & 2 deletions playbooks/files/omarchy-bgrt-sddm/Password.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 }
}
Loading