diff options
| -rw-r--r-- | README.md | 106 | ||||
| -rw-r--r-- | config/LauncherConfig.qml | 107 | ||||
| -rw-r--r-- | modules/launcher/items/ActionItem.qml | 2 | ||||
| -rw-r--r-- | modules/launcher/services/Actions.qml | 167 |
4 files changed, 241 insertions, 141 deletions
@@ -357,6 +357,112 @@ default, you must create it manually. }, "launcher": { "actionPrefix": ">", + "actions": [ + { + "name": "Calculator", + "icon": "calculate", + "description": "Do simple math equations (powered by Qalc)", + "command": ["autocomplete", "calc"], + "enabled": true, + "dangerous": false + }, + { + "name": "Scheme", + "icon": "palette", + "description": "Change the current colour scheme", + "command": ["autocomplete", "scheme"], + "enabled": true, + "dangerous": false + }, + { + "name": "Wallpaper", + "icon": "image", + "description": "Change the current wallpaper", + "command": ["autocomplete", "wallpaper"], + "enabled": true, + "dangerous": false + }, + { + "name": "Variant", + "icon": "colors", + "description": "Change the current scheme variant", + "command": ["autocomplete", "variant"], + "enabled": true, + "dangerous": false + }, + { + "name": "Transparency", + "icon": "opacity", + "description": "Change shell transparency", + "command": ["autocomplete", "transparency"], + "enabled": false, + "dangerous": false + }, + { + "name": "Random", + "icon": "casino", + "description": "Switch to a random wallpaper", + "command": ["caelestia", "wallpaper", "-r"], + "enabled": true, + "dangerous": false + }, + { + "name": "Light", + "icon": "light_mode", + "description": "Change the scheme to light mode", + "command": ["setMode", "light"], + "enabled": true, + "dangerous": false + }, + { + "name": "Dark", + "icon": "dark_mode", + "description": "Change the scheme to dark mode", + "command": ["setMode", "dark"], + "enabled": true, + "dangerous": false + }, + { + "name": "Shutdown", + "icon": "power_settings_new", + "description": "Shutdown the system", + "command": ["systemctl", "poweroff"], + "enabled": true, + "dangerous": true + }, + { + "name": "Reboot", + "icon": "cached", + "description": "Reboot the system", + "command": ["systemctl", "reboot"], + "enabled": true, + "dangerous": true + }, + { + "name": "Logout", + "icon": "exit_to_app", + "description": "Log out of the current session", + "command": ["loginctl", "terminate-user", ""], + "enabled": true, + "dangerous": true + }, + { + "name": "Lock", + "icon": "lock", + "description": "Lock the current session", + "command": ["loginctl", "lock-session"], + "enabled": true, + "dangerous": false + }, + { + "name": "Sleep", + "icon": "bedtime", + "description": "Suspend then hibernate", + "command": ["systemctl", "suspend-then-hibernate"], + "enabled": true, + "dangerous": false + } + ], "dragThreshold": 50, "vimKeybinds": false, "enableDangerousActions": false, diff --git a/config/LauncherConfig.qml b/config/LauncherConfig.qml index d021089..31a1fc5 100644 --- a/config/LauncherConfig.qml +++ b/config/LauncherConfig.qml @@ -27,4 +27,111 @@ JsonObject { property int wallpaperWidth: 280 property int wallpaperHeight: 200 } + + property list<var> actions: [ + { + name: "Calculator", + icon: "calculate", + description: "Do simple math equations (powered by Qalc)", + command: ["autocomplete", "calc"], + enabled: true, + dangerous: false + }, + { + name: "Scheme", + icon: "palette", + description: "Change the current colour scheme", + command: ["autocomplete", "scheme"], + enabled: true, + dangerous: false + }, + { + name: "Wallpaper", + icon: "image", + description: "Change the current wallpaper", + command: ["autocomplete", "wallpaper"], + enabled: true, + dangerous: false + }, + { + name: "Variant", + icon: "colors", + description: "Change the current scheme variant", + command: ["autocomplete", "variant"], + enabled: true, + dangerous: false + }, + { + name: "Transparency", + icon: "opacity", + description: "Change shell transparency", + command: ["autocomplete", "transparency"], + enabled: false, + dangerous: false + }, + { + name: "Random", + icon: "casino", + description: "Switch to a random wallpaper", + command: ["caelestia", "wallpaper", "-r"], + enabled: true, + dangerous: false + }, + { + name: "Light", + icon: "light_mode", + description: "Change the scheme to light mode", + command: ["setMode", "light"], + enabled: true, + dangerous: false + }, + { + name: "Dark", + icon: "dark_mode", + description: "Change the scheme to dark mode", + command: ["setMode", "dark"], + enabled: true, + dangerous: false + }, + { + name: "Shutdown", + icon: "power_settings_new", + description: "Shutdown the system", + command: ["systemctl", "poweroff"], + enabled: true, + dangerous: true + }, + { + name: "Reboot", + icon: "cached", + description: "Reboot the system", + command: ["systemctl", "reboot"], + enabled: true, + dangerous: true + }, + { + name: "Logout", + icon: "exit_to_app", + description: "Log out of the current session", + command: ["loginctl", "terminate-user", ""], + enabled: true, + dangerous: true + }, + { + name: "Lock", + icon: "lock", + description: "Lock the current session", + command: ["loginctl", "lock-session"], + enabled: true, + dangerous: false + }, + { + name: "Sleep", + icon: "bedtime", + description: "Suspend then hibernate", + command: ["systemctl", "suspend-then-hibernate"], + enabled: true, + dangerous: false + } + ] } diff --git a/modules/launcher/items/ActionItem.qml b/modules/launcher/items/ActionItem.qml index 54e38f3..78b608a 100644 --- a/modules/launcher/items/ActionItem.qml +++ b/modules/launcher/items/ActionItem.qml @@ -7,7 +7,7 @@ import QtQuick Item { id: root - required property Actions.Action modelData + required property var modelData required property var list implicitHeight: Config.launcher.sizes.itemHeight diff --git a/modules/launcher/services/Actions.qml b/modules/launcher/services/Actions.qml index 8259437..5c1cb6b 100644 --- a/modules/launcher/services/Actions.qml +++ b/modules/launcher/services/Actions.qml @@ -10,156 +10,43 @@ import QtQuick Searcher { id: root - readonly property list<Action> actions: [ - Action { - name: qsTr("Calculator") - desc: qsTr("Do simple math equations (powered by Qalc)") - icon: "calculate" - - function onClicked(list: AppList): void { - root.autocomplete(list, "calc"); - } - }, - Action { - name: qsTr("Scheme") - desc: qsTr("Change the current colour scheme") - icon: "palette" - - function onClicked(list: AppList): void { - root.autocomplete(list, "scheme"); - } - }, - Action { - name: qsTr("Wallpaper") - desc: qsTr("Change the current wallpaper") - icon: "image" - - function onClicked(list: AppList): void { - root.autocomplete(list, "wallpaper"); - } - }, - Action { - name: qsTr("Variant") - desc: qsTr("Change the current scheme variant") - icon: "colors" - - function onClicked(list: AppList): void { - root.autocomplete(list, "variant"); - } - }, - Action { - name: qsTr("Transparency") - desc: qsTr("Change shell transparency") - icon: "opacity" - disabled: true - - function onClicked(list: AppList): void { - root.autocomplete(list, "transparency"); - } - }, - Action { - name: qsTr("Random") - desc: qsTr("Switch to a random wallpaper") - icon: "casino" + function transformSearch(search: string): string { + return search.slice(Config.launcher.actionPrefix.length); + } - function onClicked(list: AppList): void { - list.visibilities.launcher = false; - Quickshell.execDetached(["caelestia", "wallpaper", "-r"]); - } - }, - Action { - name: qsTr("Light") - desc: qsTr("Change the scheme to light mode") - icon: "light_mode" + list: variants.instances + useFuzzy: Config.launcher.useFuzzy.actions - function onClicked(list: AppList): void { - list.visibilities.launcher = false; - Colours.setMode("light"); - } - }, - Action { - name: qsTr("Dark") - desc: qsTr("Change the scheme to dark mode") - icon: "dark_mode" + Variants { + id: variants - function onClicked(list: AppList): void { - list.visibilities.launcher = false; - Colours.setMode("dark"); - } - }, - Action { - name: qsTr("Shutdown") - desc: qsTr("Shutdown the system") - icon: "power_settings_new" - disabled: !Config.launcher.enableDangerousActions + model: Config.launcher.actions.filter(a => (a.enabled ?? true) && (Config.launcher.enableDangerousActions || !(a.dangerous ?? false))) - function onClicked(list: AppList): void { - list.visibilities.launcher = false; - Quickshell.execDetached(["systemctl", "poweroff"]); - } - }, - Action { - name: qsTr("Reboot") - desc: qsTr("Reboot the system") - icon: "cached" - disabled: !Config.launcher.enableDangerousActions + Action {} + } - function onClicked(list: AppList): void { - list.visibilities.launcher = false; - Quickshell.execDetached(["systemctl", "reboot"]); - } - }, - Action { - name: qsTr("Logout") - desc: qsTr("Log out of the current session") - icon: "exit_to_app" - disabled: !Config.launcher.enableDangerousActions + component Action: QtObject { + required property var modelData + readonly property string name: modelData.name ?? qsTr("Unnamed") + readonly property string desc: modelData.description ?? qsTr("No description") + readonly property string icon: modelData.icon ?? "help_outline" + readonly property list<string> command: modelData.command ?? [] + readonly property bool enabled: modelData.enabled ?? true + readonly property bool dangerous: modelData.dangerous ?? false - function onClicked(list: AppList): void { - list.visibilities.launcher = false; - Quickshell.execDetached(["loginctl", "terminate-user", ""]); - } - }, - Action { - name: qsTr("Lock") - desc: qsTr("Lock the current session") - icon: "lock" + function onClicked(list: AppList): void { + if (command.length === 0) + return; - function onClicked(list: AppList): void { + if (command[0] === "autocomplete" && command.length > 1) { + list.search.text = `${Config.launcher.actionPrefix}${command[1]} `; + } else if (command[0] === "setMode" && command.length > 1) { list.visibilities.launcher = false; - Quickshell.execDetached(["loginctl", "lock-session"]); - } - }, - Action { - name: qsTr("Sleep") - desc: qsTr("Suspend then hibernate") - icon: "bedtime" - - function onClicked(list: AppList): void { + Colours.setMode(command[1]); + } else { list.visibilities.launcher = false; - Quickshell.execDetached(["systemctl", "suspend-then-hibernate"]); + Quickshell.execDetached(command); } } - ] - - function transformSearch(search: string): string { - return search.slice(Config.launcher.actionPrefix.length); - } - - function autocomplete(list: AppList, text: string): void { - list.search.text = `${Config.launcher.actionPrefix}${text} `; - } - - list: actions.filter(a => !a.disabled) - useFuzzy: Config.launcher.useFuzzy.actions - - component Action: QtObject { - required property string name - required property string desc - required property string icon - property bool disabled - - function onClicked(list: AppList): void { - } } } |