From 22b356d260f77b2a4a05a39c8a4c0fd409d3f53d Mon Sep 17 00:00:00 2001 From: Tim Hämisch Date: Thu, 12 Jun 2025 14:59:55 +0200 Subject: Add shutdown, reboot, and logout actions to launcher --- modules/launcher/Actions.qml | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/modules/launcher/Actions.qml b/modules/launcher/Actions.qml index 0cbc870..4d74e05 100644 --- a/modules/launcher/Actions.qml +++ b/modules/launcher/Actions.qml @@ -67,6 +67,36 @@ Singleton { Colours.setMode("dark"); } }, + Action { + name: qsTr("Shutdown") + desc: qsTr("Shutdown the system") + icon: "power_settings_new" + + function onClicked(list: AppList): void { + list.visibilities.launcher = false; + shutdown.running = true; + } + }, + Action { + name: qsTr("Reboot") + desc: qsTr("Reboot the system") + icon: "cached" + + function onClicked(list: AppList): void { + list.visibilities.launcher = false; + reboot.running = true; + } + }, + Action { + name: qsTr("Logout") + desc: qsTr("Logout of the current session") + icon: "logout" + + function onClicked(list: AppList): void { + list.visibilities.launcher = false; + logout.running = true; + } + }, Action { name: qsTr("Lock") desc: qsTr("Lock the current session") @@ -107,6 +137,24 @@ Singleton { list.search.text = `${LauncherConfig.actionPrefix}${text} `; } + Process { + id: shutdown + + command: ["systemctl", "poweroff"] + } + + Process { + id: reboot + + command: ["systemctl", "reboot"] + } + + Process { + id: logout + + command: ["sh", "-c", "(uwsm stop | grep -q 'Compositor is not running' && loginctl terminate-user $USER) || uwsm stop"] + } + Process { id: lock -- cgit v1.2.3-freya From 0bcee304e5170214cb85aa2236c81299d01ab792 Mon Sep 17 00:00:00 2001 From: Tim Hämisch Date: Fri, 13 Jun 2025 18:04:45 +0200 Subject: launcher: add opt-in for dangerous actions --- config/LauncherConfig.qml | 1 + modules/launcher/ActionItem.qml | 12 +++++++++--- modules/launcher/Actions.qml | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/config/LauncherConfig.qml b/config/LauncherConfig.qml index 18489f7..a3c154f 100644 --- a/config/LauncherConfig.qml +++ b/config/LauncherConfig.qml @@ -8,6 +8,7 @@ Singleton { readonly property int maxWallpapers: 9 // Warning: even numbers look bad readonly property string actionPrefix: ">" readonly property Sizes sizes: Sizes {} + readonly property bool allowDangerousActions: false // Allow actions that can change the system state, like shutdown, reboot and logout component Sizes: QtObject { readonly property int itemWidth: 600 diff --git a/modules/launcher/ActionItem.qml b/modules/launcher/ActionItem.qml index a650768..20638e3 100644 --- a/modules/launcher/ActionItem.qml +++ b/modules/launcher/ActionItem.qml @@ -31,7 +31,9 @@ Item { MaterialIcon { id: icon - text: root.modelData?.icon ?? "" + text: root.modelData?.disabled + ? "disabled_by_default" + : (root.modelData?.icon ?? "") font.pointSize: Appearance.font.size.extraLarge anchors.verticalCenter: parent.verticalCenter @@ -48,14 +50,18 @@ Item { StyledText { id: name - text: root.modelData?.name ?? "" + text: root.modelData?.disabled + ? (root.modelData?.name ?? "") + " - Disabled" + : (root.modelData?.name ?? "") font.pointSize: Appearance.font.size.normal } StyledText { id: desc - text: root.modelData?.desc ?? "" + text: root.modelData?.disabled + ? (root.modelData?.disabledReason ?? "") + : (root.modelData?.desc ?? "") font.pointSize: Appearance.font.size.small color: Colours.alpha(Colours.palette.m3outline, true) diff --git a/modules/launcher/Actions.qml b/modules/launcher/Actions.qml index 4d74e05..47607c3 100644 --- a/modules/launcher/Actions.qml +++ b/modules/launcher/Actions.qml @@ -71,30 +71,33 @@ Singleton { name: qsTr("Shutdown") desc: qsTr("Shutdown the system") icon: "power_settings_new" + disabled: !LauncherConfig.allowDangerousActions + disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first") function onClicked(list: AppList): void { - list.visibilities.launcher = false; - shutdown.running = true; + root.handleDangerousAction(list, shutdown); } }, Action { name: qsTr("Reboot") desc: qsTr("Reboot the system") icon: "cached" + disabled: !LauncherConfig.allowDangerousActions + disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first") function onClicked(list: AppList): void { - list.visibilities.launcher = false; - reboot.running = true; + root.handleDangerousAction(list, reboot); } }, Action { name: qsTr("Logout") desc: qsTr("Logout of the current session") - icon: "logout" + icon: "exit_to_app" + disabled: !LauncherConfig.allowDangerousActions + disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first") function onClicked(list: AppList): void { - list.visibilities.launcher = false; - logout.running = true; + root.handleDangerousAction(list, logout); } }, Action { @@ -137,6 +140,21 @@ Singleton { list.search.text = `${LauncherConfig.actionPrefix}${text} `; } + function handleDangerousAction(list: AppList, process: QtObject): void { + list.visibilities.launcher = false; + if (!LauncherConfig.allowDangerousActions) { + dangerousActions.running = true; + return; + } + process.running = true; + } + + Process { + id: dangerousActions + + command: ["notify-send", "Quickshell", qsTr("Enable dangerous actions in config/LauncherConfig.qml to use this action."), "-i", "dialog-warning"] + } + Process { id: shutdown @@ -152,8 +170,8 @@ Singleton { Process { id: logout - command: ["sh", "-c", "(uwsm stop | grep -q 'Compositor is not running' && loginctl terminate-user $USER) || uwsm stop"] - } + command: ["hyprctl", "dispatch", "exit", "1"] + } Process { id: lock @@ -171,6 +189,8 @@ Singleton { required property string name required property string desc required property string icon + property bool disabled + property string disabledReason function onClicked(list: AppList): void { } -- cgit v1.2.3-freya From 818768e6bda3c39bf214f51d39af7bea8bcffe2d Mon Sep 17 00:00:00 2001 From: Tim Hämisch Date: Fri, 13 Jun 2025 18:13:07 +0200 Subject: launcher: use standard logout command --- modules/launcher/Actions.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/launcher/Actions.qml b/modules/launcher/Actions.qml index 47607c3..d612cb0 100644 --- a/modules/launcher/Actions.qml +++ b/modules/launcher/Actions.qml @@ -170,7 +170,7 @@ Singleton { Process { id: logout - command: ["hyprctl", "dispatch", "exit", "1"] + command: ["sh", "-c", "(uwsm stop | grep -q 'Compositor is not running' && loginctl terminate-user $USER) || uwsm stop"] } Process { -- cgit v1.2.3-freya From a44910d3971b1eb7ce0b755ac98bdd35c6c3574e Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 16 Jun 2025 00:42:09 +1000 Subject: launcher: completely hide disabled actions --- config/LauncherConfig.qml | 2 +- modules/launcher/ActionItem.qml | 12 +++--------- modules/launcher/Actions.qml | 39 ++++++++++++--------------------------- 3 files changed, 16 insertions(+), 37 deletions(-) diff --git a/config/LauncherConfig.qml b/config/LauncherConfig.qml index 1757c7e..ea3c364 100644 --- a/config/LauncherConfig.qml +++ b/config/LauncherConfig.qml @@ -4,7 +4,7 @@ JsonObject { property int maxShown: 8 property int maxWallpapers: 9 // Warning: even numbers look bad property string actionPrefix: ">" - property bool allowDangerousActions: false // Allow actions that can change the system state, like shutdown, reboot and logout + property bool enableDangerousActions: false // Allow actions that can cause losing data, like shutdown, reboot and logout property JsonObject sizes: JsonObject { property int itemWidth: 600 diff --git a/modules/launcher/ActionItem.qml b/modules/launcher/ActionItem.qml index 720b272..db3242a 100644 --- a/modules/launcher/ActionItem.qml +++ b/modules/launcher/ActionItem.qml @@ -31,9 +31,7 @@ Item { MaterialIcon { id: icon - text: root.modelData?.disabled - ? "disabled_by_default" - : (root.modelData?.icon ?? "") + text: root.modelData?.icon ?? "" font.pointSize: Appearance.font.size.extraLarge anchors.verticalCenter: parent.verticalCenter @@ -50,18 +48,14 @@ Item { StyledText { id: name - text: root.modelData?.disabled - ? (root.modelData?.name ?? "") + " - Disabled" - : (root.modelData?.name ?? "") + text: root.modelData?.name ?? "" font.pointSize: Appearance.font.size.normal } StyledText { id: desc - text: root.modelData?.disabled - ? (root.modelData?.disabledReason ?? "") - : (root.modelData?.desc ?? "") + text: root.modelData?.desc ?? "" font.pointSize: Appearance.font.size.small color: Colours.alpha(Colours.palette.m3outline, true) diff --git a/modules/launcher/Actions.qml b/modules/launcher/Actions.qml index 1f6e72b..ae732db 100644 --- a/modules/launcher/Actions.qml +++ b/modules/launcher/Actions.qml @@ -71,33 +71,33 @@ Singleton { name: qsTr("Shutdown") desc: qsTr("Shutdown the system") icon: "power_settings_new" - disabled: !LauncherConfig.allowDangerousActions - disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first") + disabled: !Config.launcher.enableDangerousActions function onClicked(list: AppList): void { - root.handleDangerousAction(list, shutdown); + list.visibilities.launcher = false; + shutdown.running = true; } }, Action { name: qsTr("Reboot") desc: qsTr("Reboot the system") icon: "cached" - disabled: !LauncherConfig.allowDangerousActions - disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first") + disabled: !Config.launcher.enableDangerousActions function onClicked(list: AppList): void { - root.handleDangerousAction(list, reboot); + list.visibilities.launcher = false; + reboot.running = true; } }, Action { name: qsTr("Logout") - desc: qsTr("Logout of the current session") + desc: qsTr("Log out of the current session") icon: "exit_to_app" - disabled: !LauncherConfig.allowDangerousActions - disabledReason: qsTr("Enable dangerous actions in config/LauncherConfig.qml first") + disabled: !Config.launcher.enableDangerousActions function onClicked(list: AppList): void { - root.handleDangerousAction(list, logout); + list.visibilities.launcher = false; + logout.running = true; } }, Action { @@ -122,7 +122,7 @@ Singleton { } ] - readonly property list preppedActions: list.map(a => ({ + readonly property list preppedActions: list.filter(a => !a.disabled).map(a => ({ name: Fuzzy.prepare(a.name), desc: Fuzzy.prepare(a.desc), action: a @@ -140,21 +140,6 @@ Singleton { list.search.text = `${Config.launcher.actionPrefix}${text} `; } - function handleDangerousAction(list: AppList, process: QtObject): void { - list.visibilities.launcher = false; - if (!LauncherConfig.allowDangerousActions) { - dangerousActions.running = true; - return; - } - process.running = true; - } - - Process { - id: dangerousActions - - command: ["notify-send", "Quickshell", qsTr("Enable dangerous actions in config/LauncherConfig.qml to use this action."), "-i", "dialog-warning"] - } - Process { id: shutdown @@ -171,7 +156,7 @@ Singleton { id: logout command: ["sh", "-c", "(uwsm stop | grep -q 'Compositor is not running' && loginctl terminate-user $USER) || uwsm stop"] - } + } Process { id: lock -- cgit v1.2.3-freya