#!/bin/bash
# off: close all windows and by default, power off

. v

x=	# exit X
c=	# just clean up: Chrome, Anki, ...
r=	# reboot

. opts

close_all() {
	while wmctrl -c "$1"; do sleep 0.2; done
}

v close_all Anki
v close_all 'Google Chrome'
v read -t 5


if [ -n "$c" ]; then
	:
elif [ -n "$x" ]; then
	v killall Xorg
elif [ -n "$r" ]; then
	v sudo reboot
else
	v sudo poweroff
fi



# xdotool search --name 'Chrome' windowclose %@
