Compare commits
2 Commits
94bbd26205
...
cd1a8beeab
Author | SHA1 | Date | |
---|---|---|---|
cd1a8beeab | |||
2d76e595a9 |
36
pw-lib.el
36
pw-lib.el
@ -30,10 +30,12 @@
|
||||
(defvar pw-lib--accessor (pw-cli-accessor))
|
||||
|
||||
(defvar pw-lib--objects '())
|
||||
(defvar pw-lib--bindings nil)
|
||||
|
||||
(defun pw-lib-refresh ()
|
||||
"Clear cache of objects retrieved from PipeWire."
|
||||
(setq pw-lib--objects (pw-access-objects pw-lib--accessor)))
|
||||
(setq pw-lib--objects (pw-access-objects pw-lib--accessor)
|
||||
pw-lib--bindings nil))
|
||||
|
||||
(defun pw-lib-objects (&optional type)
|
||||
"Return a list of PipeWire objects.
|
||||
@ -119,23 +121,26 @@ An association lists with elements of the form (PARENT . CHILD) is
|
||||
returned where PARENT and CHILD are numeric ids of PipeWire objects.
|
||||
Note that PipeWire data is cached, if you need its up-to-date
|
||||
version, call `pw-lib-refresh' first."
|
||||
(apply #'nconc (mapcar #'(lambda (o)
|
||||
(let ((o-id (pw-lib-object-id o)))
|
||||
(mapcar #'(lambda (p)
|
||||
(cons o-id (cdr p)))
|
||||
(cl-remove-if-not #'numberp (pw-lib--object-info o)
|
||||
:key #'cdr))))
|
||||
(pw-lib-objects))))
|
||||
(or pw-lib--bindings
|
||||
(setq pw-lib--bindings
|
||||
(apply #'nconc
|
||||
(mapcar #'(lambda (o)
|
||||
(let ((o-id (pw-lib-object-id o)))
|
||||
(mapcar #'(lambda (p)
|
||||
(cons o-id (cdr p)))
|
||||
(cl-remove-if-not #'numberp (pw-lib--object-info o)
|
||||
:key #'cdr))))
|
||||
(pw-lib-objects))))))
|
||||
|
||||
(defun pw-lib-children (id bindings &optional type)
|
||||
(defun pw-lib-children (id &optional type)
|
||||
"Return child objects of the object identified by numeric PipeWire ID.
|
||||
BINDINGS are object bindings as returned from `pw-lib-bindings'.
|
||||
If a string TYPE is specified then only children of the given PipeWire
|
||||
type are returned.
|
||||
Note that PipeWire data is cached, if you need its up-to-date
|
||||
version, call `pw-lib-refresh' first."
|
||||
(let ((children (mapcar #'pw-lib-get-object
|
||||
(mapcar #'car (cl-remove-if #'(lambda (b) (/= (cdr b) id)) bindings)))))
|
||||
(mapcar #'car (cl-remove-if #'(lambda (b) (/= (cdr b) id))
|
||||
(pw-lib-bindings))))))
|
||||
(when type
|
||||
(setq children (cl-remove-if-not #'(lambda (o) (equal (pw-lib-object-type o) type))
|
||||
children)))
|
||||
@ -145,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))))
|
||||
@ -233,7 +245,7 @@ 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"))
|
||||
(dolist (node (pw-lib-children (pw-lib-object-id object) "Node"))
|
||||
(pw-lib--set-default-node node stored-p)))
|
||||
("Node"
|
||||
(pw-lib--set-default-node object stored-p))
|
||||
|
8
pw-ui.el
8
pw-ui.el
@ -137,16 +137,15 @@ The indicator is displayed only on graphical terminals."
|
||||
(error "Not in a PipeWire buffer"))
|
||||
(pw-lib-refresh)
|
||||
(let ((inhibit-read-only t)
|
||||
(bindings (pw-lib-bindings))
|
||||
(default-ids (mapcar #'cdr (pw-lib-default-nodes)))
|
||||
(current-line (count-lines (point-min) (min (1+ (point)) (point-max)))))
|
||||
(erase-buffer)
|
||||
(insert (pw-ui--label "Devices") "\n")
|
||||
(dolist (device (pw-lib-objects "Device"))
|
||||
(pw-ui--insert-line (pw-ui--object-label device default-ids) device)
|
||||
(dolist (node (pw-lib-children (pw-lib-object-id device) bindings "Node"))
|
||||
(dolist (node (pw-lib-children (pw-lib-object-id device) "Node"))
|
||||
(pw-ui--insert-line (concat " " (pw-ui--object-label node default-ids)) node)
|
||||
(dolist (port (pw-lib-children (pw-lib-object-id node) bindings "Port"))
|
||||
(dolist (port (pw-lib-children (pw-lib-object-id node) "Port"))
|
||||
(pw-ui--insert-line (concat " " (pw-ui--object-label port default-ids)) port))))
|
||||
(insert (pw-ui--label "Clients") "\n")
|
||||
(dolist (client (pw-lib-objects "Client"))
|
||||
@ -165,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)
|
||||
|
Loading…
Reference in New Issue
Block a user