Can Ubuntu prompt me to save unsaved documents during logout/restart/shutdown?

Let’s say I have unsaved documents in LibreOffice or in text editors. If I logout/restart/shutdown, Ubuntu doesn’t ask me to save files. It seems like Ubuntu doesn’t close programs gracefully.

Is there a way to get prompted to save unsaved documents during session close? (Like Windows does.)

Note: I’ve found below related issue:

Ubuntu 20.04
Gnome 3.36.8

Crossposting:

GNOME Shell does prompt when there’s unsaved documents, but the application itself must support it. This is done by adding an inhibitor with e.g. g_application_inhibit(), which for example Gedit does, and so GNOME Shell shows the Gedit icon with the “There are unsaved documents” message when trying to logout or shutdown.

So LibreOffice would have to support this to have GNOME Shell prompt you to save the documents.

If LibreOffice already inhibit the session, then maybe there’s a bug somewhere? That’s anyway how you’d add an inhibitor to an application.

2 Likes

Is g_application_inhibit() available for non-GTK applications too?

Well this function is in GLib, not GTK. But anyway LibreOffice uses its own cross-platform UI library that wraps platforms’ ones (Windows, Mac OSX, etc.), called VCL. On Linux it has a GTK backend (and a KDE qt one too), so it could use this function if wanted.

Anyway g_application_inhibit() just calls to usual inhibit methods on Linux systems, like the inhibit flatpak portal or org.freedesktop.ScreenSaver, so it wouldn’t necessarily need to use the glib function.

2 Likes

Thanks @vanadiae for detailed responses. I’m surprised that this feature is not added to LibreOffice by now.

One last question. Seems like Gnome doesn’t end programs gracefully. For example, in sublime-text, if I write smtg and close the window, next time I open it, it restores my writing. But, if I write smtg in sublime and restart my PC, sublime doesn’t restore my writing. So, is there a chance Gnome to close applications gracefully, or is this an intentional decision?

1 Like

GNOME has a session manager, with a D-Bus interface that applications can subscribe to (GTK applications using the GtkApplication class do so automatically). Other environments, like XFCE, have their own, similar, D-Bus interface.

On notification that the session is ending, the applications receive a signal meant to be used to save their state, and quit immediately.

3 Likes

So, Gnome is doing their part :slight_smile: Thanks for the answers.

As I understand from your answer, this D-Bus interface is not generic. (Different for Gnome and Xfce.) Are there separate interfaces for other DEs too? I’m thinking about filing feature requests to each app I use about this. So, should I say to their developers, “Can you subscribe to session-close D-Bus interfaces for all DEs?” ? Or, is there a more generic way that all DEs use?

No, it’s not generic. Each desktop environment implements its own, because each environment may have their own requirements. There is no shared specification for session management, also because it’s a fairly complicated topic.

All GTK applications automatically deal with GNOME and Xfce session managers—provided they use GtkApplication. If they don’t use GtkApplication, they really should.

Non-GTK applications will have to handle session management themselves, yes.

No, there is no shared session management API.

1 Like

https://bugs.documentfoundation.org/show_bug.cgi?id=142176

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.