From c7a86f0fb9cf5678537f4427958ee685885683e5 Mon Sep 17 00:00:00 2001 From: Siraaj Khandkar Date: Thu, 28 Mar 2019 06:55:01 -0400 Subject: [PATCH] Just use default pulseaudio sink for volume --- x2/sanity_check | 2 +- x2/src/awk/exe/bar.awk | 10 +++---- x2/src/awk/exe/gen_bar_make_status.awk | 3 +- x2/src/awk/exe/parse_pactl_list_sinks.awk | 36 ++++++++--------------- x2/src/bash/exe/khatus_sensor_volume.sh | 4 ++- 5 files changed, 22 insertions(+), 33 deletions(-) diff --git a/x2/sanity_check b/x2/sanity_check index a6783d6..0f028a6 100755 --- a/x2/sanity_check +++ b/x2/sanity_check @@ -11,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▲ %s▼] E:%s:%s B=[%s %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_link:wlp4s0,@net_wifi:wlp4s0,@net_io_w:wlp4s0,@net_io_r:wlp4s0,@net_iface_status:enp0s31f6,@net_addr:enp0s31f6,@bluetooth_power,@bluetooth,@backlight_percent,@volume: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_link:wlp4s0,@net_wifi:wlp4s0,@net_io_w:wlp4s0,@net_io_r:wlp4s0,@net_iface_status:enp0s31f6,@net_addr:enp0s31f6,@bluetooth_power,@bluetooth,@backlight_percent,@volume,@mpd,@weather_temp_f,@datetime' \ ) \ ) \ >(stdbuf -o L ./bin/khatus_monitor_energy) \ diff --git a/x2/src/awk/exe/bar.awk b/x2/src/awk/exe/bar.awk index 1868f0e..48e00f2 100644 --- a/x2/src/awk/exe/bar.awk +++ b/x2/src/awk/exe/bar.awk @@ -220,10 +220,10 @@ function bar_make_status_backlight_percent( src) { # Volume # ----------------------------------------------------------------------------- -function bar_make_status_volume_alsa_device(device, m, l, r, show) { - cache_get(m, "khatus_sensor_volume", "mute" Kfs device, 5) - cache_get(l, "khatus_sensor_volume", "vol_left" Kfs device, 5) - cache_get(r, "khatus_sensor_volume", "vol_right" Kfs device, 5) +function bar_make_status_volume( m, l, r, show) { + cache_get(m, "khatus_sensor_volume", "mute" , 5) + cache_get(l, "khatus_sensor_volume", "vol_left" , 5) + cache_get(r, "khatus_sensor_volume", "vol_right" , 5) show = "--" if (!m["is_expired"] && !l["is_expired"] && !r["is_expired"]) { if (m["value"] == "yes") @@ -232,7 +232,7 @@ function bar_make_status_volume_alsa_device(device, m, l, r, show) { show = l["value"] #" " r["value"] else msg_out_log_error(\ - "bar_make_status_volume_alsa_device: " device ". ", \ + "bar_make_status_volume", \ "Unexpected value for 'mute' field: " m["value"] \ ) } diff --git a/x2/src/awk/exe/gen_bar_make_status.awk b/x2/src/awk/exe/gen_bar_make_status.awk index ea82f09..80cbc6f 100644 --- a/x2/src/awk/exe/gen_bar_make_status.awk +++ b/x2/src/awk/exe/gen_bar_make_status.awk @@ -39,8 +39,7 @@ BEGIN { aliases["@backlight_percent"] = "bar_make_status_backlight_percent()" - aliases["@volume"] = "bar_make_status_volume_alsa_device(%d)" - params["@volume"] = 1 + aliases["@volume"] = "bar_make_status_volume()" aliases["@mpd"] = "bar_make_status_mpd()" diff --git a/x2/src/awk/exe/parse_pactl_list_sinks.awk b/x2/src/awk/exe/parse_pactl_list_sinks.awk index 017a17e..5177d72 100644 --- a/x2/src/awk/exe/parse_pactl_list_sinks.awk +++ b/x2/src/awk/exe/parse_pactl_list_sinks.awk @@ -4,19 +4,16 @@ next } -/^\t[A-Z].+:/ { - section = $1 -} - -section == "Properties:" { - read_property() -} - /\tState:/ { state[sink] = $2 next } +/\tName:/ { + name[sink] = $2 + next +} + /\tMute:/ { mute[sink] = $2 next @@ -40,21 +37,12 @@ section == "Properties:" { END { for (sink in state) { - 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]) + # default_sink set via CLI + if (name[sink] == default_sink) { + print("state" , state[sink]) + print("mute" , mute[sink]) + print("vol_left" , vol_left[sink]) + print("vol_right" , 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 -} diff --git a/x2/src/bash/exe/khatus_sensor_volume.sh b/x2/src/bash/exe/khatus_sensor_volume.sh index 6f69829..a5f6c64 100644 --- a/x2/src/bash/exe/khatus_sensor_volume.sh +++ b/x2/src/bash/exe/khatus_sensor_volume.sh @@ -4,4 +4,6 @@ set -e dir_bin="$1" -pactl list sinks | "$dir_bin"/khatus_parse_pactl_list_sinks +pactl list sinks \ +| "$dir_bin"/khatus_parse_pactl_list_sinks \ + -v default_sink="$(pactl info | awk '/^Default Sink:/ {print $3}')" -- 2.20.1