diff --git a/README.md b/README.md index 0f2e198..3b41a54 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# Credits +This is a fork of https://gitlab.com/Nmoleo/i3-volume-brightness-indicator + +The microphone control is based on https://gitlab.com/rituparnaw16/i3-volume-brightness-indicator/-/blob/main/volume_brightness.sh?ref_type=heads + # Windows-Style Media & Brightness Notifications using Dunst ![](images/1.png) @@ -20,27 +25,28 @@ This is a Bash script that uses Dunst to show an indicator on the screen when th ## Installation -1. Verify that all of the dependancies are installed -2. Copy `volume_brightness.sh` to a folder on your computer -3. Edit `~/.config/dunst/dunstrc` -4. Under the `[global]` section, add `Font Awesome 5 Free Regular` -5. Change `origin` to `bottom-center` or your desired location -6. Edit `~/.config/i3/config` -7. Add the following lines: - ``` - bindsym XF86AudioRaiseVolume exec --no-startup-id /path/to/volume_brightness.sh volume_up - bindsym XF86AudioLowerVolume exec --no-startup-id /path/to/volume_brightness.sh volume_down - bindsym XF86AudioMute exec --no-startup-id /path/to/volume_brightness.sh volume_mute - bindsym XF86MonBrightnessUp exec --no-startup-id /path/to/volume_brightness.sh brightness_up - bindsym XF86MonBrightnessDown exec --no-startup-id /path/to/volume_brightness.sh brightness_down - bindsym XF86AudioPlayPause exec --no-startup-id /path/to/volume_brightness.sh play_pause - bindsym XF86AudioPause exec --no-startup-id /path/to/volume_brightness.sh play_pause - bindsym XF86AudioPlay exec --no-startup-id /path/to/volume_brightness.sh play_pause - bindsym XF86AudioNext exec --no-startup-id /path/to/volume_brightness.sh next_track - bindsym XF86AudioPrev exec --no-startup-id /path/to/volume_brightness.sh prev_track - ``` -8. Replace `/path/to/volume_brightness.sh` with the correct path to the script -9. Edit `volume_brightness.sh` and set your desired values for the configuration options at the top +1. Verify that all of the dependencies are installed +2. Edit `media-control` and set your desired values for the configuration options at the top +3. Copy `media-control` to a directory on your PATH +4. Edit `~/.config/dunst/dunstrc` +5. Under the `[global]` section, add `Font Awesome 5 Free Regular` +6. Change `origin` to `bottom-center` or your desired location + +For i3 keybindings: +1. Edit `~/.config/i3/config` +2. Add the following lines: + ``` + bindsym XF86AudioRaiseVolume exec --no-startup-id media-control volume_up + bindsym XF86AudioLowerVolume exec --no-startup-id media-control volume_down + bindsym XF86AudioMute exec --no-startup-id media-control volume_mute + bindsym XF86MonBrightnessUp exec --no-startup-id media-control brightness_up + bindsym XF86MonBrightnessDown exec --no-startup-id media-control brightness_down + bindsym XF86AudioPlayPause exec --no-startup-id media-control play_pause + bindsym XF86AudioPause exec --no-startup-id media-control play_pause + bindsym XF86AudioPlay exec --no-startup-id media-control play_pause + bindsym XF86AudioNext exec --no-startup-id media-control next_track + bindsym XF86AudioPrev exec --no-startup-id media-control prev_track + ``` ## Configuration Reference diff --git a/volume_brightness.sh b/media-control similarity index 67% rename from volume_brightness.sh rename to media-control index 1a8d0ce..b40e4a7 100755 --- a/volume_brightness.sh +++ b/media-control @@ -1,10 +1,14 @@ #!/bin/bash +# github https://github.com/Shringe/dunst-media-control + # See README.md for usage instructions -volume_step=1 +volume_step=5 +mic_volume_step=5 brightness_step=5 max_volume=100 -notification_timeout=1000 +mic_max_volume=100 +notification_timeout=1000 # in milliseconds download_album_art=true show_album_art=true show_music_in_volume_indicator=true @@ -19,9 +23,24 @@ function get_mute { pactl get-sink-mute @DEFAULT_SINK@ | grep -Po '(?<=Mute: )(yes|no)' } +# Uses regex to get mic volume from pactl +function get_mic_volume { + pactl get-source-volume @DEFAULT_SOURCE@ | grep -Po '[0-9]{1,3}(?=%)' | head -1 +} + +# Gets mic mute status +function get_mic_mute { + pactl get-source-mute @DEFAULT_SOURCE@ | grep -Po '(?<=Mute: )(yes|no)' +} + # Uses regex to get brightness from xbacklight function get_brightness { - sudo light | grep -Po '[0-9]{1,3}' | head -n 1 + declare -i absb + declare -i relb + absb=$(brightnessctl g) + maxb=$(brightnessctl m) + absb=$(( absb * 100 )) + echo $(( absb / maxb )) } # Returns a mute icon, a volume-low icon, or a volume-high icon, depending on the volume @@ -29,11 +48,21 @@ function get_volume_icon { volume=$(get_volume) mute=$(get_mute) if [ "$volume" -eq 0 ] || [ "$mute" == "yes" ] ; then - volume_icon="" + volume_icon="🔇" elif [ "$volume" -lt 50 ]; then - volume_icon="" + volume_icon=" " + else + volume_icon=" " + fi +} + +# Returns mute or unmute mic icon depending on mute status +function get_mic_icon { + mute=$(get_mic_mute) + if [ "$mute" == "yes" ] ; then + mic_icon="🎙️/" else - volume_icon="" + mic_icon="🎙️" fi } @@ -82,7 +111,6 @@ function show_volume_notif { if [[ $show_album_art == "true" ]]; then get_album_art fi - notify-send -t $notification_timeout -h string:x-dunst-stack-tag:volume_notif -h int:value:$volume -i "$album_art" "$volume_icon $volume%" "$current_song" else notify-send -t $notification_timeout -h string:x-dunst-stack-tag:volume_notif -h int:value:$volume "$volume_icon $volume%" @@ -98,20 +126,27 @@ function show_music_notif { if [[ $show_album_art == "true" ]]; then get_album_art fi - notify-send -t $notification_timeout -h string:x-dunst-stack-tag:music_notif -i "$album_art" "$song_title" "$song_artist - $song_album" } +# Displays mic notification +function show_mic_notif { + volume=$(get_mic_volume) + get_mic_icon + + notify-send -t $notification_timeout -h string:x-dunst-stack-tag:mic_volume_notif -h int:value:$volume "$mic_icon $volume%" +} + # Displays a brightness notification using dunstify function show_brightness_notif { brightness=$(get_brightness) - echo $brightness get_brightness_icon notify-send -t $notification_timeout -h string:x-dunst-stack-tag:brightness_notif -h int:value:$brightness "$brightness_icon $brightness%" } # Main function - Takes user input, "volume_up", "volume_down", "brightness_up", or "brightness_down" case $1 in + # Volume ============================================================= volume_up) # Unmutes and increases volume, then displays the notification pactl set-sink-mute @DEFAULT_SINK@ 0 @@ -125,7 +160,7 @@ case $1 in ;; volume_down) - # Raises volume and displays the notification + # Lowers volume and displays the notification pactl set-sink-volume @DEFAULT_SINK@ -$volume_step% show_volume_notif ;; @@ -136,18 +171,20 @@ case $1 in show_volume_notif ;; + # Brightness ========================================================= brightness_up) # Increases brightness and displays the notification - sudo light -A $brightness_step + brightnessctl s +$brightness_step% show_brightness_notif ;; brightness_down) # Decreases brightness and displays the notification - sudo light -U $brightness_step + brightnessctl s $brightness_step%- show_brightness_notif ;; + # Media keys ========================================================= next_track) # Skips to the next song and displays the notification playerctl next @@ -161,8 +198,33 @@ case $1 in ;; play_pause) + # Pauses/resumes playback and displays the notification playerctl play-pause show_music_notif - # Pauses/resumes playback and displays the notification + ;; + + # Microphone ========================================================= + mic_up) + # Unmutes and increases volume, then displays the notification + pactl set-source-mute @DEFAULT_SOURCE@ 0 + + mic_volume=$(get_mic_volume) + if [ $(( "$mic_volume" + "$mic_volume_step" )) -gt $mic_max_volume ]; then + pactl set-source-volume @DEFAULT_SOURCE@ $mic_max_volume% + else + pactl set-source-volume @DEFAULT_SOURCE@ +$mic_volume_step% + fi + show_mic_notif + ;; + + mic_down) + # Lowers volume and displays the notification + pactl set-source-volume @DEFAULT_SOURCE@ -$mic_volume_step% + show_mic_notif + ;; + + mic_mute) + pactl set-source-mute @DEFAULT_SOURCE@ toggle + show_mic_notif ;; esac