Skip to content

Add session restore support#800

Open
cheerfulScumbag wants to merge 4 commits intomangowm:mainfrom
cheerfulScumbag:feature/session-restore
Open

Add session restore support#800
cheerfulScumbag wants to merge 4 commits intomangowm:mainfrom
cheerfulScumbag:feature/session-restore

Conversation

@cheerfulScumbag
Copy link
Copy Markdown

@cheerfulScumbag cheerfulScumbag commented Mar 22, 2026

Adds opt-in session save/restore support to Mango.

When session_restore=1:

  • Mango saves a restorable snapshot on clean shutdown
  • Mango loads that snapshot on next startup
  • Mango relaunches supported apps from persisted launch_command
  • Mango restores tag, monitor, floating/fullscreen state, and floating geometry as windows map

When session_restore=0:

  • Mango behaves as before
  • no session file is written
  • no restore or relaunch path runs

Supported config:
'session_restore=0|1'

Optional override config:
'session_launch=app_id|command'
'session_launch=app_id|title|command'

Current launch-command priority:

  1. exact command Mango itself used to spawn the app
  2. normalized higher-level launcher command recovered from process metadata
  3. raw process argv fallback
  4. title-specific session_launch
  5. app-only session_launch
  6. plain app_id

Normalization currently implemented:

  • Flatpak apps normalize to desktop-entry launcher command
  • desktop-entry-backed apps normalize to the desktop file Exec= command

Validated:

  • disabled path writes no session file
  • clean shutdown save
  • self-relaunch on next Mango startup
  • duplicate foot windows with title-specific mappings
  • exact command capture for Mango-owned exec-once launches
  • process-based recovery for apps Mango did not spawn directly
  • single-monitor restore
  • floating geometry restore
  • tag restore
  • two-monitor restore when outputs already exist before clients map

@cheerfulScumbag cheerfulScumbag marked this pull request as draft March 22, 2026 23:16
@cheerfulScumbag
Copy link
Copy Markdown
Author

current implementation works, but I want to improve automatic launch recovery so common apps do not require as much manual session_launch configuration

@cheerfulScumbag
Copy link
Copy Markdown
Author

cheerfulScumbag commented Mar 23, 2026

Updated this draft with a stronger automatic launch-command recovery path.

Since the original draft, Mango now:

  • tracks exact commands for apps it launches itself
  • recovers commands from client process metadata for apps it did not launch directly
  • normalizes Flatpak apps to desktop-entry launcher command
  • normalizes desktop-entry-backed apps to the desktop file Exec= command

That reduces the need for manual session_launch rules for common apps.

@cheerfulScumbag cheerfulScumbag marked this pull request as ready for review March 23, 2026 17:03
@cheerfulScumbag cheerfulScumbag marked this pull request as draft March 23, 2026 17:19
@cheerfulScumbag cheerfulScumbag marked this pull request as ready for review March 23, 2026 19:15
@cheerfulScumbag cheerfulScumbag force-pushed the feature/session-restore branch from e87731f to 3aa9a90 Compare March 24, 2026 20:19
@cheerfulScumbag
Copy link
Copy Markdown
Author

tested on multiple programs and they all restore with no issues
so when session_restore=1:

  • Mango saves a restorable snapshot on clean shutdown
  • Mango loads that snapshot on next startup
  • Mango relaunches supported apps from persisted launch_command
  • Mango restores tag, monitor, floating/fullscreen state, and floating geometry as windows map

Give it a test and let me know what you think

@cheerfulScumbag cheerfulScumbag force-pushed the feature/session-restore branch from 3aa9a90 to f78d3b9 Compare March 25, 2026 20:43
@cheerfulScumbag cheerfulScumbag changed the title Add opt-in session save and restore support Restore Window Sessions Mar 26, 2026
@cheerfulScumbag cheerfulScumbag changed the title Restore Window Sessions Add session restore support Mar 26, 2026
@DreamMaoMao DreamMaoMao force-pushed the main branch 2 times, most recently from 0d3ed31 to 5267649 Compare March 30, 2026 10:35
@cheerfulScumbag
Copy link
Copy Markdown
Author

Small follow-up: I have been using this for a while now with no bugs i can find, multi-monitor restore works fine.

I also tightened the branch since the original draft with portable desktop-entry lookup, improved launcher recovery, and a trusted session-file check.

@DreamMaoMao whenever you have time, I’d appreciate any feedback on this.

@DreamMaoMao
Copy link
Copy Markdown
Collaborator

I'm still not sure if I want to add this feature.

@cheerfulScumbag
Copy link
Copy Markdown
Author

cheerfulScumbag commented Apr 5, 2026

Thanks for the reply.

Understood. To help me judge whether this is worth pressing further, can i ask what your hesitation mainly about?

I’m happy to reduce scope further if needed, but if the concern is that session restore itself is out of scope for Mango, that’s also useful for me to know.

Comment thread src/mango.c
Comment on lines +3249 to +3250
session_save_now(true);
session_shutdown();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Maybe i'm wrong on this, but from my understanding this two function gonna be call for everyone and not only the one who have session restore on the config

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is intentional. The session hooks are always called from the compositor lifecycle, but the feature gate is inside the session module.

Comment thread src/mango.c
Comment on lines +769 to +779
void mango_session_spawn_tracker_init(void);
void mango_session_spawn_tracker_shutdown(void);
void mango_session_track_spawned_command(pid_t pid, const char *command);
void mango_session_attach_spawn_command(Client *c);
void mango_session_remember_client_launch_command(Client *c,
const char *command);
static char *mango_session_recover_process_command(pid_t pid);
static void mango_session_attach_process_command(Client *c);
static char *mango_session_find_desktop_exec(const char *app_id);
static char *mango_session_find_flatpak_command(const char *app_id);
static char *mango_session_normalize_launch_command(Client *c, pid_t pid);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WHAT THE FUCK DO I WROTE ?

Sorry, idk why i'm thinking function declaration was global constant ....

Comment thread src/mango.c
struct wl_list link;
pid_t pid;
time_t created_at;
char command[1024];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The 1024 here seems a magic number

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point. I’ll replace those with named constants so the limits are defined in one place instead of repeating raw buffer sizes.

Comment thread src/session/session.h
char title[512];
char monitor[128];
char launch_command[1024];
int32_t pid;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Magic number here

Comment thread src/mango.c
Comment on lines +769 to +779
void mango_session_spawn_tracker_init(void);
void mango_session_spawn_tracker_shutdown(void);
void mango_session_track_spawned_command(pid_t pid, const char *command);
void mango_session_attach_spawn_command(Client *c);
void mango_session_remember_client_launch_command(Client *c,
const char *command);
static char *mango_session_recover_process_command(pid_t pid);
static void mango_session_attach_process_command(Client *c);
static char *mango_session_find_desktop_exec(const char *app_id);
static char *mango_session_find_flatpak_command(const char *app_id);
static char *mango_session_normalize_launch_command(Client *c, pid_t pid);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

WHAT THE FUCK DO I WROTE ?

Sorry, idk why i'm thinking function declaration was global constant ....

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.

3 participants