From: Siraaj Khandkar Date: Wed, 29 Aug 2018 15:09:29 +0000 (-0400) Subject: Implement user-selected status bar components X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=ab9fe663178272812f83e496c428813e3611368f;p=khatus.git Implement user-selected status bar components --- diff --git a/README.md b/README.md index f95d159..169b7d2 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ In my `~/.xinitrc` I have something like the following: -v Opt_Mpd_Song_Max_Chars=10 \ -v Opt_Net_Interfaces_To_Show=wlp3s0 \ -v Opt_Pulseaudio_Sink=0 \ + -f <(./bin/khatus_gen_make_status_bar \ + -v Status_Bar='@energy,@memory,@processes,@cpu,@disk,@net,@bluetooth,@backlight,@volume,@mpd,@weather,@datetime' \ + ) \ | "$BIN"/khatus_actuate_status_bar_to_xsetroot_name \ ) \ >(stdbuf -o L "$BIN"/khatus_monitor_energy \ diff --git a/bin/khatus_bar b/bin/khatus_bar index 6fa05ba..b1e9e36 100755 --- a/bin/khatus_bar +++ b/bin/khatus_bar @@ -45,6 +45,8 @@ $1 == "OK" { $1 == "OK" && \ $2 == "khatus_sensor_datetime" { + # Code for make_status_bar definition is expected to be passed as an + # additional source file, using -f flag. print_msg_ok("status_bar", make_status_bar()) } @@ -141,30 +143,6 @@ function cache_maybe_scale(src, key, val, key_parts) { # Status bar # ----------------------------------------------------------------------------- -function make_status_bar( position, bar, sep, i, j) { - position[++i] = "" - position[++i] = make_status_energy() - position[++i] = make_status_mem() - position[++i] = make_status_procs() - position[++i] = make_status_cpu() - position[++i] = make_status_disk() - position[++i] = make_status_net() - position[++i] = make_status_bluetooth() - position[++i] = make_status_screen_brightness() - position[++i] = make_status_volume() - position[++i] = make_status_mpd() - position[++i] = make_status_weather() - position[++i] = make_status_datetime() - position[++i] = "" - bar = "" - sep = "" - for (j = 1; j <= i; j++) { - bar = bar sep position[j] - sep = " " - } - return bar -} - function make_status_energy( state, charge, direction_of_change) { cache_get(state , "khatus_sensor_energy", "battery_state" , 0) cache_get(charge, "khatus_sensor_energy", "battery_percentage", 0) diff --git a/bin/khatus_gen_make_status_bar b/bin/khatus_gen_make_status_bar new file mode 100755 index 0000000..50e1b03 --- /dev/null +++ b/bin/khatus_gen_make_status_bar @@ -0,0 +1,39 @@ +#! /usr/bin/awk -f + +BEGIN { + aliases["@energy"] = "make_status_energy()" + aliases["@memory"] = "make_status_mem()" + aliases["@processes"] = "make_status_procs()" + aliases["@cpu"] = "make_status_cpu()" + aliases["@disk"] = "make_status_disk()" + aliases["@net"] = "make_status_net()" + aliases["@bluetooth"] = "make_status_bluetooth()" + aliases["@backlight"] = "make_status_screen_brightness()" + aliases["@volume"] = "make_status_volume()" + aliases["@mpd"] = "make_status_mpd()" + aliases["@weather"] = "make_status_weather()" + aliases["@datetime"] = "make_status_datetime()" + out = "function make_status_bar( position, bar, sep, i, j) {\n" + n = split(Status_Bar, s, ",") + for (i=1; i<=n; i++) { + alias = s[i] + function_call = aliases[alias] + if (function_call) { + out = out " position[++i] = " function_call ";\n" + } else { + printf("Unexpected status bar component alias: \"%s\"\n", alias) \ + > "/dev/stderr" + exit(1) + } + } + out = out "\ + bar = \"\";\ + sep = \"\";\ + for (j = 1; j <= i; j++) {\ + bar = bar sep position[j];\ + sep = \" \";\ + }\ + return bar;\ + }"; + print out +} diff --git a/sanity_check b/sanity_check index 8b7f969..b9022a1 100755 --- a/sanity_check +++ b/sanity_check @@ -9,6 +9,9 @@ -v Opt_Net_Interfaces_To_Show=wlp3s0 \ -v Opt_Pulseaudio_Sink=0 \ -v GC_Interval=300 \ + -f <(./bin/khatus_gen_make_status_bar \ + -v Status_Bar='@energy,@memory,@processes,@cpu,@disk,@net,@bluetooth,@backlight,@volume,@mpd,@weather,@datetime' \ + ) \ ) \ >(stdbuf -o L ./bin/khatus_monitor_energy) \ >(stdbuf -o L ./bin/khatus_monitor_errors) \