forked from quickshell/quickshell
		
	global: add Quickshell.processId and rename Process.pid
This commit is contained in:
		
							parent
							
								
									b720dfa165
								
							
						
					
					
						commit
						a35d3f9584
					
				
					 4 changed files with 15 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -15,6 +15,7 @@
 | 
			
		|||
#include <qtmetamacros.h>
 | 
			
		||||
#include <qtypes.h>
 | 
			
		||||
#include <qvariant.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
#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<QuickshellScreenInfo>* prop) {
 | 
			
		||||
	return static_cast<QuickshellGlobal*>(prop->object)->mScreens.size(); // NOLINT
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<QuickshellScreenInfo> screens();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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<QString> command() const;
 | 
			
		||||
	void setCommand(QList<QString> 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();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue