wtf is happening

This commit is contained in:
Zacharias-Brohn
2026-03-10 22:42:06 +01:00
parent 203b19ce45
commit 0375491dc8
4 changed files with 98 additions and 175 deletions
+32 -3
View File
@@ -80,8 +80,9 @@ Singleton {
onTriggered: { onTriggered: {
stat.reload(); stat.reload();
meminfo.reload(); meminfo.reload();
storage.running = true; storage.running = false;
gpuUsage.running = true; if (root.gpuName === "GENERIC")
gpuUsage.running = true;
sensors.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 { Process {
id: gpuUsage 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 { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
console.log("this is running");
if (root.gpuType === "GENERIC") { if (root.gpuType === "GENERIC") {
const percs = text.trim().split("\n"); const percs = text.trim().split("\n");
const sum = percs.reduce((acc, d) => acc + parseInt(d, 10), 0); const sum = percs.reduce((acc, d) => acc + parseInt(d, 10), 0);
+2 -2
View File
@@ -39,7 +39,7 @@ CustomRect {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
animate: true animate: true
color: Audio.muted ? DynamicColors.palette.m3error : root.textColor 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" text: Audio.muted ? "volume_off" : "volume_up"
} }
@@ -68,7 +68,7 @@ CustomRect {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
animate: true animate: true
color: (Audio.sourceMuted ?? false) ? DynamicColors.palette.m3error : root.textColor 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" text: Audio.sourceMuted ? "mic_off" : "mic"
} }
+64 -47
View File
@@ -36,58 +36,75 @@ Item {
Component.onCompleted: animatedPercentage = percentage Component.onCompleted: animatedPercentage = percentage
onPercentageChanged: animatedPercentage = percentage onPercentageChanged: animatedPercentage = percentage
Canvas { // Canvas {
id: gaugeCanvas // id: gaugeCanvas
//
anchors.centerIn: parent // anchors.centerIn: parent
height: width // height: width
width: Math.min(parent.width, parent.height) // width: Math.min(parent.width, parent.height)
//
Component.onCompleted: requestPaint() // Component.onCompleted: requestPaint()
onPaint: { // onPaint: {
const ctx = getContext("2d"); // const ctx = getContext("2d");
ctx.reset(); // ctx.reset();
const cx = width / 2; // const cx = width / 2;
const cy = (height / 2) + 1; // const cy = (height / 2) + 1;
const radius = (Math.min(width, height) - 12) / 2; // const radius = (Math.min(width, height) - 12) / 2;
const lineWidth = 3; // const lineWidth = 3;
ctx.beginPath(); // ctx.beginPath();
ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep); // ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep);
ctx.lineWidth = lineWidth; // ctx.lineWidth = lineWidth;
ctx.lineCap = "round"; // ctx.lineCap = "round";
ctx.strokeStyle = DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHigh, 2); // ctx.strokeStyle = DynamicColors.layer(DynamicColors.palette.m3surfaceContainerHigh, 2);
ctx.stroke(); // ctx.stroke();
if (root.animatedPercentage > 0) { // if (root.animatedPercentage > 0) {
ctx.beginPath(); // ctx.beginPath();
ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep * root.animatedPercentage); // ctx.arc(cx, cy, radius, root.arcStartAngle, root.arcStartAngle + root.arcSweep * root.animatedPercentage);
ctx.lineWidth = lineWidth; // ctx.lineWidth = lineWidth;
ctx.lineCap = "round"; // ctx.lineCap = "round";
ctx.strokeStyle = root.accentColor; // ctx.strokeStyle = root.accentColor;
ctx.stroke(); // ctx.stroke();
} // }
} // }
//
Connections { // Connections {
function onAnimatedPercentageChanged() { // function onAnimatedPercentageChanged() {
gaugeCanvas.requestPaint(); // gaugeCanvas.requestPaint();
} // }
//
target: root // target: root
} // }
//
Connections { // Connections {
function onPaletteChanged() { // function onPaletteChanged() {
gaugeCanvas.requestPaint(); // gaugeCanvas.requestPaint();
} // }
//
target: DynamicColors // target: DynamicColors
} // }
} // }
MaterialIcon { MaterialIcon {
id: icon
anchors.centerIn: parent anchors.centerIn: parent
color: DynamicColors.palette.m3onSurface color: DynamicColors.palette.m3onSurface
font.pointSize: 12 font.pointSize: 12
text: root.icon 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
}
}
} }
-123
View File
@@ -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;
}
}
}
}