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[1882154]: 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
$ sudo systemctl restart rtkit-daemon

I found interesting debug line:

bluetoothd[1877627]: 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       user@1003.service           -       -
:1.7031                                            1894114 pulseaudio      user1           :1.7031       user@1000.service           -       -
:1.7034                                            1894116 pulseaudio      user2   :1.7034       user@1002.service           -       -

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

Gist with code

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.

Other helpful sources:

Add new comment

The content of this field is kept private and will not be shown publicly.
  • No HTML tags allowed.
 oooooo     oooo    .oooooo.       ooooo     ooo   o8o      oooo  oooooo   oooo 
`888. .8' d8P' `Y8b `888' `8' `"' `888 `888. .8'
`888. .8' 888 888 888 8 oooo 888 `888. .8'
`888. .8' 888 888 888 8 `888 888 `888.8'
`888.8' 888 888 888 8 888 888 `888'
`888' `88b d88b `88. .8' 888 888 888
`8' `Y8bood8P'Ybd' `YbodP' o888o .o. 88P o888o

Enter the code depicted in ASCII art style.