From 01b5ae46b19db61fd4da5a33ef70bb48962345fa Mon Sep 17 00:00:00 2001 From: bbedward Date: Sat, 9 Aug 2025 21:01:39 -0400 Subject: [PATCH] try to minimize bad data before enough cpu samples are done --- README.md | 10 ++++----- Services/DankgopService.qml | 42 ++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 58f230ac..13fbcda0 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@
-![GitHub last commit](https://img.shields.io/github/last-commit/bbedward/DankMaterialShell?style=for-the-badge&labelColor=101418&color=9ccbfb) -![GitHub License](https://img.shields.io/github/license/bbedward/DankMaterialShell?style=for-the-badge&labelColor=101418&color=b9c8da) -![GitHub repo size](https://img.shields.io/github/repo-size/bbedward/DankMaterialShell?style=for-the-badge&labelColor=101418&color=d3bfe6) +![GitHub last commit](https://img.shields.io/github/last-commit/AvengeMedia/DankMaterialShell?style=for-the-badge&labelColor=101418&color=9ccbfb) +![GitHub License](https://img.shields.io/github/license/AvengeMedia/DankMaterialShell?style=for-the-badge&labelColor=101418&color=b9c8da) +![GitHub repo size](https://img.shields.io/github/repo-size/AvengeMedia/DankMaterialShell?style=for-the-badge&labelColor=101418&color=d3bfe6)
@@ -116,7 +116,7 @@ paru -S dankmaterialshell-git # Manual install mkdir -p ~/.config/quickshell -git clone https://github.com/bbedward/DankMaterialShell.git ~/.config/quickshell/DankMaterialShell +git clone https://github.com/AvengeMedia/DankMaterialShell.git ~/.config/quickshell/DankMaterialShell qs -c DankMaterialShell ``` @@ -423,7 +423,7 @@ All settings are configurable in `~/.config/DankMaterialShell/settings.json`, or **Getting help:** -- Check the [issues](https://github.com/bbedward/DankMaterialShell/issues) for known problems +- Check the [issues](https://github.com/AvengeMedia/DankMaterialShell/issues) for known problems - Share logs from `qs -c DankMaterialShell` for debugging - Join the niri community for compositor-specific questions diff --git a/Services/DankgopService.qml b/Services/DankgopService.qml index e6f059d7..6b842045 100644 --- a/Services/DankgopService.qml +++ b/Services/DankgopService.qml @@ -24,6 +24,8 @@ Singleton { // Sampling data property var cpuSampleData: null property var procSampleData: null + property int cpuSampleCount: 0 + property int processSampleCount: 0 property real cpuUsage: 0 property real cpuFrequency: 0 @@ -132,6 +134,16 @@ Singleton { if (modulesChanged) { enabledModules = enabledModules.slice() // Force property change moduleRefCounts = Object.assign({}, moduleRefCounts) // Force property change + + // Clear cursor data when CPU or process modules are no longer active + if (!enabledModules.includes("cpu")) { + cpuSampleData = null + cpuSampleCount = 0 + } + if (!enabledModules.includes("processes")) { + procSampleData = null + processSampleCount = 0 + } } } @@ -267,15 +279,20 @@ Singleton { function parseData(data) { if (data.cpu) { const cpu = data.cpu - cpuUsage = cpu.usage || 0 - cpuFrequency = cpu.frequency || 0 - cpuTemperature = cpu.temperature || 0 - cpuCores = cpu.count || 1 - cpuModel = cpu.model || "" - perCoreCpuUsage = cpu.coreUsage || [] - addToHistory(cpuHistory, cpuUsage) + cpuSampleCount++ + + // Only update CPU data if we have had at least 2 samples (first sample is inaccurate) + if (cpuSampleCount >= 2) { + cpuUsage = cpu.usage || 0 + cpuFrequency = cpu.frequency || 0 + cpuTemperature = cpu.temperature || 0 + cpuCores = cpu.count || 1 + cpuModel = cpu.model || "" + perCoreCpuUsage = cpu.coreUsage || [] + addToHistory(cpuHistory, cpuUsage) + } - // Update CPU sample data for the next run using cursor data + // Always update cursor data for next sampling if (cpu.cursor) { cpuSampleData = { previousTotal: cpu.cursor.total, @@ -360,11 +377,16 @@ Singleton { if (data.processes && Array.isArray(data.processes)) { const newProcesses = [] const newProcSample = [] + processSampleCount++ + for (const proc of data.processes) { + // Only show CPU usage if we have had at least 2 samples (first sample is inaccurate) + const cpuUsage = processSampleCount >= 2 ? (proc.cpu || 0) : 0 + newProcesses.push({ "pid": proc.pid || 0, "ppid": proc.ppid || 0, - "cpu": proc.cpu || 0, + "cpu": cpuUsage, "memoryPercent": proc.memoryPercent || proc.pssPercent || 0, "memoryKB": proc.memoryKB || proc.pssKB || 0, "command": proc.command || "", @@ -373,7 +395,7 @@ Singleton { proc.command.substring(0, 15) + "..." : (proc.command || "") }) - // Extract cursor data from pticks for next sampling call + // Always extract cursor data from pticks for next sampling call if (proc.pid && typeof proc.pticks !== 'undefined') { newProcSample.push({ pid: proc.pid,