I'm using Xubuntu which has XFCE as DE. And it's possible to switch users fast with hotkeys, without locking them. Hotkey is Ctrl+Alt+F7 (F8, F9, F10, F11).
Pulseaudio works isolated with each user so sounds are not mixed and it's good.
But bluetooth has an issue there: when you connecting to already paired bluetooth device it can be connected to ANOTHER logged user. How you can check it? Profiles will not be available when you click right mouse in bluetooth-manager applet.
There is a small percantage of luck to fix this manually: disconnecting, removing, searching and pairing device again and again.
I've noticed in logs that rtkit-daemon made a thread to not my current active user!
# tail -f /var/log/syslog rtkit-daemon: Successfully made thread 1882287 of process 33259 owned by '1003' RT at priority 5.
First my attempt to fix this was the script which make manual work described above automatically.
But it doesnt work from the first run. And that made me sick.
So I continue to searching the issue.
Enable logs for bluettohd:
$ sudo nano /usr/lib/systemd/system/bluetooth.service ExecStart=/usr/libexec/bluetooth/bluetoothd -d $ sudo systemctl daemon-reload $ sudo systemctl restart bluetooth.service
Enable debug logs for rtkit-daemon:
$ sudo systemctl edit rtkit-daemon [Service] LogLevelMax=warning $ sudo systemctl restart rtkit-daemon
I found interesting debug line:
bluetoothd: profiles/audio/transport.c:media_transport_set_owner() Transport /org/bluez/hci0/dev_12_12_12_12_12_12/sep1/fd0 Owner :1.7027
Where we can see an "Owner :1.531".
To check current id of owners:
$ busctl | grep pulseaudio :1.7027 1894100 pulseaudio user3 :1.7027 firstname.lastname@example.org - - :1.7031 1894114 pulseaudio user1 :1.7031 email@example.com - - :1.7034 1894116 pulseaudio user2 :1.7034 firstname.lastname@example.org - -
So as I understand from the source code the first user from the list will be taken and device attached to it.
It's in function lookup_client() in rtkit-daemon.c source code.
To achieve our goal we should make current user at the top of the list. We're killing all pulseaudio instances and starting it for current user. Other users will be added in short.
$ sudo killall pulseaudio $ systemctl --user start pulseaudio.service
Device should be discovered and paired (trusted) before running that script.
Problem gone! Now I can switch to any user, run that script and have sound in headphones.