aboutsummaryrefslogtreecommitdiff
path: root/Common/rofi/applets/android/backlight.sh
diff options
context:
space:
mode:
authorJakob Stendahl <jakob.stendahl@outlook.com>2021-09-04 12:04:53 +0200
committerJakob Stendahl <jakob.stendahl@outlook.com>2021-09-04 12:04:53 +0200
commit65b7f91e51d90e93c3d7c6704c0a8265467a8ea7 (patch)
tree88301071c7f1840b502f33cbd3b0f7c5e81b0c66 /Common/rofi/applets/android/backlight.sh
parenta77563ee1044ffa03f7c49e457a5f7c9f943188f (diff)
parente6df7072ab32493a561fc678eacc119b57981827 (diff)
downloaddotfiles-65b7f91e51d90e93c3d7c6704c0a8265467a8ea7.tar.gz
dotfiles-65b7f91e51d90e93c3d7c6704c0a8265467a8ea7.zip
Merge branch 'master' of https://github.com/JakobS1n/dotfiles
Diffstat (limited to 'Common/rofi/applets/android/backlight.sh')
-rwxr-xr-xCommon/rofi/applets/android/backlight.sh73
1 files changed, 73 insertions, 0 deletions
diff --git a/Common/rofi/applets/android/backlight.sh b/Common/rofi/applets/android/backlight.sh
new file mode 100755
index 0000000..141b9ae
--- /dev/null
+++ b/Common/rofi/applets/android/backlight.sh
@@ -0,0 +1,73 @@
+#!/usr/bin/env bash
+
+## Author : Aditya Shakya
+## Mail : adi1090x@gmail.com
+## Github : @adi1090x
+## Twitter : @adi1090x
+
+dir="$HOME/.config/rofi/applets/android"
+rofi_command="rofi -theme $dir/three.rasi"
+
+# Error msg
+msg() {
+ rofi -theme "$dir/message.rasi" -e "$1"
+}
+
+## Get Brightness
+if [[ -f /usr/bin/blight ]]; then
+ DEVICE=$(ls /sys/class/backlight | head -n 1)
+ BNESS="$(blight -d $DEVICE get brightness)"
+ PERC="$(($BNESS*100/255))"
+ BLIGHT=${PERC%.*}
+elif [[ -f /usr/bin/xbacklight ]]; then
+ VAR="$(xbacklight -get)"
+ BLIGHT="$(printf "%.0f\n" "$VAR")"
+else
+ msg "No suitable backlight utility found!"
+ exit 1
+fi
+
+if [[ $BLIGHT -ge 1 ]] && [[ $BLIGHT -le 29 ]]; then
+ MSG="Low"
+elif [[ $BLIGHT -ge 30 ]] && [[ $BLIGHT -le 49 ]]; then
+ MSG="Optimal"
+elif [[ $BLIGHT -ge 50 ]] && [[ $BLIGHT -le 69 ]]; then
+ MSG="High"
+elif [[ $BLIGHT -ge 70 ]] && [[ $BLIGHT -le 99 ]]; then
+ MSG="Too Much"
+fi
+
+## Icons
+ICON_UP=""
+ICON_DOWN=""
+ICON_OPT=""
+
+notify="notify-send -u low -t 1500"
+options="$ICON_UP\n$ICON_OPT\n$ICON_DOWN"
+
+## Main
+chosen="$(echo -e "$options" | $rofi_command -p "$BLIGHT%" -dmenu -selected-row 1)"
+case $chosen in
+ $ICON_UP)
+ if [[ -f /usr/bin/blight ]]; then
+ blight -d $DEVICE set +10% && $notify "Brightness Up $ICON_UP"
+ elif [[ -f /usr/bin/xbacklight ]]; then
+ xbacklight -inc 10 && $notify "Brightness Up $ICON_UP"
+ fi
+ ;;
+ $ICON_DOWN)
+ if [[ -f /usr/bin/blight ]]; then
+ blight -d $DEVICE set -10% && $notify "Brightness Down $ICON_DOWN"
+ elif [[ -f /usr/bin/xbacklight ]]; then
+ xbacklight -dec 10 && $notify "Brightness Down $ICON_DOWN"
+ fi
+ ;;
+ $ICON_OPT)
+ if [[ -f /usr/bin/blight ]]; then
+ blight -d $DEVICE set 25% && $notify "Optimal Brightness $ICON_OPT"
+ elif [[ -f /usr/bin/xbacklight ]]; then
+ xbacklight -set 30 && $notify "Optimal Brightness $ICON_OPT"
+ fi
+ ;;
+esac
+