Skip to content

Commit 56dc798

Browse files
committed
lockscreen: add example
1 parent 0c56831 commit 56dc798

File tree

6 files changed

+160
-0
lines changed

6 files changed

+160
-0
lines changed

lockscreen/AuthContext.qml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import QtQuick
2+
import Quickshell
3+
import Quickshell.Io
4+
5+
QtObject {
6+
property int status: AuthContext.Status.FirstLogin
7+
signal unlocked();
8+
9+
enum Status {
10+
FirstLogin,
11+
Authenticating,
12+
LoginFailed
13+
}
14+
15+
property string password
16+
17+
property var pamtester: Process {
18+
property bool failed: true
19+
20+
command: ["pamtester", "login", Quickshell.env("USER"), "authenticate"]
21+
22+
onStarted: this.write(`${password}\n`)
23+
24+
stdout: SplitParser {
25+
// fails go to stderr
26+
onRead: pamtester.failed = false
27+
}
28+
29+
onExited: {
30+
if (failed) {
31+
status = AuthContext.Status.LoginFailed;
32+
} else {
33+
unlocked();
34+
}
35+
}
36+
}
37+
38+
function tryLogin(password: string) {
39+
this.password = password
40+
status = AuthContext.Status.Authenticating;
41+
pamtester.running = true;
42+
}
43+
}

lockscreen/Lockscreen.qml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import QtQuick
2+
import QtQuick.Controls.Basic
3+
4+
Item {
5+
required property AuthContext context
6+
7+
Item {
8+
anchors.centerIn: parent
9+
scale: 2
10+
11+
TextField {
12+
id: entryBox
13+
anchors.centerIn: parent
14+
width: 300
15+
16+
enabled: context.status != AuthContext.Status.Authenticating
17+
focus: true
18+
horizontalAlignment: TextInput.AlignHCenter
19+
echoMode: TextInput.Password
20+
inputMethodHints: Qt.ImhSensitiveData
21+
placeholderText: "Enter password"
22+
23+
onAccepted: {
24+
if (text != "") context.tryLogin(text)
25+
}
26+
27+
onEnabledChanged: {
28+
if (enabled) text = ""
29+
}
30+
}
31+
32+
Text {
33+
id: status
34+
color: "white"
35+
36+
anchors {
37+
horizontalCenter: entryBox.horizontalCenter
38+
top: entryBox.bottom
39+
topMargin: 20
40+
}
41+
42+
text: {
43+
switch (context.status) {
44+
case AuthContext.Status.FirstLogin: return ""
45+
case AuthContext.Status.Authenticating: return "Authenticating"
46+
case AuthContext.Status.LoginFailed: return "Login Failed"
47+
}
48+
}
49+
}
50+
}
51+
}

lockscreen/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Lockscreen
2+
3+
This is a barebones lockscreen with a password input box.
4+
Note that you MUST have `pamtester` installed or you won't be able to log in.
5+
6+
You can run the lockscreen with `quickshell -c shell.qml`.
7+
8+
You can run the lockscreen in test mode (as a window) with `quickshell -c test.qml`.
9+
10+
![](./image.png)

lockscreen/image.png

21.6 KB
Loading

lockscreen/shell.qml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import QtQuick
2+
import QtQuick.Controls.Basic
3+
import Quickshell
4+
import Quickshell.Wayland
5+
6+
ShellRoot {
7+
AuthContext {
8+
id: authContext
9+
onUnlocked: lock.locked = false
10+
}
11+
12+
SessionLock {
13+
id: lock
14+
locked: true
15+
16+
onLockedChanged: {
17+
if (!locked) Qt.quit();
18+
}
19+
20+
SessionLockSurface {
21+
// You probably want to replace this with an image.
22+
color: "#303030"
23+
24+
// For your own sanity you should probably keep this
25+
// while working on the lockscreen.
26+
Button {
27+
text: "Help! I misconfigured my lockscreen!"
28+
onClicked: lock.locked = false
29+
}
30+
31+
Lockscreen {
32+
anchors.fill: parent
33+
context: authContext
34+
}
35+
}
36+
}
37+
38+
}

lockscreen/test.qml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import QtQuick
2+
import Quickshell
3+
4+
ShellRoot {
5+
AuthContext {
6+
id: authContext
7+
onUnlocked: Qt.quit()
8+
}
9+
10+
FloatingWindow {
11+
color: "#303030"
12+
13+
Lockscreen {
14+
anchors.fill: parent
15+
context: authContext
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)