Prevent Bluetooth headset from appearing as a media player in Gnome notifications
I recently upgraded Debian on my laptop to Trixie. Overall, it's great!
But one issue I had, was that suddenly my Bluetooth headphones would show up as a media device with previous/play/pause/next controls in the Gnome notification area. These controls didn't work or do anything. But what was even worse: They would steal the focus of media keys events from anywhere else. Which meant I was no longer able, with my keyboard, to play/pause music or video playing elsewhere.
I've had a hard time finding a way around it, but did find a solution today.
Someone on the Ubuntu forums had the same problem. Although they didn't find a solution, one of the responses there got me on the right track.
It turns out to be related to something called MPRIS: Via Bluetooth, the headset presents itself as having media control buttons (which it does) and then Gnome decides to show it as a controllable device. As such, a neat feature. But, unfortunately, useless.
On askubuntu.com I found the question Prevent MPRIS from recognizing an application. I'm out of my confort zone here, but with a tool called qdbus (on Trixie, it's called qdbus6 and can be installed with apt install qdbus-qt6), you can look for D-Bus objects. Searching for things related to "mpris", I got these items while my headphones were connected and a tab in LibreWolf was playing some music:
$ qdbus6 | grep mpris
org.mpris.MediaPlayer2.firefox.instance_1_1406
org.mpris.MediaPlayer2.Bose_QC_45
Following the directions in an answer to the askubuntu.com question, I then created the file /etc/dbus-1/session.d/disable-bose-mpris.conf with the following content:
<busconfig>
<policy context="mandatory">
<deny own_prefix="org.mpris.MediaPlayer2.Bose_QC_45"/>
</policy>
</busconfig>
After running sudo killall -s HUP dbus-daemon, per instructions, and turning my headset off and on again, the media controls for the headset have now disappeared from the Gnome notifications and whatever else is playing will receive any media key input. What a relief. And the media controls on my headset even still work.