From b7a0eb471da855e04eb2bbabde0959dabdf12ad3 Mon Sep 17 00:00:00 2001 From: othmane chekairi Date: Wed, 9 Sep 2026 15:27:35 +0100 Subject: [PATCH] Enable mpris-proxy so Bluetooth headset transport controls reach the player Headsets send play/pause, next and previous as AVRCP passthrough, which bluez only routes to a player registered on org.bluez.Media1. Nothing registered one, so the commands were discarded: headset buttons and stem gestures did nothing, and earbuds with in-ear detection could not pause playback when one was taken out. bluez-utils already ships mpris-proxy and its unit, disabled. Enable it, with a drop-in mirroring bt-agent.service so it stays inert on machines with no bluetooth instead of leaving a failed unit. --- .../mpris-proxy.service.d/10-omarchy.conf | 28 +++++++++++++++++++ install/user/first-run/enable-user-units.sh | 1 + migrations/1788959623.sh | 23 +++++++++++++++ test/shell.d/systemd-test.sh | 13 +++++++++ 4 files changed, 65 insertions(+) create mode 100644 default/systemd/user/mpris-proxy.service.d/10-omarchy.conf create mode 100644 migrations/1788959623.sh diff --git a/default/systemd/user/mpris-proxy.service.d/10-omarchy.conf b/default/systemd/user/mpris-proxy.service.d/10-omarchy.conf new file mode 100644 index 000000000000..83b7f8710942 --- /dev/null +++ b/default/systemd/user/mpris-proxy.service.d/10-omarchy.conf @@ -0,0 +1,28 @@ +# Let Bluetooth headsets drive the media player. +# +# Headsets send transport control as AVRCP passthrough: play/pause, next and +# previous from the buttons or stem gestures, and the pause that earbuds with +# in-ear detection emit when one is taken out. bluez only routes those to a +# player registered on org.bluez.Media1, and with nothing registered it drops +# them, so the buttons do nothing and playback runs on into an ear that is no +# longer listening. mpris-proxy is that registration, exporting session MPRIS +# players to bluez. +# +# bluez-utils ships the unit but leaves it disabled, and it carries no +# conditions or Restart=. mpris-proxy exits 1 ("Can't get on system bus") when +# bluetoothd is unreachable at startup, so enabling it as shipped leaves a +# failed unit on every machine without a usable adapter. The two conditions +# mirror bt-agent.service and skip it cleanly there instead. +# +# Restart= covers mpris-proxy itself dying, and nothing more. It does not +# recover a bluetoothd restart: a running proxy survives that without exiting, +# logging "org.bluez disappeared" and then "org.bluez appeared", so systemd is +# never involved. A user unit cannot order itself against the system +# bluetooth.service, so recovering that case is out of reach from here. +[Unit] +ConditionPathIsDirectory=/sys/class/bluetooth + +[Service] +ExecCondition=/usr/bin/systemctl is-active --quiet bluetooth.service +Restart=on-failure +RestartSec=2 diff --git a/install/user/first-run/enable-user-units.sh b/install/user/first-run/enable-user-units.sh index e08885c9e0dc..85c7c633f2c9 100755 --- a/install/user/first-run/enable-user-units.sh +++ b/install/user/first-run/enable-user-units.sh @@ -14,6 +14,7 @@ set -euo pipefail systemctl --user daemon-reload systemctl --user enable --now \ bt-agent.service \ + mpris-proxy.service \ owed.service \ omarchy-recover-internal-monitor.service \ omarchy-sleep-lock.service \ diff --git a/migrations/1788959623.sh b/migrations/1788959623.sh new file mode 100644 index 000000000000..273851d268b0 --- /dev/null +++ b/migrations/1788959623.sh @@ -0,0 +1,23 @@ +echo "Enable the Bluetooth MPRIS proxy so headset transport controls reach the player" + +# Only first-run enables the units we ship, so existing installs never picked +# this one up. The drop-in keeps it inert where there is no bluetooth, so it is +# safe to enable unconditionally here. + +systemctl --user daemon-reload >/dev/null 2>&1 || true + +# `systemctl enable` needs a live user manager, which an update from a TTY does +# not have, so fall back to writing the symlink it would have written. The unit +# bluez ships is WantedBy=default.target, not graphical-session.target. +if ! systemctl --user enable mpris-proxy.service >/dev/null 2>&1; then + wants_dir="$HOME/.config/systemd/user/default.target.wants" + mkdir -p "$wants_dir" + ln -sfn /usr/lib/systemd/user/mpris-proxy.service \ + "$wants_dir/mpris-proxy.service" +fi + +# Nothing to start into over SSH; the next login handles it. A failed start +# only delays headset button support, so it stays quiet. +if systemctl --user is-active --quiet default.target; then + systemctl --user start mpris-proxy.service >/dev/null 2>&1 || true +fi diff --git a/test/shell.d/systemd-test.sh b/test/shell.d/systemd-test.sh index ce7b79b703ed..e31d9c2a9f46 100755 --- a/test/shell.d/systemd-test.sh +++ b/test/shell.d/systemd-test.sh @@ -104,3 +104,16 @@ pass "systemd-oomd acts on sustained memory stall" grep -Fx 'systemctl enable systemd-oomd.service' "$ROOT/install/config/enable-services.sh" >/dev/null || fail "new installs ship the oomd drop-ins with the daemon that reads them disabled" pass "new installs enable systemd-oomd" + +mpris_dropin="$ROOT/default/systemd/user/mpris-proxy.service.d/10-omarchy.conf" +grep -Fx 'ConditionPathIsDirectory=/sys/class/bluetooth' "$mpris_dropin" >/dev/null || + fail "the AVRCP bridge is pulled in on machines with no bluetooth subsystem" +grep -Fx 'ExecCondition=/usr/bin/systemctl is-active --quiet bluetooth.service' "$mpris_dropin" >/dev/null || + fail "mpris-proxy exits 1 when bluetoothd is unreachable, so without this it leaves a failed unit instead of skipping" +grep -Fx 'Restart=on-failure' "$mpris_dropin" >/dev/null || + fail "a crashed proxy stays dead and headset transport controls silently stop working" +pass "the AVRCP bridge stays inert without bluetooth and recovers from its own crash" + +grep -F 'mpris-proxy.service' "$first_run_units" >/dev/null || + fail "first-run does not enable the AVRCP bridge, so bluez has no player registered and headset transport commands are discarded" +pass "first-run enables the bridge that carries headset play/pause into MPRIS"