It's trivial to run certain scripts during user login however it's impossible to do so on logout. It would be great if xfce could run script upon session logout where user would write things which got to bo executed before session is finished - think some cleanup/graceful shutdown.
I as well support this feature request. It took me some time to find a workaround: http://stackoverflow.com/questions/7579438/how-to-execute-a-script-when-xfce-session-ends A good solution from my POV would be if xfce4-session would source a file $HOME/.logout on regular exit.
I would need this feature in order to make a workaround for this bug: https://bugzilla.xfce.org/show_bug.cgi?id=10295 I would solve this bug by inserting the following code into xfce4-session/xfsm-manager.c (version 4.12.1) in xfsm_manager_save_yourself_global(..) after the call to xfsm_logout_dialog(...) /* Call logout scripts */ switch ( manager->shutdown_type /* see xfsm-shutdown.h */ ) { case XFSM_SHUTDOWN_LOGOUT : system("/bin/bash $HOME/.config/xfce4-session/hook-logout"); break; case XFSM_SHUTDOWN_SHUTDOWN : run("/bin/bash $HOME/.config/xfce4-session/hook-shutdown"); break; case XFSM_SHUTDOWN_RESTART : run("/bin/bash $HOME/.config/xfce4-session/hook-restart"); break; case XFSM_SHUTDOWN_SUSPEND : run("/bin/bash $HOME/.config/xfce4-session/hook-suspend"); break; case XFSM_SHUTDOWN_HIBERNATE: run("/bin/bash $HOME/.config/xfce4-session/hook-hibernate"); break; default: break; } It actually seems to work, but there may be better implementations regarding the system call, standard search paths and security features. (E.g. I'm not sure whether those script would be called with root privileges) Unfortunately when I compile xfce4-session 4.12.1 from source the suspend and hibernate buttons are not shown in the logout-dialog and the reboot and shutdown buttons are grayed out/not clickable. So this is not really working for me. Hoping someone implements this correctly or solves the linked bug. The scripts hook-restart, hook-shutdown and hook-logout would then contain: WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$|xfce4-panel$" | cut -f1 -d' ') for i in $WIN_IDs; do wmctrl -ic "$i"; done # Keep checking and waiting until all windows are closed while [ "$WIN_IDs" != "" ]; do sleep 0.1; WIN_IDs=$(wmctrl -l | grep -vwE "Desktop$|xfce4-panel$" | cut -f1 -d' ') done
I'm really interesting in this bug to be solved. It will make XFCE perfect.
I am too very interested in adding such a feature because it could help to solve an issue I encountered : https://forum.xfce.org/viewtopic.php?pid=50140#p50140 (which is certainly also related to #10295) It is nearly impossible to execute a command at shutdown, processes are killed too quickly by systemd. I thought about hacking into systemd configuration for it to send SIGTERM to processes instead of killing them brutally, but it does not help at all because xfce4-session is already gone at that point (so there is no more interesting variables to use by scripts). The solution would be to implement what's proposed here : let xfce4-session do things BEFORE sending the shutdown command to the system.
Created attachment 8164 Complete feature. Attention, not sure if it runs fine ! Attached a more integrated approach. The same API like for "run on login" is reused. An enum is added to pick from a list "on login", "on logout", "on shutdown", etc. The patched "xfce4-session-settings" already works fine for me, and is fully backward compatible. However so far I failed to get xfce-session to run (I as well failed to get xfce-session master to run :/ ) ... possibly I need a fully blown xfce 4.13 installation first .. to be continued.
Created attachment 8165 Screenshot of proposal for xfce4-session-settings extension
TODO: Add a dropdown inside the window, that's called by add/edit. Currently modification of the enum is only possible after adding a task.
Created attachment 8391 patch1 to move some methods which will be reused
Created attachment 8392 patch2 to introduce the feature Ok, finally I have a good implementation. I split the patch into two, in order to ease comparison. The first patch just moves some methods, used "on login" out of a .c file, since I am going to reuse them "on logout", "on shutdown", etc. The second patch actually adds the new feature - A gtk enum is used in order to allow translations of the corresponding strings - I was finally able to test most cases (did not test "on hybrid sleep" .. though implementation wise there is no difference to the others ) Before I commit the patches to master, it would be good to have some testers. So if you have time, please give the patches a try !
Both patches throw git warnings that would be good to get fixed. Patch 1 .git/rebase-apply/patch:317: new blank line at EOF. Patch 2 .git/rebase-apply/patch:522: trailing whitespace.
Created attachment 8410 patch1 to move some methods which will be reused Ops .. git warnings fixed now.
Created attachment 8411 patch2 to introduce the feature
To ease putting comments to the code: https://github.com/alexxcons/xfce4-session/commits/RunOnLogout5
Alexander Schwinn referenced this bugreport in commit 88346bde9ea6850caaf91e6868813b3132e76b10 Move three methods from startup.c to xfsm-global.c/.h https://git.xfce.org/xfce/xfce4-session/commit?id=88346bde9ea6850caaf91e6868813b3132e76b10
Alexander Schwinn referenced this bugreport in commit 9e7e160d6db39d39283bef6fafb7264f4a65d9e5 Optionally run commands on logout, suspend etc. (Bug #10172) https://git.xfce.org/xfce/xfce4-session/commit?id=9e7e160d6db39d39283bef6fafb7264f4a65d9e5
Tested and reviewed the commits. Just as feedback, there were a few more whitespace errors (in the sense of: missing or superfluous spaces), but I fixed them.
Great, thanks Simon !