Updated 'pulseaudio' module to use pactl instead of amixer.
This commit is contained in:
parent
483d5a03fc
commit
1bacaa1cf5
@ -12,7 +12,6 @@ class PulseAudio(Module, ColorRangeModule):
|
||||
"""
|
||||
Shows volume of default PulseAudio sink (output).
|
||||
|
||||
- Requires amixer for toggling mute and incrementing/decrementing volume on scroll.
|
||||
- Depends on the PyPI colour module - https://pypi.python.org/pypi/colour/0.0.5
|
||||
|
||||
.. rubric:: Available formatters:
|
||||
@ -29,7 +28,8 @@ class PulseAudio(Module, ColorRangeModule):
|
||||
("format_muted", "optional format string to use when muted"),
|
||||
"muted", "unmuted",
|
||||
"color_muted", "color_unmuted",
|
||||
("step", "percentage to increment volume on scroll"),
|
||||
("step_in_db", "change step unit from percentage to decibels"),
|
||||
("step", "percentage (or decibel value) to increment volume on scroll"),
|
||||
("bar_type", "type of volume bar. Allowed values are 'vertical' or 'horizontal'"),
|
||||
("multi_colors", "whether or not to change the color from "
|
||||
"'color_muted' to 'color_unmuted' based on volume percentage"),
|
||||
@ -46,6 +46,7 @@ class PulseAudio(Module, ColorRangeModule):
|
||||
color_unmuted = "#FFFFFF"
|
||||
|
||||
step = 5
|
||||
step_db = False
|
||||
multi_colors = False
|
||||
bar_type = 'vertical'
|
||||
vertical_bar_width = 2
|
||||
@ -78,9 +79,8 @@ class PulseAudio(Module, ColorRangeModule):
|
||||
pa_threaded_mainloop_start(_mainloop)
|
||||
|
||||
self.colors = self.get_hex_color_range(self.color_muted, self.color_unmuted, 100)
|
||||
|
||||
# Check that we have amixer for toggling mute/unmute and incrementing/decrementing volume
|
||||
self.has_amixer = shutil.which('alsamixer') is not None
|
||||
self.sink_utf = None
|
||||
self.unit = "dB" if self.step_db else "%"
|
||||
|
||||
def request_update(self, context):
|
||||
"""Requests a sink info update (sink_info_cb is called)"""
|
||||
@ -95,6 +95,8 @@ class PulseAudio(Module, ColorRangeModule):
|
||||
server_info = server_info_p.contents
|
||||
|
||||
self.sink = server_info.default_sink_name
|
||||
self.sink_utf = server_info.default_sink_name
|
||||
self.sink_utf = self.sink_utf.decode("UTF-8").strip()
|
||||
|
||||
self.request_update(context)
|
||||
|
||||
@ -161,20 +163,15 @@ class PulseAudio(Module, ColorRangeModule):
|
||||
}
|
||||
|
||||
def switch_mute(self):
|
||||
if self.has_amixer:
|
||||
command = "amixer -q -D pulse sset Master "
|
||||
if self.currently_muted:
|
||||
command += 'unmute'
|
||||
else:
|
||||
command += 'mute'
|
||||
command = "pactl -- set-sink-mute {sink} toggle".format(sink=self.sink_utf)
|
||||
subprocess.Popen(command.split())
|
||||
|
||||
def increase_volume(self):
|
||||
if self.has_amixer:
|
||||
command = "amixer -q -D pulse sset Master %s%%+" % self.step
|
||||
command = "pactl -- set-sink-volume {sink} +{step}{unit}".format(
|
||||
sink=self.sink_utf, step=self.step, unit=self.unit)
|
||||
subprocess.Popen(command.split())
|
||||
|
||||
def decrease_volume(self):
|
||||
if self.has_amixer:
|
||||
command = "amixer -q -D pulse sset Master %s%%-" % self.step
|
||||
command = "pactl -- set-sink-volume {sink} -{step}{unit}".format(
|
||||
sink=self.sink_utf, step=self.step, unit=self.unit)
|
||||
subprocess.Popen(command.split())
|
||||
|
Loading…
Reference in New Issue
Block a user