Add volumecontrol with pulsectl module

master
Lars Vierbergen 8 years ago
parent 5e1111727d
commit 4523fbeba0
  1. 2
      daemon.py
  2. 2
      modules/__init__.py
  3. 2
      modules/core.py
  4. 34
      modules/volume.py
  5. 1
      requirements.txt

@ -12,7 +12,7 @@ modules.Application(
separator='' separator=''
), ),
modules.ActionWrapperControl( modules.ActionWrapperControl(
modules.PaCtlVolumeControl(), modules.PulseCtlVolumeControl(),
action='pavucontrol', action='pavucontrol',
buttons=modules.core.Button.RIGHT buttons=modules.core.Button.RIGHT
), ),

@ -2,4 +2,4 @@ from .application import Application
from .core import GroupedControl, ActionWrapperControl from .core import GroupedControl, ActionWrapperControl
from .caffeine import CaffeineControl from .caffeine import CaffeineControl
from .redshift import RedshiftControl from .redshift import RedshiftControl
from .volume import PaCtlVolumeControl from .volume import PaCtlVolumeControl, VolumeControl, PulseCtlVolumeControl

@ -283,7 +283,7 @@ class WrappingControl(AbstractControl):
return self.child.visible return self.child.visible
def periodic(self): def periodic(self):
self.child.periodic() return self.child.periodic()
def load_state_ex(self, state): def load_state_ex(self, state):
self.child.load_state_ex(state) self.child.load_state_ex(state)

@ -139,3 +139,37 @@ class PaCtlVolumeControl(AbstractVolumeControl):
logger.debug("Calling pactl: %s %s %s", command, i, arg) logger.debug("Calling pactl: %s %s %s", command, i, arg)
subprocess.check_call(["pactl", command, i, arg], stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL) subprocess.check_call(["pactl", command, i, arg], stdin=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
try:
import pulsectl
class PulseCtlVolumeControl(AbstractVolumeControl):
def __init__(self):
super().__init__()
self.__pulse = pulsectl.Pulse(self.__class__.__name__)
self.__default_sink = None
self.periodic()
def periodic(self):
server_info = self.__pulse.server_info()
self.__default_sink = next(filter(lambda sink: sink.name == server_info.default_sink_name, self.__pulse.sink_list()))
prev_muted = self.muted
self.muted = bool(self.__default_sink.mute)
prev_volume = self.volume
if not self.muted:
self.volume = self.__default_sink.volume.value_flat
return prev_muted != self.muted or prev_volume != self.volume
def _set_muted(self, muted: bool) -> bool:
self.__pulse.sink_mute(self.__default_sink.index, muted)
return True
def _set_volume(self, volume: float) -> bool:
self.__default_sink.volume.value_flat = volume
self.__pulse.sink_volume_set(self.__default_sink.index, self.__default_sink.volume)
return True
VolumeControl = PulseCtlVolumeControl
except ImportError:
VolumeControl = PaCtlVolumeControl

@ -0,0 +1 @@
pulsectl==16.12.4
Loading…
Cancel
Save