From 5e16a0b4164733ce4e569ddbf1b3be6ef1e9ace9 Mon Sep 17 00:00:00 2001 From: reionwong Date: Wed, 28 Jul 2021 21:02:04 +0800 Subject: [PATCH] ShutdownUI: add single instance --- shutdown-ui/main.cpp | 9 ++++ shutdown-ui/main.qml | 107 ++++++++++++++++++++++++------------------- 2 files changed, 68 insertions(+), 48 deletions(-) diff --git a/shutdown-ui/main.cpp b/shutdown-ui/main.cpp index ba0bfd9..5f3e1d9 100644 --- a/shutdown-ui/main.cpp +++ b/shutdown-ui/main.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include "actions.h" @@ -33,6 +34,14 @@ int main(int argc, char *argv[]) QGuiApplication app(argc, argv); + if (!QDBusConnection::sessionBus().registerService("org.cutefish.ShutdownUI")) { + return -1; + } + + if (!QDBusConnection::sessionBus().registerObject("/ShutdownUI", &app)) { + return -1; + } + // Translations QLocale locale; QString qmFilePath = QString("%1/%2.qm").arg("/usr/share/cutefish-shutdown/translations/").arg(locale.name()); diff --git a/shutdown-ui/main.qml b/shutdown-ui/main.qml index e2d4b2d..f35b203 100644 --- a/shutdown-ui/main.qml +++ b/shutdown-ui/main.qml @@ -28,7 +28,7 @@ ApplicationWindow { height: Screen.height visible: true visibility: Window.FullScreen - flags: Qt.FramelessWindowHint | Qt.Popup + flags: Qt.FramelessWindowHint | Qt.X11BypassWindowManagerHint id: root color: "transparent" @@ -59,57 +59,68 @@ ApplicationWindow { onClicked: exit() } - RowLayout { - id: layout + Item { + id: rootItem anchors.fill: parent - spacing: root.width * 0.05 + focus: true - Item { - Layout.fillWidth: true + Keys.enabled: true + Keys.onEscapePressed: { + Qt.quit() } - IconButton { - id: shutdownButton - Layout.alignment: Qt.AlignVCenter - text: qsTr("Shutdown") - icon: "qrc:///icons/system-shutdown.svg" - onClicked: actions.shutdown() - } - - IconButton { - id: rebootButton - Layout.alignment: Qt.AlignVCenter - text: qsTr("Reboot") - icon: "qrc:///icons/system-reboot.svg" - onClicked: actions.reboot() - } - - IconButton { - id: logoutButton - Layout.alignment: Qt.AlignVCenter - text: qsTr("Logout") - icon: "qrc:///icons/system-log-out.svg" - onClicked: actions.logout() - } - - IconButton { - id: lockscreenButton - Layout.alignment: Qt.AlignVCenter - text: qsTr("Lock screen") - icon: "qrc:/icons/system-lock-screen.svg" - onClicked: actions.lockScreen() - } - - IconButton { - id: suspendButton - Layout.alignment: Qt.AlignVCenter - text: qsTr("Suspend") - icon: "qrc:///icons/system-suspend.svg" - onClicked: actions.suspend() - } - - Item { - Layout.fillWidth: true + RowLayout { + id: layout + anchors.fill: parent + spacing: root.width * 0.05 + + Item { + Layout.fillWidth: true + } + + IconButton { + id: shutdownButton + Layout.alignment: Qt.AlignVCenter + text: qsTr("Shutdown") + icon: "qrc:///icons/system-shutdown.svg" + onClicked: actions.shutdown() + } + + IconButton { + id: rebootButton + Layout.alignment: Qt.AlignVCenter + text: qsTr("Reboot") + icon: "qrc:///icons/system-reboot.svg" + onClicked: actions.reboot() + } + + IconButton { + id: logoutButton + Layout.alignment: Qt.AlignVCenter + text: qsTr("Logout") + icon: "qrc:///icons/system-log-out.svg" + onClicked: actions.logout() + } + + IconButton { + id: lockscreenButton + Layout.alignment: Qt.AlignVCenter + text: qsTr("Lock screen") + icon: "qrc:/icons/system-lock-screen.svg" + onClicked: actions.lockScreen() + } + + IconButton { + id: suspendButton + Layout.alignment: Qt.AlignVCenter + text: qsTr("Suspend") + icon: "qrc:///icons/system-suspend.svg" + onClicked: actions.suspend() + } + + Item { + Layout.fillWidth: true + } } } }