|
1 | 1 | #pragma once |
2 | 2 |
|
| 3 | +#include <utility> |
| 4 | + |
3 | 5 | #include <qclipboard.h> |
4 | 6 | #include <qcontainerfwd.h> |
| 7 | +#include <qhash.h> |
5 | 8 | #include <qjsengine.h> |
| 9 | +#include <qlist.h> |
6 | 10 | #include <qobject.h> |
7 | 11 | #include <qqmlengine.h> |
8 | 12 | #include <qqmlintegration.h> |
|
15 | 19 |
|
16 | 20 | #include "qmlscreen.hpp" |
17 | 21 |
|
| 22 | +class ProcessContext { |
| 23 | + Q_PROPERTY(QList<QString> command MEMBER command); |
| 24 | + Q_PROPERTY(QHash<QString, QVariant> environment MEMBER environment); |
| 25 | + Q_PROPERTY(bool clearEnvironment MEMBER clearEnvironment); |
| 26 | + Q_PROPERTY(QString workingDirectory MEMBER workingDirectory); |
| 27 | + Q_GADGET; |
| 28 | + QML_STRUCTURED_VALUE; |
| 29 | + QML_VALUE_TYPE(processContext); |
| 30 | + |
| 31 | +public: |
| 32 | + ProcessContext() = default; |
| 33 | + explicit ProcessContext(QList<QString> command): command(std::move(command)) {} |
| 34 | + |
| 35 | + QList<QString> command; |
| 36 | + QHash<QString, QVariant> environment; |
| 37 | + bool clearEnvironment = false; |
| 38 | + QString workingDirectory; |
| 39 | +}; |
| 40 | + |
18 | 41 | ///! Accessor for some options under the Quickshell type. |
19 | 42 | class QuickshellSettings: public QObject { |
20 | 43 | Q_OBJECT; |
@@ -152,6 +175,46 @@ class QuickshellGlobal: public QObject { |
152 | 175 | /// Returns the string value of an environment variable or null if it is not set. |
153 | 176 | Q_INVOKABLE QVariant env(const QString& variable); |
154 | 177 |
|
| 178 | + /// Launch a process detached from Quickshell. |
| 179 | + /// |
| 180 | + /// Each command argument is its own string, meaning arguments do |
| 181 | + /// not have to be escaped. |
| 182 | + /// |
| 183 | + /// > [!WARNING] This does not run command in a shell. All arguments to the command |
| 184 | + /// > must be in separate values in the list, e.g. `["echo", "hello"]` |
| 185 | + /// > and not `["echo hello"]`. |
| 186 | + /// > |
| 187 | + /// > Additionally, shell scripts must be run by your shell, |
| 188 | + /// > e.g. `["sh", "script.sh"]` instead of `["script.sh"]` unless the script |
| 189 | + /// > has a shebang. |
| 190 | + /// |
| 191 | + /// > [!INFO] You can use `["sh", "-c", <your command>]` to execute your command with |
| 192 | + /// > the system shell. |
| 193 | + /// |
| 194 | + /// This function is equivalent to @@Quickshell.Io.Process.startDetached(). |
| 195 | + Q_INVOKABLE static void execDetached(QList<QString> command); |
| 196 | + /// Launch a process detached from Quickshell. |
| 197 | + /// |
| 198 | + /// The context parameter is a JS object with the following fields: |
| 199 | + /// - `command`: A list containing the command and all its arguments. See @@Quickshell.Io.Process.command. |
| 200 | + /// - `environment`: Changes to make to the process environment. See @@Quickshell.Io.Process.environment. |
| 201 | + /// - `clearEnvironment`: Removes all variables from the environment if true. |
| 202 | + /// - `workingDirectory`: The working directory the command should run in. |
| 203 | + /// |
| 204 | + /// > [!WARNING] This does not run command in a shell. All arguments to the command |
| 205 | + /// > must be in separate values in the list, e.g. `["echo", "hello"]` |
| 206 | + /// > and not `["echo hello"]`. |
| 207 | + /// > |
| 208 | + /// > Additionally, shell scripts must be run by your shell, |
| 209 | + /// > e.g. `["sh", "script.sh"]` instead of `["script.sh"]` unless the script |
| 210 | + /// > has a shebang. |
| 211 | + /// |
| 212 | + /// > [!INFO] You can use `["sh", "-c", <your command>]` to execute your command with |
| 213 | + /// > the system shell. |
| 214 | + /// |
| 215 | + /// This function is equivalent to @@Quickshell.Io.Process.startDetached(). |
| 216 | + Q_INVOKABLE static void execDetached(const ProcessContext& context); |
| 217 | + |
155 | 218 | /// Returns a string usable for a @@QtQuick.Image.source for a given system icon. |
156 | 219 | /// |
157 | 220 | /// > [!INFO] By default, icons are loaded from the theme selected by the qt platform theme, |
|
0 commit comments