Compare commits

...

2 Commits

Author SHA1 Message Date
2e63bcff13 Allow applying pipewire-set-default on a whole device 2022-06-11 07:56:38 +02:00
f6035e710f Pop to PipeWire buffer
This is a more suitable use pattern for a tool like this.
2022-06-11 07:51:16 +02:00
2 changed files with 17 additions and 6 deletions

View File

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

View File

@ -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))
@ -251,7 +252,7 @@ applied on some of them or the buffer:
(defun pipewire ()
"Display a PipeWire buffer."
(interactive)
(switch-to-buffer pipewire-buffer)
(pop-to-buffer pipewire-buffer)
(pipewire-refresh)
(pipewire-mode))