Headphone mechanism change
This commit is contained in:
@@ -5,15 +5,51 @@
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
options.azos.headphones-whmx4000.enable = lib.mkOption {
|
||||
default = true;
|
||||
type = lib.types.bool;
|
||||
options.azos.headphones = {
|
||||
enable = lib.mkOption {
|
||||
default = false;
|
||||
example = true;
|
||||
type = lib.types.bool;
|
||||
};
|
||||
devices = lib.mkOption {
|
||||
default = [];
|
||||
type = lib.types.listOf (lib.types.submodule {
|
||||
options = {
|
||||
mac = lib.mkOption {type = lib.types.str;};
|
||||
name = lib.mkOption {type = lib.types.str;};
|
||||
};
|
||||
});
|
||||
description = "Headphone devices; first entry is the default connect target.";
|
||||
};
|
||||
};
|
||||
config = lib.mkIf config.azos.headphones-whmx4000.enable {
|
||||
home.packages = [
|
||||
(pkgs.writeShellScriptBin
|
||||
"azos-connect-headphones-whmx4000"
|
||||
"echo \"connect AC:80:0A:AF:E1:C2\" | bluetoothctl")
|
||||
|
||||
config = lib.mkIf config.azos.headphones.enable {
|
||||
home.packages = let
|
||||
deviceEntries =
|
||||
lib.concatMapStrings
|
||||
(d: " ${lib.escapeShellArg "${d.mac} ${d.name}"}\n")
|
||||
config.azos.headphones.devices;
|
||||
defaultMac =
|
||||
if config.azos.headphones.devices == []
|
||||
then ""
|
||||
else (lib.head config.azos.headphones.devices).mac;
|
||||
in [
|
||||
(pkgs.writeShellScriptBin "azos-connect-headphones" ''
|
||||
DEVICES=(
|
||||
${deviceEntries})
|
||||
|
||||
case "$1" in
|
||||
--list)
|
||||
printf '%s\n' "''${DEVICES[@]}"
|
||||
;;
|
||||
--mac)
|
||||
echo "connect $2" | bluetoothctl
|
||||
;;
|
||||
*)
|
||||
echo "connect ${defaultMac}" | bluetoothctl
|
||||
;;
|
||||
esac
|
||||
'')
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
@@ -43,9 +43,24 @@
|
||||
** Headphones
|
||||
|
||||
#+begin_src emacs-lisp
|
||||
(defun azos/connect-headphones ()
|
||||
(interactive)
|
||||
(start-process-shell-command "connect-headphones" nil "azos-connect-headphones-whmx4000"))
|
||||
(defun azos/connect-headphones (&optional arg)
|
||||
"Connect to headphones via bluetoothctl.
|
||||
Without prefix ARG, connects to the first device in the list.
|
||||
With prefix ARG, prompts to choose from all configured devices."
|
||||
(interactive "P")
|
||||
(if (not arg)
|
||||
(start-process-shell-command "connect-headphones" nil "azos-connect-headphones")
|
||||
(let* ((raw (shell-command-to-string "azos-connect-headphones --list"))
|
||||
(lines (split-string (string-trim raw) "\n" t))
|
||||
(choices (mapcar (lambda (line)
|
||||
(let ((space (string-match " " line)))
|
||||
(cons (substring line (1+ space))
|
||||
(substring line 0 space))))
|
||||
lines))
|
||||
(name (completing-read "Connect headphones: " (mapcar #'car choices) nil t))
|
||||
(mac (cdr (assoc name choices))))
|
||||
(start-process-shell-command "connect-headphones" nil
|
||||
(concat "azos-connect-headphones --mac " mac)))))
|
||||
|
||||
(define-key azos/global-minor-mode/open-keymap
|
||||
(kbd "h") 'azos/connect-headphones)
|
||||
|
||||
Reference in New Issue
Block a user