Reply to topic

Inhibit/Delay shutdown in KDE

peckto
Registered Member
Posts
3
Karma
0

Inhibit/Delay shutdown in KDE

Sat Aug 26, 2017 3:28 pm
Hi,

I'm currently developing a Backup solution for Linux Desktop Users.
The software is meant to run in user-land and should fit nicely in the KDE desktop environment.
When a backup process is running and the user wants to poweroff the system (either via Menu->Exit->Shutdown or by pressing the power button)
the user should be given the opportunity to delay the shutdown until the backup is finished.
Unfortunately I could not find an interface which meets this use-case.
(When the user triggers the shutdown as root eg. sudo poweroff, its a different story, in this case I can only stop the backup process gracefully, that's OK)

What I found so far:
org.freedesktop.login1.Manager.Inhibit
Systemd provides a DBus interface to inhibit shutdown.
This works when a non root user triggers the shutdown event via systemd (eg. systemctl poweroff), but KDE seems not to recognize this Lock.

org.gnome.SessionManager.Inhibit
For the Gnome Desktop I found the DBus interface org.gnome.SessionManager.Inhibit, which creates an entry in the shutdown confirmation window.
This method works only for Gnome and it only informs the user about unsaved changes, but does not actually prevent or delay the shutdown.

Power Management
There are also some DBus interfaces to tell the power management no to activate the screensaver, or not to go to standby when idle
* org.kde.Solid.PowerManagement.PolicyAgent->AddInhibition
* org.freedesktop.PowerManagement.Inhibit->Inhibit


My questions are now:
1. Does KDE provide an interface for an application to interact with the shutdown process?
2. Or is there a different Layer in the shutdown process I can use?
3. How are other applications doing this (eg. system updater)?
4. Are they doing this at all?

I would be really happy if you could point me in the right direction.

Best regards,
peckto
airdrik
Registered Member
Posts
1854
Karma
5
OS

Re: Inhibit/Delay shutdown in KDE

Tue Aug 29, 2017 8:31 pm
This seems similar to the way that various editors can prompt the user to save/discard unsaved changes when the editor is closed which also pops up and pauses the shutdown/logout process.
If I understand correctly they work by intercepting the SIGINT and/or SIGTERM signals that normally get sent when closing the application (either by closing its window or by the shutdown/logout process) and using that to initiate prompting the user if they wish to save their work. The shutdown process will usually wait a while for processes to finish closing after which they should prompt if the user wishes to wait longer or shut down immediately (in which case the shutdown process should start issuing SIGKILL signals to forcibly terminate any remaining (child) processes).

I don't know if there are other higher-level ways to do handle that provided by Qt/KDE libraries, so you might peruse the code for e.g. kate and see how they do it.


airdrik, proud to be a member of KDE forums since 2008-Dec.
peckto
Registered Member
Posts
3
Karma
0

Re: Inhibit/Delay shutdown in KDE

Tue Sep 12, 2017 12:05 pm
Thank you for your answer airdrik!
I did not know this behavior of Kate and other editors, this is a useful hint.
Apparently this behavior is done inside Qt, by overwriting the closeEvent handler function of a widget:
http://doc.qt.io/qt-4.8/qwidget.html#closeEvent
In this layer you have the possibility to either accept or ignore the closeEvent.
In case of ignoring the closeEvent, the Exit or system shutdown does not take place.
Example code:
https://gist.github.com/anonymous/2f149 ... f6cf0f97c6

This is different from catching the system level SIGINT/SIGTERM signals, which are one-way.
In case of catching SIGINT/SIGTERM, my KDE desktop does not even wait a second before closing the desktop environment.

The only problem with the closeEvent is, that it requires a Window (and the Window must be shown!),
because the Window (and not the Application) receives the closeEvent.
The Application itself has only the aboutToQuit handler, which can take no influence on the event:
http://doc.qt.io/qt-4.8/qcoreapplicatio ... boutToQuit

For my backup solution I would like to have a background daemon, which has no active window when making a backup.
Does somebody know an interface for a non GUI application (could still use Qt or GTK) similar to the closeEvent (with accept/ignore event)?
How is closeEvent working under the hood, can I use it somehow without a window?
Is there a DBus interface?

Best regards,
peckto
peckto
Registered Member
Posts
3
Karma
0

Re: Inhibit/Delay shutdown in KDE

Mon Jul 16, 2018 3:11 pm
Hi,

is there any news on this topic?
If there is no such option in KDE right now, where can I propose this as a new feature?

Best regards,
peckto

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], cylverbak, funkyskywalker, Google [Bot], ineuw, Majestic-12 [Bot], maxmu, MRK0017, Sogou [Bot], sylvainrousseau, Yahoo [Bot]