Skip to content

wayland: implement session management#17732

Open
mahkoh wants to merge 1 commit intompv-player:masterfrom
mahkoh:jorth/session-management
Open

wayland: implement session management#17732
mahkoh wants to merge 1 commit intompv-player:masterfrom
mahkoh:jorth/session-management

Conversation

@mahkoh
Copy link
Copy Markdown
Contributor

@mahkoh mahkoh commented Apr 10, 2026

If the compositor supports session management, the mpv window is always added to a session. The user can manage multiple sessions my using --wayland-session=<human-readable-name>. Human-readable names are mapped to session ids via files under ~/.local/state/mpv/sessions. The file name is computed as a hash of XDG_CURRENT_DESKTOP and the human-readable name.

If multiple mpv instances are started with the same session name, the latter mpv instance takes over the session.

Upon session restoration, the mpv window is restored by the compositor according to its state from the previous session. What that entails is compositor policy.

Copilot AI review requested due to automatic review settings April 10, 2026 10:52
Copy link
Copy Markdown

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.

Pull request overview

Implements Wayland session management support (xdg-session-management-v1) so mpv’s Wayland window can participate in compositor-managed sessions, with a new --wayland-session option to select a human-readable session name persisted under the user state directory.

Changes:

  • Add xdg-session-management-v1 integration to the Wayland VO (create/restore session + persist session id to disk).
  • Introduce --wayland-session VO option and plumb it into option structs/defaults.
  • Extend Meson Wayland-protocol generation to include wayland-protocols 1.48 and document the new option/change.

Reviewed changes

Copilot reviewed 4 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
video/out/wayland_common.h Store xdg session objects in Wayland VO state (guarded by HAVE_WAYLAND_PROTOCOLS_1_48).
video/out/wayland_common.c Bind xdg-session-manager, create/restore sessions, and persist session ids under the state dir.
video/out/meson.build Add wayland-protocols 1.48 feature detection and generate xdg-session-management protocol code.
options/options.h Add wayland_session field to VO options struct.
options/options.c Register --wayland-session and set default to empty string.
DOCS/man/options.rst Document new --wayland-session option.
DOCS/interface-changes/wayland-session.txt Record interface change for the new option/behavior.

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

Comment thread DOCS/man/options.rst Outdated
@mahkoh mahkoh force-pushed the jorth/session-management branch 2 times, most recently from daf7f16 to 0552713 Compare April 10, 2026 11:04
@mahkoh mahkoh force-pushed the jorth/session-management branch from 0552713 to 8b1d0c6 Compare April 11, 2026 13:47
Comment thread DOCS/man/options.rst Outdated
Comment thread video/out/wayland_common.c Outdated
@mahkoh mahkoh force-pushed the jorth/session-management branch 2 times, most recently from 5f5c725 to aa28b41 Compare April 16, 2026 15:43
Comment thread options/options.c Outdated
Comment thread video/out/wayland_common.c
Comment thread video/out/wayland_common.c Outdated
Comment thread video/out/wayland_common.c Outdated
char *xdg_current_desktop = getenv("XDG_CURRENT_DESKTOP");
if (!xdg_current_desktop)
xdg_current_desktop = "";
const char *session = vo->opts->wayland_session;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
const char *session = vo->opts->wayland_session;
bstr session = bstr0(vo->opts->wayland_session);
if (!session.len)
// handle unset

(return NULL probably)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

wayland_session can't be null here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This function is guarded by the check in line 2940.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At init? What if someone do set wayland-session bla from keybind/console?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also, this is arguably a nitpick, but I would consolidate checks in one place. So you call read_session_id and it gives you session or not, and act on it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I wasn't aware that these settings could change at runtime. In that case we'll need to make a safety copy of the variable during initialization since the name of the wayland session cannot change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes. Generally all options in mpv can change at runtime, but if it's not possible to change session in wayland, we have to read this option only once, like you noted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread video/out/wayland_common.c Outdated
Comment thread video/out/wayland_common.c Outdated
Comment thread video/out/wayland_common.c Outdated
@mahkoh mahkoh force-pushed the jorth/session-management branch 3 times, most recently from a7aeba7 to 8181ccf Compare April 18, 2026 15:36
Comment thread video/out/wayland_common.c Outdated
@mahkoh mahkoh force-pushed the jorth/session-management branch 4 times, most recently from 89e50e3 to bed0b9a Compare April 19, 2026 13:06
@Dudemanguy Dudemanguy self-requested a review April 20, 2026 00:07
Copy link
Copy Markdown
Member

@kasper93 kasper93 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

Comment thread video/out/wayland_common.h Outdated
If the compositor supports session management, the mpv window is always
added to a session. The user can manage multiple sessions by using
`--wayland-session=<human-readable-name>`. Human-readable names are
mapped to session ids via files under `~/.local/state/mpv/sessions`. The
file name is computed as a hash of XDG_CURRENT_DESKTOP and the
human-readable name.

If multiple mpv instances are started with the same session name, the
latter mpv instance takes over the session.

Upon session restoration, the mpv window is restored by the compositor
according to its state from the previous session. What that entails is
compositor policy.
@mahkoh mahkoh force-pushed the jorth/session-management branch from bed0b9a to 19093fe Compare April 20, 2026 20:28
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.

6 participants