From 2e63bcff139fb22dbfef28cd5ecaf76c98feea3a Mon Sep 17 00:00:00 2001 From: Milan Zamazal Date: Sat, 11 Jun 2022 07:56:38 +0200 Subject: [PATCH] Allow applying pipewire-set-default on a whole device --- pw-lib.el | 18 ++++++++++++++---- pw-ui.el | 3 ++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/pw-lib.el b/pw-lib.el index d50b2c9..269772c 100644 --- a/pw-lib.el +++ b/pw-lib.el @@ -219,15 +219,25 @@ otherwise set the volume to the same value for all the related channels." (make-list (length orig-value) float-volume)))))) (pw-access-set-properties pw-lib--accessor node-id (list (cons property value)))))) -(defun pw-lib-set-default (object stored-p) - "Set PipeWire OBJECT as the default sink or source. -If STORED-P is non-nil, set the stored default sink or source, -otherwise set the current default sink or source." +(defun pw-lib--set-default-node (object stored-p) (let ((suffix (mapconcat #'downcase (split-string (pw-lib-object-value object "media.class") "/") ".")) (prefix (if stored-p "default.configured." "default.")) (node-name (pw-lib-object-value object "node.name"))) (pw-access-set-default pw-lib--accessor (concat prefix suffix) node-name))) + +(defun pw-lib-set-default (object stored-p) + "Set PipeWire OBJECT as the default sink or source. +If STORED-P is non-nil, set the stored default sink or source, +otherwise set the current default sink or source." + (pcase (pw-lib-object-type object) + ("Device" + (dolist (node (pw-lib-children (pw-lib-object-id object) (pw-lib-bindings) "Node")) + (pw-lib--set-default-node node stored-p))) + ("Node" + (pw-lib--set-default-node object stored-p)) + (_ + (error "Cannot set this kind of object as default.")))) (provide 'pw-lib) diff --git a/pw-ui.el b/pw-ui.el index c53cdfa..2636be1 100644 --- a/pw-ui.el +++ b/pw-ui.el @@ -212,9 +212,10 @@ object. Otherwise apply it on the default audio sink." (defun pipewire-set-default () "Set default sink or source. If on a Node in a PipeWire buffer, apply it on the given object. +If on a Device, apply it on all its nodes. Otherwise ask for the Node to set as the default Node." (interactive) - (let ((object (or (pw-ui--current-object nil '("Node")) + (let ((object (or (pw-ui--current-object nil '("Device" "Node")) (let* ((default-node-ids (mapcar #'cdr (pw-lib-default-nodes))) (nodes (cl-remove-if #'(lambda (n) (member (pw-lib-object-id n) default-node-ids))