Skip to content

fix: prefer dedicated music players over browsers for media keys#5985

Open
loicfavory wants to merge 2 commits into
basecamp:devfrom
loicfavory:fix/media-keys-browser-priority
Open

fix: prefer dedicated music players over browsers for media keys#5985
loicfavory wants to merge 2 commits into
basecamp:devfrom
loicfavory:fix/media-keys-browser-priority

Conversation

@loicfavory
Copy link
Copy Markdown

Problem

Browsers (Chromium, Firefox) register as MPRIS players as soon as they open, even when no media is playing. When playerctld is running, it can pick the browser as the active player — causing media keys (play/pause/next/prev) to silently target the browser instead of a running music app (cliamp, Spotify, etc.).

The result: play/pause only works intermittently, or not at all, depending on which player playerctld happens to have prioritized.

Fix

Extend omarchy-swayosd-client to detect this situation when --playerctl is used without an explicit --player: it scans all MPRIS players and injects --player <best> with the following priority:

Priority Condition
1st Dedicated music player that is Playing
2nd Browser that is Playing (e.g. YouTube actively running)
3rd Dedicated music player that is Paused
4th Browser that is Paused

This means:

  • cliamp/Spotify playing + Chrome open → music player gets the command
  • YouTube playing + cliamp paused → YouTube gets the command
  • Only Chrome open (stopped) → falls back to default playerctl behavior ✓

Scope

  • No changes to media.lua or any bindings
  • Transparent when --player is already supplied explicitly
  • Only activates for --playerctl calls, leaving all other swayosd behavior untouched

Browsers (Chromium, Firefox) register as MPRIS players as soon as they
open, even with no media playing. When playerctld is also running, it
can pick a browser as the active player, causing media keys to silently
target the browser instead of a running music app (cliamp, Spotify…).

Extend omarchy-swayosd-client to detect this situation when --playerctl
is used without an explicit --player: it scans all MPRIS players and
injects --player <best> with the following priority:

  1. Dedicated music player that is Playing
  2. Browser that is Playing  (e.g. YouTube actively running)
  3. Dedicated music player that is Paused
  4. Browser that is Paused

This keeps the existing media.lua bindings unchanged and is transparent
when --player is already supplied explicitly.
Copilot AI review requested due to automatic review settings May 27, 2026 16:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

When --playerctl is used without --player:
- If a dedicated music player (non-browser) is Playing, always target it
  regardless of what browsers are doing.
- If no browser is Playing and a music player is Paused, target it to
  resume it (avoids resuming YouTube when nothing is happening there).
- Otherwise fall through to playerctld, letting it handle the active
  player naturally (e.g. YouTube playing while music is paused).

The previous full-priority approach (music > browser > music-paused >
browser-paused) caused a cycling bug: with cliamp and YouTube both
playing, pressing play-pause once paused cliamp, then playerctld handed
control to YouTube, then both were paused and the script kept resuming
cliamp in a loop — YouTube stayed paused indefinitely.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants