Merge pull request #977 from jebaum/main

allow setting sink ID in pipewire module
This commit is contained in:
tobi-wan-kenobi 2023-07-17 01:41:01 +02:00 committed by GitHub
commit 839d79e68f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -29,6 +29,8 @@ class Module(core.module.Module):
/ 100.0 / 100.0
) # divide by 100 because wpctl represents 100% volume as 1.00, 50% as 0.50, etc ) # divide by 100 because wpctl represents 100% volume as 1.00, 50% as 0.50, etc
self.__id = self.parameter("sink_id") or "@DEFAULT_AUDIO_SINK@"
events = [ events = [
{ {
"type": "mute", "type": "mute",
@ -51,20 +53,16 @@ class Module(core.module.Module):
core.input.register(self, button=event["button"], cmd=event["action"]) core.input.register(self, button=event["button"], cmd=event["action"])
def toggle(self, event): def toggle(self, event):
util.cli.execute("wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle") util.cli.execute("wpctl set-mute {} toggle".format(self.__id))
def increase_volume(self, event): def increase_volume(self, event):
util.cli.execute( util.cli.execute(
"wpctl set-volume --limit 1.0 @DEFAULT_AUDIO_SINK@ {}+".format( "wpctl set-volume --limit 1.0 {} {}+".format(self.__change, self.__id)
self.__change
)
) )
def decrease_volume(self, event): def decrease_volume(self, event):
util.cli.execute( util.cli.execute(
"wpctl set-volume --limit 1.0 @DEFAULT_AUDIO_SINK@ {}-".format( "wpctl set-volume --limit 1.0 {} {}-".format(self.__change, self.__id)
self.__change
)
) )
def volume(self, widget): def volume(self, widget):
@ -75,7 +73,7 @@ class Module(core.module.Module):
def update(self): def update(self):
try: try:
# `wpctl get-volume` will return a string like "Volume: n.nn" or "Volume: n.nn [MUTED]" # `wpctl get-volume` will return a string like "Volume: n.nn" or "Volume: n.nn [MUTED]"
volume = util.cli.execute("wpctl get-volume @DEFAULT_AUDIO_SINK@") volume = util.cli.execute("wpctl get-volume {}".format(self.__id))
v = re.search("\d\.\d+", volume) v = re.search("\d\.\d+", volume)
m = re.search("MUTED", volume) m = re.search("MUTED", volume)
self.__level = v.group() self.__level = v.group()