From 506aeeff43f8151811ab7c1f270e1c251ca8756d Mon Sep 17 00:00:00 2001 From: Sem Date: Fri, 3 Apr 2026 19:52:27 +0200 Subject: [PATCH] Add showing level of value through bar --- quickshell/services/SystemStats.qml | 22 +++++++++++++++-- quickshell/shell.qml | 1 + quickshell/ui/BarText.qml | 37 +++++++++++++++++++++++++++++ quickshell/ui/TopBar.qml | 31 +++++++++++------------- 4 files changed, 72 insertions(+), 19 deletions(-) create mode 100644 quickshell/ui/BarText.qml diff --git a/quickshell/services/SystemStats.qml b/quickshell/services/SystemStats.qml index e3e4775..1152b9a 100644 --- a/quickshell/services/SystemStats.qml +++ b/quickshell/services/SystemStats.qml @@ -10,13 +10,13 @@ Item { // ===================== property int cpuUsage: 0 property int memUsage: 0 + property int gpuUsage: 0 property var lastCpuIdle: 0 property var lastCpuTotal: 0 Process { id: cpuProc - // get cpu usage, first line of /proc/stat command: ["cat", "/proc/stat"] stdout: StdioCollector { onStreamFinished: { @@ -56,12 +56,29 @@ Item { var parts = data.trim().split(/\s+/); var total = parseInt(parts[1]) || 1; var used = parseInt(parts[2]) || 0; - memUsage = Math.round(100 * used / total); + root.memUsage = Math.round(100 * used / total); } } Component.onCompleted: running = true } + Process { + id: gpuProc + command: ["cat", "/sys/class/drm/card1/device/gpu_busy_percent"] + + stdout: StdioCollector { + onStreamFinished: { + console.log("GPU usage data:", this.text); + if (!this.text) { + return; + } + var gpuUsage = parseInt(this.text.trim()) || 0; + root.gpuUsage = gpuUsage; + } + } + + } + // Update loop Timer { interval: 2000 @@ -70,6 +87,7 @@ Item { onTriggered: { cpuProc.running = true; memProc.running = true; + gpuProc.running = true; } } } diff --git a/quickshell/shell.qml b/quickshell/shell.qml index e14ae89..7cd5056 100644 --- a/quickshell/shell.qml +++ b/quickshell/shell.qml @@ -48,6 +48,7 @@ ShellRoot { cpuUsage: stats.cpuUsage memUsage: stats.memUsage + gpuUsage: stats.gpuUsage } } diff --git a/quickshell/ui/BarText.qml b/quickshell/ui/BarText.qml new file mode 100644 index 0000000..c193051 --- /dev/null +++ b/quickshell/ui/BarText.qml @@ -0,0 +1,37 @@ +import QtQuick +import Quickshell + +import "../constants" + +Item { + id: root + property int value: 0 + property string prefix: "" + property string separator: "-" + property int valuePadding: 3 + property int padding: 4 + property string paddingChar: "0" + + width: textItem.implicitWidth + padding + height: textItem.implicitHeight + padding + + Rectangle { + anchors.bottom: parent.bottom + anchors.horizontalCenter: parent.horizontalCenter + width: parent.width + height: Math.max(1, root.value / 100 * parent.height) + color: Colors.md3.on_secondary + opacity: 1.0 + } + + Text { + id: textItem + anchors.centerIn: parent + z: 1 + text: root.prefix + root.separator + String(root.value).padStart(root.valuePadding, root.paddingChar) + color: Colors.md3.inverse_primary + font.pixelSize: Constants.fontSize + font.family: Constants.fontFamily + font.bold: true + } +} diff --git a/quickshell/ui/TopBar.qml b/quickshell/ui/TopBar.qml index a6b20fe..b3d0c10 100644 --- a/quickshell/ui/TopBar.qml +++ b/quickshell/ui/TopBar.qml @@ -16,6 +16,7 @@ Item { property int cpuUsage: 0 property int memUsage: 0 + property int gpuUsage: 0 RowLayout { anchors.fill: parent @@ -71,35 +72,31 @@ Item { RowLayout { spacing: 10 - //TODO put this in separate component - Text { - id: cpuText - text: "CPU: " + cpuUsage + "%" - color: Constants.colYellow - font.pixelSize: Constants.fontSize - font.family: Constants.fontFamily - font.bold: true + BarText { + prefix: "C" + value: cpuUsage } Rectangle { width: 1 height: 16 - color: Constants.colMuted + color: Colors.md3.on_background } - Text { - id: memText - text: "Mem: " + memUsage + "%" - color: Constants.colCyan - font.pixelSize: Constants.fontSize - font.family: Constants.fontFamily - font.bold: true + BarText { + prefix: "M" + value: memUsage } Rectangle { width: 1 height: 16 - color: Constants.colMuted + color: Colors.md3.on_background + } + + BarText { + prefix: "G" + value: gpuUsage } Clock {}