mirror of
https://github.com/hyprwm/hyprsysteminfo.git
synced 2026-05-05 08:48:01 +02:00
core: use qt libraries and follow qml module conventions
Uses a qml module instead of a context property. Replaces usages of std and hyprutils with qtbase where applicable. Removes dependencies: hyprutils, wl-copy, whoami, uname. Rolls c++ version back to 20, as 23 isn't currently required for anything.
This commit is contained in:
parent
9b50bb2c29
commit
6738e7db72
17 changed files with 421 additions and 429 deletions
|
|
@ -9,39 +9,16 @@ project(hsi VERSION ${VER} LANGUAGES CXX)
|
|||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(Qt6 6.5 REQUIRED COMPONENTS Widgets Quick QuickControls2)
|
||||
find_package(PkgConfig REQUIRED)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
||||
pkg_check_modules(
|
||||
deps
|
||||
REQUIRED
|
||||
IMPORTED_TARGET
|
||||
hyprutils)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
|
||||
qt_standard_project_setup(REQUIRES 6.5)
|
||||
|
||||
qt_add_executable(hyprsysteminfo
|
||||
src/main.cpp src/util/Utils.cpp src/util/Utils.hpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(hyprsysteminfo
|
||||
URI hsi
|
||||
VERSION 1.0
|
||||
QML_FILES
|
||||
qml/main.qml
|
||||
SOURCES
|
||||
qmlSources/SystemInternals.hpp qmlSources/SystemInternals.cpp qmlSources/SystemIconProvider.hpp
|
||||
)
|
||||
add_subdirectory(src)
|
||||
|
||||
qt_add_resources(hyprsysteminfo "resource"
|
||||
PREFIX "/"
|
||||
FILES
|
||||
resource/hyprlandlogo.svg
|
||||
resource/hyprlandlogo.png
|
||||
)
|
||||
|
||||
target_link_libraries(hyprsysteminfo
|
||||
PRIVATE Qt6::Widgets Qt6::Quick Qt6::Gui Qt6::QuickControls2 PkgConfig::deps
|
||||
)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
|
|
|
|||
24
flake.lock
generated
24
flake.lock
generated
|
|
@ -1,28 +1,5 @@
|
|||
{
|
||||
"nodes": {
|
||||
"hyprutils": {
|
||||
"inputs": {
|
||||
"nixpkgs": [
|
||||
"nixpkgs"
|
||||
],
|
||||
"systems": [
|
||||
"systems"
|
||||
]
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1727300645,
|
||||
"narHash": "sha256-OvAtVLaSRPnbXzOwlR1fVqCXR7i+ICRX3aPMCdIiv+c=",
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprutils",
|
||||
"rev": "3f5293432b6dc6a99f26aca2eba3876d2660665c",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "hyprwm",
|
||||
"repo": "hyprutils",
|
||||
"type": "github"
|
||||
}
|
||||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1728492678,
|
||||
|
|
@ -41,7 +18,6 @@
|
|||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"hyprutils": "hyprutils",
|
||||
"nixpkgs": "nixpkgs",
|
||||
"systems": "systems"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,12 +4,6 @@
|
|||
inputs = {
|
||||
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
|
||||
systems.url = "github:nix-systems/default-linux";
|
||||
|
||||
hyprutils = {
|
||||
url = "github:hyprwm/hyprutils";
|
||||
inputs.nixpkgs.follows = "nixpkgs";
|
||||
inputs.systems.follows = "systems";
|
||||
};
|
||||
};
|
||||
|
||||
outputs = {
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@
|
|||
lib,
|
||||
stdenv,
|
||||
cmake,
|
||||
pkg-config,
|
||||
hyprutils,
|
||||
kdePackages,
|
||||
pciutils,
|
||||
qt6,
|
||||
|
|
@ -26,12 +24,10 @@ in
|
|||
|
||||
nativeBuildInputs = [
|
||||
cmake
|
||||
pkg-config
|
||||
qt6.wrapQtAppsHook
|
||||
];
|
||||
|
||||
buildInputs = [
|
||||
hyprutils
|
||||
kdePackages.kirigami-addons
|
||||
qt6.qtbase
|
||||
qt6.qtsvg
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ in {
|
|||
default = self.overlays.hyprsysteminfo;
|
||||
|
||||
hyprsysteminfo = lib.composeManyExtensions [
|
||||
inputs.hyprutils.overlays.default
|
||||
(final: prev: {
|
||||
hyprsysteminfo = final.callPackage ./. {
|
||||
version = "${version}+date=${date}_${self.shortRev or "dirty"}";
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
#include "SystemInternals.hpp"
|
||||
#include "src/util/Utils.hpp"
|
||||
#include <format>
|
||||
|
||||
void CSystemInternals::copySystemInfo() {
|
||||
execAndGet(std::format("echo '{}' | wl-copy && hyprctl notify 5 5000 0 'Copied system info to the clipboard.'", hlSystemInfo.toStdString()).c_str());
|
||||
}
|
||||
|
||||
void CSystemInternals::copyVersion() {
|
||||
execAndGet(std::format("echo '{}' | wl-copy && hyprctl notify 5 5000 0 'Copied version info to the clipboard.'", hlSystemVersion.toStdString()).c_str());
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
#ifndef SYSTEMINTERNALS_H
|
||||
#define SYSTEMINTERNALS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QPixmap>
|
||||
#include <QIcon>
|
||||
|
||||
class CSystemInternals : public QObject {
|
||||
Q_OBJECT;
|
||||
|
||||
public:
|
||||
explicit CSystemInternals(QObject* parent = nullptr) : QObject(parent) {
|
||||
;
|
||||
}
|
||||
|
||||
QString systemLogoName, systemName = "Linux", systemURL = "https://kernel.org/", systemKernel = "unknown";
|
||||
QString hyprlandVersion, hyprlandVersionLong;
|
||||
|
||||
QString cpuInfo = "missing dependency: lscpu";
|
||||
std::vector<QString> gpuInfo = {"missing dependency: lspci"};
|
||||
QString ramInfo = "?";
|
||||
|
||||
QString hlSystemInfo = "[error]", hlSystemVersion = "[error]";
|
||||
|
||||
QString uptime = "unknown", DE = "Unknown", screens = "unknown", board = "", user = "";
|
||||
|
||||
Q_INVOKABLE bool hasSystemLogoName() {
|
||||
return systemLogoName.size() > 0;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getSystemLogoName() {
|
||||
return systemLogoName;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getSystemName() {
|
||||
return systemName;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getSystemURL() {
|
||||
return systemURL;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getSystemKernel() {
|
||||
return systemKernel;
|
||||
}
|
||||
|
||||
Q_INVOKABLE bool hasHyprland() {
|
||||
return hyprlandVersionLong.size() > 0;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getHyprlandVersion() {
|
||||
return hyprlandVersion;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getHyprlandVersionLong() {
|
||||
return hyprlandVersionLong;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getCPUInfo() {
|
||||
return cpuInfo;
|
||||
}
|
||||
|
||||
Q_INVOKABLE int getGPUInfoCount() {
|
||||
return gpuInfo.size();
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getGPUInfo(int idx) {
|
||||
if (idx >= gpuInfo.size())
|
||||
return "[error]";
|
||||
return gpuInfo.at(idx);
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getRAMInfo() {
|
||||
return ramInfo;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getDE() {
|
||||
return DE;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getUptime() {
|
||||
return uptime;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getDisplays() {
|
||||
return screens;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getModel() {
|
||||
return board;
|
||||
}
|
||||
|
||||
Q_INVOKABLE QString getUserAt() {
|
||||
return user;
|
||||
}
|
||||
|
||||
Q_INVOKABLE void copySystemInfo();
|
||||
Q_INVOKABLE void copyVersion();
|
||||
};
|
||||
|
||||
#endif // SYSTEMINTERNALS_H
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 346 KiB |
14
src/CMakeLists.txt
Normal file
14
src/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
qt_add_executable(hyprsysteminfo
|
||||
main.cpp
|
||||
util/Utils.cpp
|
||||
SystemInfo.cpp
|
||||
SystemIconProvider.cpp
|
||||
)
|
||||
|
||||
qt_add_qml_module(hyprsysteminfo
|
||||
URI org.hyprland.systeminfo
|
||||
VERSION 1.0
|
||||
QML_FILES main.qml
|
||||
)
|
||||
|
||||
target_link_libraries(hyprsysteminfo PRIVATE Qt6::Widgets Qt6::QuickControls2)
|
||||
25
src/SystemIconProvider.cpp
Normal file
25
src/SystemIconProvider.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include "SystemIconProvider.hpp"
|
||||
#include <qicon.h>
|
||||
#include <qlogging.h>
|
||||
#include <qpixmap.h>
|
||||
|
||||
QPixmap CSystemIconProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
|
||||
auto icon = QIcon::fromTheme(id);
|
||||
|
||||
if (!requestedSize.isValid()) {
|
||||
qCritical() << "Icon requests without an explicit size are not allowed.";
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
auto pixmap = icon.pixmap(requestedSize.width(), requestedSize.height());
|
||||
|
||||
if (pixmap.isNull()) {
|
||||
qWarning() << "Could not load icon" << id;
|
||||
return QPixmap();
|
||||
}
|
||||
|
||||
if (size != nullptr)
|
||||
*size = pixmap.size();
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
|
@ -1,20 +1,14 @@
|
|||
#ifndef SYSTEMICONPROVIDER_H
|
||||
#define SYSTEMICONPROVIDER_H
|
||||
#pragma once
|
||||
|
||||
#include <QIcon>
|
||||
#include <QObject>
|
||||
#include <QPixmap>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickImageProvider>
|
||||
#include <iostream>
|
||||
|
||||
class CSystemIconProvider : public QQuickImageProvider {
|
||||
public:
|
||||
CSystemIconProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap) {}
|
||||
|
||||
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override {
|
||||
return QIcon::fromTheme(id).pixmap({512, 512});
|
||||
}
|
||||
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
|
||||
};
|
||||
|
||||
#endif // SYSTEMICONPROVIDER_H
|
||||
273
src/SystemInfo.cpp
Normal file
273
src/SystemInfo.cpp
Normal file
|
|
@ -0,0 +1,273 @@
|
|||
#include "SystemInfo.hpp"
|
||||
#include "util/Utils.hpp"
|
||||
#include <qclipboard.h>
|
||||
#include <array>
|
||||
#include <qfiledevice.h>
|
||||
#include <qimage.h>
|
||||
#include <qobject.h>
|
||||
#include <qscreen.h>
|
||||
#include <qfile.h>
|
||||
|
||||
#include <qguiapplication.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
#include <qwindowdefs.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
CSystemInternals::CSystemInternals(QObject* parent) : QObject(parent) {
|
||||
// gather data from os-release
|
||||
{
|
||||
QFile osInfo("/etc/os-release");
|
||||
if (osInfo.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
auto stream = QTextStream(&osInfo);
|
||||
|
||||
while (!stream.atEnd()) {
|
||||
auto line = stream.readLine();
|
||||
auto split = line.split('=');
|
||||
if (split.length() != 2)
|
||||
continue;
|
||||
|
||||
const auto& key = split.at(0);
|
||||
auto value = split.at(1);
|
||||
|
||||
if (value.length() >= 2 && value.at(0) == '\"')
|
||||
value = value.sliced(1).chopped(1);
|
||||
|
||||
if (key == "PRETTY_NAME") {
|
||||
systemName = value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key == "HOME_URL") {
|
||||
systemURL = value;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (key == "LOGO") {
|
||||
systemLogoName = value;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get kernel ver
|
||||
utsname unamebuf;
|
||||
if (uname(&unamebuf) == 0) {
|
||||
systemKernel = unamebuf.release;
|
||||
}
|
||||
|
||||
// get hyprland info
|
||||
if (getenv("HYPRLAND_INSTANCE_SIGNATURE")) {
|
||||
hlSystemVersion = execAndGet("hyprctl", {"version"});
|
||||
auto tagIndex = hlSystemVersion.indexOf("Tag: ");
|
||||
|
||||
if (tagIndex != -1) {
|
||||
hyprlandVersionLong = hlSystemVersion.sliced(tagIndex + 5);
|
||||
auto commaIndex = hyprlandVersionLong.indexOf(',');
|
||||
if (commaIndex != -1)
|
||||
hyprlandVersionLong = hyprlandVersionLong.first(commaIndex);
|
||||
|
||||
auto dashIndex = hyprlandVersionLong.indexOf('-');
|
||||
if (dashIndex == -1)
|
||||
hyprlandVersion = hyprlandVersionLong;
|
||||
else
|
||||
hyprlandVersion = hyprlandVersionLong.first(dashIndex);
|
||||
}
|
||||
|
||||
if (hyprlandVersionLong.isEmpty() && hlSystemVersion.contains("at commit")) {
|
||||
auto commitIndex = hlSystemVersion.indexOf("at commit ");
|
||||
if (commitIndex != -1) {
|
||||
hyprlandVersionLong = hlSystemVersion.sliced(commitIndex + 10);
|
||||
|
||||
hyprlandVersionLong = substrUntil(hyprlandVersionLong, ' ').left(7);
|
||||
hyprlandVersion = hyprlandVersionLong;
|
||||
}
|
||||
}
|
||||
|
||||
if (hyprlandVersionLong.isEmpty()) {
|
||||
hyprlandVersionLong = "unknown";
|
||||
hyprlandVersion = "unknown";
|
||||
}
|
||||
|
||||
hlSystemInfo = execAndGet("hyprctl", {"systeminfo"});
|
||||
if (!hlSystemInfo.contains("Hyprland"))
|
||||
hlSystemInfo = "";
|
||||
}
|
||||
|
||||
// get cpu info
|
||||
{
|
||||
auto DATA = execAndGet("lscpu");
|
||||
if (DATA.contains("odel name")) {
|
||||
QString arch, model, ghz, nproc;
|
||||
auto textStream = QTextStream(&DATA);
|
||||
|
||||
while (!textStream.atEnd()) {
|
||||
auto line = textStream.readLine();
|
||||
auto indexOfColon = line.indexOf(':');
|
||||
if (indexOfColon == -1)
|
||||
continue;
|
||||
|
||||
auto left = line.sliced(0, indexOfColon).trimmed();
|
||||
auto right = line.sliced(indexOfColon + 1).trimmed();
|
||||
|
||||
if (left == "Architecture") {
|
||||
arch = right;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (left == "Model name") {
|
||||
model = right;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (left == "CPU(s)") {
|
||||
nproc = right;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (left == "CPU max MHz") {
|
||||
auto ok = false;
|
||||
auto ghzFloat = right.toFloat(&ok);
|
||||
|
||||
if (ok)
|
||||
ghz = QString("%1Ghz").arg(ghzFloat / 1000.F, 2, 'g', 2);
|
||||
else
|
||||
ghz = "?Ghz";
|
||||
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
cpuInfo = QString("%1 at %2x%3 (%4)").arg(model).arg(nproc).arg(ghz).arg(arch);
|
||||
}
|
||||
}
|
||||
|
||||
// get gpu info
|
||||
{
|
||||
auto DATA = execAndGet("lspci", {"-vnn"});
|
||||
auto textStream = QTextStream(&DATA);
|
||||
|
||||
if (!DATA.isEmpty())
|
||||
gpuInfo.clear();
|
||||
|
||||
while (!textStream.atEnd()) {
|
||||
auto line = textStream.readLine();
|
||||
|
||||
auto indexOfVga = line.indexOf("VGA");
|
||||
if (indexOfVga == -1)
|
||||
continue;
|
||||
|
||||
line = line.sliced(indexOfVga);
|
||||
|
||||
auto indexOfColon = line.indexOf(": ");
|
||||
if (indexOfColon == -1)
|
||||
continue;
|
||||
|
||||
line = line.sliced(indexOfColon + 2);
|
||||
|
||||
gpuInfo.emplaceBack(line);
|
||||
}
|
||||
|
||||
if (gpuInfo.isEmpty()) {
|
||||
gpuInfo.emplaceBack("No GPUs found");
|
||||
}
|
||||
}
|
||||
|
||||
// get ram info
|
||||
{
|
||||
auto DATA = execAndGet("free");
|
||||
auto textStream = QTextStream(&DATA);
|
||||
|
||||
if (textStream.readLine().contains("total")) {
|
||||
auto ramIntToReadable = [](QStringView datapoint) -> QString {
|
||||
auto ok = false;
|
||||
auto ghzFloat = datapoint.toULongLong(&ok);
|
||||
|
||||
if (ok)
|
||||
return QString("%1GB").arg(ghzFloat / 1000000.0, 3, 'g', 3);
|
||||
else
|
||||
return "[error]";
|
||||
};
|
||||
|
||||
auto props = textStream.readLine().simplified().split(' ');
|
||||
ramInfo = QString("%1 / %2").arg(ramIntToReadable(props[2])).arg(ramIntToReadable(props[1]));
|
||||
}
|
||||
}
|
||||
|
||||
// other, misc
|
||||
if (auto DE = qEnvironmentVariable("XDG_CURRENT_DESKTOP"); !DE.isEmpty())
|
||||
this->DE = DE;
|
||||
|
||||
{
|
||||
QFile uptimeFile("/proc/uptime");
|
||||
if (uptimeFile.open(QFile::ReadOnly | QFile::Text)) {
|
||||
auto ok = false;
|
||||
auto uptime = substrUntil(uptimeFile.readAll(), ' ').toFloat(&ok);
|
||||
|
||||
if (ok) {
|
||||
int uptimeSeconds = std::round(uptime);
|
||||
int uptimeDays = std::floor(uptimeSeconds / 3600.0 / 24.0);
|
||||
int uptimeHours = std::floor((uptimeSeconds % (3600 * 24)) / 3600.0);
|
||||
int uptimeMinutes = std::floor((uptimeSeconds % (3600)) / 60.0);
|
||||
|
||||
QString upStr;
|
||||
auto textStream = QTextStream(&upStr);
|
||||
|
||||
if (uptimeDays > 0)
|
||||
textStream << uptimeDays << " days, ";
|
||||
|
||||
if (uptimeHours > 0)
|
||||
textStream << uptimeHours << " hours, ";
|
||||
|
||||
if (uptimeMinutes > 0)
|
||||
textStream << uptimeMinutes << " minutes, ";
|
||||
|
||||
if (!upStr.isEmpty())
|
||||
upStr.chop(2);
|
||||
|
||||
this->uptime = upStr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
QString screens;
|
||||
QTextStream textStream(&screens);
|
||||
for (auto* s : QGuiApplication::screens()) {
|
||||
textStream << s->name() << ' ' << '(' << s->geometry().width() << 'x' << s->geometry().height() << "), ";
|
||||
}
|
||||
|
||||
if (!screens.isEmpty())
|
||||
screens.chop(2);
|
||||
|
||||
this->screens = screens;
|
||||
}
|
||||
|
||||
if (auto* username = getlogin()) {
|
||||
std::array<char, 128> hostname;
|
||||
if (gethostname(hostname.data(), hostname.size()) == 0)
|
||||
user = QString("%1@%2").arg(QLatin1StringView(username)).arg(QLatin1StringView(hostname.data()));
|
||||
}
|
||||
|
||||
{
|
||||
QFile productFile("/sys/devices/virtual/dmi/id/product_name");
|
||||
if (productFile.open(QFile::ReadOnly | QFile::Text))
|
||||
board = productFile.readAll().trimmed();
|
||||
else {
|
||||
productFile.setFileName("/sys/devices/virtual/dmi/id/board_name");
|
||||
if (productFile.open(QFile::ReadOnly | QFile::Text))
|
||||
board = productFile.readAll().trimmed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CSystemInternals::copySystemInfo() {
|
||||
QGuiApplication::clipboard()->setText(hlSystemInfo);
|
||||
execAndGet("hyprctl", {"notify", "5", "5000", "0", "Copied system info to the clipboard."});
|
||||
}
|
||||
|
||||
void CSystemInternals::copyVersion() {
|
||||
QGuiApplication::clipboard()->setText(hlSystemVersion);
|
||||
execAndGet("hyprctl", {"notify", "5", "5000", "0", "Copied version info to the clipboard."});
|
||||
}
|
||||
46
src/SystemInfo.hpp
Normal file
46
src/SystemInfo.hpp
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QPixmap>
|
||||
#include <QIcon>
|
||||
#include <qcontainerfwd.h>
|
||||
#include <qqmlintegration.h>
|
||||
#include <qtmetamacros.h>
|
||||
|
||||
class CSystemInternals : public QObject {
|
||||
Q_OBJECT;
|
||||
QML_NAMED_ELEMENT(SystemInfo);
|
||||
QML_SINGLETON;
|
||||
Q_PROPERTY(QString systemLogoName MEMBER systemLogoName CONSTANT);
|
||||
Q_PROPERTY(QString systemName MEMBER systemName CONSTANT);
|
||||
Q_PROPERTY(QString systemUrl MEMBER systemURL CONSTANT);
|
||||
Q_PROPERTY(QString systemKernel MEMBER systemKernel CONSTANT);
|
||||
Q_PROPERTY(QString hyprlandVersion MEMBER hyprlandVersion CONSTANT);
|
||||
Q_PROPERTY(QString hyprlandVersionLong MEMBER hyprlandVersionLong CONSTANT);
|
||||
Q_PROPERTY(QString cpuInfo MEMBER cpuInfo CONSTANT);
|
||||
Q_PROPERTY(QVector<QString> gpuInfo MEMBER gpuInfo CONSTANT);
|
||||
Q_PROPERTY(QString ramInfo MEMBER ramInfo CONSTANT);
|
||||
Q_PROPERTY(QString uptime MEMBER uptime CONSTANT);
|
||||
Q_PROPERTY(QString de MEMBER DE CONSTANT);
|
||||
Q_PROPERTY(QString screens MEMBER screens CONSTANT);
|
||||
Q_PROPERTY(QString model MEMBER board CONSTANT);
|
||||
Q_PROPERTY(QString user MEMBER user CONSTANT);
|
||||
|
||||
public:
|
||||
explicit CSystemInternals(QObject* parent = nullptr);
|
||||
|
||||
QString systemLogoName, systemName = "Linux", systemURL = "https://kernel.org/", systemKernel = "unknown";
|
||||
QString hyprlandVersion, hyprlandVersionLong;
|
||||
|
||||
QString cpuInfo = "missing dependency: lscpu";
|
||||
QVector<QString> gpuInfo = {"missing dependency: lspci"};
|
||||
QString ramInfo = "?";
|
||||
|
||||
QString hlSystemInfo = "[error]", hlSystemVersion = "[error]";
|
||||
|
||||
QString uptime = "unknown", DE = "Unknown", screens = "unknown", board = "", user = "";
|
||||
|
||||
Q_INVOKABLE void copySystemInfo();
|
||||
Q_INVOKABLE void copyVersion();
|
||||
};
|
||||
216
src/main.cpp
216
src/main.cpp
|
|
@ -1,209 +1,8 @@
|
|||
#include "qmlSources/SystemIconProvider.hpp"
|
||||
#include "qmlSources/SystemInternals.hpp"
|
||||
#include <QApplication>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickStyle>
|
||||
#include <QScreen>
|
||||
#include <fstream>
|
||||
#include <format>
|
||||
#include "util/Utils.hpp"
|
||||
|
||||
#include <hyprutils/string/VarList.hpp>
|
||||
#include <hyprutils/string/String.hpp>
|
||||
#include "SystemIconProvider.hpp"
|
||||
#include <qapplication.h>
|
||||
#include <qqmlapplicationengine.h>
|
||||
#include <qquickstyle.h>
|
||||
#include <qtenvironmentvariables.h>
|
||||
using namespace Hyprutils::String;
|
||||
|
||||
static std::string readFile(const std::string& filename) {
|
||||
try {
|
||||
std::ifstream ifs(filename);
|
||||
if (ifs.good()) {
|
||||
std::string data(std::istreambuf_iterator<char>{ifs}, {});
|
||||
ifs.close();
|
||||
return trim(data);
|
||||
}
|
||||
} catch (...) { return "[error]"; }
|
||||
return "[error]";
|
||||
}
|
||||
|
||||
static void getSystemInfo(CSystemInternals* hsi, QGuiApplication* app) {
|
||||
|
||||
// gather data from os-release
|
||||
std::ifstream osInfo("/etc/os-release");
|
||||
if (osInfo.good()) {
|
||||
std::string data(std::istreambuf_iterator<char>{osInfo}, {});
|
||||
|
||||
osInfo.close();
|
||||
|
||||
CVarList lines(data, 0, '\n');
|
||||
|
||||
for (auto& line : lines) {
|
||||
CVarList param(line, 2, '=');
|
||||
|
||||
static auto stripName = [](const std::string& in) -> std::string { return in.length() > 0 && in.at(0) == '\"' ? in.substr(1, in.length() - 2) : in; };
|
||||
|
||||
if (param[0] == "PRETTY_NAME") {
|
||||
hsi->systemName = stripName(param[1]).c_str();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param[0] == "HOME_URL") {
|
||||
hsi->systemURL = stripName(param[1]).c_str();
|
||||
continue;
|
||||
}
|
||||
|
||||
if (param[0] == "LOGO") {
|
||||
hsi->systemLogoName = stripName(param[1]).c_str();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get kernel ver
|
||||
hsi->systemKernel = trim(execAndGet("uname -r")).c_str();
|
||||
|
||||
// get hyprland info
|
||||
if (getenv("HYPRLAND_INSTANCE_SIGNATURE")) {
|
||||
const auto DATA = execAndGet("hyprctl version");
|
||||
hsi->hlSystemVersion = DATA.c_str();
|
||||
|
||||
if (DATA.contains("Tag:")) {
|
||||
auto temp = DATA.substr(DATA.find("Tag:") + 5);
|
||||
temp = temp.substr(0, temp.find(","));
|
||||
hsi->hyprlandVersionLong = temp.c_str();
|
||||
hsi->hyprlandVersion = temp.substr(0, temp.find("-")).c_str();
|
||||
}
|
||||
|
||||
if (hsi->hyprlandVersionLong.length() <= 0 && DATA.contains("at commit")) {
|
||||
auto temp = DATA.substr(DATA.find("at commit") + 10);
|
||||
temp = temp.substr(0, temp.find(" "));
|
||||
hsi->hyprlandVersionLong = temp.substr(0, 7).c_str();
|
||||
hsi->hyprlandVersion = temp.substr(0, 7).c_str();
|
||||
}
|
||||
|
||||
if (hsi->hyprlandVersionLong.length() <= 0) {
|
||||
hsi->hyprlandVersionLong = "unknown";
|
||||
hsi->hyprlandVersion = "unknown";
|
||||
}
|
||||
|
||||
const auto DATA2 = execAndGet("hyprctl systeminfo");
|
||||
if (DATA2.contains("Hyprland"))
|
||||
hsi->hlSystemInfo = DATA2.c_str();
|
||||
}
|
||||
|
||||
// get cpu info
|
||||
{
|
||||
const auto DATA = execAndGet("lscpu");
|
||||
if (DATA.contains("odel name")) {
|
||||
std::string arch, model, ghz, nproc;
|
||||
|
||||
CVarList data(DATA, 0, '\n');
|
||||
for (auto& line : data) {
|
||||
std::string left, right;
|
||||
left = trim(line.substr(0, line.find(":")));
|
||||
right = trim(line.substr(line.find(":") + 1));
|
||||
|
||||
if (left == "Architecture") {
|
||||
arch = right;
|
||||
continue;
|
||||
}
|
||||
if (left == "Model name") {
|
||||
model = right;
|
||||
continue;
|
||||
}
|
||||
if (left == "CPU(s)") {
|
||||
nproc = right;
|
||||
continue;
|
||||
}
|
||||
if (left == "CPU max MHz") {
|
||||
try {
|
||||
ghz = std::format("{:.02}GHz", std::stof(right) / 1000.F);
|
||||
} catch (...) { ghz = "?GHz"; }
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
hsi->cpuInfo = std::format("{} at {}x{} ({})", model, nproc, ghz, arch).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
// get gpu info
|
||||
{
|
||||
const auto DATA = execAndGet("lspci -vnn | grep VGA");
|
||||
if (DATA.contains("VGA")) {
|
||||
CVarList data(DATA, 0, '\n');
|
||||
hsi->gpuInfo.clear();
|
||||
for (auto& line : data) {
|
||||
if (!line.contains("VGA"))
|
||||
continue;
|
||||
hsi->gpuInfo.emplace_back(std::format("{}", line.substr(line.find(":", line.find("VGA")) + 2)).c_str());
|
||||
}
|
||||
} else {
|
||||
hsi->gpuInfo = {"No GPUs found"};
|
||||
}
|
||||
}
|
||||
|
||||
// get ram info
|
||||
{
|
||||
const auto DATA = execAndGet("free");
|
||||
if (DATA.contains("total")) {
|
||||
CVarList data(DATA, 0, '\n');
|
||||
|
||||
auto ramIntToReadable = [](const std::string& datapoint) -> std::string {
|
||||
try {
|
||||
auto asInt = std::stoull(datapoint);
|
||||
return std::format("{:.03}GB", asInt / 1000000.0);
|
||||
} catch (...) { return "[error]"; }
|
||||
};
|
||||
|
||||
CVarList props(data[1], 0, 's', true);
|
||||
|
||||
hsi->ramInfo = std::format("{} / {}", ramIntToReadable(props[2]), ramIntToReadable(props[1])).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
// other, misc
|
||||
if (const auto DE = getenv("XDG_CURRENT_DESKTOP"); DE)
|
||||
hsi->DE = DE;
|
||||
|
||||
if (const auto UPTIME = readFile("/proc/uptime"); UPTIME != "[error]") {
|
||||
CVarList data(UPTIME, 0, 's', true);
|
||||
try {
|
||||
int uptimeSeconds = std::round(std::stof(data[0]));
|
||||
int uptimeDays = std::floor(uptimeSeconds / 3600.0 / 24.0);
|
||||
int uptimeHours = std::floor((uptimeSeconds % (3600 * 24)) / 3600.0);
|
||||
int uptimeMinutes = std::floor((uptimeSeconds % (3600)) / 60.0);
|
||||
|
||||
auto upStr = std::format("{}{}{}", (uptimeDays > 0 ? std::format("{} days, ", uptimeDays) : ""), (uptimeHours > 0 ? std::format("{} hours, ", uptimeHours) : ""),
|
||||
(uptimeMinutes > 0 ? std::format("{} minutes, ", uptimeMinutes) : ""));
|
||||
|
||||
if (!upStr.empty())
|
||||
upStr = upStr.substr(0, upStr.length() - 2);
|
||||
|
||||
hsi->uptime = upStr.c_str();
|
||||
} catch (...) { ; }
|
||||
}
|
||||
|
||||
{
|
||||
std::string screens;
|
||||
|
||||
for (auto& s : app->screens()) {
|
||||
screens += std::format("{} ({}x{}), ", s->name().toStdString(), s->geometry().width(), s->geometry().height());
|
||||
}
|
||||
|
||||
if (!screens.empty())
|
||||
screens = screens.substr(0, screens.length() - 2);
|
||||
|
||||
hsi->screens = screens.c_str();
|
||||
}
|
||||
|
||||
hsi->user = std::format("{}@{}", trim(execAndGet("whoami")), readFile("/etc/hostname")).c_str();
|
||||
|
||||
if (const auto PRODUCT = readFile("/sys/devices/virtual/dmi/id/product_name"); PRODUCT != "[error]")
|
||||
hsi->board = PRODUCT.c_str();
|
||||
else if (const auto BOARD = readFile("/sys/devices/virtual/dmi/id/board_name"); BOARD != "[error]")
|
||||
hsi->board = BOARD.c_str();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
|
|
@ -213,15 +12,10 @@ int main(int argc, char* argv[]) {
|
|||
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE"))
|
||||
QQuickStyle::setStyle("org.kde.desktop");
|
||||
|
||||
auto systemInternals = new CSystemInternals;
|
||||
|
||||
getSystemInfo(systemInternals, &app);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
engine.rootContext()->setContextProperty("hsi", systemInternals);
|
||||
engine.addImageProvider("systemIcons", new CSystemIconProvider);
|
||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection);
|
||||
engine.load(QUrl{u"qrc:/qt/qml/hsi/qml/main.qml"_qs});
|
||||
engine.load("qrc:/qt/qml/org/hyprland/systeminfo/main.qml");
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ pragma ComponentBehavior: Bound
|
|||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import org.hyprland.systeminfo
|
||||
|
||||
ApplicationWindow {
|
||||
id: window
|
||||
|
|
@ -58,8 +59,8 @@ ApplicationWindow {
|
|||
spacing: fontMetrics.height
|
||||
|
||||
Image {
|
||||
visible: hsi.hasSystemLogoName()
|
||||
source: "image://systemIcons/" + hsi.getSystemLogoName()
|
||||
visible: SystemInfo.systemLogoName != ""
|
||||
source: "image://systemIcons/" + SystemInfo.systemLogoName
|
||||
sourceSize.width: firstPanelHeight
|
||||
sourceSize.height: firstPanelHeight
|
||||
Layout.preferredWidth: firstPanelHeight
|
||||
|
|
@ -76,17 +77,17 @@ ApplicationWindow {
|
|||
Layout.alignment: Qt.AlignVCenter
|
||||
|
||||
Label {
|
||||
text: hsi.getSystemName()
|
||||
text: SystemInfo.systemName
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
Label {
|
||||
text: hsi.getSystemURL()
|
||||
text: SystemInfo.systemUrl
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
Label {
|
||||
text: hsi.getSystemKernel()
|
||||
text: SystemInfo.systemKernel
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
}
|
||||
|
|
@ -98,7 +99,7 @@ ApplicationWindow {
|
|||
|
||||
RowLayout {
|
||||
id: hyprlandInfo
|
||||
visible: hsi.hasHyprland()
|
||||
visible: SystemInfo.hyprlandVersionLong != ""
|
||||
spacing: fontMetrics.height
|
||||
|
||||
Image {
|
||||
|
|
@ -123,13 +124,13 @@ ApplicationWindow {
|
|||
}
|
||||
|
||||
Label {
|
||||
text: hsi.getHyprlandVersion()
|
||||
text: SystemInfo.hyprlandVersion
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
|
||||
Label {
|
||||
visible: hsi.getHyprlandVersion() != hsi.getHyprlandVersionLong()
|
||||
text: hsi.getHyprlandVersionLong()
|
||||
visible: SystemInfo.hyprlandVersion != text
|
||||
text: SystemInfo.hyprlandVersionLong
|
||||
Layout.alignment: Qt.AlignHCenter
|
||||
}
|
||||
}
|
||||
|
|
@ -151,23 +152,23 @@ ApplicationWindow {
|
|||
wrapMode: Text.NoWrap
|
||||
}
|
||||
|
||||
DetailsLabel { text: "User: " + hsi.getUserAt(); visible: hsi.getUserAt() != "" }
|
||||
DetailsLabel { text: "Model: " + hsi.getModel(); visible: hsi.getModel() != "" }
|
||||
DetailsLabel { text: "CPU: " + hsi.getCPUInfo() }
|
||||
DetailsLabel { text: "User: " + SystemInfo.user; visible: text != "" }
|
||||
DetailsLabel { text: "Model: " + SystemInfo.model; visible: text != "" }
|
||||
DetailsLabel { text: "CPU: " + SystemInfo.cpuInfo }
|
||||
|
||||
Repeater {
|
||||
model: hsi.getGPUInfoCount()
|
||||
model: SystemInfo.gpuInfo
|
||||
|
||||
DetailsLabel {
|
||||
required property int index
|
||||
text: "GPU: " + hsi.getGPUInfo(index)
|
||||
required property string modelData
|
||||
text: "GPU: " + modelData
|
||||
}
|
||||
}
|
||||
|
||||
DetailsLabel { text: "Memory: " + hsi.getRAMInfo() }
|
||||
DetailsLabel { text: "DE: " + hsi.getDE() }
|
||||
DetailsLabel { text: "Uptime: " + hsi.getUptime() }
|
||||
DetailsLabel { text: "Displays: " + hsi.getDisplays() }
|
||||
DetailsLabel { text: "Memory: " + SystemInfo.ramInfo }
|
||||
DetailsLabel { text: "DE: " + SystemInfo.de }
|
||||
DetailsLabel { text: "Uptime: " + SystemInfo.uptime }
|
||||
DetailsLabel { text: "Displays: " + SystemInfo.screens }
|
||||
}
|
||||
|
||||
Item { Layout.fillHeight: true }
|
||||
|
|
@ -175,19 +176,19 @@ ApplicationWindow {
|
|||
HSeparator {}
|
||||
|
||||
RowLayout {
|
||||
visible: hsi.hasHyprland()
|
||||
visible: SystemInfo.hyprlandVersionLong != ""
|
||||
spacing: 6
|
||||
Layout.leftMargin: 20
|
||||
Layout.rightMargin: 20
|
||||
|
||||
Button {
|
||||
text: "Copy Hyprland System Info"
|
||||
onClicked: hsi.copySystemInfo();
|
||||
onClicked: SystemInfo.copySystemInfo();
|
||||
}
|
||||
|
||||
Button {
|
||||
text: "Copy Hyprland Version"
|
||||
onClicked: hsi.copyVersion();
|
||||
onClicked: SystemInfo.copyVersion();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,32 @@
|
|||
#include "Utils.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include <qdebug.h>
|
||||
#include <qlogging.h>
|
||||
#include <qprocess.h>
|
||||
|
||||
std::string execAndGet(const char* cmd) {
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
const std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
|
||||
if (!pipe)
|
||||
QString execAndGet(const QString& program, const QStringList& arguments) {
|
||||
QProcess process;
|
||||
process.setProcessChannelMode(QProcess::SeparateChannels);
|
||||
process.start(program, arguments, QIODevice::ReadOnly);
|
||||
|
||||
if (!process.waitForStarted(-1)) {
|
||||
qCritical() << "Failed to start process" << program << arguments;
|
||||
return "";
|
||||
|
||||
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
|
||||
result += buffer.data();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (!process.waitForFinished(-1)) {
|
||||
qCritical() << "Failed to run process" << program << arguments;
|
||||
return "";
|
||||
}
|
||||
|
||||
return process.readAll();
|
||||
}
|
||||
|
||||
QString substrUntil(const QString& string, char until) {
|
||||
auto index = string.indexOf(until);
|
||||
|
||||
if (index == -1)
|
||||
return string;
|
||||
else
|
||||
return string.first(index);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <qlist.h>
|
||||
#include <qstring.h>
|
||||
|
||||
std::string execAndGet(const char* cmd);
|
||||
QString execAndGet(const QString& program, const QStringList& arguments = {});
|
||||
QString substrUntil(const QString& string, char until);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue