volumeControl.sh refctored and added brightness control functionality which supersedes brightnessControl.sh

master
Meliurwen 3 years ago
parent 2777961ee9
commit 8cec99898f
Signed by: meliurwen
GPG Key ID: 818A8B35E9F1CE10
  1. 15
      i3/.config/i3/config
  2. 81
      i3/.config/i3/scripts/brightnessControl.sh
  3. 138
      i3/.config/i3/scripts/volumeControl.sh
  4. BIN
      icons/.icons/Adwaita-dark-custom/32x32/status/dialog-error.png

@ -199,17 +199,14 @@ bindsym XF86ScreenSaver exec "dm-tool lock"
bindsym Print --release exec "screenshot_image=$(date +%F_%T).png && deepin-screenshot --no-notification -s /tmp/$screenshot_image && xclip -selection c -t image/png < /tmp/$screenshot_image && rm /tmp/$screenshot_image && unset screenshot_image"
# Speakers and Mic Controls
bindsym XF86AudioRaiseVolume exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh up
bindsym XF86AudioLowerVolume exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh down
bindsym XF86AudioMute exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh mute
bindsym XF86AudioMicMute exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh mic
bindsym XF86AudioRaiseVolume exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh audio up
bindsym XF86AudioLowerVolume exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh audio down
bindsym XF86AudioMute exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh audio mute
bindsym XF86AudioMicMute exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh mic mute
# Screen brightness controls
##bindsym XF86MonBrightnessUp exec "xbacklight -inc 10"
##bindsym XF86MonBrightnessDown exec "xbacklight -dec 10"
bindsym XF86MonBrightnessUp exec --no-startup-id ~/.config/i3/scripts/brightnessControl.sh up
bindsym XF86MonBrightnessDown exec --no-startup-id ~/.config/i3/scripts/brightnessControl.sh down
bindsym XF86MonBrightnessUp exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh brightness up
bindsym XF86MonBrightnessDown exec --no-startup-id ~/.config/i3/scripts/volumeControl.sh brightness down
# Turn screen off
bindsym XF86Launch1 exec --no-startup-id xset dpms force off

@ -1,81 +0,0 @@
#!/usr/bin/env bash
# You can call this script like this:
# $ ./brightnessControl.sh up
# $ ./brightnessControl.sh down
# Script inspired by these wonderful people:
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a
function get_brightness {
#xbacklight -get | cut -d '.' -f 1 # This seems to no longer work on Intel graphics
max_bright=$(cat /sys/class/backlight/intel_backlight/max_brightness)
act_bright=$(cat /sys/class/backlight/intel_backlight/actual_brightness)
# To round down/up/nearest in sh: https://stackoverflow.com/a/2395294
# In this case we round to the nearest: (num + (denom / 2)) / denom
echo $(( (act_bright*100+(max_bright/2))/max_bright ))
}
function draw_bar {
percentual=$1
slices=$2
lvl=$((percentual / slices))
empty=$(((100 / slices) - lvl))
lvl_bar=""
for X in $(seq "$lvl"); do
lvl_bar="$lvl_bar$(printf '\u2588')"
done
empty_bar=""
for X in $(seq "$empty"); do
empty_bar="$empty_bar$(printf '\u2591')"
done
echo "$lvl_bar$empty_bar"
}
function send_notification {
if [ ! -d "/sys/class/backlight/intel_backlight/" ]; then
notif_icon="display-brightness-disabled-dark"
notif_text="Disabled"
else
brightness=$(get_brightness)
if [ $brightness -le 0 ] ; then
notif_icon="display-brightness-none-dark"
else
if [ $brightness -le 30 ] ; then
notif_icon="display-brightness-low-dark"
else
if [ $brightness -le 85 ] ; then
notif_icon="display-brightness-medium-dark"
else
if [ $brightness -le 100 ] ; then
notif_icon="display-brightness-high-dark"
else
notif_icon="display-brightness-overamplified-dark"
fi
fi
fi
fi
notif_text=$(draw_bar $brightness 5)
fi
# Send the notification
dunstify -i "$notif_icon" -r 5555 -u normal "$notif_text"
}
case $1 in
up)
# increase the backlight by 5%
##xbacklight -inc 5
brightnessctl s +5%
send_notification
;;
down)
# decrease the backlight by 5%
##xbacklight -dec 5
brightnessctl s 5%-
send_notification
;;
esac
# Note: Seems that `xbacklight` doesn't work without a proper DE under i3.
# `brightnessctl` seems an interesting alternative. :)

@ -1,12 +1,14 @@
#!/bin/sh
# You can call this script like this:
# $ ./volumeControl.sh up
# $ ./volumeControl.sh down
# $ ./volumeControl.sh mute
# $ ./volumeControl.sh mic
# $ ./volumeControl.sh audio up
# $ ./volumeControl.sh audio down
# $ ./volumeControl.sh audio mute
# $ ./volumeControl.sh mic mute
# $ ./volumeControl.sh brightness up
# $ ./volumeControl.sh brightness down
# Script modified from these wonderful people:
# Acknowledgements:
# https://github.com/dastorm/volume-notification-dunst/blob/master/volume.sh
# https://gist.github.com/sebastiencs/5d7227f388d93374cebdf72e783fbd6a
@ -22,6 +24,26 @@ is_mic_mute() {
amixer get Capture | grep '%' | grep -oE '[^ ]+$' | grep off > /dev/null
}
get_brightness() {
max_bright=$(cat /sys/class/backlight/intel_backlight/max_brightness)
act_bright=$(cat /sys/class/backlight/intel_backlight/actual_brightness)
echo $(( (act_bright*100+(max_bright/2))/max_bright ))
}
get_level_icon() {
if [ "$1" -le 0 ] ; then
printf %s "$2-none-dark"
elif [ "$1" -le 30 ] ; then
printf %s "$2-low-dark"
elif [ "$1" -le 85 ] ; then
printf %s "$2-medium-dark"
elif [ "$1" -le 100 ] ; then
printf %s "$2-high-dark"
else
printf %s "$2-overamplified-dark"
fi
}
draw_bar() {
percentual=$1
slices=$2
@ -48,21 +70,11 @@ send_notification() {
notif_icon="audio-volume-muted-dark"
notif_text="Audio Muted"
else
volume=$(get_volume)
if [ "$volume" -le 0 ] ; then
notif_icon="audio-volume-none-dark"
elif [ "$volume" -le 30 ] ; then
notif_icon="audio-volume-low-dark"
elif [ "$volume" -le 85 ] ; then
notif_icon="audio-volume-medium-dark"
elif [ "$volume" -le 100 ] ; then
notif_icon="audio-volume-high-dark"
else
notif_icon="audio-volume-overamplified-dark"
fi
notif_text="$(draw_bar "$volume" 5)"
level=$(get_volume)
notif_icon=$(get_level_icon "$level" "audio-volume")
notif_text="$(draw_bar "$level" 5)"
fi
else
elif [ "$1" = "mic" ]; then
replace_id=2594
if is_mic_mute ; then
notif_icon="microphone-sensitivity-muted"
@ -71,32 +83,84 @@ send_notification() {
notif_icon="microphone-sensitivity-high"
notif_text="Microphone On"
fi
elif [ "$1" = "brightness" ] ; then
replace_id=2595
if [ ! -d "/sys/class/backlight/intel_backlight/" ]; then
notif_icon="display-brightness-disabled-dark"
notif_text="Backlight Disabled"
else
level="$(get_brightness)"
notif_icon=$(get_level_icon "$level" "display-brightness")
notif_text="$(draw_bar "$level" 5)"
fi
else
replace_id=2590
notif_icon="dialog-error"
notif_text="Script-error: option not found"
fi
# Send the notification
dunstify -i $notif_icon -r $replace_id -u normal "$notif_text"
}
# set the volume on (if it was muted)
# and then up/down the volume of the 5%
set_audio() {
case $1 in
up)
amixer -D pulse set Master on > /dev/null
amixer -D pulse sset Master 5%+ > /dev/null
send_notification audio
;;
down)
amixer -D pulse set Master on > /dev/null
amixer -D pulse sset Master 5%- > /dev/null
send_notification audio
;;
mute)
# toggle mute
amixer -D pulse set Master 1+ toggle > /dev/null
send_notification audio
;;
mic)
# toggle microphone mute
amixer -D pulse set Capture toggle > /dev/null
send_notification mic
;;
esac
}
# increase/decrease the backlight by 5%
set_brightness() {
case $1 in
up)
brightnessctl s +5%
send_notification brightness
;;
down)
brightnessctl s 5%-
send_notification brightness
;;
esac
}
set_mic() {
case $1 in
mute)
# toggle microphone mute
amixer -D pulse set Capture toggle > /dev/null
send_notification mic
;;
esac
}
case $1 in
up)
# set the volume on (if it was muted)
# and then up/down the volume of the 5%
amixer -D pulse set Master on > /dev/null
amixer -D pulse sset Master 5%+ > /dev/null
send_notification audio
;;
down)
amixer -D pulse set Master on > /dev/null
amixer -D pulse sset Master 5%- > /dev/null
send_notification audio
audio)
set_audio "$2"
;;
mute)
# toggle mute
amixer -D pulse set Master 1+ toggle > /dev/null
send_notification audio
brightness)
set_brightness "$2"
;;
mic)
# toggle microphone mute
amixer -D pulse set Capture toggle > /dev/null
send_notification mic
set_mic "$2"
;;
esac

Binary file not shown.

After

Width:  |  Height:  |  Size: 418 B

Loading…
Cancel
Save