You are not logged in.

#1 2015-08-28 20:29:08

garrett92895
Member
Registered: 2015-08-28
Posts: 1

Changing the volume step in GNOME 3 while keeping GNOME's volume OSD

What I have is not a question, but a workaround for an issue that seems fairly common. This is my first time posting in the Arch forums so I'm not exactly sure if this is the right way to go about this.

The issue at hand is that GNOME 3 (including 3.16 as of writing this) does not allow the user to configure the percentage by which the volume decreases/increases when you change the volume. It is actually hard coded to 6 in their code (gnome-settings-daemon/plugins/media-keys/gsd-media-keys-manager.c). You can adjust the step size by binding the volume keys to a command that changes the volume for you, but then the volume notification OSD no longer shows up. You can create your own notification that is triggered by your command, but that doesn't work if you'd like to stick with GNOME's volume OSD.

I wrote a script that resolves this, which you can find along with an explanation at https://github.com/garrett92895/gnome-volume-step-osd but I will also post the script here for easier access

import dbus
import sys
from subprocess import getoutput

session_bus = dbus.SessionBus()
proxy = session_bus.get_object('org.gnome.Shell', '/org/gnome/Shell')
interface = dbus.Interface(proxy, 'org.gnome.Shell')

vol_action = sys.argv[1]
vol_percent_change = sys.argv[2]

command = 'amixer -D pulse sset Master ' + vol_percent_change + '%'

if vol_action == 'increase':
    command += '+ > /dev/null && amixer -D pulse set Master unmute'
else:
    command += '-'

command += ' | grep -oP "\[\d*%\]" | head -n 1 | sed s:[][%]::g'

current_vol_percentage = int(getoutput(command))

logo = 'audio-volume-'
if current_vol_percentage < 20:
    logo += 'low'
elif current_vol_percentage >= 20 and current_vol_percentage < 80:
    logo += 'medium'
else:
    logo += 'high'
logo += '-symbolic'

interface.ShowOSD({"icon":logo, "level":current_vol_percentage})

If amixer does not successfully adjust your volume, then you'll have to edit the script to use a command that does. Furthermore, I use amixer's output to find the system's current volume percentage. Again, if you aren't going to use the amixer command then you'll have to find some way to get the current volume level before sending the method call to the gnome shell.

If you're wondering why I didn't write this as a bash script, it's because the dbus-send command does not support variants within dictionaries and I therefore needed to find another way to send the dbus method call so that the gnome shell could properly interpret the arguments.

This issue was bothersome for me, and so I hope some of you can benefit from my workaround smile

Offline

Board footer

Powered by FluxBB