diff options
author | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2015-07-09 15:18:15 +0200 |
---|---|---|
committer | Alexander Sulfrian <alexander.sulfrian@fu-berlin.de> | 2015-07-09 15:18:15 +0200 |
commit | fc297ff81a9e5b612c5ffbc23e185b7f9a4e7dfe (patch) | |
tree | 0b8e7167091cc4cc03723c03a35bdabebdc9203f /bin | |
parent | c03547585cc68ca0ab7a67eaa3b13263958109b7 (diff) | |
download | dzen2-config-fc297ff81a9e5b612c5ffbc23e185b7f9a4e7dfe.tar.gz dzen2-config-fc297ff81a9e5b612c5ffbc23e185b7f9a4e7dfe.tar.xz dzen2-config-fc297ff81a9e5b612c5ffbc23e185b7f9a4e7dfe.zip |
pulse-dbus-receive: Use FallbackSource as default
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/pulse-dbus-receive.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/bin/pulse-dbus-receive.py b/bin/pulse-dbus-receive.py index 3e00d6a..62a967a 100755 --- a/bin/pulse-dbus-receive.py +++ b/bin/pulse-dbus-receive.py @@ -12,7 +12,7 @@ import time home = os.path.expanduser('~') safe = { - 'sink': '/org/pulseaudio/core1/sink0', + 'sink': None, 'muted': False, 'volume': 0, 'baseVolume': 0, @@ -54,23 +54,30 @@ def update_muted(muted, force=False): def signal_cb(*args, **kwargs): msg = kwargs['msg'] - - if msg.get_path() != safe['sink']: - return - - if msg.get_interface() == 'org.PulseAudio.Core1.Device' and \ - msg.get_member() == 'VolumeUpdated': - update_volume(args[0]) - elif msg.get_interface() == 'org.PulseAudio.Core1.Device' and \ - msg.get_member() == 'MuteUpdated': - update_muted(args[0]) + bus = kwargs['bus'] + + if msg.get_interface() == 'org.PulseAudio.Core1.Device': + if safe['sink'] is not None and msg.get_path() != safe['sink']: + return + if msg.get_member() == 'VolumeUpdated': + update_volume(args[0]) + elif msg.get_member() == 'MuteUpdated': + update_muted(args[0]) + elif msg.get_interface() == 'org.PulseAudio.Core1': + if msg.get_member() == 'FallbackSinkUpdated': + init(bus, args[0]) else: print msg -def init(bus): - if len(sys.argv) > 1: +def init(bus, sink=None): + if sink is not None: + safe['sink'] = sink + elif len(sys.argv) > 1: safe['sink'] = sys.argv[1] + core = bus.get_object(object_path="/org/pulseaudio/core1") + safe['sink'] = core.Get('org.PulseAudio.Core1', 'FallbackSink') + sink = bus.get_object('org.PulseAudio.Core1.Device', safe['sink']) safe['baseVolume'] = sink.Get('org.PulseAudio.Core1.Device', 'BaseVolume') @@ -96,10 +103,14 @@ def setup(loop, conn=None): bus.call_on_disconnection(partial(setup, loop)) init(bus) - bus.add_signal_receiver(signal_cb, message_keyword='msg') + bus.add_signal_receiver(partial(signal_cb, bus=bus), message_keyword='msg') core = bus.get_object(object_path="/org/pulseaudio/core1") core.ListenForSignal('org.PulseAudio.Core1.Device.VolumeUpdated', dbus.Array(signature='o')) core.ListenForSignal('org.PulseAudio.Core1.Device.MuteUpdated', dbus.Array(signature='o')) + + if len(sys.argv) <= 1: + core.ListenForSignal('org.PulseAudio.Core1.FallbackSinkUpdated', dbus.Array(signature='o')) + loop.run() if __name__ == '__main__': |