aboutsummaryrefslogtreecommitdiff
path: root/modules/system/quickshell/LockSurface.qml
blob: eacd98fec60819c856853d548344a10904369e39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import Quickshell.Wayland

Item {
    id: root
    required property LockContext context
    focus: true

    property bool showInput: false
    property string realName: ""

    Process {
        id: nameProc
        command: ["sh", "-c", "NAME=$(getent passwd $USER | cut -d: -f5 | cut -d, -f1); if [ -n \"$NAME\" ]; then echo \"$NAME\"; else whoami; fi"]
        running: true
        stdout: SplitParser {
            onRead: line => {
                root.realName = line.trim()
            }
        }
    }

    // Capture keyboard input to reveal the text field
    Keys.onPressed: (event) => {
        if (!showInput && event.key !== Qt.Key_Escape) {
            showInput = true
            passwordInput.forceActiveFocus()
            if (event.text !== "") {
                passwordInput.text = event.text
                root.context.currentText = event.text
            }
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            root.showInput = true
            passwordInput.forceActiveFocus()
        }
    }

    Image {
        anchors.fill: parent
        source: "./wallpaper.jpg"
        fillMode: Image.PreserveAspectCrop
    }

    // Main Content (Clock)
    Column {
        anchors {
            top: parent.top
            topMargin: 120
            horizontalCenter: parent.horizontalCenter
        }
        spacing: 0
        Text {
            anchors.horizontalCenter: parent.horizontalCenter
            text: Qt.formatDateTime(new Date(), "dddd, MMMM d")
            color: "white"
            opacity: 0.9
            font {
                family: Theme.mainFont
                pixelSize: 24
                weight: Font.Medium
            }
        }
        Text {
            anchors.horizontalCenter: parent.horizontalCenter
            text: Qt.formatDateTime(new Date(), "HH:mm")
            color: "white"
            font {
                family: Theme.mainFont
                pixelSize: 150
                weight: Font.DemiBold
                letterSpacing: -8
            }
        }    }

    // Profile and Password Area (Bottom Center)
    ColumnLayout {
        id: passwordContainer
        anchors {
            bottom: parent.bottom
            horizontalCenter: parent.horizontalCenter
            bottomMargin: 100
        }
        spacing: 15

        SequentialAnimation {
            id: shakeAnimation
            NumberAnimation { target: passwordContainer; property: "anchors.horizontalCenterOffset"; to: -6; duration: 30; easing.type: Easing.OutQuad }
            NumberAnimation { target: passwordContainer; property: "anchors.horizontalCenterOffset"; to: 6; duration: 60; easing.type: Easing.InOutQuad }
            NumberAnimation { target: passwordContainer; property: "anchors.horizontalCenterOffset"; to: -6; duration: 60; easing.type: Easing.InOutQuad }
            NumberAnimation { target: passwordContainer; property: "anchors.horizontalCenterOffset"; to: 6; duration: 60; easing.type: Easing.InOutQuad }
            NumberAnimation { target: passwordContainer; property: "anchors.horizontalCenterOffset"; to: -6; duration: 60; easing.type: Easing.InOutQuad }
            NumberAnimation { target: passwordContainer; property: "anchors.horizontalCenterOffset"; to: 6; duration: 60; easing.type: Easing.InOutQuad }
            NumberAnimation { target: passwordContainer; property: "anchors.horizontalCenterOffset"; to: 0; duration: 30; easing.type: Easing.InQuad }
        }

        Connections {
            target: root.context
            function onFailed() {
                shakeAnimation.start();
            }
        }

        // Avatar Placeholder
        Rectangle {
            Layout.alignment: Qt.AlignHCenter
            width: 60
            height: 60
            radius: 30
            color: "#b0b0b0"
        }

        // User Name
        Text {
            Layout.alignment: Qt.AlignHCenter
            text: root.realName || "User"
            color: "white"
            font {
                family: Theme.mainFont
                pixelSize: 16
                weight: Font.DemiBold
            }
            visible: !root.showInput
        }

        // Prompt Text
        Text {
            Layout.alignment: Qt.AlignHCenter
            text: "Enter Password"
            color: "white"
            opacity: 0.7
            font {
                family: Theme.mainFont
                pixelSize: 13
            }
            visible: !root.showInput
        }

        // Password Input Field
        TextField {
            id: passwordInput
            Layout.preferredWidth: 220
            Layout.preferredHeight: 32
            Layout.alignment: Qt.AlignHCenter
            visible: root.showInput
            
            placeholderText: root.context.pamMessage || "Enter Password"
            placeholderTextColor: Theme.textPlaceholder
            echoMode: TextInput.Password
            inputMethodHints: Qt.ImhSensitiveData
            enabled: !root.context.unlockInProgress
            
            // Update context when text is changed directly in this field
            onTextChanged: root.context.currentText = this.text
            
            // Sync text from context to support multi-monitor mirroring securely
            Connections {
                target: root.context
                function onCurrentTextChanged() {
                    if (passwordInput.text !== root.context.currentText) {
                        passwordInput.text = root.context.currentText;
                    }
                }
            }
            
            background: Rectangle {
                radius: height / 2
                color: Theme.surface
                border.color: parent.activeFocus ? Theme.accent : Theme.border
                border.width: 1
            }

            color: Theme.text
            font.pixelSize: 13
            horizontalAlignment: TextInput.AlignHCenter
            verticalAlignment: TextInput.AlignVCenter

            onAccepted: {
                root.context.tryUnlock()
            }

            Keys.onEscapePressed: {
                root.showInput = false
                root.context.currentText = ""
                root.forceActiveFocus()
            }
        }
    }
}