You are not logged in.

#1 2017-07-17 22:31:52

ralph_13
Member
Registered: 2015-02-06
Posts: 73

[SOLVED] Reliable way to set volume from fn keys with pulseaudio?

Both pulseaudio-ctl and pavolume are very slow for me, there's a huge delay that starts to build up when I'm raising or lowering the volume that ends up with the volume still going up/down several seconds after I stopped pressing the keys. Besides that, both of them send a new notifications for each time I press the key, clogging up my desktop instead of a single one that gets updated with each keypress.

pnmixer works fine, but since it's not supposed to be compatible with pulse, there are some limitations, such as being unable to raise the volume above 100% and unmuting does not work.

So, how do you guys have it set up? I couldn't find any other ways besides using pactl, but that doesn't send any notifications at all as far as I know.

Thanks for any info on this

Last edited by ralph_13 (2017-07-20 03:51:41)

Offline

#2 2017-07-18 03:24:12

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [SOLVED] Reliable way to set volume from fn keys with pulseaudio?

ralph_13 wrote:

pnmixer works fine, but since it's not supposed to be compatible with pulse, there are some limitations, such as being unable to raise the volume above 100% and unmuting does not work.

I guess you mean pamixer, I don't know any pnmixer. pamixer supports mute/unmute. Volume is limited to 100%, which is acutally good for me, as my little speakers don't work well with high volumes.

ralph_13 wrote:

So, how do you guys have it set up? I couldn't find any other ways besides using pactl, but that doesn't send any notifications at all as far as I know.

Here is my keybinding for mute/unmute key

bindcode 121 exec /home/sharad/bin/mute && notify-send "Mute: $(pamixer --get-mute)"

Here is /home/sharad/bin/mute script

#!/bin/bash

sinks=$(pamixer --list-sink | grep ^[0-9] | awk '{print $1}' | xargs)

for x in $sinks; do
    pamixer --sink $x -t ;
done

There are similar scripts for volumeup & down keys, and all have notification support.

Offline

#3 2017-07-18 04:25:03

adesh
Member
Registered: 2016-10-05
Posts: 167

Re: [SOLVED] Reliable way to set volume from fn keys with pulseaudio?

If you do not want to work with custom scripts, I suggest volumeicon; allows for customization of keys, notification type and other mixer settings.

Offline

#4 2017-07-20 03:43:09

ralph_13
Member
Registered: 2015-02-06
Posts: 73

Re: [SOLVED] Reliable way to set volume from fn keys with pulseaudio?

adesh wrote:

If you do not want to work with custom scripts, I suggest volumeicon; allows for customization of keys, notification type and other mixer settings.

Volumeicon worked for me, but it didn't support volume boosting.

Docbroke wrote:

I guess you mean pamixer, I don't know any pnmixer

I actually did mean pnmixer, I wasn't aware about pamixer. Ended up using xbindkeys to:

#volume up
"pamixer -i 5 --allow-boost && notify-send "volume: $(pamixer --get-volume)%""
   XF86AudioRaiseVolume

#volume down
"pamixer -d 5 --allow-boost && notify-send "volume: $(pamixer --get-volume)%""
   XF86AudioLowerVolume

#mute
"pamixer -t && notify-send "mute: $(pamixer --get-mute)""
   XF86AudioMute

Works like a charm, thanks for the tips

Last edited by ralph_13 (2017-07-20 03:46:00)

Offline

#5 2017-07-20 04:26:13

HiImTye
Member
From: Halifax, NS, Canada
Registered: 2012-05-09
Posts: 1,072

Re: [SOLVED] Reliable way to set volume from fn keys with pulseaudio?

here's my volume control script. I call it with: <script> up; <script> down; <script> mute; <script> list; and <script> <percentage>. just set your media keys to those and away you go.

#!/bin/bash
sinkName=$(pacmd info | grep 'Default sink' | awk '{print $4}')
sinkNumber=$(pacmd info | grep "sink:.*$sinkName" | awk '{print $2}')

getVolume() {
 volumeInput=$(pactl list sinks)
 currentVolume=$(echo "${volumeInput#*Sink #$sinkNumber}" | grep -E 'V.*-left' | grep -oE '[0-9]+%' | tail -n 1)
 notify-send "Volume: $currentVolume"
 echo Volume: "$currentVolume"
}

case "$1" in
 up) pactl set-sink-volume @DEFAULT_SINK@ +5%; getVolume;;
 down) pactl set-sink-volume @DEFAULT_SINK@ -5%; getVolume;;
 mute) muted=$(pactl list sinks | grep 'Mute: yes')
       if [ -z "$muted" ]; then
        pactl set-sink-mute @DEFAULT_SINK@ 1
        notify-send Volume: Muted
	echo Volume: Muted
       else
        pactl set-sink-mute @DEFAULT_SINK@ 0
        getVolume
       fi;;
 list) getVolume;;
esac

if [[ "$1" =~ [0-9]+ ]]; then
 pactl set-sink-volume @DEFAULT_SINK@ "$1%"; getVolume
fi

Offline

#6 2017-07-21 18:44:13

ralph_13
Member
Registered: 2015-02-06
Posts: 73

Re: [SOLVED] Reliable way to set volume from fn keys with pulseaudio?

For future reference, I swapped notify-send for dunstify to set up an id so dunst updates it instead of sending multiple notifications.

Offline

#7 2017-07-22 01:01:18

Docbroke
Member
From: India
Registered: 2015-06-13
Posts: 1,433

Re: [SOLVED] Reliable way to set volume from fn keys with pulseaudio?

I wasn't aware of dunstify, thanks for sharing.

Offline

Board footer

Powered by FluxBB