From: Siraaj Khandkar Date: Sat, 8 Dec 2018 17:53:06 +0000 (-0500) Subject: Index volume by alsa.device property X-Git-Url: https://git.xandkar.net/?a=commitdiff_plain;h=0c4f892ec9d0cd7dc87c83c01b52259d0aed1ae3;p=khatus.git Index volume by alsa.device property instead of pulseaudio sink number, which keeps changing upon plugging/unplugging of speakers --- diff --git a/README.md b/README.md index 35f8d30..6e755a9 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ In my `~/.xinitrc` I have something like the following: -v GC_Interval=1800 \ -f <("$BIN"/khatus_gen_bar_make_status \ -v Status_Fmt=' E=%s%% M=%d%% P=[%s %sr %sd %st %si %sz] C=[%s %s°C %srpm] D=[%s%% %s▲ %s▼] W=[%s %s▲ %s▼] B=%s *=%s%% (%s) [%s] %s°F %s ' \ - -v Status_Args='@energy_percent,@memory_percent,@processes_count_all,@processes_count_r,@processes_count_d,@processes_count_t,@processes_count_i,@processes_count_z,@cpu_loadavg,@cpu_temp,@cpu_fan_speed,@disk_space,@disk_io_w,@disk_io_r,@net_wifi:wlp3s0,@net_io_w:wlp3s0,@net_io_r:wlp3s0,@bluetooth_power,@backlight_percent,@volume_pa_sink:0,@mpd,@weather_temp_f,@datetime' \ + -v Status_Args='@energy_percent,@memory_percent,@processes_count_all,@processes_count_r,@processes_count_d,@processes_count_t,@processes_count_i,@processes_count_z,@cpu_loadavg,@cpu_temp,@cpu_fan_speed,@disk_space,@disk_io_w,@disk_io_r,@net_wifi:wlp3s0,@net_io_w:wlp3s0,@net_io_r:wlp3s0,@bluetooth_power,@backlight_percent,@volume_pa_device:0,@mpd,@weather_temp_f,@datetime' \ ) \ | "$BIN"/khatus_actuate_status_bar_to_xsetroot_name \ ) \ diff --git a/sanity_check b/sanity_check index 8fb8a8a..ef95ef6 100755 --- a/sanity_check +++ b/sanity_check @@ -2,7 +2,8 @@ ./bin/khatus \ --dir_bin ./bin \ - --wifi_interface wlp3s0 \ + --wifi_interface wlp4s0 \ + --screen_brightness_device_name intel_backlight \ | stdbuf -o L tee \ >(stdbuf -o L ./bin/khatus_bar \ -v Opt_Mpd_Song_Max_Chars=10 \ @@ -10,7 +11,7 @@ -v GC_Interval=300 \ -f <(./bin/khatus_gen_bar_make_status \ -v Status_Fmt=' E=%s%% M=%d%% P=[%s %sr %sd %st %si %sz] C=[%s %s°C %srpm] D=[%s%% %s▲ %s▼] W=[%s %s▲ %s▼] B=%s *=%s%% (%s) [%s] %s°F %s ' \ - -v Status_Args='@energy_percent,@memory_percent,@processes_count_all,@processes_count_r,@processes_count_d,@processes_count_t,@processes_count_i,@processes_count_z,@cpu_loadavg,@cpu_temp,@cpu_fan_speed,@disk_space,@disk_io_w,@disk_io_r,@net_wifi:wlp3s0,@net_io_w:wlp3s0,@net_io_r:wlp3s0,@bluetooth_power,@backlight_percent,@volume_pa_sink:0,@mpd,@weather_temp_f,@datetime' \ + -v Status_Args='@energy_percent,@memory_percent,@processes_count_all,@processes_count_r,@processes_count_d,@processes_count_t,@processes_count_i,@processes_count_z,@cpu_loadavg,@cpu_temp,@cpu_fan_speed,@disk_space,@disk_io_w,@disk_io_r,@net_wifi:wlp4s0,@net_io_w:wlp4s0,@net_io_r:wlp4s0,@bluetooth_power,@backlight_percent,@volume:0,@mpd,@weather_temp_f,@datetime' \ ) \ ) \ >(stdbuf -o L ./bin/khatus_cache_dumper $(hostname) 5 "$PWD/data") \ diff --git a/src/awk/exe/bar.awk b/src/awk/exe/bar.awk index b902448..bd37305 100644 --- a/src/awk/exe/bar.awk +++ b/src/awk/exe/bar.awk @@ -194,17 +194,17 @@ function bar_make_status_backlight_percent( src) { # Volume # ----------------------------------------------------------------------------- -function bar_make_status_volume_pulseaudio_sink(sink, mu, vl, vr, show) { - cache_get(mu, "khatus_sensor_volume", "mute" Kfs sink, 5) - cache_get(vl, "khatus_sensor_volume", "vol_left" Kfs sink, 5) - cache_get(vr, "khatus_sensor_volume", "vol_right" Kfs sink, 5) +function bar_make_status_volume_alsa_device(device, mu, vl, vr, show) { + cache_get(mu, "khatus_sensor_volume", "mute" Kfs device, 5) + cache_get(vl, "khatus_sensor_volume", "vol_left" Kfs device, 5) + cache_get(vr, "khatus_sensor_volume", "vol_right" Kfs device, 5) show = "--" if (!mu["is_expired"] && !vl["is_expired"] && !vr["is_expired"]) { if (mu["value"] == "yes") {show = "X"} else if (mu["value"] == "no") {show = vl["value"] " " vr["value"]} else { msg_out_log_error(\ - "bar_make_status_volume_pulseaudio_sink: " sink ". ", \ + "bar_make_status_volume_alsa_device: " device ". ", \ "Unexpected value for 'mute' field: " mu["value"] \ ) } diff --git a/src/awk/exe/gen_bar_make_status.awk b/src/awk/exe/gen_bar_make_status.awk index 7c34148..63b5e5b 100644 --- a/src/awk/exe/gen_bar_make_status.awk +++ b/src/awk/exe/gen_bar_make_status.awk @@ -34,8 +34,8 @@ BEGIN { aliases["@backlight_percent"] = "bar_make_status_backlight_percent()" - aliases["@volume_pa_sink"] = "bar_make_status_volume_pulseaudio_sink(%d)" - params["@volume_pa_sink"] = 1 + aliases["@volume"] = "bar_make_status_volume_alsa_device(%d)" + params["@volume"] = 1 aliases["@mpd"] = "bar_make_status_mpd()" diff --git a/src/awk/exe/parse_pactl_list_sinks.awk b/src/awk/exe/parse_pactl_list_sinks.awk index 6a2a4a1..017a17e 100644 --- a/src/awk/exe/parse_pactl_list_sinks.awk +++ b/src/awk/exe/parse_pactl_list_sinks.awk @@ -4,6 +4,14 @@ next } +/^\t[A-Z].+:/ { + section = $1 +} + +section == "Properties:" { + read_property() +} + /\tState:/ { state[sink] = $2 next @@ -32,9 +40,21 @@ END { for (sink in state) { - print("state" Kfs sink, state[sink]) - print("mute" Kfs sink, mute[sink]) - print("vol_left" Kfs sink, vol_left[sink]) - print("vol_right" Kfs sink, vol_right[sink]) + device = properties[sink, "alsa.device"] + print("state" Kfs device, state[sink]) + print("mute" Kfs device, mute[sink]) + print("vol_left" Kfs device, vol_left[sink]) + print("vol_right" Kfs device, vol_right[sink]) } } + +function read_property() { + key = $1 + # Yes, the sequence (x-1+1) is redundant, but it keeps the variable names + # true to their meaning: + val_begin = index($0, "\"") + 1 # +1 to exclude first quote + val_end = length($0) - 1 # -1 to exclude last quote + val_len = (val_end - val_begin) + 1 # +1 to include final character + val = substr($0, val_begin, val_len) + properties[sink, key] = val +}