initial commit
This commit is contained in:
commit
9fde6d4fc6
27 changed files with 1110 additions and 0 deletions
51
modules/Cpu.qml
Normal file
51
modules/Cpu.qml
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import QtQuick
|
||||
import Quickshell.Io
|
||||
import "." as M
|
||||
|
||||
Text {
|
||||
id: root
|
||||
|
||||
property int usage: 0
|
||||
property real freqGhz: 0
|
||||
|
||||
property var _prev: null
|
||||
|
||||
FileView {
|
||||
id: stat
|
||||
path: "/proc/stat"
|
||||
onLoaded: {
|
||||
const line = text().split("\n")[0];
|
||||
const f = line.trim().split(/\s+/).slice(1).map(Number);
|
||||
const idle = f[3] + f[4];
|
||||
const total = f.reduce((a, b) => a + b, 0);
|
||||
if (root._prev) {
|
||||
const dIdle = idle - root._prev.idle;
|
||||
const dTotal = total - root._prev.total;
|
||||
if (dTotal > 0) root.usage = Math.round((1 - dIdle / dTotal) * 100);
|
||||
}
|
||||
root._prev = { idle, total };
|
||||
}
|
||||
}
|
||||
FileView {
|
||||
id: cpuinfo
|
||||
path: "/proc/cpuinfo"
|
||||
onLoaded: {
|
||||
const lines = text().split("\n").filter(l => l.startsWith("cpu MHz"));
|
||||
if (lines.length === 0) return;
|
||||
const sum = lines.reduce((a, l) => a + parseFloat(l.split(":")[1]), 0);
|
||||
root.freqGhz = sum / lines.length / 1000;
|
||||
}
|
||||
}
|
||||
Timer {
|
||||
interval: 1000
|
||||
running: true
|
||||
repeat: true
|
||||
onTriggered: { stat.reload(); cpuinfo.reload(); }
|
||||
}
|
||||
|
||||
text: " " + root.usage.toString().padStart(2) + "%@" + root.freqGhz.toFixed(2)
|
||||
color: M.Theme.base05
|
||||
font.pixelSize: M.Theme.fontSize
|
||||
font.family: M.Theme.fontFamily
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue