You are not logged in.

#1 2017-09-13 05:47:38

positronik
Member
Registered: 2016-02-08
Posts: 94

[Solved] Inhibit shutdown/restart if other users are logged in on Xfce

Hi!
I would like to have a popup that alerts me when I'm
trying to shutdown/reboot the pc and other users are logged in.
I use Xfce and I start it from console without any dm.

I tried to install Gnome and this popup appears by default.
It would be awesome to have the same feature on Xfce.

Last edited by positronik (2017-09-13 14:21:40)

Offline

#2 2017-09-13 13:14:16

toz
Member
Registered: 2011-10-28
Posts: 494

Re: [Solved] Inhibit shutdown/restart if other users are logged in on Xfce

Xfce doesn't currently provide this functionality.

A while back, I wrote a script that did 2 things on shutdown/reboot/logout/etc: it checked for an prompted if other users were logged in, and also made sure that all open programs closed properly (current xfce4-session just kills active programs on shutdown).

If you are interested, here is the script:

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

# if dialog already displayed, exit
wmctrl -l | grep "Xfce Exit"  && exit 1

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
}

check_if_other_users_logged_in () {
	# check if anyone other than $USER is logged in
	U=$(loginctl --no-legend list-users | awk '{print $2}' | grep -v $USER)

	# if yes, ask if to continue
	if [ "$U" != "" ]; then
		ans=$(yad  --window-icon=system-devices-panel-information --on-top --sticky --fixed --center --title "Xfce Exit" --text-align=center --buttons-layout=center --title "Confirm" --text " The following users are currently logged in: \n\n$U\n\nContinue with action?")
		ret=$?
		[[ $ret -eq 1 ]] && exit 1		#if cancel, exit
	fi
}

# display dialog asking for exit/suspend/lok options
ans=$(yad  --window-icon=system-devices-panel-information --on-top --sticky --fixed --center --width 200 --entry --title "Xfce Exit" --text "\nSelect an action:\n" --image=xfce4_xicon3 --image-on-top --button="gtk-ok:0" --button="gtk-cancel:1" --text-align center --entry-text  "Logout" "Reboot" "Suspend" "Hibernate" "Power Off" "Lock Screen")
ret=$?
[[ $ret -eq 1 ]] && exit 1		#if cancel, exit

case $ans in
	Logout*)
		check_if_other_users_logged_in
		close_apps
		/usr/bin/xfce4-session-logout -l
	;;
	Power*)
		check_if_other_users_logged_in
		close_apps
		/usr/bin/xfce4-session-logout -h
	;;
	Reboot*)
		check_if_other_users_logged_in
		close_apps
		/usr/bin/xfce4-session-logout -r
	;;
	Suspend*)
		/usr/bin/xfce4-session-logout -s
	;;
	Hibernate*)
		/usr/bin/xfce4-session-logout --hibernate
	;;
	Lock*)
		xflock4
	;;
	*) ;;
esac

exit 0

Save the file as /usr/local/bin/xfce4-session-logout and make it executable. It will intercept the regular Xfce shudown commands and run this script instead where it will check these two things before firing off the actual Xfce commands to shutdown.

Adapt the script as needed.

Offline

#3 2017-09-13 13:52:23

positronik
Member
Registered: 2016-02-08
Posts: 94

Re: [Solved] Inhibit shutdown/restart if other users are logged in on Xfce

Thanks a lot toz!
It's weird that I had to create a custom launcher in my panel that points to xfce4-session-logout
because the Action Menu included in xfce bypasses the bin you provided...
Do you have any ideas why?

Offline

#4 2017-09-13 17:07:43

toz
Member
Registered: 2011-10-28
Posts: 494

Re: [Solved] Inhibit shutdown/restart if other users are logged in on Xfce

Should of mentioned that it doesn't work with the Actions plugin because this plugin uses dbus calls for these actions. Using a panel launcher in lieu of the actions plugin will work.

Offline

Board footer

Powered by FluxBB