From 5d42d503647a7a52d10dda64adef7e5df5fb1abf Mon Sep 17 00:00:00 2001 From: Charles Daniels Date: Thu, 16 May 2019 19:29:38 -0400 Subject: [PATCH] wrote dpmsconf --- install.sh | 4 ++- install_dpmsconf.sh | 10 +++++++ overlay/bin/apply-dpms | 56 ++++++++++++++++++++++++++++++++++++++ overlay/bin/configure-dpms | 37 ------------------------- overlay/bin/dpmsconf | 50 ++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 38 deletions(-) create mode 100755 install_dpmsconf.sh create mode 100755 overlay/bin/apply-dpms delete mode 100755 overlay/bin/configure-dpms create mode 100755 overlay/bin/dpmsconf diff --git a/install.sh b/install.sh index 4ded7f1..5d6e0fd 100755 --- a/install.sh +++ b/install.sh @@ -66,6 +66,8 @@ curl -SsfLo ~/.zsh/completions/_docker-compose https://raw.githubusercontent.com mkdir -p ~/.local/share/xfce4/terminal/colorschemes curl -SsfLo ~/.local/share/xfce4/terminal/colorschemes/gruvbox-dark.theme 'https://raw.githubusercontent.com/morhetz/gruvbox-contrib/master/xfce4-terminal/gruvbox-dark.theme' -./applymime.sh +cd "$DOTFILES_DIR" +sh ./install_dpmsconf.sh +sh ./applymime.sh exit 0 diff --git a/install_dpmsconf.sh b/install_dpmsconf.sh new file mode 100755 index 0000000..774fa84 --- /dev/null +++ b/install_dpmsconf.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# install dpmsconf cronjob for the current user + +if [ $(crontab -l 2>/dev/null | wc -l) -eq 0 ] ; then + # user has no crontab + echo '*/5 * * * * apply-dpms' | crontab - +else + (crontab -l | grep -v "apply-dpms" ; echo '*/5 * * * * apply-dpms') | crontab - +fi diff --git a/overlay/bin/apply-dpms b/overlay/bin/apply-dpms new file mode 100755 index 0000000..2b68b49 --- /dev/null +++ b/overlay/bin/apply-dpms @@ -0,0 +1,56 @@ +#!/bin/sh + +set -e +set -u + +CFG_FILE="$HOME/.config/dpmsconf" +DEFAULT=20 + +# Configure DPMS settings to one of several profiles + +# if no profile specified, then read CFG_FILE, which should be TSV with +# either AC or BAT as column 0, and a profile as column 1 + +# A profile may be either the string 'never', which means to never sleep the +# monitor, or a number of minutes before blanking + +# if "printcfg" is used as the profile, then CFG_FILE is printed to standard +# out and the DPMS settings are unchanged + +if [ $# -eq 0 ] ; then + if [ -e "$CFG_FILE" ] ; then + if acpi -a | grep "on-line" > /dev/null 2>&1 ; then + # on AC + config="$(cat "$CFG_FILE" | grep AC | cut -f2)" + else + # on battery + config="$(cat "$CFG_FILE" | grep BAT | cut -f2)" + fi + else + echo "no profile specified, and no $CFG_FILE" 1>&2 + exit 1 + fi +else + config="$1" +fi + +# not sure this does much on modern systems, but in theory it turns of the +# bell, whatever that is. +xset b off + +case "$config" in + never) + xset dpms 0 0 0 + ;; + [0-9]*) + timeout=$(expr $config '*' 60) + xset dpms $timeout $timeout $timeout + ;; + printcfg) + echo "$CFG_FILE" + ;; + *) + echo "Invalid DPMS configuration '$config'" 1>&2 + exit 1 + ;; +esac diff --git a/overlay/bin/configure-dpms b/overlay/bin/configure-dpms deleted file mode 100755 index 358ca1c..0000000 --- a/overlay/bin/configure-dpms +++ /dev/null @@ -1,37 +0,0 @@ -#!/bin/sh - -set -e -set -u - -# Configure DPMS settings to one of several profiles - -CONFIGURATION="$1" - -echo "Setting DPMS configuration to $CONFIGURATION" - -# not sure this does much on modern systems, but in theory it turns of the -# bell, whatever that is. -xset b off - -case "$CONFIGURATION" in - docked) - # 15 * 60 = 900 - # 30 * 60 = 1800 - # 45 * 60 = 2700 - xset dpms 900 1800 2700 - ;; - undocked) - # 3 * 60 = 180 - # 6 * 60 = 360 - # 9 * 60 = 540 - xset dpms 180 360 540 - ;; - nosleep) - echo "monitor will never sleep, remember to re-enable sleep when you are done" - xset dpms 0 0 0 - ;; - *) - echo "Invalid DPMS configuration '$CONFIGURATION'" - exit 1 - ;; -esac diff --git a/overlay/bin/dpmsconf b/overlay/bin/dpmsconf new file mode 100755 index 0000000..1710302 --- /dev/null +++ b/overlay/bin/dpmsconf @@ -0,0 +1,50 @@ +#!/bin/sh + +set -e +set -u + +config_file="$(apply-dpms printcfg)" + +ac_choices="5!10!15!30!60!never" +bat_choices="$ac_choices" + +# set default to current values, if any +if [ -e "$config_file" ] ; then + ac_current="$(cat "$config_file" | awk '$1 ~ /AC/ {print($2)}')" + bat_current="$(cat "$config_file" | awk '$1 ~ /BAT/ {print($2)}')" + + if [ -z "$ac_current" ] ; then + echo "" # no current AC config + elif echo "$ac_choices" | grep "$ac_current" > /dev/null 2>&1 ; then + ac_choices="$(echo "$ac_choices" | sed 's/'"$ac_current"'/^'"$ac_current"'/g')" + else + ac_choices="$(echo "$ac_choices!^$ac_current")" + fi + + if [ -z "$bat_current" ] ; then + echo "" # no current BAT config + elif echo "$bat_choices" | grep "$bat_current" > /dev/null 2>&1 ; then + bat_choices="$(echo "$bat_choices" | sed 's/'"$bat_current"'/^'"$bat_current"'/g')" + else + bat_choices="$(echo "$bat_choices!^$bat_current")" + fi +else + ac_choices="$(echo "$ac_choices" | sed 's/60/^60/g')" + bat_choices="$(echo "$bat_choices" | sed 's/10/^10/g')" +fi + +choice="$(yad --form --title "DPMS Profile" \ + --text "Configure DPMS profile" \ + --field="On AC":CB \ + "$ac_choices" \ + --field="On Battery":CB \ + "$bat_choices")" + +ac_profile="$(echo "$choice" | awk -F '|' '{print $1}')" +bat_profile="$(echo "$choice" | awk -F '|' '{print $2}')" + + +printf "AC\t$ac_profile\n" > "$config_file" +printf "BAT\t$bat_profile\n" >> "$config_file" + +apply-dpms -- 2.45.2