import org.kde.breeze.componentsimport QtQuickimport QtQuick.Layoutsimport QtQuick.Controls as QQC2import org.kde.plasma.components as PlasmaComponents3import org.kde.plasma.extras as PlasmaExtrasimport org.kde.kirigami as KirigamiSessionManagementScreen {id: rootproperty Item mainPasswordBox: passwordBoxproperty bool showUsernamePrompt: !showUserListproperty string lastUserNameproperty bool loginScreenUiVisible: false//the y position that should be ensured visible when the on screen keyboard is visibleproperty int visibleBoundary: mapFromItem(loginButton, 0, 0).yonHeightChanged: visibleBoundary = mapFromItem(loginButton, 0, 0).y + loginButton.height + Kirigami.Units.smallSpacingproperty real fontSize: Kirigami.Theme.defaultFont.pointSizesignal loginRequest(string username, string password)onShowUsernamePromptChanged: {if (!showUsernamePrompt) {lastUserName = ""}}onUserSelected: {// Don't startLogin() here, because the signal is connected to the// Escape key as well, for which it wouldn't make sense to trigger// login.passwordBox.clear()focusFirstVisibleFormControl();}QQC2.StackView.onActivating: {// Controls are not visible yet.Qt.callLater(focusFirstVisibleFormControl);}function focusFirstVisibleFormControl() {const nextControl = (userNameInput.visible? userNameInput: (passwordBox.visible? passwordBox: loginButton));// Using TabFocusReason, so that the loginButton gets the visual highlight.nextControl.forceActiveFocus(Qt.TabFocusReason);}/** Login has been requested with the following username and password* If username field is visible, it will be taken from that, otherwise from the "name" property of the currentIndex*/function startLogin() {const username = showUsernamePrompt ? userNameInput.text : userList.selectedUserconst password = passwordBox.textfooter.enabled = falsemainStack.enabled = falseuserListComponent.userList.opacity = 0.75// This is partly because it looks nicer, but more importantly it// works round a Qt bug that can trigger if the app is closed with a// TextField focused.//// See https://bugreports.qt.io/browse/QTBUG-55460loginButton.forceActiveFocus();loginRequest(username, password);}PlasmaComponents3.TextField {id: userNameInputfont.pointSize: fontSize + 1Layout.fillWidth: truetext: lastUserNamevisible: showUsernamePromptfocus: showUsernamePrompt && !lastUserName //if there's a username prompt it gets focus first, otherwise password doesplaceholderText: i18ndc("plasma-desktop-sddm-theme", "@info:placeholder in textfield", "Username")onAccepted: {if (root.loginScreenUiVisible) {passwordBox.forceActiveFocus()}}}RowLayout {Layout.fillWidth: truePlasmaExtras.PasswordField {id: passwordBoxfont.pointSize: fontSize + 1Layout.fillWidth: trueplaceholderText: i18ndc("plasma-desktop-sddm-theme", "@info:placeholder in textfield", "Password")focus: !showUsernamePrompt || lastUserName// Disable reveal password action because SDDM does not have the breeze icon set loadedrightActions: []onAccepted: {if (root.loginScreenUiVisible) {startLogin();}}visible: root.showUsernamePrompt || userList.currentItem.needsPasswordKeys.onEscapePressed: {mainStack.currentItem.forceActiveFocus();}//if empty and left or right is pressed change selection in user switch//this cannot be in keys.onLeftPressed as then it doesn't reach the password boxKeys.onPressed: event => {if (event.key === Qt.Key_Left && !text) {userList.decrementCurrentIndex();event.accepted = true}if (event.key === Qt.Key_Right && !text) {userList.incrementCurrentIndex();event.accepted = true}}Connections {target: sddmfunction onLoginFailed() {passwordBox.selectAll()passwordBox.forceActiveFocus()}}}PlasmaComponents3.Button {id: loginButtonAccessible.name: i18ndc("plasma-desktop-sddm-theme", "@action:button Accessible name", "Log in")Layout.preferredHeight: passwordBox.implicitHeightLayout.preferredWidth: text.length === 0 ? loginButton.Layout.preferredHeight : -1icon.name: text.length === 0 ? (root.LayoutMirroring.enabled ? "go-previous" : "go-next") : ""text: root.showUsernamePrompt || userList.currentItem.needsPassword ? "" : i18nc("@action:button", "Log In")onClicked: startLogin()Keys.onEnterPressed: clicked()Keys.onReturnPressed: clicked()}}}