1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
import Quickshell
import Quickshell.Io
import QtQuick
Scope {
Timer {
interval: 2000
running: true
repeat: true
onTriggered: {
cpuProc.running = true
memProc.running = true
brightnessProc.running = true
volumeProc.running = true
batteryProc.running = true
networkProc.running = true
temperatureProc.running = true
}
}
Process {
id: cpuProc
command: ["sh", "-c", "head -1 /proc/stat"]
stdout: SplitParser {
onRead: data => {
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)
if (lastCpuTotal > 0) {
cpuUsage = Math.round(100 * (1 - (idle - lastCpuIdle) / (total - lastCpuTotal)))
}
lastCpuTotal = total
lastCpuIdle = idle
}
}
Component.onCompleted: running = true
}
Process {
id: memProc
command: ["sh", "-c", "free | grep Mem"]
stdout: SplitParser {
onRead: data => {
var parts = data.trim().split(/\s+/)
var total = parseInt(parts[1]) || 1
var used = parseInt(parts[2]) || 0
memUsage = Math.round(100 * used / total)
}
}
Component.onCompleted: running = true
}
Process {
id: temperatureProc
command: ["sh", "-c", "~/.config/quickshell/scripts/cpu_temp.sh"]
stdout: SplitParser {
onRead: data => {
cpu_temperature = parseInt(data.trim()) || 13;
}
}
Component.onCompleted: running = true
}
Process {
id: brightnessProc
command: ["sh", "-c", "~/.config/quickshell/scripts/brightness.sh"]
stdout: SplitParser {
onRead: data => {
var parts = data.trim().split(/\s+/)
brightness = parseInt(parts[0]) || 100
temperature = parseInt(parts[1]) || 6000
}
}
Component.onCompleted: running = true
}
Process {
id: volumeProc
command: ["sh", "-c", "~/.config/quickshell/scripts/volume.sh"]
stdout: SplitParser {
onRead: data => {
volume = parseInt(data.trim()) || 13;
}
}
Component.onCompleted: running = true
}
Process {
id: batteryProc
command: ["sh", "-c", "~/.config/quickshell/scripts/battery.sh"]
stdout: SplitParser {
onRead: data => {
battery = parseInt(data.trim()) || 13;
}
}
Component.onCompleted: running = true
}
Process {
id: networkProc
command: ["sh", "-c", "~/.config/quickshell/scripts/network.sh"]
stdout: SplitParser {
onRead: data => {
var parts = data.trim().split(/\s+/)
wifiName = parts[0];
}
}
Component.onCompleted: running = true
}
}
|