i3: get the current pulseaudio sink before adjusting volume

Adjusted from Jens Erat from
https://faq.i3wm.org/question/125/how-to-change-the-systems-volume.1.html

According to a comment this only works when something is playing, but I
think that is the only case when I need volume keys and is improvement
over it stopping working with volume devices changing. The proposed
cutting running again resulted to three devices being listed and thus
doesn't work.

I also have the volumeicon which I can use to adjust volume if I really
need to while there is nothing playing.
This commit is contained in:
Aminda Suomalainen 2019-02-05 00:09:46 +02:00
parent 0afc716ccf
commit e8dfc6a726
No known key found for this signature in database
GPG Key ID: 0C207F07B2F32B67

View File

@ -175,14 +175,17 @@ bindsym $mod+Escape exec "i3lock; sudo /usr/sbin/hibernate"
# Microsoft Wired Keyboard 600 # Microsoft Wired Keyboard 600
bindsym XF86AudioPlay exec --no-startup-id playerctl play-pause bindsym XF86AudioPlay exec --no-startup-id playerctl play-pause
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume 0 -5%
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume 0 +5%
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute 0 toggle # mute sound
#bindsym XF86Search #bindsym XF86Search
# unknown key here looking like a share button? XF86Community ? # unknown key here looking like a share button? XF86Community ?
#bindsym XF86Display #bindsym XF86Display
# unknown key, likely XF86BrightnessAdjust as it's a sun, but could be XF86ContrastAdjust # unknown key, likely XF86BrightnessAdjust as it's a sun, but could be XF86ContrastAdjust
bindsym XF86Calculator exec --no-startup-id galculator bindsym XF86Calculator exec --no-startup-id galculator
# Volume keys NOTE: won't work if nothing is playing (which I consider an improvement
# over randomly stopping working as I enable and disable audio devices).
set $sink $(pactl list short sinks | grep RUNNING | cut -f1)
bindsym XF86AudioLowerVolume exec --no-startup-id pactl set-sink-volume $sink -5%
bindsym XF86AudioRaiseVolume exec --no-startup-id pactl set-sink-volume $sink +5%
bindsym XF86AudioMute exec --no-startup-id pactl set-sink-mute $sink toggle # mute sound
# Float these apps by default # Float these apps by default
for_window [title="^Mozilla Firefox$"] floating enable for_window [title="^Mozilla Firefox$"] floating enable