commit 9c3feafca860cca7cf08a86f59415fc100e54306
parent 6c8ecb88c29fb9c07bf87645108bef19d46ce779
Author: Alex Balgavy <EMAIL>
Date: Sun, 29 Sep 2019 16:16:33 -0400
Brightness controls with polybar indicator
Former-commit-id: e8ab38e38a48c5f13f0d96d3ec952f2dafb86750
Diffstat:
3 files changed, 33 insertions(+), 6 deletions(-)
diff --git a/i3/config b/i3/config
@@ -219,6 +219,8 @@ bindsym XF86AudioMute exec --no-startup-id /usr/bin/pactl set-sink-mute 0 toggle
# Sreen brightness controls
bindsym XF86MonBrightnessUp exec --no-startup-id /home/zeroalpha/.dotfiles/scripts/xrandr-brightness up
bindsym XF86MonBrightnessDown exec --no-startup-id /home/zeroalpha/.dotfiles/scripts/xrandr-brightness down
+bindsym Shift+XF86MonBrightnessUp exec --no-startup-id /home/zeroalpha/.dotfiles/scripts/xrandr-brightness up 0.1
+bindsym Shift+XF86MonBrightnessDown exec --no-startup-id /home/zeroalpha/.dotfiles/scripts/xrandr-brightness down 0.1
# Media player controls
# bindsym XF86AudioPlay exec playerctl play
# bindsym XF86AudioPause exec playerctl pause
diff --git a/polybar/config b/polybar/config
@@ -19,7 +19,7 @@ font-2 = Termsynu:size=8:antialias=false;-2
font-3 = FontAwesome:size=10;0
modules-left = powermenu
-modules-right = volume wireless-network wired-network battery date
+modules-right = brightness volume wireless-network wired-network battery date
[bar/top_light]
width = 100%
@@ -42,7 +42,7 @@ font-2 = Termsynu:size=8:antialias=false;-2
font-3 = FontAwesome:size=10;0
modules-left = powermenu
-modules-right = volume wireless-network wired-network battery date
+modules-right = brightness volume wireless-network wired-network battery date
[bar/bottom]
bottom = true
@@ -360,6 +360,15 @@ label-urgent-padding = 2
; Separator in between workspaces
; label-separator = |
+[module/brightness]
+type = custom/script
+exec = /home/zeroalpha/.scripts/xrandr-brightness get brightness
+exec-if = command -v xrandr
+scroll-up = /home/zeroalpha/.scripts/xrandr-brightness down 0.1
+scroll-down = /home/zeroalpha/.scripts/xrandr-brightness up 0.1
+interval = 5
+format = <label>
+format-padding = 1
[settings]
screenchange-reload = true
diff --git a/scripts/xrandr-brightness b/scripts/xrandr-brightness
@@ -1,19 +1,35 @@
-#!/bin/sh
+#!/usr/bin/env bash
if [ "$1" = "up" ]; then
brightness="$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')"
gamma="$(xrandr --verbose | grep Gamma | tr -d ' \t\n' | awk -F: '{ printf "%f:%f:%f", 1/$2, 1/$3, 1/$4 }')"
if ! [ "$brightness" = "1.0" ]; then
- xrandr --output LVDS-0 --gamma "$gamma" --brightness $(echo "$brightness 0.05" | awk '{printf "%f", $1 + $2}')
+ step=${2:-"0.05"}
+ result=$(echo "$brightness $step" | awk '{ if ($1+$2 > 1) printf "1.0"; else printf "%f", $1+$2 }')
+ xrandr --output LVDS-0 --gamma "$gamma" --brightness "$result"
fi
elif [ "$1" = "down" ]; then
brightness="$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')"
gamma="$(xrandr --verbose | grep Gamma | tr -d ' \t\n' | awk -F: '{ printf "%f:%f:%f", 1/$2, 1/$3, 1/$4 }')"
if ! [ "$brightness" = "0.0" ]; then
- xrandr --output LVDS-0 --gamma "$gamma" --brightness $(echo "$brightness 0.05" | awk '{printf "%f", $1 - $2}')
+ step=${2:-0.05}
+ result=$(echo "$brightness $step" | awk '{ if ($1-$2 < 0) printf "0.0"; else printf "%f", $1-$2 }')
+ xrandr --output LVDS-0 --gamma "$gamma" --brightness "$result"
fi
elif [ "$1" = "gamma" ]; then
brightness="$(xrandr --verbose |grep Brightness |grep -o '[0-9].*')"
- xrandr --output LVDS-0 --gamma "$2" --brightness "$brightness"
+ if [ "$2" = "night" ]; then
+ xrandr --output LVDS-0 --gamma "1.1:0.7:0.6" --brightness "$brightness"
+ else
+ xrandr --output LVDS-0 --gamma "$2" --brightness "$brightness"
+ fi
+elif [ "$1" = "get" ]; then
+ if [ "$2" = "brightness" ]; then
+ result=$(xrandr --verbose |grep Brightness | grep -o '[0-9\.]*')
+ echo "$result" | awk '{ printf "%d%%", $1*100 }'
+ else
+ echo "Brightness: $(xrandr --verbose |grep Brightness |grep -o '[0-9].*')"
+ echo "Gamma: $(xrandr --verbose | grep Gamma | tr -d ' \t\n' | awk -F: '{ printf "%f:%f:%f", 1/$2, 1/$3, 1/$4 }')"
+ fi
else
echo "up, down, gamma r:g:b"
fi