Files
z-bar-qt/Plugins/ZShell/Services/gpu.hpp
T
AramJonghu 467e44bb9f
C++ / build (pull_request) Failing after 15s
Lint & Format (JS/TS) / lint-format (pull_request) Successful in 28s
Python / lint-format (pull_request) Successful in 45s
Python / test (pull_request) Successful in 38s
Lint & Format (Rust) / lint-format (pull_request) Successful in 1m45s
tidy&format(all): all files formatted and relevant warnings resolved
2026-06-30 02:04:24 +02:00

89 lines
2.3 KiB
C++

#pragma once
#include "tickingservice.hpp"
#include <qprocess.h>
#include <qqmlintegration.h>
namespace ZShell::services {
class Gpu : public TickingService {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
public:
enum Type {
Auto, // user override is empty (config "") — defer to detected autoType
None, // no usable GPU
Nvidia, // queried via nvidia-smi
Generic, // queried via /sys/class/drm/card*/device/gpu_busy_percent
};
Q_ENUM(Type)
private:
Q_PROPERTY(Type type READ type NOTIFY typeChanged)
Q_PROPERTY(Type userType READ userType NOTIFY userTypeChanged)
Q_PROPERTY(Type autoType READ autoType NOTIFY autoTypeChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(qreal percentage READ percentage NOTIFY percentageChanged)
Q_PROPERTY(qreal temperature READ temperature NOTIFY temperatureChanged)
Q_PROPERTY(qreal memoryUsed READ memoryUsed NOTIFY memoryUsedChanged)
Q_PROPERTY(qreal memoryTotal READ memoryTotal NOTIFY memoryTotalChanged)
public:
explicit Gpu(QObject* parent = nullptr);
[[nodiscard]] Type type() const;
[[nodiscard]] Type userType() const;
[[nodiscard]] Type autoType() const;
[[nodiscard]] QString name() const;
[[nodiscard]] qreal percentage() const;
[[nodiscard]] qreal temperature() const;
[[nodiscard]] qreal memoryUsed() const;
[[nodiscard]] qreal memoryTotal() const;
signals:
void typeChanged();
void userTypeChanged();
void autoTypeChanged();
void nameChanged();
void percentageChanged();
void temperatureChanged();
void memoryUsedChanged();
void memoryTotalChanged();
protected:
void tick() override;
private:
void detectTypeOnce();
void detectNameOnce();
void readGenericUsage();
void startNvidiaUsage();
void readGpuTemperature();
void setUserType(Type value);
void setAutoType(Type value);
void setName(QString value);
void setMemoryUsed(qreal value);
void setMemoryTotal(qreal value);
[[nodiscard]] static Type parseType(const QString& s);
[[nodiscard]] static QString cleanName(QString s);
Type m_userType = Auto;
Type m_autoType = None;
QString m_name;
qreal m_percentage = 0.0;
qreal m_temperature = 0.0;
qreal m_memoryUsed = 0.0;
qreal m_memoryTotal = 0.0;
QProcess* m_typeProc = nullptr;
QProcess* m_nameProc = nullptr;
QProcess* m_nvidiaProc = nullptr;
};
} // namespace ZShell::services