Xfce Forum

Sub domains
 

You are not logged in.

#1 2015-04-14 05:28:43

user
Member
Registered: 2015-04-14
Posts: 4

[Solved] Proper close apps before logout

I'd found few topics about this problem to solve using wmctl and manual scripts. Is it still relevant or there is an built-in solution now? Or it's not problem of xfce?

Last edited by user (2015-04-14 05:30:11)

Offline

#2 2015-04-14 10:18:01

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,931

Re: [Solved] Proper close apps before logout

Can you be a little more specific about your question? Which apps are you referring to? What do you mean by "proper close apps"? Perhaps you could reference these topics that you have found?

Its a little difficult to understand exactly what your asking.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2015-04-14 11:47:16

user
Member
Registered: 2015-04-14
Posts: 4

Re: [Solved] Proper close apps before logout

I mean to close applications as though I close them manually. For example libreoffice don't ask about saving unsaved documents when I press logout, shutdown or restart, it's just killed. Same thing with Sublime Text. Firefox ask fo restore bookmarks after rebooting because it was closed improperly. Related topics: Reference 1Reference 2. So I'm asking, should I use script from the first reference or there is another solution in xfce now.

Last edited by user (2015-04-14 11:51:42)

Offline

#4 2015-04-14 13:26:14

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,931

Re: [Solved] Proper close apps before logout

Unfortunately, no. xfce4-session does not have the functionality to properly close open applications like this. It also doesn't properly deal with running scripts on close. There is a workaround for that included in the bug report. That workaround won't work for gui (X) apps, because xfce4-session has died by the time you get to the logout script and has already killed the X apps.

The closest existing bug/enhancement report for what you are asking for is https://bugzilla.xfce.org/show_bug.cgi?id=10295. Feel free to add to this report or create a new one of your own.

For the time being, you'll need to use a script like the one at https://forum.manjaro.org/index.php?topic=4412.0 to properly deal with closing applications.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2015-04-14 17:32:57

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,931

Re: [Solved] Proper close apps before logout

Here is a workaround that you can use that is based on the script from https://forum.manjaro.org/index.php?topic=4412.0. You need to have wmctrl and zenity installed.

1. Create the following file as /usr/local/bin/exit_with_save:

#!/bin/bash
# requires wmctrl and zenity packages

close_apps () {
	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
}

ans=$(zenity  --title "Save With Exit" --height 230 --width 200 --list  --text "Log Out: $USER" --radiolist  --column " " --column "Method" TRUE logout FALSE Shutdown FALSE Reboot FALSE Suspend FALSE Hibernate FALSE "Lock Screen") 

case $ans in 
	Logout)
		close_apps
		xfce4-session-logout -l
	;;
	Shutdown)
		close_apps
		xfce4-session-logout -h
	;;
	Reboot)
		close_apps
		xfce4-session-logout -r
	;;
	Suspend)
		xfce4-session-logout -s
	;;
	Hibernate)
		xfce4-session-logout --hibernate
	;;
        "Lock Screen")
                xflock4
        ;;

	*)
	;;
esac
exit 0

2. Make the file executable:

sudo chmod +x /usr/local/bin/exit_with_save

3. Add a launcher to your panel and/or desktop that points to this script.

4. Use this launcher to exit when wanting to save open documents first.

I've tested this with a few basic apps (mousepad, inkscape, gedit) and in each case, it prompts to save the file before logout/shutdown/reboot, etc.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#6 2015-04-14 19:47:29

user
Member
Registered: 2015-04-14
Posts: 4

Re: [Solved] Proper close apps before logout

Yes, that is what I meant. Thanks, I will try your solution.

Offline

#7 2015-04-16 17:00:01

user
Member
Registered: 2015-04-14
Posts: 4

Re: [Solved] Proper close apps before logout

Script works. Thank you.

Offline

#8 2015-12-07 20:13:26

xyzdragon
Member
Registered: 2015-12-06
Posts: 17

Re: [Solved] Proper close apps before logout

I wasn't very impressed with the look of the solution posted, so I tried to improve it a bit:

You can install the needed prerequisites with:

sudo apt-get install wmctrl yad

You will need these 2 scripts in ~/bin/

#!/bin/bash
# graceful-logout

# This script shows a dialog listing all .desktop links in ~/.config/grafecul-logout/
# which then call gracefully-close-windows and xfce4-session-logout with
# different parameters

yad --undecorated --center --icons --item-width="60" --single-click --read-dir="$HOME/.config/graceful-logout" --width="300" --height="250" --field=Option:CHK FALSE --field=Text2:LBL --button="Cancel:1"
#!/bin/bash
# gracefully-close-windows

# Get all Window IDs (doesn't work for tray only programs), send close
# signal and wait for windows to close

stringContains() {
    #echo "    String to test: $1"
    #echo "    Substring to test for: $2"
    [ -z "${1##*$2*}" ] && [ ! -z "$1" ]
}
getWinIds(){ wmctrl -l | grep -vwE "Desktop$|xfce4-panel$" | cut -f1 -d' '; }

winids="NON-EMPT-INIT"
windowsCloseSent=()
while [ "$winids" != "" ]; do
    winids=$(getWinIds)
    for winid in $winids; do
        if ! stringContains "${windowsCloseSent[*]}" "$winid"; then
            wmctrl -ic "$winid"
            windowsCloseSent+=( "$winid" )
        fi
    done
    sleep 0.1;
done

# This line should be customized to kill all programs normally open in the system tray only:
pkill java hexchat pidgin thunderbird

exit 0

The yad script then will show and execute .desktop files in ~/.config/graceful-logout/
The following install scripts creates 6 .desktop files for the common actions and also tries to install missing icon files, if they don't exist. (Beware! This may create discrepancies with your current theme. I used the icons from an Ultra Flat Theme and created the icons for hibernate and suspend myself):
https://odoepner.wordpress.com/2014/01/ … ate-icons/
https://github.com/daniruiz/Super-Flat-Remix/issues/10
https://bugs.debian.org/cgi-bin/bugrepo … bug=686735
The install scripts also tries to set the script as the standard command for the xfce-whiskermenu, which I use.

#!/bin/bash
# install-graceful-logout.sh
# This script installs the .desktop links needed for the yad-Skript to work
# and also missing icons (doesn't overwrite existing icons)

configPath="$HOME/.config/graceful-logout-new"
mkdir -P "$configPath"
cd "$configPath"

################ copy icons to currently activated icon theme ################

wget 'https://github.com/daniruiz/Super-Flat-Remix/files/54449/icons.zip'
unzip -o icons.zip && rm icons.zip
iconNames=( "logout" "reboot" "shutdown" "suspend" "hibernate" "lock-screen" )

# ~/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml:    <property name="IconThemeName" type="string" value="sable-ultra-flat-icons"/>
iconTheme=$(sed -rn 's/^.*IconThemeName.*value="([^"]*)".*/\1/p' $HOME/.config/xfce4/xfconf/xfce-perchannel-xml/xsettings.xml)
targetDir=""
if test -d /usr/share/icons/$iconTheme/; then targetDir=/usr/share/icons/$iconTheme; fi
if test -d $HOME/.icons/$iconTheme/; then targetDir=$HOME/.icons/$iconTheme; fi

# copy files to icon theme, but don't overwrite existing icons
for icon in "${iconNames[@]}"; do
    fname=system-$icon.svg
    targetIcon="$targetDir/apps/scalable/$fname"
    if [ ! -f $targetIcon ]; then
        echo "create $targetIcon"
        cp --no-clobber $fname $targetIcon
    fi
    rm $fname
    targetIcon="$targetDir/apps/scalable/xfsm-$icon.svg"
    if [ ! -f $targetIcon ]; then
        echo "create $targetIcon"
        ln -s $targetDir/apps/scalable/$fname $targetIcon
    fi
done

################ create .desktop files ################

names=( "Logout" "Reboot" "Shutdown" "Suspend" "Hibernate" "Lock" )
closeCmd="gracefully-close-windows && xfce4-session-logout --fast"
execs=( "$closeCmd --logout" "$closeCmd --reboot" "$closeCmd --halt"
        "xfce4-session-logout --suspend" "xfce4-session-logout --hibernate"
        "xflock4" )

for ((i=0; i<${#names[@]}; i++ )); do
    lowercaseName=$(echo ${names[i]} | tr '[:upper:]' '[:lower:]')
    fileName="$configPath/0$i-$lowercaseName.desktop"
    cat > "$fileName" << EOF
[Desktop Entry]
Name=${names[i]}
Comment=${names[i]} system
Exec=${execs[i]}
Icon=system-${iconNames[i]}
Termina=false
Type=Application
EOF
    chmod a+x "$fileName"
done

################ change xfce-whiskermenu logout command to script ################

#~/.config/xfce4/panel/whiskermenu-5.rc:command-logout=~/bin/graceful-logout
sed -ir 's/^command-logout=.*/command-logout=$HOME/bin/graceful-logout/' ~/.config/xfce4/panel/whiskermenu-5.rc

It's kinda disappointing, that a graceful logout isn't a default feature. Furthermore I couldn't find a hook, which will be executed after choosing the logout-type in the xfce4-session-logout dialog which would be executed before all windows have been closed. There are many tricks to find hooks, but they will only be executed, after xfce4-session has exited, which means all windows are already killed.
https://bugzilla.xfce.org/show_bug.cgi?id=10172
https://bugzilla.xfce.org/show_bug.cgi?id=10295

Last edited by xyzdragon (2015-12-07 21:38:28)

Offline

Board footer

Powered by FluxBB