From a2028419fc88d8cb22a726c2a0a441edbf8a7927 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 13 Oct 2024 16:54:23 +0100 Subject: [PATCH] core: fixup elision on gpu data --- qml/main.qml | 21 ++++++++++++++------- qmlSources/SystemInternals.hpp | 24 +++++++++++++++--------- src/main.cpp | 9 ++++----- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/qml/main.qml b/qml/main.qml index ac91308..5d3685e 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -159,13 +159,20 @@ ApplicationWindow { wrapMode: Text.NoWrap } - Text { - text: hsi.getGPUInfo() - Layout.maximumWidth: _width - 120 - color: system.windowText - elide: Text.ElideRight - textFormat: Text.PlainText - wrapMode: Text.NoWrap + Repeater { + model: hsi.getGPUInfoCount() + + Text { + required property int index + + text: "GPU: " + hsi.getGPUInfo(index) + Layout.maximumWidth: _width - 120 + color: system.windowText + elide: Text.ElideRight + textFormat: Text.PlainText + wrapMode: Text.NoWrap + } + } Text { diff --git a/qmlSources/SystemInternals.hpp b/qmlSources/SystemInternals.hpp index 6a9a520..153fe1e 100644 --- a/qmlSources/SystemInternals.hpp +++ b/qmlSources/SystemInternals.hpp @@ -14,16 +14,16 @@ class CSystemInternals : public QObject { ; } - QString systemLogoName, systemName = "Linux", systemURL = "https://kernel.org/", systemKernel = "unknown"; - QString hyprlandVersion, hyprlandVersionLong; + QString systemLogoName, systemName = "Linux", systemURL = "https://kernel.org/", systemKernel = "unknown"; + QString hyprlandVersion, hyprlandVersionLong; - QString cpuInfo = "missing dependency: lscpu"; - QString gpuInfo = "GPU: missing dependency: lspci"; - QString ramInfo = "?"; + QString cpuInfo = "missing dependency: lscpu"; + std::vector gpuInfo = {"missing dependency: lspci"}; + QString ramInfo = "?"; - QString hlSystemInfo = "[error]", hlSystemVersion = "[error]"; + QString hlSystemInfo = "[error]", hlSystemVersion = "[error]"; - Q_INVOKABLE bool hasSystemLogoName() { + Q_INVOKABLE bool hasSystemLogoName() { return systemLogoName.size() > 0; } @@ -59,8 +59,14 @@ class CSystemInternals : public QObject { return cpuInfo; } - Q_INVOKABLE QString getGPUInfo() { - return gpuInfo; + 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() { diff --git a/src/main.cpp b/src/main.cpp index a8ae370..ee1c4cd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -105,16 +105,15 @@ static void getSystemInfo(CSystemInternals* hsi) { { const auto DATA = execAndGet("lspci -vnn | grep VGA"); if (DATA.contains("VGA")) { - CVarList data(DATA, 0, '\n'); - std::string gpuInfo; + CVarList data(DATA, 0, '\n'); + hsi->gpuInfo.clear(); for (auto& line : data) { if (!line.contains("VGA")) continue; - gpuInfo += std::format("GPU: {}\n", line.substr(line.find(":", line.find("VGA")) + 1)); + hsi->gpuInfo.emplace_back(std::format("{}", line.substr(line.find(":", line.find("VGA")) + 2)).c_str()); } - hsi->gpuInfo = gpuInfo.substr(0, gpuInfo.length() - 1).c_str(); } else { - hsi->gpuInfo = "No GPUs found"; + hsi->gpuInfo = {"No GPUs found"}; } }