[modules/pulsectl] add preliminary version of event-based pulseaudio

add a new module based on pulsectl, with pulsein for microphone and
pulseout for speakers.

should eventually become a drop-in replacement for pasink and pasource.

see #917
This commit is contained in:
tobi-wan-kenobi 2022-09-09 21:21:09 +02:00
parent f4bd0fba0b
commit cc910f1198
5 changed files with 95 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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"

View file

@ -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"
},