Added toggle mute/unmute on left click, increment/decrement volume on
scroll.
This commit is contained in:
parent
27182f3196
commit
556eed9fde
@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
import shutil
|
||||||
from i3pystatus.core.color import ColorRangeModule
|
from i3pystatus.core.color import ColorRangeModule
|
||||||
from i3pystatus.core.util import make_vertical_bar, make_bar
|
from i3pystatus.core.util import make_vertical_bar, make_bar
|
||||||
from .pulse import *
|
from .pulse import *
|
||||||
@ -9,6 +11,8 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
"""
|
"""
|
||||||
Shows volume of default PulseAudio sink (output).
|
Shows volume of default PulseAudio sink (output).
|
||||||
|
|
||||||
|
Requires amixer for toggling mute and incrementing/decrementing volume on scroll.
|
||||||
|
|
||||||
Available formatters:
|
Available formatters:
|
||||||
|
|
||||||
* `{volume}` — volume in percent (0...100)
|
* `{volume}` — volume in percent (0...100)
|
||||||
@ -34,6 +38,8 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
unmuted = ""
|
unmuted = ""
|
||||||
format = "♪: {volume}"
|
format = "♪: {volume}"
|
||||||
format_muted = None
|
format_muted = None
|
||||||
|
currently_muted = False
|
||||||
|
has_amixer = False
|
||||||
color_muted = "#FF0000"
|
color_muted = "#FF0000"
|
||||||
color_unmuted = "#FFFFFF"
|
color_unmuted = "#FFFFFF"
|
||||||
|
|
||||||
@ -66,6 +72,9 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
|
|
||||||
self.colors = self.get_hex_color_range(self.color_muted, self.color_unmuted, 100)
|
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
|
||||||
|
|
||||||
def request_update(self, context):
|
def request_update(self, context):
|
||||||
"""Requests a sink info update (sink_info_cb is called)"""
|
"""Requests a sink info update (sink_info_cb is called)"""
|
||||||
pa_operation_unref(pa_context_get_sink_info_by_name(
|
pa_operation_unref(pa_context_get_sink_info_by_name(
|
||||||
@ -109,6 +118,7 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
sink_info = sink_info_p.contents
|
sink_info = sink_info_p.contents
|
||||||
volume_percent = int(100 * sink_info.volume.values[0] / 0x10000)
|
volume_percent = int(100 * sink_info.volume.values[0] / 0x10000)
|
||||||
volume_db = pa_sw_volume_to_dB(sink_info.volume.values[0])
|
volume_db = pa_sw_volume_to_dB(sink_info.volume.values[0])
|
||||||
|
self.currently_muted = sink_info.mute
|
||||||
|
|
||||||
if volume_db == float('-Infinity'):
|
if volume_db == float('-Infinity'):
|
||||||
volume_db = "-∞"
|
volume_db = "-∞"
|
||||||
@ -144,6 +154,25 @@ class PulseAudio(Module, ColorRangeModule):
|
|||||||
}
|
}
|
||||||
|
|
||||||
def on_leftclick(self):
|
def on_leftclick(self):
|
||||||
import subprocess
|
|
||||||
|
|
||||||
subprocess.Popen(["pavucontrol"])
|
subprocess.Popen(["pavucontrol"])
|
||||||
|
|
||||||
|
def on_rightclick(self):
|
||||||
|
if self.has_amixer:
|
||||||
|
command = "amixer -q -D pulse sset Master "
|
||||||
|
if self.currently_muted:
|
||||||
|
command += 'unmute'
|
||||||
|
else:
|
||||||
|
command += 'mute'
|
||||||
|
subprocess.Popen(command.split())
|
||||||
|
|
||||||
|
def on_upscroll(self):
|
||||||
|
if self.has_amixer:
|
||||||
|
command = "amixer -q -D pulse sset Master %s%%+" % self.step
|
||||||
|
subprocess.Popen(command.split())
|
||||||
|
|
||||||
|
def on_downscroll(self):
|
||||||
|
if self.has_amixer:
|
||||||
|
command = "amixer -q -D pulse sset Master %s%%-" % self.step
|
||||||
|
subprocess.Popen(command.split())
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user