Skip to content

ALI-2358: MPRIS, so media controllers, playerctl and the screensaver work - #9

Merged
michaelaguiar merged 45 commits into
mainfrom
ali-2358-player-mpris
Dec 3, 2026
Merged

michaelaguiar merged 45 commits into
mainfrom
ali-2358-player-mpris

Conversation

@michaelaguiar

Copy link
Copy Markdown
Member

Part of ALI-2358: Alias View plays video and music. This is the last of the stack: #6 (tokens) ← #7 (playback) ← #8 (player UI) ← this.

This PR adds MPRIS. The ticket needs it "so the bar's media controls and playerctl work. The screensaver's PiP pause relies on this," and the canvas's keys board says the same: play, pause, next, previous and position.

What changes

  • When it runs. src/mpris.rs serves org.mpris.MediaPlayer2 and org.mpris.MediaPlayer2.Player as org.mpris.MediaPlayer2.alias_view.instance<pid>, using zbus 5.19. accesskit_unix already builds that version with the same async-io executor; blocking-api only adds the blocking wrappers, so the build gains no new crate. It starts when the first video or song opens, never for pictures alone, and only with a session bus. It joins the bus on its own thread, so a slow bus never holds up the window.
  • Requests. Requests arrive on zbus's thread and reach the loop over a channel with a wake, as the screen reader's actions do. They're handled before the player syncs, so Next opens the next file on the same turn.
  • Play and pause:
    • PlayPause, Play and Pause work. Stop pauses, because a file is never "stopped" while open.
    • A Pause while a file opens is kept: the file reads Paused and stays paused once loaded.
    • Play after the end plays from the start.
  • Next and Previous go to the next or previous video or song in the folder, skipping pictures and going round. CanGoNext and CanGoPrevious say whether there's one.
  • Position and seeking:
    • Seek goes past the end to the next track, or to the end when there's none.
    • SetPosition applies only to the current track and only within its length.
    • Seeked is sent for every real seek (keys, the slider, Seek, SetPosition, the screen reader, replay), with Position already updated.
    • Position is read on demand and never signalled.
  • Properties:
    • Volume is 0 to 1, and reads 0 while muted. A set is known at once, so its change signal carries the new value.
    • Metadata carries mpris:trackid (a new track per file), mpris:length in µs, xesam:title (the tag, or the file name), xesam:artist, xesam:album, and xesam:url, percent-encoded from the path's bytes.
    • With a picture showing, the player reports Stopped, with the NoTrack id only and CanPlay, CanPause and CanSeek false.
  • Change signals. Each property is signalled once, only when it changed. What MPRIS reports is rebuilt only when it changed, not on every wake.
  • Announcements. A volume change or seek from a controller is announced to the screen reader, as the same change from a key would be.

Security

MPRIS exposes control only: play, pause, seek, volume, next, previous and quit. OpenUri does nothing and no URI schemes are listed, so a bus client can't make Alias View open anything.

Checks

  • cargo +1.100 clippy --all-targets -D warnings is clean, and 134 tests pass. New tests cover the metadata keys and types, the URL for names that aren't UTF-8, the Stopped metadata, and skipping pictures and going round.
  • Live, against a private D-Bus session bus. Run in the private headless weston and PipeWire, with a minimal config: no service directories, so nothing can be auto-started. Driven with busctl:
    • PlaybackStatus while opening, playing and paused;
    • Pause while opening;
    • PlayPause, Play and Pause;
    • SetPosition, including one beyond the length (ignored);
    • Seek, Seeked (watched with busctl monitor), and Seek past the end moving to the next song;
    • Volume;
    • Metadata, including the title, artist, album and URL;
    • Identity and CanGoNext.
  • Not yet run: playerctl against Mike's live session, and the bar's media widget. Both need Mike's OK.

Review

/review-loop ran four rounds with a fresh-context reviewer before this PR was opened:

  • Round 1: play and pause while opening, Seeked guessed from jumps, duplicate signals, volume while muted, the SetPosition and Seek spec cases, pictures in Next, announcements, and the bus joined on the loop.
  • Round 2: tags arriving one by one went unsignalled, and Seeked came before Position; plus pause while opening, seek with no next track, volume with nothing open, replay's Seeked, URLs for names that aren't UTF-8, and the cached neighbours.
  • Round 3: Next waited for the next input, replay's Position, a paused resume, and late or impossible seeks.
  • Round 4: no P1 or P2. Its two P3s are fixed: requests now act on the file that's open, and MPRIS starts on the same turn.

Declined:

  • Moving signal emission off the window's thread. An emission only waits to queue a small write, and a wedged session bus would already stall AccessKit.
  • One transient after a replay or a seek from the end, where a helper report sent before the seek briefly shows the old position. The next report corrects it.

New tokens for the player design on the Alias View canvas, for Mike to
review before any player code is written:
- spacing: controls-gap, cover-gap;
- sizes: controls-height, control-icon, seek-track, seek-played, seek-thumb,
  volume-width, cover-art;
- motion: controls-hide, seek-step;
- scale: volume-step.

The colours stay the seven theme roles. New contrast pairs: an icon on a
hovered button (foreground on border, 3:1), the music view's artist line
(muted on base, 4.5:1) and the seek bar's unplayed part (muted on panel,
3:1). They pass in every shipped theme and the built-in two.
- A video or song in the list opens in alias-playback's GPU helper: libmpv in a
  bubblewrap jail, drawing on the card the compositor uses (from linux-dmabuf feedback)
  and handing its frames over as dmabufs. They show in a subsurface above the window, so
  they never pass through this process. Sound goes through the session's PulseAudio
  socket, bound into the jail read-only.
- The folder list takes videos and songs, so n, p, Page Up and Page Down move between
  them and pictures.
- Space plays and pauses (after the end, plays from the start), Left and Right seek 5 s
  (seek-step), f toggles full screen and Escape leaves it.
- While a file opens, the window says so; a file that can't play says why.
- alias-playback is a git dependency on the branch of its PR #3 until #2 and #3 merge.
- The control bar from the design canvas, on an overlay subsurface above the video:
  Previous, Play (pause and replay icons), Next, the time, Position, Mute, Volume and
  Full screen, every target 44 px, with the focus ring and a border-coloured hover fill.
  The played part of a slider is thicker than the rest.
- It hides 2 s after the last pointer move or key while a video plays, and stays while
  paused, ended, opening, for music, and while the keyboard focus is in it.
- Keys from the canvas: Space and k, Left and Right seek, Up and Down volume, m, f and
  double-click, Home, t, Tab through the bar, and the media keys.
- The music view: cover art at up to 320 px with rounded corners, or a panel with a note,
  and the title with "artist · album" under it. A song plays on to the next song in the
  folder and stops after the last.
- AccessKit: named buttons, toggle buttons and sliders with values, and polite
  announcements for opening, play and pause, the end, failures, volume and seeks.
- Tokens: time-pad, controls-group-gap, cover-icon, seek-announce and double-click,
  proposed with #6's. Lucide's ISC notice for the icons is in LICENSE.
…IFOs, full screen

- A buffer the helper sends is checked before it reaches the compositor: its format and
  modifier must be one the compositor listed (dmabuf feedback's table, or v3's events) and
  its planes must fit in the dmabuf. A bad one was a protocol error that closed the window;
  now the file can't play and says why.
- A buffer replaced while on screen is destroyed with the video layer if it's never let go.
- A buffer the compositor lets go while still on screen goes back to the helper once the
  next frame replaces it; before, the slot was lost, and after three the video froze.
- The frame on screen moves to the middle of the window when it changes size, even with
  no new frame coming (paused, ended, a song's cover).
- A helper that dies mid-play takes its last frame with it, so the reason shows.
- Session::failure ends the helper before waiting for it: the socket can fail with the
  helper still running, and the wait froze the window.
- A path that isn't a regular file (a FIFO) is refused before it's opened, which waited
  for a writer.
- Full screen carries from one video to the next, and ends for a song or a picture.
- Left and Right change file when the file can't play, as for pictures.
…ay, Ctrl+C

Merges ali-2358-player-video (its review round: buffer checks, re-centring, failures, FIFOs,
full screen). Conflicts resolved to keep both: the player's keys stay in media_key, which
now lets Left and Right change file when the file can't play.

Review fixes for this PR:
- The keyboard focus in the bar stays on the same control from file to file (Next
  pressed again goes on); close_media had reset it before it was read.
- Announcements are said once: each goes in one of two alternating status nodes and is
  gone from the next tree, so the same words twice (t) are said again, and a stale one
  is never read back when a toast ends.
- A position or volume report redraws only the bar on the overlay, not all of it.
- Ctrl+C on a video or song offers the file only; it offered a PNG the picture
  decoders would have tried to make from the media file.
- The music view's fallback line height comes from the type tokens.
…kept

- A file that can't play (a refused buffer, or the helper saying it can't) ends its
  helper, so no sound plays on under the reason, and frames that still arrive are
  given back, not shown.
- A helper that closed its socket cleanly is waited for, not killed, so its exit code
  says why (libmpv missing, the sandbox not set up). Only after a read error is it ended
  first.
- The format table comment says what the table is now used for.
…e bus off the loop

- Play and Pause do what they say while a file opens (Play no longer toggled it to paused;
  Pause no longer did nothing), and Opening reads as Playing.
- Seeked is sent for each real seek (keys, the slider, Seek, SetPosition, the screen
  reader) with where it went, not guessed from jumps in position.
- Each property is signalled once and only when it changed: Metadata not on a pause, and
  CanSeek once.
- Volume reads 0 while muted, and a Volume set is known at once, so its change signal
  carries the new value.
- Seek past the end goes to the next track; SetPosition is ignored when stopped or past
  the end, as the spec says.
- Next and Previous (and CanGoNext and CanGoPrevious) go to the next video or song, past
  pictures, going round.
- A volume set or seek from a controller is announced as a key's would be.
- The session bus is joined on a thread, so a slow bus never holds up the window; what
  MPRIS says is rebuilt only when it changed, with Position stored on each wake.
- The zbus comment is back above its own line.
- Session::send waited for nothing: the socket is non-blocking (for reading), so a full
  one dropped the command, and a lost release left the helper a buffer short for good. A
  full socket is now waited on briefly.
- Video is shown only where the compositor has viewporter, which places a frame at any
  window scale; without it the frame would be drawn at the wrong size.
… player keys in --help

- Opening the grid closes the player; back from it, the same video or song picks up at
  the position it had, playing or paused as it was, instead of from the start.
- The hover fill keeps the icon at 3:1 in any theme: a theme whose border is too close to
  its text gets a fill moved toward the panel until it passes (with a test).
- The key-list fit test covers the player's list too, at 100%, 125% and 200%.
- --help lists the player's keys, and the usage and folder messages say videos and songs.
…reset

- alias-playback e11d5f4: #2's requests and reads that never wait, and #3's tags read
  with them (a song's cover played 12 of 12 times in the private weston, tags each time).
- A helper whose socket ends in a reset rather than a clean close (it exited with
  commands unread) gets 100 ms to finish before it's ended, so its exit code still says
  why it stopped.
…me stays paused

- The place kept for the file the grid closed was dropped only when another video or
  song opened, so after closing the grid onto a picture, the file could open much later
  at the old place. It now lasts only until the grid closes: onto that file it's used,
  onto any other it's dropped.
- A file paused before the grid is asked to pause as it opens, so it no longer plays
  briefly from the start before the seek.
…se while opening

- What MPRIS says is rebuilt when any tag changes, not only the first: tags arrive one by
  one, and the artist or album could go unsignalled.
- On a seek, Position is stored before Seeked is sent, so a controller reading it then
  gets the new place.
- A pause while a file opens is kept (it stays paused once loaded, and reads Paused),
  and Play or Play/Pause undoes it.
- Seek past the end with no next track goes to the end.
- A Volume set with nothing playing isn't stored.
- Replay from the end sends Seeked to 0.
- The file's URL is made from its bytes, so a name that isn't UTF-8 still names it.
- The next and previous video or song are kept while the list and the place are the
  same, not looked for on every wake.
- A controller's requests are handled before the player syncs, so Next and Previous
  open the next file on the same turn, not on the next input.
- Replay from the end shows the start at once, so the Position read on its Seeked is 0.
- A file reopened paused after the grid is paused the way a controller's pause is, so it
  reads Paused while it opens and Play/Pause plays it.
- A seek made before the bus joined isn't sent late; a SeekTo while a file opens isn't
  announced, as it can't happen.
With no list (the table couldn't be read), any modifier was taken; now nothing is, so a
buffer from the helper is never one the compositor hasn't said it takes.
@michaelaguiar
michaelaguiar added this pull request to stack #10 December 2, 2026 22:42
@michaelaguiar
michaelaguiar marked this pull request as ready for review December 2, 2026 22:43
main's tree is the same as ali-2358-player-video's c4eeb7d, which this branch
already merged, so the branch's side is kept as it is.
Mike approved the player's tokens on 2026-12-02 (the ones from #6, and
time-pad, controls-group-gap, cover-icon, seek-announce and double-click
added after it). Their usage notes, the player's contrast pairs, and the
player clauses on border, muted and accent now read as plain fact.
src/tokens.rs regenerated with design/build.
Mike's decision of 2026-12-02: once the bar hides by itself over a playing
video, the pointer hides with it, and whatever brings the bar back (any
pointer motion, a key, a pause) brings the pointer back with the shape it
would have. Music, a paused or ended video, and keyboard focus in the bar
never hide it, as they never hide the bar.

The pointer is hidden with wl_pointer.set_cursor and no surface, at the
serial of the last enter, and kept hidden when it enters the window again.
Only where cursor-shape-v1 is offered: without it the shape can't be set
again, so the pointer is never hidden there.
…8-player-mpris

# Conflicts:
#	src/app/player_ui.rs
The pointer comes back with the bar on a key, a click or a pause as well as on
pointer motion, and hides only where cursor-shape-v1 is offered. Review round
5 on #8.
The jailed GPU helper's branch (ali-2358-gpu-media) merged as fef4a47, with the same code as
the 4a05f2c this was pinned to.
Base automatically changed from ali-2358-player-ui to main December 3, 2026 00:39
@michaelaguiar

Copy link
Copy Markdown
Member Author

Merged main into the branch after #8's squash merge (a9ce309), keeping this branch's side. a9ce309's tree is identical to #8's final head caa95f4, which this branch already contained, so the files are unchanged from 78335bc, whose checks passed, and the diff against main is only this PR's change.

@michaelaguiar
michaelaguiar merged commit 7723db3 into main Dec 3, 2026
2 checks passed
@michaelaguiar
michaelaguiar deleted the ali-2358-player-mpris branch December 3, 2026 00:55
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.

1 participant