From 4f7666533c9cd94e497a87c4c81153bee059625a Mon Sep 17 00:00:00 2001 From: Tobi-wan Kenobi Date: Sat, 17 Dec 2016 08:16:10 +0100 Subject: [PATCH] [modules/pulseaudio] Refactor callback registration Make it easier to add/extend callbacks in the future. fixes #35 --- bumblebee/modules/pulseaudio.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/bumblebee/modules/pulseaudio.py b/bumblebee/modules/pulseaudio.py index 2252b26..7578438 100644 --- a/bumblebee/modules/pulseaudio.py +++ b/bumblebee/modules/pulseaudio.py @@ -33,12 +33,17 @@ class Module(bumblebee.engine.Module): ] engine.input.register_callback(self, button=bumblebee.input.RIGHT_MOUSE, cmd="pavucontrol") - engine.input.register_callback(self, button=bumblebee.input.LEFT_MOUSE, - cmd="pactl set-{}-mute @DEFAULT_{}@ toggle".format(channel, channel.upper())) - engine.input.register_callback(self, button=bumblebee.input.WHEEL_UP, - cmd="pactl set-{}-volume @DEFAULT_{}@ +2%".format(channel, channel.upper())) - engine.input.register_callback(self, button=bumblebee.input.WHEEL_DOWN, - cmd="pactl set-{}-volume @DEFAULT_{}@ -2%".format(channel, channel.upper())) + + events = [ + { "type": "mute", "action": "toggle", "button": bumblebee.input.LEFT_MOUSE }, + { "type": "volume", "action": "+2%", "button": bumblebee.input.WHEEL_UP }, + { "type": "volume", "action": "-2%", "button": bumblebee.input.WHEEL_DOWN }, + ] + + for event in events: + engine.input.register_callback(self, button=event["button"], + cmd="pactl set-{}-{} @DEFAULT_{}@ {}".format(channel, event["type"], + channel.upper(), event["action"])) def mute(self, value): self._mute = value