Session management with Qt

Hey, I wanted to ask about the intended use of the new xdg-session-management Wayland protocol and ways to use it in Qt apps.

As an application developer, I’d like my app to be able to restore its windows when it’s launched. The session management protocol can provide just that. With KDE 6.7 and Qt 6.12, I was able to get this working in my app.

However, loading the session ID is a bit inconvenient for clients in Qt, because the session ID needs to be passed when constructing a QGuiApplication (in argv with -session). This seems to be related to the session management on X. There, the client would tell the session manager about the restart command. But on Wayland this doesn’t seem to exist.

I’m not sure if I’m using the session management in the intended way. Is the protocol intended for restoring the client application state or the state of the whole desktop. In the MR for xdg-session-management (!18) this sounded like it was intended for restoring the whole desktop:

This helps for e.g., a compositor/client crashing (definitely not due to
bugs) or a backgrounded client deciding to temporarily destroy its
surfaces in order to conserve resources.

Whereas in the MR for xx-zones (!264), it was said that clients should use xdg-session-management for window restoration:

This protocol will be abused to restore window positions instead of using xdg-session-management
This might indeed be possible. But toolkits will prefer the more widely available, better supported and more complete protocol for this purpose, and that will be xdg-session-management (once merged).

If the protocol is intended for restoring window positions for clients when launched, shouldn’t there be a more convenient way in Qt to restore the session without messing with argc/argv? If so I’ll ask on the Qt forum, but I’m not sure if I understand the protocol correctly.

Yes, it might be that Qt currently only supports the case of a session being tied to the life time of the app process, no saving/restoring during runtime.

There is currently discussion on how to do this independent of the display system and also cover sandboxed applications (e.g. Flatpak, Snap, etc).

Neither but it is intended to be part of both and even more use cases, e.g. switching profiles or app modes.

Ultimately it is the app which wants to save and restore state, whether it does that individually at runtime, on shutdown/restart or when asked by the desktop session.

The Wayland protocol assists in any of those tasks by saving/restoring the current state of the app’s windows. It doesn’t make assumptions on what these tasks are or why the clients wants to do it.

Yes, this is one of the scenarios.

Yes, indeed.

At least allowing it to be set via a method, e.g. on QGuiApplication or the session manager, before startup.
Ideally at any time to support save/restore of profiles, e.g. having different window configurations when a laptop is docked or mobile.