forked from talyamm/VoidSDDM
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.qml
More file actions
359 lines (323 loc) · 13.5 KB
/
Copy pathMain.qml
File metadata and controls
359 lines (323 loc) · 13.5 KB
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
import QtQuick 2.0
import SddmComponents 2.0
import "components"
import "utils/ConfigManager.js" as ConfigManager
import "utils/NavigationHandler.js" as NavigationHandler
Rectangle {
id: mainRect
focus: true
property string activeSelector: "password" // "password", "user", "session", "power"
property int activePowerButton: 0 // 0=shutdown, 1=restart, 2=suspend
property bool capsLockActive: false
// Config properties
color: config.stringValue("background") || '#000000'
property string backgroundImage: config.stringValue("backgroundImage") || ""
// Background image
Image {
id: backgroundImageComponent
anchors.fill: parent
source: mainRect.backgroundImage
fillMode: Image.PreserveAspectCrop
visible: mainRect.backgroundImage !== ""
}
property int animationDuration: config.intValue("animationDuration") || 200
property int fadeInDuration: config.intValue("fadeInDuration") || 300
property int elementSpacing: config.intValue("elementSpacing") || 15
property bool showPreview: config.boolValue("showSelectorPreview") || false
property bool showHelpTips: config.boolValue("showHelpTips") || false
property bool showCapsLockIndicator: config.boolValue("showCapsLockIndicator") || false
property bool allowEmptyPassword: config.boolValue("allowEmptyPassword") || false
property bool clearPasswordOnError: config.boolValue("clearPasswordOnError") !== false
property int passwordFieldOffsetX: config.intValue("passwordFieldOffsetX") || 0
property int passwordFieldOffsetY: config.intValue("passwordFieldOffsetY") || 0
property bool showClock: config.boolValue("showClock") || false
property int clockOffsetX: config.intValue("clockOffsetX") || 0
property int clockOffsetY: config.intValue("clockOffsetY") || -200
property real elementOpacity: ConfigManager.getElementOpacity(config)
// Fade-in animation state
property bool fadeInComplete: false
Component.onCompleted: {
fadeInComplete = true
passwordField.passwordInput.focus = true
}
// Clock
Clock {
id: clock
showClock: mainRect.showClock
clockOffsetX: mainRect.clockOffsetX
clockOffsetY: mainRect.clockOffsetY
animationDuration: mainRect.animationDuration
elementOpacity: mainRect.elementOpacity
}
// Help tips
HelpTips {
id: helpTips
showHelpTips: mainRect.showHelpTips
fadeInComplete: mainRect.fadeInComplete
fadeInDuration: mainRect.fadeInDuration
elementOpacity: mainRect.elementOpacity
}
// User preview
SelectorPreview {
id: userPreview
previewText: userSelect.selectedUser
showPreview: mainRect.showPreview
activeSelector: mainRect.activeSelector
hideWhenSelector: "user"
fadeInComplete: mainRect.fadeInComplete
animationDuration: mainRect.animationDuration
elementOpacity: mainRect.elementOpacity
anchors.horizontalCenter: passwordField.horizontalCenter
anchors.bottom: passwordField.top
anchors.bottomMargin: config.intValue("selectorPreviewMargin") || 10
}
// User selector container
Item {
id: userSelectContainer
width: passwordField.width
height: mainRect.activeSelector === "user" ? (config.intValue("selectorHeight") || 35) : 0
anchors.horizontalCenter: passwordField.horizontalCenter
anchors.bottom: passwordField.top
anchors.bottomMargin: mainRect.elementSpacing
clip: true
opacity: mainRect.elementOpacity
Behavior on height {
NumberAnimation { duration: mainRect.animationDuration; easing.type: Easing.OutCubic }
}
UserSelect {
id: userSelect
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
opacity: (mainRect.activeSelector === "user" ? 1 : 0) * mainRect.elementOpacity
visible: opacity > 0
Behavior on opacity {
NumberAnimation { duration: mainRect.animationDuration; easing.type: Easing.OutCubic }
}
}
}
// Caps Lock indicator
CapsLockIndicator {
id: capsLockIndicator
showCapsLockIndicator: mainRect.showCapsLockIndicator
capsLockActive: mainRect.capsLockActive
animationDuration: mainRect.animationDuration
elementOpacity: mainRect.elementOpacity
anchors.right: passwordField.left
anchors.rightMargin: 15
anchors.verticalCenter: passwordField.verticalCenter
}
// Password field
PasswordField {
id: passwordField
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenterOffset: mainRect.passwordFieldOffsetX
anchors.verticalCenterOffset: mainRect.passwordFieldOffsetY
enabled: mainRect.activeSelector === "password"
fadeInComplete: mainRect.fadeInComplete
fadeInDuration: mainRect.fadeInDuration
elementOpacity: mainRect.elementOpacity
onLoginRequested: {
var savedPassword = passwordField.passwordText
// Check if empty password is allowed
if (!mainRect.allowEmptyPassword && savedPassword.length === 0) {
return
}
sddm.login(userSelect.selectedUser, savedPassword, sessionSelect.selectedIndex)
loginErrorTimer.start()
}
}
// Login error timer
Timer {
id: loginErrorTimer
interval: config.intValue("loginErrorDelay") || 500
onTriggered: {
if (mainRect.activeSelector === "password") {
passwordField.hasError = true
if (mainRect.clearPasswordOnError) {
passwordField.passwordText = ""
}
}
}
}
// Session selector container
Item {
id: sessionSelectContainer
width: passwordField.width
height: mainRect.activeSelector === "session" ? (config.intValue("selectorHeight") || 35) : 0
anchors.horizontalCenter: passwordField.horizontalCenter
anchors.top: passwordField.bottom
anchors.topMargin: mainRect.elementSpacing
clip: true
opacity: mainRect.elementOpacity
Behavior on height {
NumberAnimation { duration: mainRect.animationDuration; easing.type: Easing.OutCubic }
}
SessionSelect {
id: sessionSelect
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
opacity: (mainRect.activeSelector === "session" ? 1 : 0) * mainRect.elementOpacity
visible: opacity > 0
Behavior on opacity {
NumberAnimation { duration: mainRect.animationDuration; easing.type: Easing.OutCubic }
}
}
}
// Session preview
SelectorPreview {
id: sessionPreview
previewText: sessionSelect.selectedSession
showPreview: mainRect.showPreview
activeSelector: mainRect.activeSelector
hideWhenSelector: "session"
fadeInComplete: mainRect.fadeInComplete
animationDuration: mainRect.animationDuration
elementOpacity: mainRect.elementOpacity
anchors.horizontalCenter: passwordField.horizontalCenter
anchors.top: passwordField.bottom
anchors.topMargin: config.intValue("selectorPreviewMargin") || 10
visible: mainRect.showPreview && mainRect.activeSelector !== "session" && mainRect.activeSelector !== "power" && sessionSelect.selectedSession !== ""
}
// Power buttons selector container
Item {
id: powerButtonContainer
width: passwordField.width
height: mainRect.activeSelector === "power" ? (config.intValue("selectorHeight") || 35) : 0
anchors.horizontalCenter: passwordField.horizontalCenter
anchors.top: passwordField.bottom
anchors.topMargin: mainRect.elementSpacing
clip: true
opacity: mainRect.elementOpacity
Behavior on height {
NumberAnimation { duration: mainRect.animationDuration; easing.type: Easing.OutCubic }
}
PowerButtons {
id: powerButtons
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
activeButton: mainRect.activeSelector === "power" ? mainRect.activePowerButton : 0
fadeInComplete: mainRect.fadeInComplete
fadeInDuration: mainRect.fadeInDuration
elementOpacity: mainRect.elementOpacity
opacity: (mainRect.activeSelector === "power" ? 1 : 0) * mainRect.elementOpacity
visible: opacity > 0
onActiveButtonChanged: {
if (mainRect.activeSelector === "power") {
mainRect.activePowerButton = powerButtons.activeButton
}
}
Behavior on opacity {
NumberAnimation { duration: mainRect.animationDuration; easing.type: Easing.OutCubic }
}
}
}
// Navigation functions
function activatePowerButton() {
if (mainRect.activeSelector === "power" && powerButtons) {
powerButtons.activateCurrentButton()
}
}
function returnToPassword() {
mainRect.activeSelector = "password"
passwordField.passwordInput.focus = true
}
function navigateSelector(selector, direction) {
return NavigationHandler.navigateSelector(selector, direction, userSelect, sessionSelect)
}
// Keyboard event handler
Keys.onPressed: function(event) {
var handled = false
// Track Caps Lock state
if (event.key === Qt.Key_CapsLock) {
mainRect.capsLockActive = !mainRect.capsLockActive
return
}
if (event.key === Qt.Key_Up) {
if (mainRect.activeSelector === "password") {
mainRect.activeSelector = "user"
mainRect.focus = true
handled = true
} else if (mainRect.activeSelector === "power") {
mainRect.activeSelector = "session"
mainRect.focus = true
handled = true
} else if (mainRect.activeSelector === "session") {
returnToPassword()
handled = true
} else if (mainRect.activeSelector === "user") {
handled = false
} else {
returnToPassword()
handled = true
}
} else if (event.key === Qt.Key_Down) {
if (mainRect.activeSelector === "password") {
mainRect.activeSelector = "session"
mainRect.focus = true
handled = true
} else if (mainRect.activeSelector === "session") {
mainRect.activeSelector = "power"
mainRect.activePowerButton = 0
mainRect.focus = true
handled = true
} else if (mainRect.activeSelector === "power") {
handled = false
} else {
returnToPassword()
handled = true
}
} else if (event.key === Qt.Key_Left) {
if (mainRect.activeSelector === "user") {
handled = navigateSelector("user", "left")
} else if (mainRect.activeSelector === "session") {
handled = navigateSelector("session", "left")
} else if (mainRect.activeSelector === "power") {
var newButton = NavigationHandler.navigatePowerButton("left", powerButtons, mainRect.activePowerButton)
if (newButton !== false) {
mainRect.activePowerButton = newButton
}
handled = true
}
} else if (event.key === Qt.Key_Right) {
if (mainRect.activeSelector === "user") {
handled = navigateSelector("user", "right")
} else if (mainRect.activeSelector === "session") {
handled = navigateSelector("session", "right")
} else if (mainRect.activeSelector === "power") {
var newButton = NavigationHandler.navigatePowerButton("right", powerButtons, mainRect.activePowerButton)
if (newButton !== false) {
mainRect.activePowerButton = newButton
}
handled = true
}
} else if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) {
if (mainRect.activeSelector === "power") {
activatePowerButton()
handled = true
}
} else if (event.key === Qt.Key_F10) {
sddm.suspend()
handled = true
} else if (event.key === Qt.Key_F11) {
sddm.powerOff()
handled = true
} else if (event.key === Qt.Key_F12) {
sddm.reboot()
handled = true
}
if (handled) {
event.accepted = true
}
}
// Hide cursor if configured
Loader {
active: config.boolValue("showCursor") === false
anchors.fill: parent
sourceComponent: MouseArea {
enabled: false
cursorShape: Qt.BlankCursor
acceptedButtons: Qt.NoButton
}
}
}