Main.qml (20771B)
1 // the chamesle sign-in screen: a lock screen with the clock first, any key or click slides it up to sign in, 2 // like windows does it. sddm hands us userModel, sessionModel, sddm (login, power) and config (theme.conf) 3 import QtQuick 4 import QtQuick.Controls 5 6 Rectangle { 7 id: root 8 width: 1920 9 height: 1080 10 color: "#246070" 11 12 readonly property string fontName: config.font || "Inter" 13 // everything is drawn for 1080p and scaled to the screen 14 readonly property real s: Math.min(width / 1920, height / 1080) 15 // preview=signin in theme.conf starts on the sign-in box, for screenshots of it 16 property bool locked: config.preview !== "signin" 17 property int userIndex: userModel.lastIndex >= 0 ? userModel.lastIndex : 0 18 property int sessionIndex: sessionModel.lastIndex >= 0 ? sessionModel.lastIndex : 0 19 property string error: "" 20 21 // the users, read through a repeater: sddm's model only gives its roles to delegates 22 Repeater { 23 id: users 24 model: userModel 25 delegate: Item { 26 property string login: model.name 27 property string realName: model.realName 28 property string icon: model.icon 29 property bool needsPassword: model.needsPassword 30 } 31 } 32 readonly property var user: users.count > 0 ? users.itemAt(Math.min(userIndex, users.count - 1)) : null 33 readonly property string userName: user ? user.login : "" 34 readonly property string shownName: user ? (user.realName || user.login) : "" 35 36 function unlock() { 37 if (!locked) return 38 locked = false 39 password.forceActiveFocus() 40 } 41 function signIn() { 42 if (busy.running) return 43 error = "" 44 busy.running = true 45 sddm.login(userName, password.text, sessionIndex) 46 } 47 48 Connections { 49 target: sddm 50 function onLoginFailed() { 51 busy.running = false 52 password.text = "" 53 error = "That password isn't right. Try again." 54 shake.restart() 55 password.forceActiveFocus() 56 } 57 function onLoginSucceeded() { busy.running = false } 58 } 59 60 Image { 61 anchors.fill: parent 62 source: config.background || "assets/background.jpg" 63 fillMode: Image.PreserveAspectCrop 64 asynchronous: false 65 } 66 67 // dark at the top and bottom so the white clock and labels read on bright photos 68 Rectangle { 69 anchors.top: parent.top 70 width: parent.width 71 height: parent.height * 0.42 72 gradient: Gradient { 73 GradientStop { position: 0; color: "#66000000" } 74 GradientStop { position: 1; color: "#00000000" } 75 } 76 } 77 Rectangle { 78 anchors.bottom: parent.bottom 79 width: parent.width 80 height: parent.height * 0.2 81 gradient: Gradient { 82 GradientStop { position: 0; color: "#00000000" } 83 GradientStop { position: 1; color: "#73000000" } 84 } 85 } 86 87 // ---- the lock screen ---- 88 Item { 89 id: lock 90 width: parent.width 91 height: parent.height 92 y: root.locked ? 0 : -parent.height * 0.12 93 opacity: root.locked ? 1 : 0 94 visible: opacity > 0 95 Behavior on y { NumberAnimation { duration: 350; easing.type: Easing.OutCubic } } 96 Behavior on opacity { NumberAnimation { duration: 250 } } 97 98 Text { 99 id: time 100 anchors.horizontalCenter: parent.horizontalCenter 101 y: parent.height * 0.11 102 color: "white" 103 font.family: root.fontName 104 font.pixelSize: 132 * root.s 105 font.weight: Font.DemiBold 106 text: Qt.formatTime(clock.now, config.clock === "12" ? "h:mm" : "HH:mm") 107 style: Text.Raised 108 styleColor: "#30000000" 109 } 110 Text { 111 anchors.horizontalCenter: parent.horizontalCenter 112 anchors.top: time.bottom 113 anchors.topMargin: 2 * root.s 114 color: "white" 115 font.family: root.fontName 116 font.pixelSize: 26 * root.s 117 font.weight: Font.Medium 118 text: Qt.formatDate(clock.now, "dddd, d MMMM") 119 } 120 } 121 Timer { 122 id: clock 123 property date now: new Date() 124 interval: 1000 125 running: true 126 repeat: true 127 onTriggered: now = new Date() 128 } 129 130 // ---- signing in ---- 131 Item { 132 id: signin 133 anchors.fill: parent 134 opacity: root.locked ? 0 : 1 135 visible: opacity > 0 136 Behavior on opacity { NumberAnimation { duration: 200 } } 137 138 // a grey panel with a black title bar, like a NeXT login window 139 Rectangle { 140 id: pane 141 anchors.horizontalCenter: parent.horizontalCenter 142 anchors.verticalCenter: parent.verticalCenter 143 width: 560 * root.s 144 height: title.height + box.implicitHeight + 56 * root.s 145 color: "black" 146 // the shadow it throws on the wallpaper, hard edged 147 Rectangle { 148 z: -1 149 x: 8 * root.s; y: 8 * root.s 150 width: parent.width; height: parent.height 151 color: "#60000000" 152 } 153 Bevel { 154 anchors.fill: parent 155 anchors.margins: 1 156 } 157 Rectangle { 158 id: title 159 x: 1; y: 1 160 width: parent.width - 2 161 height: 30 * root.s 162 color: "black" 163 Text { 164 anchors.centerIn: parent 165 text: "Sign in to " + (sddm.hostName || "Chamesle") 166 color: "white" 167 font.family: root.fontName 168 font.pixelSize: 15 * root.s 169 font.weight: Font.DemiBold 170 } 171 } 172 Rectangle { x: 1; y: title.height + 1; width: parent.width - 2; height: 1; color: "#555555" } 173 174 Row { 175 id: box 176 x: 28 * root.s 177 anchors.top: title.bottom 178 anchors.topMargin: 28 * root.s 179 spacing: 24 * root.s 180 181 // the picture people set, or the plain one, sunk into the panel 182 Bevel { 183 width: 112 * root.s 184 height: width 185 sunk: true 186 face: "#ffffff" 187 Image { 188 id: face 189 anchors.fill: parent 190 anchors.margins: 3 * root.s 191 source: root.user && root.user.icon ? root.user.icon : "assets/user.svg" 192 sourceSize: Qt.size(width * 2, height * 2) 193 fillMode: Image.PreserveAspectCrop 194 onStatusChanged: if (status === Image.Error) source = "assets/user.svg" 195 } 196 } 197 198 Column { 199 spacing: 12 * root.s 200 width: pane.width - 112 * root.s - 80 * root.s 201 202 Text { 203 color: "black" 204 font.family: root.fontName 205 font.pixelSize: 24 * root.s 206 font.weight: Font.DemiBold 207 text: root.shownName 208 elide: Text.ElideRight 209 width: parent.width 210 } 211 212 // the password box, sunk in, with a button that has the arrow on it 213 Item { 214 id: field 215 width: parent.width 216 height: 34 * root.s 217 visible: !root.user || root.user.needsPassword 218 property real shakeX: 0 219 transform: Translate { x: field.shakeX } 220 SequentialAnimation { 221 id: shake 222 NumberAnimation { target: field; property: "shakeX"; to: -12 * root.s; duration: 50 } 223 NumberAnimation { target: field; property: "shakeX"; to: 12 * root.s; duration: 70 } 224 NumberAnimation { target: field; property: "shakeX"; to: -6 * root.s; duration: 60 } 225 NumberAnimation { target: field; property: "shakeX"; to: 0; duration: 50 } 226 } 227 Bevel { 228 id: well 229 anchors.left: parent.left 230 anchors.right: go.left 231 anchors.rightMargin: 8 * root.s 232 height: parent.height 233 sunk: true 234 face: "#ffffff" 235 } 236 TextInput { 237 id: password 238 anchors.left: well.left 239 anchors.right: reveal.left 240 anchors.leftMargin: 10 * root.s 241 anchors.verticalCenter: parent.verticalCenter 242 color: "black" 243 font.family: root.fontName 244 font.pixelSize: 17 * root.s 245 echoMode: reveal.pressed ? TextInput.Normal : TextInput.Password 246 passwordCharacter: "•" 247 clip: true 248 selectByMouse: true 249 selectionColor: "#246070" 250 onAccepted: root.signIn() 251 onTextChanged: if (text.length) root.error = "" 252 Keys.onEscapePressed: { text = ""; root.locked = true } 253 Text { 254 anchors.verticalCenter: parent.verticalCenter 255 text: "Password" 256 color: "#888888" 257 font: password.font 258 visible: !password.text && !password.preeditText 259 } 260 } 261 MouseArea { 262 id: reveal 263 anchors.right: well.right 264 anchors.verticalCenter: parent.verticalCenter 265 width: 32 * root.s 266 height: parent.height 267 visible: password.text.length > 0 268 Image { 269 anchors.centerIn: parent 270 source: "assets/eye-dark.svg" 271 width: 18 * root.s 272 height: width 273 sourceSize: Qt.size(width * 2, height * 2) 274 opacity: reveal.pressed ? 1 : 0.6 275 } 276 } 277 MouseArea { 278 id: go 279 anchors.right: parent.right 280 width: 46 * root.s 281 height: parent.height 282 onClicked: root.signIn() 283 Bevel { anchors.fill: parent; sunk: go.pressed } 284 Image { 285 anchors.centerIn: parent 286 anchors.horizontalCenterOffset: go.pressed ? 1 : 0 287 anchors.verticalCenterOffset: go.pressed ? 1 : 0 288 source: "assets/arrow-dark.svg" 289 width: 20 * root.s 290 height: width 291 sourceSize: Qt.size(width * 2, height * 2) 292 visible: !busy.running 293 } 294 BusyIndicator { 295 id: busy 296 anchors.centerIn: parent 297 width: 22 * root.s 298 height: width 299 running: false 300 visible: running 301 } 302 } 303 } 304 305 // no password on this account (autologin users): just a button 306 MouseArea { 307 id: plain 308 visible: root.user && !root.user.needsPassword 309 width: 140 * root.s 310 height: 34 * root.s 311 onClicked: root.signIn() 312 Bevel { anchors.fill: parent; sunk: plain.pressed } 313 Text { 314 anchors.centerIn: parent 315 text: "Sign in" 316 color: "black" 317 font.family: root.fontName 318 font.pixelSize: 16 * root.s 319 } 320 } 321 322 Text { 323 color: "#800000" 324 font.family: root.fontName 325 font.pixelSize: 14 * root.s 326 width: parent.width 327 wrapMode: Text.WordWrap 328 text: root.error || (keyboard.capsLock ? "Caps Lock is on" : " ") 329 } 330 } 331 } 332 } 333 334 // other people on this computer, bottom left 335 Column { 336 anchors.left: parent.left 337 anchors.bottom: parent.bottom 338 anchors.margins: 28 * root.s 339 spacing: 4 * root.s 340 visible: users.count > 1 341 Repeater { 342 model: userModel 343 delegate: Rectangle { 344 width: 260 * root.s 345 height: 52 * root.s 346 radius: 6 * root.s 347 color: index === root.userIndex ? "#38ffffff" : (pick.containsMouse ? "#20ffffff" : "transparent") 348 Row { 349 anchors.verticalCenter: parent.verticalCenter 350 anchors.left: parent.left 351 anchors.leftMargin: 10 * root.s 352 spacing: 12 * root.s 353 Canvas { 354 width: 34 * root.s 355 height: width 356 property string img: model.icon || "assets/user.svg" 357 Component.onCompleted: loadImage(img) 358 onImageLoaded: requestPaint() 359 onPaint: { 360 var c = getContext("2d") 361 c.reset(); c.beginPath() 362 c.arc(width / 2, height / 2, width / 2, 0, 2 * Math.PI) 363 c.closePath(); c.clip() 364 if (isImageLoaded(img)) c.drawImage(img, 0, 0, width, height) 365 else { c.fillStyle = "#e6e9ee"; c.fill() } 366 } 367 } 368 Text { 369 anchors.verticalCenter: parent.verticalCenter 370 text: model.realName || model.name 371 color: "white" 372 font.family: root.fontName 373 font.pixelSize: 16 * root.s 374 } 375 } 376 MouseArea { 377 id: pick 378 anchors.fill: parent 379 hoverEnabled: true 380 onClicked: { root.userIndex = index; password.text = ""; root.error = ""; password.forceActiveFocus() } 381 } 382 } 383 } 384 } 385 } 386 387 Row { 388 anchors.horizontalCenter: parent.horizontalCenter 389 anchors.bottom: parent.bottom 390 anchors.bottomMargin: 30 * root.s 391 spacing: 12 * root.s 392 Image { 393 anchors.verticalCenter: parent.verticalCenter 394 source: "assets/logo.png" 395 width: 34 * root.s 396 height: width 397 } 398 Text { 399 anchors.verticalCenter: parent.verticalCenter 400 text: "Chamesle" 401 color: "white" 402 font.family: root.fontName 403 font.pixelSize: 26 * root.s 404 font.weight: Font.DemiBold 405 } 406 Text { 407 anchors.verticalCenter: parent.verticalCenter 408 text: config.version || "" 409 color: "#d9ffffff" 410 font.family: root.fontName 411 font.pixelSize: 20 * root.s 412 } 413 } 414 415 // bottom right on both screens: which desktop, and power 416 Row { 417 anchors.right: parent.right 418 anchors.bottom: parent.bottom 419 anchors.margins: 24 * root.s 420 spacing: 6 * root.s 421 422 Repeater { 423 id: sessions 424 model: sessionModel 425 delegate: Item { property string label: model.name } 426 } 427 Corner { 428 visible: sessions.count > 1 429 icon: "assets/desktop.svg" 430 label: sessions.count ? sessions.itemAt(Math.min(root.sessionIndex, sessions.count - 1)).label : "" 431 onClicked: sessionMenu.open() 432 Menu { 433 id: sessionMenu 434 y: -height - 8 435 Repeater { 436 model: sessionModel 437 MenuItem { 438 text: model.name 439 checkable: true 440 checked: index === root.sessionIndex 441 onTriggered: root.sessionIndex = index 442 } 443 } 444 } 445 } 446 Corner { 447 icon: "assets/power.svg" 448 red: true 449 onClicked: powerMenu.open() 450 Menu { 451 id: powerMenu 452 y: -height - 8 453 MenuItem { text: "Sleep"; enabled: sddm.canSuspend; onTriggered: sddm.suspend() } 454 MenuItem { text: "Shut down"; enabled: sddm.canPowerOff; onTriggered: sddm.powerOff() } 455 MenuItem { text: "Restart"; enabled: sddm.canReboot; onTriggered: sddm.reboot() } 456 } 457 } 458 } 459 460 component Corner: MouseArea { 461 id: corner 462 property string icon 463 property string label: "" 464 property bool red: false 465 width: label ? labelText.implicitWidth + 56 * root.s : 44 * root.s 466 height: 40 * root.s 467 Rectangle { 468 anchors.fill: parent 469 color: "black" 470 Bevel { anchors.fill: parent; anchors.margins: 1; sunk: corner.pressed } 471 } 472 Row { 473 anchors.centerIn: parent 474 spacing: 8 * root.s 475 Image { 476 anchors.verticalCenter: parent.verticalCenter 477 // the black copy of the icon, for the grey button 478 source: corner.icon.replace(".svg", "-dark.svg") 479 width: 22 * root.s 480 height: width 481 sourceSize: Qt.size(width * 2, height * 2) 482 } 483 Text { 484 id: labelText 485 anchors.verticalCenter: parent.verticalCenter 486 visible: corner.label !== "" 487 text: corner.label 488 color: "black" 489 font.family: root.fontName 490 font.pixelSize: 15 * root.s 491 } 492 } 493 } 494 495 // grey with a light top-left edge and a dark bottom-right one, or the other way round when sunk in 496 component Bevel: Item { 497 property bool sunk: false 498 property color face: "#aaaaaa" 499 readonly property int b: Math.max(1, Math.round(2 * root.s)) 500 Rectangle { anchors.fill: parent; color: sunk ? "#ffffff" : "#555555" } 501 Rectangle { width: parent.width - b; height: parent.height - b; color: sunk ? "#555555" : "#ffffff" } 502 Rectangle { x: b; y: b; width: parent.width - 2 * b; height: parent.height - 2 * b; color: face } 503 } 504 505 // the lock screen goes on any key or click 506 MouseArea { 507 anchors.fill: parent 508 enabled: root.locked 509 visible: root.locked 510 onClicked: root.unlock() 511 } 512 focus: true 513 Keys.onPressed: function (event) { 514 if (root.locked) { 515 root.unlock() 516 // the first letter typed goes into the password, like windows 517 if (event.text && event.text.trim() !== "" && event.key !== Qt.Key_Space) password.insert(0, event.text) 518 event.accepted = true 519 } 520 } 521 Component.onCompleted: locked ? forceActiveFocus() : password.forceActiveFocus() 522 }