wayland: implement session management#17732
Conversation
There was a problem hiding this comment.
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-sessionVO 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.
daf7f16 to
0552713
Compare
0552713 to
8b1d0c6
Compare
8b1d0c6 to
5f5c725
Compare
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.
5f5c725 to
aa28b41
Compare
| .timing_offset = 0.050, | ||
| .swapchain_depth = 2, | ||
| .focus_on = 1, | ||
| .wayland_session = "", |
There was a problem hiding this comment.
No need for that. Generally all internal code in mpv, should treat "" and NULL string options the same way. We generally don't initialize them.
| static void xdg_session_replaced(void *data, struct xdg_session_v1 *xdg_session_v1) | ||
| { | ||
| struct vo_wayland_state *wl = data; | ||
| MP_WARN(wl, "Session has been replaced!\n"); |
There was a problem hiding this comment.
Is the WARN correct here? This sounds more like an INFO or VERBOSE kind of information, no?
| if (!xdg_current_desktop) | ||
| xdg_current_desktop = ""; | ||
| const char *session = vo->opts->wayland_session; | ||
| char *full_name = ta_asprintf(talloc_ctx, "%16" PRIx64 "%s%16" PRIx64 "%s", |
There was a problem hiding this comment.
Use bstr_xappend_asprintf please.
| char *xdg_current_desktop = getenv("XDG_CURRENT_DESKTOP"); | ||
| if (!xdg_current_desktop) | ||
| xdg_current_desktop = ""; | ||
| const char *session = vo->opts->wayland_session; |
There was a problem hiding this comment.
| const char *session = vo->opts->wayland_session; | |
| bstr session = bstr0(vo->opts->wayland_session); | |
| if (!session.len) | |
| // handle unset |
(return NULL probably)
| char *file_path; | ||
| file_path = mp_find_user_file(NULL, vo->global, "state", "sessions"); |
There was a problem hiding this comment.
| char *file_path; | |
| file_path = mp_find_user_file(NULL, vo->global, "state", "sessions"); | |
| char *file_path = mp_find_user_file(NULL, vo->global, "state", "sessions"); |
| char *file_path; | ||
| file_path = mp_find_user_file(NULL, vo->global, "state", "sessions"); | ||
| mp_mkdirp(file_path); | ||
| file_path = mp_path_join(talloc_ctx, file_path, (char*)file_name.start); |
There was a problem hiding this comment.
bstr.start may not be null-terminated, you cannot use it like so. Use mp_path_join_bstr please.
| return NULL; | ||
| if (bstr_validate_utf8(id) < 0) | ||
| return NULL; | ||
| return (char*)id.start; |
There was a problem hiding this comment.
Cannot do that, bstr may not be null terminated. Return bstr or use bstrto0()
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.