Mirror lock input across screens

This commit is contained in:
David Heinemeier Hansson
2026-05-21 08:08:59 +02:00
parent 80469fc51e
commit aa5896766b
2 changed files with 23 additions and 4 deletions
+17 -4
View File
@@ -12,7 +12,9 @@ Item {
property string failureMessage: ""
property int failedAttempts: 0
property bool inputEnabled: true
property string passwordText: ""
property real scaleFactor: 1
property bool syncingPasswordText: false
readonly property string fingerprintGlyph: "\uDB80\uDE37"
readonly property string placeholderText: fingerprintConfigured ? "Enter Password " + fingerprintGlyph : "Enter Password"
@@ -25,6 +27,7 @@ Item {
readonly property bool showPasswordCursor: inputEnabled && !authenticatingPassword && failureMessage.length === 0
signal submitPassword(string password)
signal passwordTextEdited(string password)
signal clearFailureRequested()
signal wakeRequested()
@@ -42,13 +45,22 @@ Item {
}
function clearPassword() {
passwordInput.text = ""
passwordTextEdited("")
}
function syncPasswordText() {
if (passwordInput.text === passwordText) return
syncingPasswordText = true
passwordInput.text = passwordText
syncingPasswordText = false
}
onPasswordTextChanged: syncPasswordText()
onInputEnabledChanged: {
if (inputEnabled) Qt.callLater(forcePasswordFocus)
}
Component.onCompleted: {
syncPasswordText()
if (inputEnabled) Qt.callLater(forcePasswordFocus)
}
@@ -122,6 +134,7 @@ Item {
}
onTextChanged: {
if (!root.syncingPasswordText) root.passwordTextEdited(text)
if (text.length > 0) {
root.wakeRequested()
}
@@ -129,15 +142,15 @@ Item {
}
onAccepted: {
var submitted = text
text = ""
var submitted = root.passwordText
root.passwordTextEdited("")
if (submitted.length > 0) root.submitPassword(submitted)
}
Keys.onPressed: function(event) {
root.wakeRequested()
if (event.key === Qt.Key_Escape || (event.modifiers & Qt.ControlModifier && event.key === Qt.Key_U)) {
text = ""
root.passwordTextEdited("")
event.accepted = true
}
}
+6
View File
@@ -21,6 +21,7 @@ Item {
property bool passwordPamConfigured: false
property bool fingerprintConfigured: false
property bool previewVisible: false
property string enteredPassword: ""
property string pendingPassword: ""
property string failureMessage: ""
property int failedAttempts: 0
@@ -39,6 +40,7 @@ Item {
}
function resetAuthenticationState() {
enteredPassword = ""
pendingPassword = ""
failureMessage = ""
failedAttempts = 0
@@ -106,6 +108,7 @@ Item {
if (!lockRequested) return
authenticatingPassword = false
enteredPassword = ""
pendingPassword = ""
failedAttempts += 1
failureMessage = "Authentication failed (" + failedAttempts + ")"
@@ -164,7 +167,9 @@ Item {
failureMessage: root.failureMessage
failedAttempts: root.failedAttempts
inputEnabled: root.lockRequested
passwordText: root.enteredPassword
scaleFactor: lockSurface.screen && lockSurface.screen.devicePixelRatio > 0 ? lockSurface.screen.devicePixelRatio : 1
onPasswordTextEdited: function(password) { root.enteredPassword = password }
onSubmitPassword: function(password) { root.submitPassword(password) }
onClearFailureRequested: root.failureMessage = ""
onWakeRequested: root.runWake()
@@ -192,6 +197,7 @@ Item {
failureMessage: ""
failedAttempts: 0
inputEnabled: false
passwordText: ""
scaleFactor: previewWindow.screen && previewWindow.screen.devicePixelRatio > 0 ? previewWindow.screen.devicePixelRatio : 1
}