From 2e5127649ad3fea03026efa39b8df6a0d7257ecc Mon Sep 17 00:00:00 2001
From: Ben Grande <ben.grande.b@gmail.com>
Date: Fri, 19 Jan 2024 11:18:37 +0100
Subject: [PATCH] feat: seamless audio integration with bluetooth

---
 salt/sys-audio/README.md  | 31 ++++++++++++++++++++++++++++++-
 salt/sys-audio/create.sls |  1 +
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/salt/sys-audio/README.md b/salt/sys-audio/README.md
index eccc0fa..cd69053 100644
--- a/salt/sys-audio/README.md
+++ b/salt/sys-audio/README.md
@@ -10,6 +10,8 @@ Audio operations in Qubes OS.
   * [Audio control](#audio-control)
   * [Client started before it's AudioVM](#client-started-before-its-audiovm)
   * [Client turned off with a device attached](#client-turned-off-with-a-device-attached)
+  * [How to use USB devices, Bluetooth, Camera and Microphone](#how-to-use-usb-devices-bluetooth-camera-and-microphone)
+  * [How to attach Bluetooth to the AudioVM persistenly](#how-to-attach-bluetooth-to-the-audiovm-persistenly)
 
 ## Description
 
@@ -36,7 +38,7 @@ qubesctl --skip-dom0 --targets=dvm-sys-audio state.apply sys-audio.configure-dvm
 ```
 <!-- pkg:end:post-install -->
 
-If you need Bluetooth support:
+If you need Bluetooth support, install the dependencies:
 ```sh
 qubesctl --skip-dom0 --targets=tpl-sys-audio state.apply sys-audio.install-bluetooth
 ```
@@ -87,3 +89,30 @@ To use these devices, you have to attach them to their respective qubes:
 
 - audio server: Bluetooth; and
 - audio client: cameras, speakers, microphones.
+
+### How to attach Bluetooth to the AudioVM persistenly
+
+If using Bluetooth, you probably want to have it persistently attached to the
+AudioVM. Bluetooth devices are held by the USB stack, thus you need to attach
+from you `(disp-)sys-usb` to the `disp-sys-audio`.
+
+First, start the qube holding the USB stack:
+```sh
+qvm-start disp-sys-usb
+```
+
+Identify you Bluetooth controller:
+```
+qvm-usb list disp-sys-usb
+```
+
+If you haven't identified the device, run `lsusb` in the USB stack server:
+```sh
+qvm-run -p disp-sys-usb -- lsusb
+```
+
+Permanently attach the Bluetooth controller to the AudioVM (change `DEVID` for
+the one you identified above):
+```sh
+qvm-usb attach --persistent disp-sys-audio disp-sys-usb:DEVID
+```
diff --git a/salt/sys-audio/create.sls b/salt/sys-audio/create.sls
index 0081e54..b42546a 100644
--- a/salt/sys-audio/create.sls
+++ b/salt/sys-audio/create.sls
@@ -60,6 +60,7 @@ features:
 - enable:
   - servicevm
   - service.audiovm
+  - service.blueman
 - disable:
   - service.cups
   - service.cups-browsed