Skip to content

Commit

Permalink
[modules/pulseaudio] Refactor callback registration
Browse files Browse the repository at this point in the history
Make it easier to add/extend callbacks in the future.

fixes #35
  • Loading branch information
tobi-wan-kenobi committed Dec 17, 2016
1 parent cfd1406 commit 4f76665
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions bumblebee/modules/pulseaudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ def __init__(self, engine, config):
]

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
Expand Down

0 comments on commit 4f76665

Please sign in to comment.