import Quickshell import Quickshell.Io import QtQuick import qs Rectangle { id: root property real lastCpuTotal: 0.0 property real lastCpuIdle: 0.0 property real cpuUsage: 0.0 color: Appearance.colAppBg implicitHeight: Appearance.appletRadHeight implicitWidth: cpuText.width + 25 radius: Appearance.appletRadHeight Process { id: cpuProc command: ["sh", "-c", "head -1 /proc/stat"] property double cpuUsage stdout: SplitParser { onRead: data => { if (!data) { return; } else { var p = data.trim().split(/\s+/); var idle = parseInt(p[4]) + parseInt(p[5]); var total = p.slice(1, 8).reduce((a, b) => a + parseInt(b), 0); root.cpuUsage = Math.round(100 * (1 - (idle - root.lastCpuIdle) / (total - root.lastCpuTotal))); root.lastCpuTotal = total; root.lastCpuIdle = idle; } } } Component.onCompleted: running = true } Timer { id: cpuProcRestarter interval: 2000 repeat: true running: true onTriggered: cpuProc.running = true } Text { font.family: Appearance.font font.pixelSize: Appearance.fontSize font.bold: true color: Appearance.colFg id: cpuText anchors.centerIn: parent text: "CPU: " + root.cpuUsage + "%" } }