2020-10-29 10:39:24 +00:00
|
|
|
#!/bin/sh
|
2021-07-04 21:22:53 +00:00
|
|
|
# Set Workrave mode to quiet and wait the given amount of minutes (default: 10)
|
2020-10-29 10:39:24 +00:00
|
|
|
# If no amount is given or the -f flag is provided, it checks whether a fullscreen application is running and if no, exits
|
2021-07-04 21:22:53 +00:00
|
|
|
# On exit or Ctrl-C (SIGINT) set Workrave mode back to normal
|
2020-10-29 10:39:24 +00:00
|
|
|
|
|
|
|
while true; do
|
2021-07-04 21:22:53 +00:00
|
|
|
case $1 in
|
|
|
|
(-q) quiet=1; shift 1;;
|
|
|
|
(-f) fullscreen=1; shift 1;;
|
|
|
|
(*) break;;
|
|
|
|
esac
|
2020-10-29 10:39:24 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
getFullscreen() {
|
2021-07-04 21:22:53 +00:00
|
|
|
# See https://askubuntu.com/a/1265587
|
|
|
|
# Get screen size
|
|
|
|
root_geo=$(xwininfo -root | awk -F'[ +x]' '$3 ~ /-geometry/ {printf "%dx%d",$4/'"$(xrandr | grep ' connected ' | wc -l)"',$5}')
|
|
|
|
# Check if any window fills the screen
|
|
|
|
xwininfo -root -tree | grep $root_geo | grep -qv "\(Desktop\|has no name\)"
|
2020-10-29 10:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setWorkraveOperationMode() {
|
2021-07-04 21:22:53 +00:00
|
|
|
dbus-send --session --dest=org.workrave.Workrave --type=method_call \
|
2020-10-29 10:39:24 +00:00
|
|
|
/org/workrave/Workrave/Core org.workrave.CoreInterface.SetOperationMode \
|
|
|
|
string:"$1"
|
|
|
|
}
|
|
|
|
|
|
|
|
resetWorkraveMode() {
|
2021-07-04 21:22:53 +00:00
|
|
|
test "$quiet" || echo "Setting Workrave operation mode to normal"
|
|
|
|
setWorkraveOperationMode "normal"
|
2020-10-29 10:39:24 +00:00
|
|
|
}
|
|
|
|
trap resetWorkraveMode EXIT INT
|
|
|
|
|
|
|
|
test "$quiet" || echo "Silencing workrave"
|
|
|
|
setWorkraveOperationMode "quiet"
|
|
|
|
while true; do
|
2021-07-04 21:22:53 +00:00
|
|
|
sleep ${1:-10}m
|
|
|
|
test "$fullscreen" && getFullscreen || break
|
2020-10-29 10:39:24 +00:00
|
|
|
done
|