wlogout: add example

This commit is contained in:
outfoxxed 2024-03-08 04:30:51 -08:00
parent 56dc79816b
commit bc279df183
Signed by: outfoxxed
GPG Key ID: 4C88A185FB89301E
11 changed files with 182 additions and 0 deletions

7
wlogout/README.md Normal file
View File

@ -0,0 +1,7 @@
# Wlogout clone
This is a mostly faithful clone of [wlogout](https://github.com/ArtsyMacaw/wlogout).
You can run the example with `quickshell -c shell.qml`.
![](./image.png)

106
wlogout/WLogout.qml Normal file
View File

@ -0,0 +1,106 @@
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Io
import Quickshell.Wayland
Variants {
id: root
property color backgroundColor: "#e60c0c0c"
property color buttonColor: "#1e1e1e"
property color buttonHoverColor: "#3700b3"
default property list<WlButton> buttons
variants: Quickshell.screens.map(screen => ({ screen }))
PanelWindow {
id: w
exclusionMode: ExclusionMode.Ignore
WlrLayershell.layer: Layer.Overlay
WlrLayershell.keyboardFocus: KeyboardFocus.Exclusive
color: "transparent"
contentItem {
focus: true
Keys.onPressed: event => {
if (event.key == Qt.Key_Escape) Qt.quit();
else {
for (let i = 0; i < buttons.length; i++) {
let button = buttons[i];
if (event.key == button.keybind) button.exec();
}
}
}
}
anchors {
top: true
left: true
bottom: true
right: true
}
Rectangle {
color: backgroundColor;
anchors.fill: parent
MouseArea {
anchors.fill: parent
onClicked: Qt.quit()
GridLayout {
anchors.centerIn: parent
width: parent.width * 0.75
height: parent.height * 0.75
columns: 3
columnSpacing: 0
rowSpacing: 0
Repeater {
model: buttons
delegate: Rectangle {
required property WlButton modelData;
Layout.fillWidth: true
Layout.fillHeight: true
color: ma.containsMouse ? buttonHoverColor : buttonColor
border.color: "black"
border.width: ma.containsMouse ? 0 : 1
MouseArea {
id: ma
anchors.fill: parent
hoverEnabled: true
onClicked: modelData.exec()
}
Image {
id: icon
anchors.centerIn: parent
source: `icons/${modelData.icon}.png`
width: parent.width * 0.25
height: parent.width * 0.25
}
Text {
anchors {
top: icon.bottom
topMargin: 20
horizontalCenter: parent.horizontalCenter
}
text: modelData.text
font.pointSize: 20
color: "white"
}
}
}
}
}
}
}
}

21
wlogout/WlButton.qml Normal file
View File

@ -0,0 +1,21 @@
import QtQuick
import Quickshell.Io
QtObject {
required property string command
required property string text
required property string icon
property var keybind: null
id: button
readonly property var process: Process {
command: ["sh", "-c", button.command]
manageLifetime: false
}
function exec() {
process.running = true;
Qt.quit();
}
}

BIN
wlogout/icons/hibernate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
wlogout/icons/lock.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

BIN
wlogout/icons/logout.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

BIN
wlogout/icons/reboot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

BIN
wlogout/icons/shutdown.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

BIN
wlogout/icons/suspend.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
wlogout/image.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 110 KiB

48
wlogout/shell.qml Normal file
View File

@ -0,0 +1,48 @@
import QtQuick
import Quickshell
ShellRoot {
WLogout {
WlButton {
command: "loginctl lock-screen"
keybind: Qt.Key_K
text: "Lock"
icon: "lock"
}
WlButton {
command: "loginctl terminate-user $USER"
keybind: Qt.Key_E
text: "Logout"
icon: "logout"
}
WlButton {
command: "systemctl suspend"
keybind: Qt.Key_U
text: "Suspend"
icon: "suspend"
}
WlButton {
command: "systemctl hibernate"
keybind: Qt.Key_H
text: "Hibernate"
icon: "hibernate"
}
WlButton {
command: "systemctl poweroff"
keybind: Qt.Key_K
text: "Shutdown"
icon: "shutdown"
}
WlButton {
command: "systemctl reboot"
keybind: Qt.Key_R
text: "Reboot"
icon: "reboot"
}
}
}