From cd1a8beeab8bb0b464ae0300327762ea5c78dd35 Mon Sep 17 00:00:00 2001 From: Milan Zamazal Date: Mon, 13 Jun 2022 20:04:20 +0200 Subject: [PATCH] Change volume of playback ports by default This seems to be more correct than changing volume of the whole sink. The default volume of the sink is 1 (100) and alsamixer also changes volume of the ports. --- pw-lib.el | 7 +++++++ pw-ui.el | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pw-lib.el b/pw-lib.el index 8245eec..75ffcfd 100644 --- a/pw-lib.el +++ b/pw-lib.el @@ -150,6 +150,13 @@ version, call `pw-lib-refresh' first." "Return a PipeWire object that is the current default audio sink." (pw-lib-get-object (cdr (assoc "default.audio.sink" (pw-lib-default-nodes))))) +(defun pw-lib-default-playback-ports () + "Return list of PipeWire objects that are default playback ports." + (cl-remove-if-not #'(lambda (o) + (if-let ((name (pw-lib-object-value o "port.name"))) + (string-match "^playback" name))) + (pw-lib-children (pw-lib-object-id (pw-lib-default-audio-sink)) "Port"))) + (defun pw-lib--volume-% (volume) (when volume (round (* 100 volume)))) diff --git a/pw-ui.el b/pw-ui.el index b6dac12..a7e4504 100644 --- a/pw-ui.el +++ b/pw-ui.el @@ -164,7 +164,8 @@ The indicator is displayed only on graphical terminals." (not (member (pw-lib-object-type object) allowed-types))) (setq object nil)) (when (and use-default-p (not object)) - (setq object (pw-lib-default-audio-sink))) + (setq object (or (car (pw-lib-default-playback-ports)) + (pw-lib-default-audio-sink)))) object)) (defvar pw-ui--osd-timer nil)