1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-08 06:28:27 -04:00

lock: synchronize password inputs between displays and fix video

screensave/password focus
fixes #1933
This commit is contained in:
bbedward
2026-07-04 11:28:45 -04:00
parent 7e095415a7
commit 9911698237
3 changed files with 299 additions and 285 deletions
+272 -247
View File
@@ -25,142 +25,179 @@ Rectangle {
property string strClose: "keyboard_hide" property string strClose: "keyboard_hide"
property var modelKeyboard: { property var modelKeyboard: {
"row_1": [{ "row_1": [
"text": 'q', {
"symbol": '1', "text": 'q',
"width": 1 "symbol": '1',
}, { "width": 1
"text": 'w', },
"symbol": '2', {
"width": 1 "text": 'w',
}, { "symbol": '2',
"text": 'e', "width": 1
"symbol": '3', },
"width": 1 {
}, { "text": 'e',
"text": 'r', "symbol": '3',
"symbol": '4', "width": 1
"width": 1 },
}, { {
"text": 't', "text": 'r',
"symbol": '5', "symbol": '4',
"width": 1 "width": 1
}, { },
"text": 'y', {
"symbol": '6', "text": 't',
"width": 1 "symbol": '5',
}, { "width": 1
"text": 'u', },
"symbol": '7', {
"width": 1 "text": 'y',
}, { "symbol": '6',
"text": 'i', "width": 1
"symbol": '8', },
"width": 1 {
}, { "text": 'u',
"text": 'o', "symbol": '7',
"symbol": '9', "width": 1
"width": 1 },
}, { {
"text": 'p', "text": 'i',
"symbol": '0', "symbol": '8',
"width": 1 "width": 1
}], },
"row_2": [{ {
"text": 'a', "text": 'o',
"symbol": '-', "symbol": '9',
"width": 1 "width": 1
}, { },
"text": 's', {
"symbol": '/', "text": 'p',
"width": 1 "symbol": '0',
}, { "width": 1
"text": 'd', }
"symbol": ':', ],
"width": 1 "row_2": [
}, { {
"text": 'f', "text": 'a',
"symbol": ';', "symbol": '-',
"width": 1 "width": 1
}, { },
"text": 'g', {
"symbol": '(', "text": 's',
"width": 1 "symbol": '/',
}, { "width": 1
"text": 'h', },
"symbol": ')', {
"width": 1 "text": 'd',
}, { "symbol": ':',
"text": 'j', "width": 1
"symbol": '€', },
"width": 1 {
}, { "text": 'f',
"text": 'k', "symbol": ';',
"symbol": '&', "width": 1
"width": 1 },
}, { {
"text": 'l', "text": 'g',
"symbol": '@', "symbol": '(',
"width": 1 "width": 1
}], },
"row_3": [{ {
"text": strShift, "text": 'h',
"symbol": strShift, "symbol": ')',
"width": 1.5 "width": 1
}, { },
"text": 'z', {
"symbol": '.', "text": 'j',
"width": 1 "symbol": '€',
}, { "width": 1
"text": 'x', },
"symbol": ',', {
"width": 1 "text": 'k',
}, { "symbol": '&',
"text": 'c', "width": 1
"symbol": '?', },
"width": 1 {
}, { "text": 'l',
"text": 'v', "symbol": '@',
"symbol": '!', "width": 1
"width": 1 }
}, { ],
"text": 'b', "row_3": [
"symbol": "'", {
"width": 1 "text": strShift,
}, { "symbol": strShift,
"text": 'n', "width": 1.5
"symbol": "%", },
"width": 1 {
}, { "text": 'z',
"text": 'm', "symbol": '.',
"symbol": '"', "width": 1
"width": 1 },
}, { {
"text": strBackspace, "text": 'x',
"symbol": strBackspace, "symbol": ',',
"width": 1.5 "width": 1
}], },
"row_4": [{ {
"text": strClose, "text": 'c',
"symbol": strClose, "symbol": '?',
"width": 1.5 "width": 1
}, { },
"text": "123", {
"symbol": 'ABC', "text": 'v',
"width": 1.5 "symbol": '!',
}, { "width": 1
"text": ' ', },
"symbol": ' ', {
"width": 4.5 "text": 'b',
}, { "symbol": "'",
"text": '.', "width": 1
"symbol": '.', },
"width": 1 {
}, { "text": 'n',
"text": strEnter, "symbol": "%",
"symbol": strEnter, "width": 1
"width": 1.5 },
}] {
"text": 'm',
"symbol": '"',
"width": 1
},
{
"text": strBackspace,
"symbol": strBackspace,
"width": 1.5
}
],
"row_4": [
{
"text": strClose,
"symbol": strClose,
"width": 1.5
},
{
"text": "123",
"symbol": 'ABC',
"width": 1.5
},
{
"text": ' ',
"symbol": ' ',
"width": 4.5
},
{
"text": '.',
"symbol": '.',
"width": 1
},
{
"text": strEnter,
"symbol": strEnter,
"width": 1.5
}
]
} }
//Here is the corresponding table between the ascii and the key event //Here is the corresponding table between the ascii and the key event
@@ -210,9 +247,7 @@ Rectangle {
"_;": Qt.Key_Semicolon, "_;": Qt.Key_Semicolon,
"_(": Qt.Key_BracketLeft, "_(": Qt.Key_BracketLeft,
"_)": Qt.Key_BracketRight, "_)": Qt.Key_BracketRight,
"_€": parseInt( "_€": parseInt("20ac", 16) // I didn't find the appropriate Qt event so I used the hex format
"20ac",
16) // I didn't find the appropriate Qt event so I used the hex format
, ,
"_&": Qt.Key_Ampersand, "_&": Qt.Key_Ampersand,
"_@": Qt.Key_At, "_@": Qt.Key_At,
@@ -224,121 +259,111 @@ Rectangle {
"_'": Qt.Key_Apostrophe, "_'": Qt.Key_Apostrophe,
"_%": Qt.Key_Percent, "_%": Qt.Key_Percent,
"_*": Qt.Key_Asterisk "_*": Qt.Key_Asterisk
} }
Item { Item {
id: keyboard_container id: keyboard_container
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: 5 anchors.leftMargin: 5
anchors.right: parent.right anchors.right: parent.right
anchors.top: parent.top anchors.top: parent.top
anchors.topMargin: 5 anchors.topMargin: 5
anchors.bottom: parent.bottom anchors.bottom: parent.bottom
anchors.bottomMargin: 5 anchors.bottomMargin: 5
//One column which contains 5 rows //One column which contains 5 rows
Column { Column {
spacing: columnSpacing spacing: columnSpacing
Row { Row {
id: row_1 id: row_1
spacing: rowSpacing spacing: rowSpacing
Repeater { Repeater {
model: modelKeyboard["row_1"] model: modelKeyboard["row_1"]
delegate: CustomButtonKeyboard { delegate: CustomButtonKeyboard {
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase() : modelData.text
() : modelData.text width: modelData.width * keyboard_container.width / columns - rowSpacing
width: modelData.width * keyboard_container.width / columns - rowSpacing height: keyboard_container.height / rows - columnSpacing
height: keyboard_container.height / rows - columnSpacing
onClicked: root.clicked(text) onClicked: root.clicked(text)
} }
} }
} }
Row { Row {
id: row_2 id: row_2
spacing: rowSpacing spacing: rowSpacing
Repeater { Repeater {
model: modelKeyboard["row_2"] model: modelKeyboard["row_2"]
delegate: CustomButtonKeyboard { delegate: CustomButtonKeyboard {
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase() : modelData.text
() : modelData.text width: modelData.width * keyboard_container.width / columns - rowSpacing
width: modelData.width * keyboard_container.width / columns - rowSpacing height: keyboard_container.height / rows - columnSpacing
height: keyboard_container.height / rows - columnSpacing
onClicked: root.clicked(text) onClicked: root.clicked(text)
} }
} }
} }
Row { Row {
id: row_3 id: row_3
spacing: rowSpacing spacing: rowSpacing
Repeater { Repeater {
model: modelKeyboard["row_3"] model: modelKeyboard["row_3"]
delegate: CustomButtonKeyboard { delegate: CustomButtonKeyboard {
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase() : modelData.text
() : modelData.text width: modelData.width * keyboard_container.width / columns - rowSpacing
width: modelData.width * keyboard_container.width / columns - rowSpacing height: keyboard_container.height / rows - columnSpacing
height: keyboard_container.height / rows - columnSpacing isShift: shift && text === strShift
isShift: shift && text === strShift
onClicked: root.clicked(text) onClicked: root.clicked(text)
} }
} }
} }
Row { Row {
id: row_4 id: row_4
spacing: rowSpacing spacing: rowSpacing
Repeater { Repeater {
model: modelKeyboard["row_4"] model: modelKeyboard["row_4"]
delegate: CustomButtonKeyboard { delegate: CustomButtonKeyboard {
text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase text: symbols ? modelData.symbol : shift ? modelData.text.toUpperCase() : modelData.text
() : modelData.text width: modelData.width * keyboard_container.width / columns - rowSpacing
width: modelData.width * keyboard_container.width / columns - rowSpacing height: keyboard_container.height / rows - columnSpacing
height: keyboard_container.height / rows - columnSpacing
onClicked: root.clicked(text) onClicked: root.clicked(text)
} }
} }
} }
} }
} }
signal clicked(string text) signal clicked(string text)
Connections { Connections {
target: root target: root
function onClicked(text) { function onClicked(text) {
if (!keyboard_controller.target) if (!keyboard_controller.target)
return return;
if (text === strShift) { if (text === strShift) {
root.shift = !root.shift root.shift = !root.shift;
} else if (text === '123') { } else if (text === '123') {
root.symbols = true root.symbols = true;
} else if (text === 'ABC') { } else if (text === 'ABC') {
root.symbols = false root.symbols = false;
} else if (text === strEnter) { } else if (text === strEnter) {
if (keyboard_controller.target.accepted) { if (keyboard_controller.target.accepted) {
keyboard_controller.target.accepted() keyboard_controller.target.accepted();
} }
} else if (text === strClose) { } else if (text === strClose) {
root.dismissed() root.dismissed();
} else { } else {
if (text === strBackspace) { if (text === strBackspace) {
var current = keyboard_controller.target.text keyboard_controller.target.backspace();
keyboard_controller.target.text = current.slice(0, current.length - 1) } else {
} else { var charToInsert = root.symbols ? text : (root.shift ? text.toUpperCase() : text);
var charToInsert = root.symbols ? text : (root.shift ? text.toUpperCase keyboard_controller.target.insertText(charToInsert);
() : text) }
var current = keyboard_controller.target.text
var cursorPos = keyboard_controller.target.cursorPosition
keyboard_controller.target.text = current.slice(0,
cursorPos) + charToInsert + current.slice(cursorPos)
keyboard_controller.target.cursorPosition = cursorPos + 1
}
if (root.shift && text !== strShift) if (root.shift && text !== strShift)
root.shift = false root.shift = false;
} }
} }
} }
} }
+25 -33
View File
@@ -46,6 +46,7 @@ Item {
} }
signal unlockRequested signal unlockRequested
signal passwordEdited(string text)
function resetLockState() { function resetLockState() {
lockerReadySent = false; lockerReadySent = false;
@@ -56,6 +57,12 @@ Item {
pam.lockMessage = ""; pam.lockMessage = "";
} }
function focusPasswordField() {
if (demoMode || !passwordField)
return;
passwordField.forceActiveFocus();
}
function currentAuthFeedbackText() { function currentAuthFeedbackText() {
if (!pam) if (!pam)
return ""; return "";
@@ -799,7 +806,7 @@ Item {
FocusScope { FocusScope {
id: passwordField id: passwordField
property string text: root.passwordBuffer readonly property string text: root.passwordBuffer
property int cursorPosition: text.length property int cursorPosition: text.length
signal accepted signal accepted
@@ -809,7 +816,7 @@ Item {
} }
function clear() { function clear() {
text = ""; root.passwordEdited("");
cursorPosition = 0; cursorPosition = 0;
} }
@@ -817,23 +824,27 @@ Item {
if (value.length === 0) if (value.length === 0)
return; return;
clampCursorPosition(); clampCursorPosition();
text = text.slice(0, cursorPosition) + value + text.slice(cursorPosition); const pos = cursorPosition;
cursorPosition += value.length; root.passwordEdited(text.slice(0, pos) + value + text.slice(pos));
cursorPosition = pos + value.length;
} }
function backspace() { function backspace() {
clampCursorPosition(); clampCursorPosition();
if (cursorPosition === 0) if (cursorPosition === 0)
return; return;
text = text.slice(0, cursorPosition - 1) + text.slice(cursorPosition); const pos = cursorPosition;
cursorPosition -= 1; root.passwordEdited(text.slice(0, pos - 1) + text.slice(pos));
cursorPosition = pos - 1;
} }
function deleteForward() { function deleteForward() {
clampCursorPosition(); clampCursorPosition();
if (cursorPosition === text.length) if (cursorPosition === text.length)
return; return;
text = text.slice(0, cursorPosition) + text.slice(cursorPosition + 1); const pos = cursorPosition;
root.passwordEdited(text.slice(0, pos) + text.slice(pos + 1));
cursorPosition = pos;
} }
function isPrintableText(value) { function isPrintableText(value) {
@@ -868,11 +879,7 @@ Item {
focus: true focus: true
enabled: !demoMode enabled: !demoMode
activeFocusOnTab: !demoMode activeFocusOnTab: !demoMode
onTextChanged: { onTextChanged: cursorPosition = text.length
if (!demoMode) {
root.passwordBuffer = text;
}
}
onAccepted: { onAccepted: {
if (!demoMode && !root.unlocking && !pam.passwd.active && !pam.u2fPending) { if (!demoMode && !root.unlocking && !pam.passwd.active && !pam.u2fPending) {
pam.passwd.start(); pam.passwd.start();
@@ -958,7 +965,7 @@ Item {
} }
onActiveFocusChanged: { onActiveFocusChanged: {
if (!activeFocus && !demoMode && visible && passwordField && !powerMenu.isVisible) { if (!activeFocus && !demoMode && passwordField && !powerMenu.isVisible) {
Qt.callLater(() => { Qt.callLater(() => {
if (passwordField && passwordField.forceActiveFocus) { if (passwordField && passwordField.forceActiveFocus) {
passwordField.forceActiveFocus(); passwordField.forceActiveFocus();
@@ -968,7 +975,7 @@ Item {
} }
onEnabledChanged: { onEnabledChanged: {
if (enabled && !demoMode && visible && passwordField && !powerMenu.isVisible) { if (enabled && !demoMode && passwordField && !powerMenu.isVisible) {
Qt.callLater(() => { Qt.callLater(() => {
if (passwordField && passwordField.forceActiveFocus) { if (passwordField && passwordField.forceActiveFocus) {
passwordField.forceActiveFocus(); passwordField.forceActiveFocus();
@@ -976,17 +983,6 @@ Item {
}); });
} }
} }
Connections {
target: root
function onPasswordBufferChanged() {
if (passwordField.text === root.passwordBuffer)
return;
passwordField.text = root.passwordBuffer;
passwordField.cursorPosition = passwordField.text.length;
}
}
} }
KeyboardController { KeyboardController {
@@ -1121,8 +1117,7 @@ Item {
visible: root.canStartSecurityKeyUnlock() visible: root.canStartSecurityKeyUnlock()
enabled: visible enabled: visible
onClicked: { onClicked: {
passwordField.text = ""; passwordField.clear();
root.passwordBuffer = "";
pam.u2f.startForAlternativeAuth(); pam.u2f.startForAlternativeAuth();
} }
} }
@@ -1845,8 +1840,7 @@ Item {
function onUnlockRequested() { function onUnlockRequested() {
root.unlocking = true; root.unlocking = true;
lockerReadyArmed = false; lockerReadyArmed = false;
passwordField.text = ""; passwordField.clear();
root.passwordBuffer = "";
root.unlockRequested(); root.unlockRequested();
} }
@@ -1856,15 +1850,13 @@ Item {
return; return;
root.unlocking = false; root.unlocking = false;
placeholderDelay.restart(); placeholderDelay.restart();
passwordField.text = ""; passwordField.clear();
root.passwordBuffer = "";
} }
function onU2fPendingChanged() { function onU2fPendingChanged() {
if (!root.pam.u2fPending) if (!root.pam.u2fPending)
return; return;
passwordField.text = ""; passwordField.clear();
root.passwordBuffer = "";
if (keyboardController.isKeyboardActive) if (keyboardController.isKeyboardActive)
keyboardController.hide(); keyboardController.hide();
} }
+2 -5
View File
@@ -40,11 +40,7 @@ FocusScope {
focus: !videoScreensaver.active focus: !videoScreensaver.active
opacity: videoScreensaver.active ? 0 : 1 opacity: videoScreensaver.active ? 0 : 1
onUnlockRequested: root.unlockRequested() onUnlockRequested: root.unlockRequested()
onPasswordBufferChanged: { onPasswordEdited: text => root.passwordChanged(text)
if (root.sharedPasswordBuffer !== passwordBuffer) {
root.passwordChanged(passwordBuffer);
}
}
Behavior on opacity { Behavior on opacity {
NumberAnimation { NumberAnimation {
@@ -57,6 +53,7 @@ FocusScope {
id: videoScreensaver id: videoScreensaver
anchors.fill: parent anchors.fill: parent
screenName: root.screenName screenName: root.screenName
onDismissed: Qt.callLater(() => lockContent.focusPasswordField())
} }
Component.onCompleted: forceActiveFocus() Component.onCompleted: forceActiveFocus()