···
7
7
8
8
# eww configuration
9
9
ewwYuck = pkgs.writeText "eww.yuck" ''
10
10
-
; Variables with polling - set initial values to avoid empty string errors
11
11
-
(defpoll time :interval "1s" :initial "00:00" "date '+%H:%M'")
12
12
-
(defpoll date :interval "60s" :initial "0000-00-00" "date '+%Y-%m-%d'")
13
13
-
(defpoll cpu :interval "2s" :initial '{"usage": 0, "load": "0.00", "freq": 0}' "${lib.getExe cpuScript}")
14
14
-
(defpoll memory :interval "2s" :initial 0 "${lib.getExe memScript}")
10
10
+
; Magic variables (built-in, no polling needed)
11
11
+
; EWW_TIME provides current time
12
12
+
; EWW_CPU provides {cores: [...], avg: X}
13
13
+
; EWW_RAM provides {used_mem_perc: X, available_mem: Y, total_mem: Z, ...}
14
14
+
15
15
+
; Custom variables with polling
16
16
+
(defpoll cpu-freq :interval "2s" :initial 0 "${lib.getExe cpuFreqScript}")
17
17
+
(defpoll cpu-load :interval "2s" :initial "0.00" "cut -d' ' -f1 /proc/loadavg")
15
18
(defpoll temperature :interval "2s" :initial '{"temp": 0, "fan": 0}' "${lib.getExe tempScript}")
16
19
(defpoll battery :interval "10s" :initial '{"capacity": "100", "icon": "", "watts": "0", "time_remaining": "--", "status": "Full"}' "${lib.getExe batteryScript}")
17
20
(defpoll volume :interval "1s" :initial '{"level": "0", "icon": ""}' "${lib.getExe volumeScript}")
···
33
36
34
37
(defwidget center []
35
38
(box :class "center" :orientation "h" :space-evenly false :halign "center"
36
36
-
(label :text "''${time}")))
39
39
+
(label :text {formattime(EWW_TIME, "%H:%M")})))
37
40
38
41
(defwidget right []
39
42
(box :class "right" :orientation "h" :space-evenly false :halign "end" :spacing 8
40
43
(network-widget)
41
44
(volume-widget)
42
42
-
(graph-widget :value {cpu.usage} :icon "" :class "cpu" :unit "%" :tooltip "Load: ''${cpu.load} | ''${cpu.freq} MHz")
43
43
-
(graph-widget :value memory :icon "" :class "memory" :unit "%")
45
45
+
(graph-widget :value {EWW_CPU.avg} :icon "" :class "cpu" :unit "%" :tooltip "Load: ''${cpu-load} | ''${cpu-freq} MHz")
46
46
+
(graph-widget :value {EWW_RAM.used_mem_perc} :icon "" :class "memory" :unit "%")
44
47
(graph-widget :value {temperature.temp} :icon "" :class "temp" :unit "°" :tooltip "Fan: ''${temperature.fan} RPM")
45
48
(brightness-widget)
46
49
(battery-widget)
47
50
(idle-inhibitor)
48
48
-
(label :class "date" :text "''${date}")
51
51
+
(label :class "date" :text {formattime(EWW_TIME, "%Y-%m-%d")})
49
52
(systray :class "systray" :icon-size 18 :spacing 4)))
50
53
51
54
(defwidget workspaces-widget []
···
67
70
:dynamic true
68
71
:line-style "round"
69
72
:width 75)
70
70
-
(label :text "''${value}''${unit} ''${icon}")))
73
73
+
(label :text "''${round(value, 0)}''${unit} ''${icon}")))
71
74
72
75
(defwidget battery-widget []
73
76
(box :class "battery" :orientation "h" :space-evenly false
···
199
202
}
200
203
'';
201
204
202
202
-
cpuScript = pkgs.writeShellApplication {
203
203
-
name = "eww-cpu";
204
204
-
runtimeInputs = [ pkgs.jq ];
205
205
+
cpuFreqScript = pkgs.writeShellApplication {
206
206
+
name = "eww-cpu-freq";
207
207
+
runtimeInputs = [ ];
205
208
text = ''
206
206
-
STATE_FILE="/tmp/eww-cpu-state"
207
207
-
read -r _cpu user nice system idle _rest < /proc/stat
208
208
-
total=$((user + nice + system + idle))
209
209
-
210
210
-
if [ -f "$STATE_FILE" ]; then
211
211
-
read -r prev_total prev_idle < "$STATE_FILE"
212
212
-
diff_total=$((total - prev_total))
213
213
-
diff_idle=$((idle - prev_idle))
214
214
-
if [ "$diff_total" -gt 0 ]; then
215
215
-
usage=$((100 * (diff_total - diff_idle) / diff_total))
216
216
-
else
217
217
-
usage=0
218
218
-
fi
219
219
-
else
220
220
-
usage=0
221
221
-
fi
222
222
-
echo "$total $idle" > "$STATE_FILE"
223
223
-
224
224
-
# Get load average (1 min)
225
225
-
load=$(cut -d' ' -f1 /proc/loadavg)
226
226
-
227
209
# Get average CPU frequency in MHz
228
210
freq=0
229
211
count=0
···
237
219
if [ "$count" -gt 0 ]; then
238
220
freq=$((freq / count / 1000))
239
221
fi
240
240
-
241
241
-
jq -n --argjson usage "$usage" --arg load "$load" --argjson freq "$freq" \
242
242
-
'{usage: $usage, load: $load, freq: $freq}'
243
243
-
'';
244
244
-
};
245
245
-
246
246
-
memScript = pkgs.writeShellApplication {
247
247
-
name = "eww-mem";
248
248
-
runtimeInputs = [ pkgs.gawk ];
249
249
-
text = ''
250
250
-
awk '/MemTotal/ {total=$2} /MemAvailable/ {available=$2} END {printf "%d", (total-available)*100/total}' /proc/meminfo
222
222
+
echo "$freq"
251
223
'';
252
224
};
253
225