3 # - global, builtin : ALLCAPS
4 # - global, public : Camel_Snake_Man_Bear_Pig
5 # - global, private : _snake_case_prefixed_underscore
8 # - global, public : snake_case
10 # -----------------------------------------------------------------------------
12 # -----------------------------------------------------------------------------
18 $
2 ==
"khatus_sensor_datetime" {
19 # Code for bar_make_status is expected to be passed as an
20 # additional source file, using -f flag.
21 msg_out_ok
("status_bar", bar_make_status
())
25 # -----------------------------------------------------------------------------
27 # -----------------------------------------------------------------------------
29 function bar_make_status_energy_percent
() {
30 return cache_get_fmt_def
("khatus_sensor_energy", "battery_percentage", 0, "%d")
33 function bar_make_status_energy_direction
( state
, direction_of_change
) {
34 cache_get
(state
, "khatus_sensor_energy", "battery_state", 0)
35 if (state
["value"] ==
"discharging") {
36 direction_of_change =
"<"
37 } else if (state
["value"] ==
"charging") {
38 direction_of_change =
">"
40 direction_of_change =
"="
42 return direction_of_change
45 # -----------------------------------------------------------------------------
47 # -----------------------------------------------------------------------------
49 function bar_make_status_mem_percent
( total
, used
, percent
, percent_str
) {
50 cache_get
(total
, "khatus_sensor_memory", "total", 5)
51 cache_get
(used
, "khatus_sensor_memory", "used" , 5)
52 # Checking total["value"] to avoid division by zero when data is missing
53 if (!total
["is_expired"] && \
54 !used
["is_expired"] && \
57 percent = util_round
((used
["value"] / total
["value"]) * 100)
58 percent_str =
sprintf("%d", percent
)
65 # -----------------------------------------------------------------------------
67 # -----------------------------------------------------------------------------
69 # D uninterruptible sleep (usually IO)
70 # R running or runnable (on run queue)
71 # S interruptible sleep (waiting for an event to complete)
72 # T stopped by job control signal
73 # t stopped by debugger during the tracing
74 # W paging (not valid since the 2.6.xx kernel)
75 # X dead (should never be seen)
76 # Z defunct ("zombie") process, terminated but not reaped by its parent
78 # Additionally, not documented in ps man page:
81 function bar_make_status_procs_count_all
() {
82 return cache_get_fmt_def
("khatus_sensor_procs", "total_procs", 15, "%d")
85 function bar_make_status_procs_count_r
( src
) {
86 src =
"khatus_sensor_procs"
87 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"R", 15, "%d", "0")
90 function bar_make_status_procs_count_d
( src
) {
91 src =
"khatus_sensor_procs"
92 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"D", 15, "%d", "0")
95 function bar_make_status_procs_count_t
( src
) {
96 src =
"khatus_sensor_procs"
97 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"T", 15, "%d", "0")
100 function bar_make_status_procs_count_i
( src
) {
101 src =
"khatus_sensor_procs"
102 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"I", 15, "%d", "0")
105 function bar_make_status_procs_count_z
( src
) {
106 src =
"khatus_sensor_procs"
107 return cache_get_fmt_def
(src
, "total_per_state" Kfs
"Z", 15, "%d", "0")
110 # -----------------------------------------------------------------------------
112 # -----------------------------------------------------------------------------
114 function bar_make_status_cpu_loadavg
( src
) {
115 src =
"khatus_sensor_loadavg"
116 return cache_get_fmt_def
(src
, "load_avg_1min", 5, "%4.2f")
119 function bar_make_status_cpu_temperature
() {
120 return cache_get_fmt_def
("khatus_sensor_temperature", "temp_c", 5, "%d")
123 function bar_make_status_cpu_fan_speed
() {
124 return cache_get_fmt_def
("khatus_sensor_fan", "speed", 5, "%4d")
127 # -----------------------------------------------------------------------------
129 # -----------------------------------------------------------------------------
131 function bar_make_status_disk_space
( src
) {
132 src =
"khatus_sensor_disk_space"
133 return cache_get_fmt_def
(src
, "disk_usage_percentage", 10, "%s")
136 function bar_make_status_disk_io_w
( src
) {
137 src =
"khatus_sensor_disk_io"
138 return cache_get_fmt_def
(src
, "sectors_written", 5, "%0.3f")
141 function bar_make_status_disk_io_r
( src
) {
142 src =
"khatus_sensor_disk_io"
143 return cache_get_fmt_def
(src
, "sectors_read", 5, "%0.3f")
146 # -----------------------------------------------------------------------------
148 # -----------------------------------------------------------------------------
150 function bar_make_status_net_addr
(interface
, src
) {
151 src =
"khatus_sensor_net_addr_io"
152 return cache_get_fmt_def
(src
, "addr" Kfs interface
, 5, "%s", "")
155 function bar_make_status_net_io_w
(interface
, src
) {
156 src =
"khatus_sensor_net_addr_io"
157 return cache_get_fmt_def
(src
, "bytes_written" Kfs interface
, 5, "%0.3f")
160 function bar_make_status_net_io_r
(interface
, src
) {
161 src =
"khatus_sensor_net_addr_io"
162 return cache_get_fmt_def
(src
, "bytes_read" Kfs interface
, 5, "%0.3f")
165 function bar_make_status_net_wifi
(interface
, src
) {
166 src =
"khatus_sensor_net_wifi_status"
167 return cache_get_fmt_def
(src
, "status" Kfs interface
, 10, "%s")
170 # -----------------------------------------------------------------------------
172 # -----------------------------------------------------------------------------
174 function bar_make_status_bluetooth_power
( src
) {
175 src =
"khatus_sensor_bluetooth_power"
176 return cache_get_fmt_def
(src
, "power_status", 10, "%s")
179 # -----------------------------------------------------------------------------
180 # Backlight (screen brightness)
181 # -----------------------------------------------------------------------------
183 function bar_make_status_backlight_percent
( src
) {
184 src =
"khatus_sensor_screen_brightness"
185 return cache_get_fmt_def
(src
, "percentage", 5, "%d")
188 # -----------------------------------------------------------------------------
190 # -----------------------------------------------------------------------------
192 function bar_make_status_volume_pulseaudio_sink
(sink
, mu
, vl
, vr
, show
) {
193 cache_get
(mu
, "khatus_sensor_volume", "mute" Kfs sink
, 5)
194 cache_get
(vl
, "khatus_sensor_volume", "vol_left" Kfs sink
, 5)
195 cache_get
(vr
, "khatus_sensor_volume", "vol_right" Kfs sink
, 5)
197 if (!mu
["is_expired"] && !vl
["is_expired"] && !vr
["is_expired"]) {
198 if (mu
["value"] ==
"yes") {show =
"X"}
199 else if (mu
["value"] ==
"no") {show = vl
["value"] " " vr
["value"]}
202 "bar_make_status_volume_pulseaudio_sink: " sink
". ", \
203 "Unexpected value for 'mute' field: " mu
["value"] \
210 # -----------------------------------------------------------------------------
212 # -----------------------------------------------------------------------------
214 function bar_make_status_mpd
( state
, status
) {
215 cache_get
(state
, "khatus_sensor_mpd", "state", 5)
216 if (!state
["is_expired"] && state
["value"]) {
217 if (state
["value"] ==
"play") {
218 status = bar_make_status_mpd_state_known
("▶")
219 } else if (state
["value"] ==
"pause") {
220 status = bar_make_status_mpd_state_known
("❚❚")
221 } else if (state
["value"] ==
"stop") {
222 status = bar_make_status_mpd_state_known
("⬛")
225 "bar_make_status_mpd", \
226 "Unexpected value for 'state' field: " state
["value"] \
236 function bar_make_status_mpd_state_known
(symbol
, s
, song
, time
, percentage
) {
237 s =
"khatus_sensor_mpd"
238 song = cache_get_fmt_def
(s
, "song" , 5, "%s", "?")
239 time = cache_get_fmt_def
(s
, "play_time_minimal_units", 5, "%s", "?")
240 percent = cache_get_fmt_def
(s
, "play_time_percentage" , 5, "%s", "?")
241 song =
substr(song
, 1, Opt_Mpd_Song_Max_Chars
)
242 return sprintf("%s %s %s %s", symbol
, time
, percent
, song
)
245 # -----------------------------------------------------------------------------
247 # -----------------------------------------------------------------------------
249 function bar_make_status_weather_temp_f
( src
, hour
) {
250 src =
"khatus_sensor_weather"
252 return cache_get_fmt_def
(src
, "temperature_f", 3 * hour
, "%d")
255 # -----------------------------------------------------------------------------
257 # -----------------------------------------------------------------------------
259 function bar_make_status_datetime
( dt
) {
260 return cache_get_fmt_def
("khatus_sensor_datetime", "datetime", 5, "%s")