diff options
| -rw-r--r-- | i3/.i3/config | 12 | ||||
| -rwxr-xr-x | yoga/bin/night-light | 44 | ||||
| -rwxr-xr-x | yoga/bin/setmonitor | 89 | 
3 files changed, 97 insertions, 48 deletions
| diff --git a/i3/.i3/config b/i3/.i3/config index 3647d28..a6952d5 100644 --- a/i3/.i3/config +++ b/i3/.i3/config @@ -48,10 +48,14 @@ bindsym XF86MonBrightnessUp exec bash -c 'echo "$(($(cat /sys/class/backlight/am  bindsym XF86MonBrightnessDown exec bash -c 'echo "$(($(cat /sys/class/backlight/amdgpu_bl0/brightness)-10))" > /sys/class/backlight/amdgpu_bl0/brightness'  bindsym Shift+XF86MonBrightnessUp exec bash -c 'echo 255 > /sys/class/backlight/amdgpu_bl0/brightness'  bindsym Shift+XF86MonBrightnessDown exec bash -c 'echo 1 > /sys/class/backlight/amdgpu_bl0/brightness' -bindsym Ctrl+XF86MonBrightnessUp exec night-light increase -bindsym Ctrl+XF86MonBrightnessDown exec night-light decrease -bindsym Ctrl+Shift+XF86MonBrightnessUp exec night-light day -bindsym Ctrl+Shift+XF86MonBrightnessDown exec night-light night +bindsym Ctrl+XF86MonBrightnessUp exec setmonitor dp-brightness increase +bindsym Ctrl+XF86MonBrightnessDown exec setmonitor dp-brightness decrease +bindsym Ctrl+ShiftXF86MonBrightnessUp exec setmonitor dp-brightness max +bindsym Ctrl+ShiftXF86MonBrightnessDown exec setmonitor dp-brightness min +bindsym $mod+XF86MonBrightnessUp exec setmonitor night-light increase +bindsym $mod+XF86MonBrightnessDown exec setmonitor night-light decrease +bindsym $mod+Shift+XF86MonBrightnessUp exec setmonitor night-light day +bindsym $mod+Shift+XF86MonBrightnessDown exec setmonitor night-light night  bindsym $mod+F7 exec toggle-dp  bindsym $mod+Shift+F7 exec toggle-dp-brightness diff --git a/yoga/bin/night-light b/yoga/bin/night-light deleted file mode 100755 index b76054d..0000000 --- a/yoga/bin/night-light +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash -# Usage: night-light [increase|decrease|day|night] -set -e - -TMPFILE=/tmp/.night-light-index - -# https://askubuntu.com/a/1061304 -STEPS=( -    "1:0.18172716:0.00000001" -    "1:0.42322816:0.00000001" -    "1:0.54360078:0.08679949" -    "1:0.64373109:0.28819679" -    "1:0.71976951:0.42860152" -    "1:0.77987699:0.54642268" -    "1:0.82854786:0.64816570" -    "1:0.86860704:0.73688797" -    "1:0.90198230:0.81465502" -    "1:0.93853986:0.88130458" -    "1:0.97107439:0.94305985" -	"1:1:1" -) - -CUR=$((${#STEPS[@]}-1)) -if [ -f $TMPFILE ]; then -	CUR=$(cat $TMPFILE) -fi - -case "$1" in -	increase) NEW=$(($CUR >= ${#STEPS[@]} ? $CUR : $CUR+1)) ;; -	decrease) NEW=$(($CUR <= 0 ? $CUR : $CUR-1)) ;; -	day) NEW=$((${#STEPS[@]}-1)) ;; -	night) NEW=0 ;; -	*) -		echo "Invalid argument '$1'" -		exit 1 -		;; -esac - -echo $NEW > $TMPFILE - -for MONITOR in $(xrandr --listactivemonitors | tail -n +2 | cut -d'+' -f2 | cut -d' ' -f1 | sed 's/^\*//'); do -	BRIGHTNESS=$(xrandr --verbose | grep "^$MONITOR" -A5 | grep Brightness | cut -d':' -f2 | sed 's/\s*//') -	xrandr --output $MONITOR --gamma ${STEPS[$NEW]} --brightness $BRIGHTNESS || true -done diff --git a/yoga/bin/setmonitor b/yoga/bin/setmonitor new file mode 100755 index 0000000..f9fa5c1 --- /dev/null +++ b/yoga/bin/setmonitor @@ -0,0 +1,89 @@ +#!/bin/bash +# Usage: +# - setmonitor dp-brightness [increase|decrease|min|max] +# - setmonitor night-light [increase|decrease|day|night] +set -e + +if [ $# -ne 2 ]; then +	echo 'Check setmonitor source for usage' +	exit 1 +fi + +MONITORS="$(xrandr --listactivemonitors | tail -n +2 | cut -d'+' -f2 | cut -d' ' -f1 | sed 's/^\*//')" +EXTERNAL_MONITORS="$(echo $MONITORS | tr ' ' '\n' | grep -v eDP)" + +# Usage: brightness MONITOR +brightness () { +	echo "$(xrandr --verbose | grep "^$1" -A5 | grep Brightness | cut -d':' -f2 | sed 's/\s*//')" +} + +# Usage: dp_brightness [increase|decrease|min|max] MONITOR +dp_brightness () { +	STEP=5 +	BRIGHTNESS="$(bc <<< "$(brightness "$2")*100")" + +	case "$1" in +		increase) BRIGHTNESS="$(bc <<< "$BRIGHTNESS+$STEP")" ;; +		decrease) BRIGHTNESS="$(bc <<< "$BRIGHTNESS-$STEP")" ;; +		min) BRIGHTNESS=0 ;; +		max) BRIGHTNESS=100 ;; +		*) +			echo "Invalid argument '$1'" +			exit 1 +			;; +	esac + +	BRIGHTNESS="$(bc <<< "scale=2; $BRIGHTNESS/100")" + +	xrandr --output "$MONITOR" --brightness "$BRIGHTNESS" +} + +# Usage: nightlight [increase|decrease|day|night] +nightlight () { +	TMPFILE=/tmp/.night-light-index + +	# https://askubuntu.com/a/1061304 +	STEPS=( +		"1:0.18172716:0.00000001" "1:0.42322816:0.00000001" "1:0.54360078:0.08679949" +		"1:0.64373109:0.28819679" "1:0.71976951:0.42860152" "1:0.77987699:0.54642268" +		"1:0.82854786:0.64816570" "1:0.86860704:0.73688797" "1:0.90198230:0.81465502" +		"1:0.93853986:0.88130458" "1:0.97107439:0.94305985" "1:1:1" +	) + +	CUR=$((${#STEPS[@]}-1)) +	if [ -f $TMPFILE ]; then +		CUR=$(cat $TMPFILE) +	fi + +	case "$1" in +		increase) NEW=$(($CUR >= ${#STEPS[@]} ? $CUR : $CUR+1)) ;; +		decrease) NEW=$(($CUR <= 0 ? $CUR : $CUR-1)) ;; +		day) NEW=$((${#STEPS[@]}-1)) ;; +		night) NEW=0 ;; +		*) +			echo "Invalid argument '$1'" +			exit 1 +			;; +	esac + +	echo $NEW > $TMPFILE + +	for MONITOR in $MONITORS; do +		BRIGHTNESS=$(brightness "$MONITOR") +		xrandr --output "$MONITOR" --gamma "${STEPS[$NEW]}" --brightness "$BRIGHTNESS" || true +	done +} + +case "$1" in +	dp-brightness) +		for MONITOR in $EXTERNAL_MONITORS; do +			dp_brightness "$2" "$MONITOR" +		done +		;; +	night-light) +		nightlight "$2" +		;; +	*) +		echo 'Check setmonitor source for usage' +		exit 1 +esac | 
