#!/bin/bash name=$(basename "$0") me="[${name:0:1}]${name:1}" run=$(ps -ef | grep "$me" -c) function checkstatus { smpfs="nope" while IFS= read -r line; do if [ "$(xprop -id $line | grep "_NET_WM_STATE(ATOM)" | grep -c "_NET_WM_STATE_FULLSCREEN")" -eq 1 ]; then smpfs="yep" break fi done <<< "$(wmctrl -lp | grep SMPlayer | cut -d " " -f1 | tr ' ' '\n')" echo $smpfs } if [ "$run" -ge 3 ]; then # already running exit 1 fi cmd=/usr/local/bin/g710-set-light delay=5 while [ true ]; do check=$(xset q | grep Monitor | sed 's/.*Monitor is //' ) if [ "$check" != "$prevstate" ]; then if [ "$check" = "On" ]; then prevstate="$check" $($cmd wasd 3) $($cmd 1 15) elif [ "$(wmctrl -lp | grep -c SMPlayer)" -eq 1 ]; then if [ "$(checkstatus)" = "yep" ]; then #SMPlayer is in fullscreen mode - turn off backlight prevstate="Off" # force recheck $($cmd wasd 4) $($cmd 1 0) else #SMPlayyer is in window mode - keep backlight on prevstate="On" # Force recheck $($cmd wasd 3) $($cmd 1 15) fi else prevstate="$check" $($cmd wasd 4) $($cmd 1 0) fi fi sleep $delay done