From eedc8201c2ab2cb164ee4f28db7fb2f761a50545 Mon Sep 17 00:00:00 2001 From: Pitriss Date: Fri, 1 Feb 2019 09:49:45 +0100 Subject: [PATCH] First commit. --- README.md | 8 ++++++-- g710-backlight.sh | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100755 g710-backlight.sh diff --git a/README.md b/README.md index 6b08cbd..e46b04f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ -# G710_backlight +# G710 backlight -Bash script that is checking status of DPMS of screen and turns on/off backlight of the keyboard. \ No newline at end of file +Bash script that is checking status of DPMS of screen and turns on/off backlight of the keyboard. + +Script runs in a loop and chekcks some aspects of system (in this case if smplayer is running in window or fullscreen) and reacts appropriatelly. + +I decided to create repo for it, because it can help somebody to achieve simmilar results. \ No newline at end of file diff --git a/g710-backlight.sh b/g710-backlight.sh new file mode 100755 index 0000000..b563837 --- /dev/null +++ b/g710-backlight.sh @@ -0,0 +1,53 @@ +#!/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