From a35d3f9584dcc79e149e1c24c8b481b5e11e5231 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Fri, 8 Mar 2024 23:25:54 -0800 Subject: [PATCH] global: add Quickshell.processId and rename Process.pid --- src/core/qmlglobal.cpp | 5 +++++ src/core/qmlglobal.hpp | 4 ++++ src/io/process.cpp | 6 +++--- src/io/process.hpp | 6 +++--- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/core/qmlglobal.cpp b/src/core/qmlglobal.cpp index 99ec066..99f2563 100644 --- a/src/core/qmlglobal.cpp +++ b/src/core/qmlglobal.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "qmlscreen.hpp" #include "rootwrapper.hpp" @@ -67,6 +68,10 @@ QuickshellGlobal::QuickshellGlobal(QObject* parent): QObject(parent) { } } +qint32 QuickshellGlobal::processId() const { // NOLINT + return getpid(); +} + qsizetype QuickshellGlobal::screensCount(QQmlListProperty* prop) { return static_cast(prop->object)->mScreens.size(); // NOLINT } diff --git a/src/core/qmlglobal.hpp b/src/core/qmlglobal.hpp index 72a4e37..8dceea1 100644 --- a/src/core/qmlglobal.hpp +++ b/src/core/qmlglobal.hpp @@ -46,6 +46,8 @@ private: class QuickshellGlobal: public QObject { Q_OBJECT; // clang-format off + /// Quickshell's process id. + Q_PROPERTY(qint32 processId READ processId CONSTANT); /// All currently connected screens. /// /// This property updates as connected screens change. @@ -77,6 +79,8 @@ class QuickshellGlobal: public QObject { QML_NAMED_ELEMENT(Quickshell); public: + [[nodiscard]] qint32 processId() const; + QuickshellGlobal(QObject* parent = nullptr); QQmlListProperty screens(); diff --git a/src/io/process.cpp b/src/io/process.cpp index b202f72..9fae90e 100644 --- a/src/io/process.cpp +++ b/src/io/process.cpp @@ -43,7 +43,7 @@ void Process::setRunning(bool running) { else if (this->isRunning()) this->process->terminate(); } -QVariant Process::pid() const { +QVariant Process::processId() const { if (this->process == nullptr) return QVariant::fromValue(nullptr); return QVariant::fromValue(this->process->processId()); } @@ -233,7 +233,7 @@ void Process::startProcessIfReady() { } void Process::onStarted() { - emit this->pidChanged(); + emit this->processIdChanged(); emit this->runningChanged(); emit this->started(); } @@ -246,7 +246,7 @@ void Process::onFinished(qint32 exitCode, QProcess::ExitStatus exitStatus) { emit this->exited(exitCode, exitStatus); emit this->runningChanged(); - emit this->pidChanged(); + emit this->processIdChanged(); } void Process::onErrorOccurred(QProcess::ProcessError error) { diff --git a/src/io/process.hpp b/src/io/process.hpp index 004bbb6..120c431 100644 --- a/src/io/process.hpp +++ b/src/io/process.hpp @@ -43,7 +43,7 @@ class Process: public QObject { /// ``` Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged); /// The process ID of the running process or `null` if `running` is false. - Q_PROPERTY(QVariant pid READ pid NOTIFY pidChanged); + Q_PROPERTY(QVariant processId READ processId NOTIFY processIdChanged); /// The command to execute. Each argument is its own string, which means you don't have /// to deal with quoting anything. /// @@ -139,7 +139,7 @@ public: [[nodiscard]] bool isRunning() const; void setRunning(bool running); - [[nodiscard]] QVariant pid() const; + [[nodiscard]] QVariant processId() const; [[nodiscard]] QList command() const; void setCommand(QList command); @@ -170,7 +170,7 @@ signals: void exited(qint32 exitCode, QProcess::ExitStatus exitStatus); void runningChanged(); - void pidChanged(); + void processIdChanged(); void commandChanged(); void workingDirectoryChanged(); void environmentChanged();