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 string failureMessage: ""
property int failedAttempts: 0 property int failedAttempts: 0
property bool inputEnabled: true property bool inputEnabled: true
property string passwordText: ""
property real scaleFactor: 1 property real scaleFactor: 1
property bool syncingPasswordText: false
readonly property string fingerprintGlyph: "\uDB80\uDE37" readonly property string fingerprintGlyph: "\uDB80\uDE37"
readonly property string placeholderText: fingerprintConfigured ? "Enter Password " + fingerprintGlyph : "Enter Password" readonly property string placeholderText: fingerprintConfigured ? "Enter Password " + fingerprintGlyph : "Enter Password"
@@ -25,6 +27,7 @@ Item {
readonly property bool showPasswordCursor: inputEnabled && !authenticatingPassword && failureMessage.length === 0 readonly property bool showPasswordCursor: inputEnabled && !authenticatingPassword && failureMessage.length === 0
signal submitPassword(string password) signal submitPassword(string password)
signal passwordTextEdited(string password)
signal clearFailureRequested() signal clearFailureRequested()
signal wakeRequested() signal wakeRequested()
@@ -42,13 +45,22 @@ Item {
} }
function clearPassword() { function clearPassword() {
passwordInput.text = "" passwordTextEdited("")
} }
function syncPasswordText() {
if (passwordInput.text === passwordText) return
syncingPasswordText = true
passwordInput.text = passwordText
syncingPasswordText = false
}
onPasswordTextChanged: syncPasswordText()
onInputEnabledChanged: { onInputEnabledChanged: {
if (inputEnabled) Qt.callLater(forcePasswordFocus) if (inputEnabled) Qt.callLater(forcePasswordFocus)
} }
Component.onCompleted: { Component.onCompleted: {
syncPasswordText()
if (inputEnabled) Qt.callLater(forcePasswordFocus) if (inputEnabled) Qt.callLater(forcePasswordFocus)
} }
@@ -122,6 +134,7 @@ Item {
} }
onTextChanged: { onTextChanged: {
if (!root.syncingPasswordText) root.passwordTextEdited(text)
if (text.length > 0) { if (text.length > 0) {
root.wakeRequested() root.wakeRequested()
} }
@@ -129,15 +142,15 @@ Item {
} }
onAccepted: { onAccepted: {
var submitted = text var submitted = root.passwordText
text = "" root.passwordTextEdited("")
if (submitted.length > 0) root.submitPassword(submitted) if (submitted.length > 0) root.submitPassword(submitted)
} }
Keys.onPressed: function(event) { Keys.onPressed: function(event) {
root.wakeRequested() root.wakeRequested()
if (event.key === Qt.Key_Escape || (event.modifiers & Qt.ControlModifier && event.key === Qt.Key_U)) { if (event.key === Qt.Key_Escape || (event.modifiers & Qt.ControlModifier && event.key === Qt.Key_U)) {
text = "" root.passwordTextEdited("")
event.accepted = true event.accepted = true
} }
} }
+6
View File
@@ -21,6 +21,7 @@ Item {
property bool passwordPamConfigured: false property bool passwordPamConfigured: false
property bool fingerprintConfigured: false property bool fingerprintConfigured: false
property bool previewVisible: false property bool previewVisible: false
property string enteredPassword: ""
property string pendingPassword: "" property string pendingPassword: ""
property string failureMessage: "" property string failureMessage: ""
property int failedAttempts: 0 property int failedAttempts: 0
@@ -39,6 +40,7 @@ Item {
} }
function resetAuthenticationState() { function resetAuthenticationState() {
enteredPassword = ""
pendingPassword = "" pendingPassword = ""
failureMessage = "" failureMessage = ""
failedAttempts = 0 failedAttempts = 0
@@ -106,6 +108,7 @@ Item {
if (!lockRequested) return if (!lockRequested) return
authenticatingPassword = false authenticatingPassword = false
enteredPassword = ""
pendingPassword = "" pendingPassword = ""
failedAttempts += 1 failedAttempts += 1
failureMessage = "Authentication failed (" + failedAttempts + ")" failureMessage = "Authentication failed (" + failedAttempts + ")"
@@ -164,7 +167,9 @@ Item {
failureMessage: root.failureMessage failureMessage: root.failureMessage
failedAttempts: root.failedAttempts failedAttempts: root.failedAttempts
inputEnabled: root.lockRequested inputEnabled: root.lockRequested
passwordText: root.enteredPassword
scaleFactor: lockSurface.screen && lockSurface.screen.devicePixelRatio > 0 ? lockSurface.screen.devicePixelRatio : 1 scaleFactor: lockSurface.screen && lockSurface.screen.devicePixelRatio > 0 ? lockSurface.screen.devicePixelRatio : 1
onPasswordTextEdited: function(password) { root.enteredPassword = password }
onSubmitPassword: function(password) { root.submitPassword(password) } onSubmitPassword: function(password) { root.submitPassword(password) }
onClearFailureRequested: root.failureMessage = "" onClearFailureRequested: root.failureMessage = ""
onWakeRequested: root.runWake() onWakeRequested: root.runWake()
@@ -192,6 +197,7 @@ Item {
failureMessage: "" failureMessage: ""
failedAttempts: 0 failedAttempts: 0
inputEnabled: false inputEnabled: false
passwordText: ""
scaleFactor: previewWindow.screen && previewWindow.screen.devicePixelRatio > 0 ? previewWindow.screen.devicePixelRatio : 1 scaleFactor: previewWindow.screen && previewWindow.screen.devicePixelRatio > 0 ? previewWindow.screen.devicePixelRatio : 1
} }