diff --git a/wlogout/README.md b/wlogout/README.md new file mode 100644 index 0000000..c73b84b --- /dev/null +++ b/wlogout/README.md @@ -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) diff --git a/wlogout/WLogout.qml b/wlogout/WLogout.qml new file mode 100644 index 0000000..8965882 --- /dev/null +++ b/wlogout/WLogout.qml @@ -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 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" + } + } + } + } + } + } + } +} diff --git a/wlogout/WlButton.qml b/wlogout/WlButton.qml new file mode 100644 index 0000000..93f0100 --- /dev/null +++ b/wlogout/WlButton.qml @@ -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(); + } +} diff --git a/wlogout/icons/hibernate.png b/wlogout/icons/hibernate.png new file mode 100644 index 0000000..a6322aa Binary files /dev/null and b/wlogout/icons/hibernate.png differ diff --git a/wlogout/icons/lock.png b/wlogout/icons/lock.png new file mode 100644 index 0000000..f0b1eaf Binary files /dev/null and b/wlogout/icons/lock.png differ diff --git a/wlogout/icons/logout.png b/wlogout/icons/logout.png new file mode 100644 index 0000000..345a8aa Binary files /dev/null and b/wlogout/icons/logout.png differ diff --git a/wlogout/icons/reboot.png b/wlogout/icons/reboot.png new file mode 100644 index 0000000..29cfa2f Binary files /dev/null and b/wlogout/icons/reboot.png differ diff --git a/wlogout/icons/shutdown.png b/wlogout/icons/shutdown.png new file mode 100644 index 0000000..4d7d499 Binary files /dev/null and b/wlogout/icons/shutdown.png differ diff --git a/wlogout/icons/suspend.png b/wlogout/icons/suspend.png new file mode 100644 index 0000000..647bd66 Binary files /dev/null and b/wlogout/icons/suspend.png differ diff --git a/wlogout/image.png b/wlogout/image.png new file mode 100644 index 0000000..8040384 Binary files /dev/null and b/wlogout/image.png differ diff --git a/wlogout/shell.qml b/wlogout/shell.qml new file mode 100644 index 0000000..f406d02 --- /dev/null +++ b/wlogout/shell.qml @@ -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" + } + } +}