~whynothugo/dotfiles

ref: adf6af99 dotfiles/home/.local/lib/waybar-mic -rwxr-xr-x 1.3 KiB
adf6af99Hugo Osvaldo Barrera waybar: Typo in comment 5 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/sh
#
# Helper for waybar to show current mic status.
#
# This shows a small icon with the current microphone status in the taskbar. I
# use a global hotkey (Super+M) to control the microphone, so I don't have to
# remember a different muting hotkey for each [web] application. It also makes
# it easier to make sure I'm muted when handling multiple things at once.
#
# Waybar's CSS is set so that an open mic is a RED icon, and it's less flashy
# when the mic is muted.
#
# It might make sense to hide the module if no microphone is unmuted. This
# depends on: https://github.com/Alexays/Waybar/issues/699
#
# TODO: If a non-primary microphone is on, that should somehow be reflected.

show() {
  # Prints the current micrphone state.

  if ponymix --source is-muted; then
    CLASS="muted"
    TEXT=""
  else
    CLASS="not-muted"
    TEXT=""
  fi

  jq --compact-output \
    --null-input \
    --arg text "$TEXT" \
    --arg class "$CLASS" \
    '{"text": $text, "class": $class}'
}

monitor() {
  # Monitors for changes in microphone state.

  pactl subscribe | /usr/bin/grep --line-buffered "'change' on source" |
    while read -r _; do
      show
    done
  exit
}

show  # Print once, so that the right state is shown at startup.
monitor  # Update whenever pactl indicates there's been a change.