Skip to content

Commit

Permalink
🔧 polybar[brightness]: add brightness control
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianmiranda committed Jan 7, 2024
1 parent c098017 commit eb03f48
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 6 additions & 2 deletions home/.config/polybar/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ separator-foreground = ${colors.disabled}

modules-left = logo i3 sxhkd-ipc hotkeys-ipc spotify-now-playing
modules-center =
modules-right = dolarblue dozer microphone pulseaudio-control-output network cpu-temperature cpu memory weather custom-date trayseparator spotify owl thunderbird github vpn packages dunst trayseparator
modules-right = dolarblue dozer microphone pulseaudio-control-output brightness network cpu-temperature cpu memory weather custom-date trayseparator spotify owl thunderbird github vpn packages dunst trayseparator

cursor-click = pointer
cursor-scroll = ns-resize
Expand Down Expand Up @@ -254,6 +254,11 @@ label-empty-padding = 0
type = internal/xwindow
label = %title:0:60:...%

[module/brightness]
type = custom/script
interval = 1
exec = xrandr --verbose | awk '/Brightness/ {print $2 * 100; exit}' | xargs printf "󰃞 %.0f%%"

[module/pulseaudio-control-output]
type = custom/script
tail = true
Expand Down Expand Up @@ -469,7 +474,6 @@ exec = .config/polybar/scripts/packages

[module/owl]
type = custom/script
interval = 5
format = <label>
label = "%output%"
label-padding = 0
Expand Down
6 changes: 6 additions & 0 deletions home/.config/sxhkd/sxhkdrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
###########################################################################
# Multimedia
###########################################################################
# Brightness Up
XF86MonBrightnessUp
~/bin/adjust-brightness +
# Brightness Down
XF86MonBrightnessDown
~/bin/adjust-brightness -
# Rewind
{XF86AudioPrev, shift + F10}
dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous
Expand Down
16 changes: 13 additions & 3 deletions home/bin/adjust-brightness
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@
# Get current brightness
BRIGHTNESS=$(xrandr --verbose | awk '{if ($1 ~ /Brightness/) {print $NF; exit}}');

# Add 0.05
BRIGHTNESS=`echo "$BRIGHTNESS $1 0.05" | bc`;
# Adjust brightness
ADJUSTMENT=0.1
if [ "$1" == "+" ]; then
BRIGHTNESS=$(echo "scale=2; $BRIGHTNESS + $ADJUSTMENT" | bc);
elif [ "$1" == "-" ]; then
echo $BRIGHTNESS
BRIGHTNESS=$(echo "scale=2; $BRIGHTNESS - $ADJUSTMENT" | bc);
echo $BRIGHTNESS
else
echo "Invalid argument. Use '+' or '-'."
exit 1
fi

# Apply value
xrandr --output eDP-1 --brightness $BRIGHTNESS
xrandr --listmonitors | awk '{ print $ 4 }' | sed 's/\s*//g' | xargs -I {} xrandr --output {} --brightness $BRIGHTNESS

# Notify
#MSG_ID="991050"
Expand Down

0 comments on commit eb03f48

Please sign in to comment.