global: add Quickshell.processId and rename Process.pid

This commit is contained in:
outfoxxed 2024-03-08 23:25:54 -08:00
parent b720dfa165
commit a35d3f9584
Signed by untrusted user: outfoxxed
GPG key ID: 4C88A185FB89301E
4 changed files with 15 additions and 6 deletions

View file

@ -15,6 +15,7 @@
#include <qtmetamacros.h> #include <qtmetamacros.h>
#include <qtypes.h> #include <qtypes.h>
#include <qvariant.h> #include <qvariant.h>
#include <unistd.h>
#include "qmlscreen.hpp" #include "qmlscreen.hpp"
#include "rootwrapper.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<QuickshellScreenInfo>* prop) { qsizetype QuickshellGlobal::screensCount(QQmlListProperty<QuickshellScreenInfo>* prop) {
return static_cast<QuickshellGlobal*>(prop->object)->mScreens.size(); // NOLINT return static_cast<QuickshellGlobal*>(prop->object)->mScreens.size(); // NOLINT
} }

View file

@ -46,6 +46,8 @@ private:
class QuickshellGlobal: public QObject { class QuickshellGlobal: public QObject {
Q_OBJECT; Q_OBJECT;
// clang-format off // clang-format off
/// Quickshell's process id.
Q_PROPERTY(qint32 processId READ processId CONSTANT);
/// All currently connected screens. /// All currently connected screens.
/// ///
/// This property updates as connected screens change. /// This property updates as connected screens change.
@ -77,6 +79,8 @@ class QuickshellGlobal: public QObject {
QML_NAMED_ELEMENT(Quickshell); QML_NAMED_ELEMENT(Quickshell);
public: public:
[[nodiscard]] qint32 processId() const;
QuickshellGlobal(QObject* parent = nullptr); QuickshellGlobal(QObject* parent = nullptr);
QQmlListProperty<QuickshellScreenInfo> screens(); QQmlListProperty<QuickshellScreenInfo> screens();

View file

@ -43,7 +43,7 @@ void Process::setRunning(bool running) {
else if (this->isRunning()) this->process->terminate(); else if (this->isRunning()) this->process->terminate();
} }
QVariant Process::pid() const { QVariant Process::processId() const {
if (this->process == nullptr) return QVariant::fromValue(nullptr); if (this->process == nullptr) return QVariant::fromValue(nullptr);
return QVariant::fromValue(this->process->processId()); return QVariant::fromValue(this->process->processId());
} }
@ -233,7 +233,7 @@ void Process::startProcessIfReady() {
} }
void Process::onStarted() { void Process::onStarted() {
emit this->pidChanged(); emit this->processIdChanged();
emit this->runningChanged(); emit this->runningChanged();
emit this->started(); emit this->started();
} }
@ -246,7 +246,7 @@ void Process::onFinished(qint32 exitCode, QProcess::ExitStatus exitStatus) {
emit this->exited(exitCode, exitStatus); emit this->exited(exitCode, exitStatus);
emit this->runningChanged(); emit this->runningChanged();
emit this->pidChanged(); emit this->processIdChanged();
} }
void Process::onErrorOccurred(QProcess::ProcessError error) { void Process::onErrorOccurred(QProcess::ProcessError error) {

View file

@ -43,7 +43,7 @@ class Process: public QObject {
/// ``` /// ```
Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged); Q_PROPERTY(bool running READ isRunning WRITE setRunning NOTIFY runningChanged);
/// The process ID of the running process or `null` if `running` is false. /// 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 /// The command to execute. Each argument is its own string, which means you don't have
/// to deal with quoting anything. /// to deal with quoting anything.
/// ///
@ -139,7 +139,7 @@ public:
[[nodiscard]] bool isRunning() const; [[nodiscard]] bool isRunning() const;
void setRunning(bool running); void setRunning(bool running);
[[nodiscard]] QVariant pid() const; [[nodiscard]] QVariant processId() const;
[[nodiscard]] QList<QString> command() const; [[nodiscard]] QList<QString> command() const;
void setCommand(QList<QString> command); void setCommand(QList<QString> command);
@ -170,7 +170,7 @@ signals:
void exited(qint32 exitCode, QProcess::ExitStatus exitStatus); void exited(qint32 exitCode, QProcess::ExitStatus exitStatus);
void runningChanged(); void runningChanged();
void pidChanged(); void processIdChanged();
void commandChanged(); void commandChanged();
void workingDirectoryChanged(); void workingDirectoryChanged();
void environmentChanged(); void environmentChanged();