Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace pacmd calls with pactl to support Pipewire #818

Open
wants to merge 1 commit into
base: current
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions i3pystatus/pulseaudio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,23 @@ def sink_info_cb(self, context, sink_info_p, eol, _):
else:
raise Exception("bar_type must be 'vertical' or 'horizontal'")

selected = ""
dump = subprocess.check_output("pacmd dump".split(), universal_newlines=True)
for line in dump.split("\n"):
if line.startswith("set-default-sink"):
default_sink = line.split()[1]
if default_sink == self.current_sink:
selected = self.format_selected
# TODO: Looks like we can't access daemon config using pactl.
# Remove this part if that's true or find an appropriate pactl alternative.
# selected = ""
# dump = subprocess.check_output("pacmd dump".split(), universal_newlines=True)
# for line in dump.split("\n"):
# if line.startswith("set-default-sink"):
# default_sink = line.split()[1]
# if default_sink == self.current_sink:
# selected = self.format_selected
Copy link
Contributor

@hasB4K hasB4K Jan 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure that this issue can be easily be resolved with the following:

            selected = ""
            default_sink = subprocess.check_output("pactl get-default-sink".split()).strip()
            if default_sink == self.current_sink:
                selected = self.format_selected

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have tested with a full pulseaudio and a full pipewire setup, and this patch works.

pactl get-default-sink and pacmd dump | grep set-default-sink | awk '{print $2}' (the equivalent bash command of the current code) gives the same outputs on a full pulseaudio setup.


self.output = {
"color": color,
"full_text": output_format.format(
muted=muted,
volume=volume_percent,
db=volume_db,
volume_bar=volume_bar,
selected=selected),
volume_bar=volume_bar),
}

self.send_output()
Expand All @@ -229,16 +230,16 @@ def change_sink(self):
next_sink = self.current_sink

if self.move_sink_inputs:
sink_inputs = subprocess.check_output("pacmd list-sink-inputs".split(),
sink_inputs = subprocess.check_output("pactl list sink-inputs".split(),
universal_newlines=True)
for input_index in re.findall(r'index:\s+(\d+)', sink_inputs):
command = "pacmd move-sink-input {} {}".format(input_index, next_sink)
command = "pactl move-sink-input {} {}".format(input_index, next_sink)

# Not all applications can be moved and pulseaudio, and when
# this fail pacmd print error messaging
with open(os.devnull, 'w') as devnull:
subprocess.call(command.split(), stdout=devnull)
subprocess.call("pacmd set-default-sink {}".format(next_sink).split())
subprocess.call("pactl set-default-sink {}".format(next_sink).split())

def switch_mute(self):
subprocess.call(['pactl', '--', 'set-sink-mute', self.current_sink, "toggle"])
Expand Down