From 0375491dc84a5ebeeed8633057eb1f6888db7817 Mon Sep 17 00:00:00 2001 From: Zacharias-Brohn Date: Tue, 10 Mar 2026 22:42:06 +0100 Subject: [PATCH] wtf is happening --- Helpers/SystemUsage.qml | 35 ++++++++++- Modules/AudioWidget.qml | 4 +- Modules/Resource.qml | 111 +++++++++++++++++++--------------- Modules/ResourceUsage.qml | 123 -------------------------------------- 4 files changed, 98 insertions(+), 175 deletions(-) delete mode 100644 Modules/ResourceUsage.qml diff --git a/Helpers/SystemUsage.qml b/Helpers/SystemUsage.qml index d9234e9..eb7802a 100644 --- a/Helpers/SystemUsage.qml +++ b/Helpers/SystemUsage.qml @@ -80,8 +80,9 @@ Singleton { onTriggered: { stat.reload(); meminfo.reload(); - storage.running = true; - gpuUsage.running = true; + storage.running = false; + if (root.gpuName === "GENERIC") + gpuUsage.running = true; sensors.running = true; } } @@ -274,13 +275,41 @@ Singleton { } } + Process { + id: gpuUsageNvidia + + command: ["/usr/bin/nvidia-smi", "--query-gpu=utilization.gpu,temperature.gpu,memory.used", "--format=csv,noheader,nounits", "-lms", "1000"] + running: true + + stderr: SplitParser { + onRead: data => { + console.log("nvidia-smi stderr:", String(data).trim()); + } + } + stdout: SplitParser { + onRead: data => { + const [usage, temp, mem] = String(data).trim().split(/\s*,\s*/); + + root.gpuPerc = parseInt(usage, 10) / 100; + root.gpuTemp = parseInt(temp, 10); + root.gpuMemUsed = parseInt(mem, 10) / root.gpuMemTotal; + } + } + + onExited: (exitCode, exitStatus) => { + console.log("gpuUsageNvidia exited:", exitCode, exitStatus); + } + onStarted: console.log("gpuUsageNvidia started, pid =", processId) + } + Process { id: gpuUsage - command: root.gpuType === "GENERIC" ? ["sh", "-c", "cat /sys/class/drm/card*/device/gpu_busy_percent"] : root.gpuType === "NVIDIA" ? ["nvidia-smi", "--query-gpu=utilization.gpu,temperature.gpu,memory.used", "--format=csv,noheader,nounits"] : ["echo"] + command: root.gpuType === "GENERIC" ? ["sh", "-c", "cat /sys/class/drm/card*/device/gpu_busy_percent"] : ["echo"] stdout: StdioCollector { onStreamFinished: { + console.log("this is running"); if (root.gpuType === "GENERIC") { const percs = text.trim().split("\n"); const sum = percs.reduce((acc, d) => acc + parseInt(d, 10), 0); diff --git a/Modules/AudioWidget.qml b/Modules/AudioWidget.qml index a4d0185..64c4f46 100644 --- a/Modules/AudioWidget.qml +++ b/Modules/AudioWidget.qml @@ -39,7 +39,7 @@ CustomRect { Layout.alignment: Qt.AlignVCenter animate: true color: Audio.muted ? DynamicColors.palette.m3error : root.textColor - font.pointSize: Appearance.font.size.normal + font.pointSize: Appearance.font.size.larger text: Audio.muted ? "volume_off" : "volume_up" } @@ -68,7 +68,7 @@ CustomRect { Layout.alignment: Qt.AlignVCenter animate: true color: (Audio.sourceMuted ?? false) ? DynamicColors.palette.m3error : root.textColor - font.pointSize: Appearance.font.size.normal + font.pointSize: Appearance.font.size.larger text: Audio.sourceMuted ? "mic_off" : "mic" } diff --git a/Modules/Resource.qml b/Modules/Resource.qml index e26085c..323aebc 100644 --- a/Modules/Resource.qml +++ b/Modules/Resource.qml @@ -36,58 +36,75 @@ Item { Component.onCompleted: animatedPercentage = percentage onPercentageChanged: animatedPercentage = percentage - Canvas { - id: gaugeCanvas - - anchors.centerIn: parent - height: width - width: Math.min(parent.width, parent.height) - - Component.onCompleted: requestPaint() - onPaint: { - const ctx = getContext("2d"); - ctx.reset(); - const cx = width / 2; - const cy = (height / 2) + 1; - const radius = (Math.min(width, height) - 12) / 2; - const lineWidth = 3; - ctx.beginPath(); - ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep); - ctx.lineWidth = lineWidth; - ctx.lineCap = "round"; - ctx.strokeStyle = DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHigh, 2); - ctx.stroke(); - if (root.animatedPercentage > 0) { - ctx.beginPath(); - ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep * root.animatedPercentage); - ctx.lineWidth = lineWidth; - ctx.lineCap = "round"; - ctx.strokeStyle = root.accentColor; - ctx.stroke(); - } - } - - Connections { - function onAnimatedPercentageChanged() { - gaugeCanvas.requestPaint(); - } - - target: root - } - - Connections { - function onPaletteChanged() { - gaugeCanvas.requestPaint(); - } - - target: DynamicColors - } - } + // Canvas { + // id: gaugeCanvas + // + // anchors.centerIn: parent + // height: width + // width: Math.min(parent.width, parent.height) + // + // Component.onCompleted: requestPaint() + // onPaint: { + // const ctx = getContext("2d"); + // ctx.reset(); + // const cx = width / 2; + // const cy = (height / 2) + 1; + // const radius = (Math.min(width, height) - 12) / 2; + // const lineWidth = 3; + // ctx.beginPath(); + // ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep); + // ctx.lineWidth = lineWidth; + // ctx.lineCap = "round"; + // ctx.strokeStyle = DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHigh, 2); + // ctx.stroke(); + // if (root.animatedPercentage > 0) { + // ctx.beginPath(); + // ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep * root.animatedPercentage); + // ctx.lineWidth = lineWidth; + // ctx.lineCap = "round"; + // ctx.strokeStyle = root.accentColor; + // ctx.stroke(); + // } + // } + // + // Connections { + // function onAnimatedPercentageChanged() { + // gaugeCanvas.requestPaint(); + // } + // + // target: root + // } + // + // Connections { + // function onPaletteChanged() { + // gaugeCanvas.requestPaint(); + // } + // + // target: DynamicColors + // } + // } MaterialIcon { + id: icon + anchors.centerIn: parent color: DynamicColors.palette.m3onSurface font.pointSize: 12 text: root.icon } + + CustomRect { + anchors.left: icon.right + color: DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHigh, 2) + implicitHeight: parent.height + implicitWidth: 5 + radius: Appearance.rounding.full + + CustomRect { + anchors.bottom: parent.bottom + anchors.left: parent.left + anchors.right: parent.right + color: root.mainColor + } + } } diff --git a/Modules/ResourceUsage.qml b/Modules/ResourceUsage.qml deleted file mode 100644 index f1b01ce..0000000 --- a/Modules/ResourceUsage.qml +++ /dev/null @@ -1,123 +0,0 @@ -pragma Singleton -pragma ComponentBehavior: Bound - -import QtQuick -import Quickshell -import Quickshell.Io -import qs.Config - -Singleton { - id: root - - property string autoGpuType: "NONE" - property double cpuUsage: 0 - property double gpuMemUsage: 0 - readonly property string gpuType: Config.services.gpuType.toUpperCase() || autoGpuType - property double gpuUsage: 0 - property double memoryFree: 1 - property double memoryTotal: 1 - property double memoryUsed: memoryTotal - memoryFree - property double memoryUsedPercentage: memoryUsed / memoryTotal - property var previousCpuStats - property double swapFree: 1 - property double swapTotal: 1 - property double swapUsed: swapTotal - swapFree - property double swapUsedPercentage: swapTotal > 0 ? (swapUsed / swapTotal) : 0 - property double totalMem: 0 - - Timer { - interval: 1 - repeat: true - running: true - - onTriggered: { - // Reload files - fileMeminfo.reload(); - fileStat.reload(); - - // Parse memory and swap usage - const textMeminfo = fileMeminfo.text(); - memoryTotal = Number(textMeminfo.match(/MemTotal: *(\d+)/)?.[1] ?? 1); - memoryFree = Number(textMeminfo.match(/MemAvailable: *(\d+)/)?.[1] ?? 0); - swapTotal = Number(textMeminfo.match(/SwapTotal: *(\d+)/)?.[1] ?? 1); - swapFree = Number(textMeminfo.match(/SwapFree: *(\d+)/)?.[1] ?? 0); - - // Parse CPU usage - const textStat = fileStat.text(); - const cpuLine = textStat.match(/^cpu\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/); - if (cpuLine) { - const stats = cpuLine.slice(1).map(Number); - const total = stats.reduce((a, b) => a + b, 0); - const idle = stats[3]; - - if (previousCpuStats) { - const totalDiff = total - previousCpuStats.total; - const idleDiff = idle - previousCpuStats.idle; - cpuUsage = totalDiff > 0 ? (1 - idleDiff / totalDiff) : 0; - } - - previousCpuStats = { - total, - idle - }; - } - if (root.gpuType === "NVIDIA") { - processGpu.running = true; - } - - interval = 3000; - } - } - - FileView { - id: fileMeminfo - - path: "/proc/meminfo" - } - - FileView { - id: fileStat - - path: "/proc/stat" - } - - Process { - id: gpuTypeCheck - - command: ["sh", "-c", "if command -v nvidia-smi &>/dev/null && nvidia-smi -L &>/dev/null; then echo NVIDIA; elif ls /sys/class/drm/card*/device/gpu_busy_percent 2>/dev/null | grep -q .; then echo GENERIC; else echo NONE; fi"] - running: !Config.services.gpuType - - stdout: StdioCollector { - onStreamFinished: root.autoGpuType = text.trim() - } - } - - Process { - id: oneshotMem - - command: ["nvidia-smi", "--query-gpu=memory.total", "--format=csv,noheader,nounits"] - running: root.gpuType === "NVIDIA" && totalMem === 0 - - stdout: StdioCollector { - onStreamFinished: { - totalMem = Number(this.text.trim()); - oneshotMem.running = false; - } - } - } - - Process { - id: processGpu - - command: ["nvidia-smi", "--query-gpu=utilization.gpu,memory.used", "--format=csv,noheader,nounits"] - running: false - - stdout: StdioCollector { - onStreamFinished: { - const parts = this.text.trim().split(", "); - gpuUsage = Number(parts[0]) / 100; - gpuMemUsage = Number(parts[1]) / totalMem; - } - } - } -}