diff --git a/bumblebee_status/modules/core/pulsectl.py b/bumblebee_status/modules/core/pulsectl.py new file mode 100644 index 0000000..70fc356 --- /dev/null +++ b/bumblebee_status/modules/core/pulsectl.py @@ -0,0 +1,44 @@ +# pylint: disable=C0111,R0903 + +import pulsectl + +import core.module +import core.widget +import core.decorators +import core.input +import core.event + +class Module(core.module.Module): + def __init__(self, config, theme, type): + super().__init__(config, theme, core.widget.Widget(self.display)) + self.background = True + + self.__type = type + self.__volume = "n/a" + self.__muted = False + + self.process(None) + + def display(self, _): + return f"{int(self.__volume*100)}%" + + def process(self, _): + with pulsectl.Pulse(self.id + "proc") as pulse: + dev = pulse.sink_list()[0] if self.__type == "sink" else pulse.source_list()[0] + self.__volume = dev.volume.value_flat + self.__muted = dev.mute + core.event.trigger("update", [self.id], redraw_only=True) + core.event.trigger("draw") + + def update(self): + with pulsectl.Pulse(self.id) as pulse: + pulse.event_mask_set(self.__type) + pulse.event_callback_set(self.process) + pulse.event_listen() + + def state(self, _): + if self.__muted: + return ["warning", "muted"] + return ["unmuted"] + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee_status/modules/core/pulsein.py b/bumblebee_status/modules/core/pulsein.py new file mode 100644 index 0000000..0034dd0 --- /dev/null +++ b/bumblebee_status/modules/core/pulsein.py @@ -0,0 +1,9 @@ +from .pulsectl import Module + + +class Module(Module): + def __init__(self, config, theme): + super().__init__(config, theme, "source") + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/bumblebee_status/modules/core/pulseout.py b/bumblebee_status/modules/core/pulseout.py new file mode 100644 index 0000000..31fecec --- /dev/null +++ b/bumblebee_status/modules/core/pulseout.py @@ -0,0 +1,9 @@ +from .pulsectl import Module + + +class Module(Module): + def __init__(self, config, theme): + super().__init__(config, theme, "sink") + + +# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 diff --git a/themes/icons/ascii.json b/themes/icons/ascii.json index 77ef931..089fa3c 100644 --- a/themes/icons/ascii.json +++ b/themes/icons/ascii.json @@ -64,6 +64,14 @@ "prefix": "audio" } }, + "pulseout": { + "muted": { + "prefix": "audio(mute)" + }, + "unmuted": { + "prefix": "audio" + } + }, "amixer": { "muted": { "prefix": "audio(mute)" @@ -80,6 +88,14 @@ "prefix": "mic" } }, + "pulsein": { + "muted": { + "prefix": "mic(mute)" + }, + "unmuted": { + "prefix": "mic" + } + }, "nic": { "wireless-up": { "prefix": "wifi" diff --git a/themes/icons/awesome-fonts.json b/themes/icons/awesome-fonts.json index a3de1d2..acd1fc3 100644 --- a/themes/icons/awesome-fonts.json +++ b/themes/icons/awesome-fonts.json @@ -197,6 +197,14 @@ "prefix": "" } }, + "pulseout": { + "muted": { + "prefix": "" + }, + "unmuted": { + "prefix": "" + } + }, "amixer": { "muted": { "prefix": "" @@ -213,6 +221,14 @@ "prefix": "" } }, + "pulsein": { + "muted": { + "prefix": "" + }, + "unmuted": { + "prefix": "" + } + }, "kernel": { "prefix": "\uf17c" }, @@ -707,4 +723,4 @@ "thunderbird": { "prefix": "" } -} \ No newline at end of file +}