diff --git a/Configs/.config/hypr/keybindings.conf b/Configs/.config/hypr/keybindings.conf index 779f49a..6407002 100644 --- a/Configs/.config/hypr/keybindings.conf +++ b/Configs/.config/hypr/keybindings.conf @@ -132,12 +132,12 @@ bindm = $mainMod, mouse:273, resizewindow # Laptop multimedia keys for volume and LCD brightness -bindel = ,XF86AudioRaiseVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%+ -bindel = ,XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 5%- +bindel = ,XF86AudioRaiseVolume, exec, ~/.config/hypr/scripts/volumecontrol.sh -o i +bindel = ,XF86AudioLowerVolume, exec, ~/.config/hypr/scripts/volumecontrol.sh -o d bindel = ,XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle bindel = ,XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle -bindel = ,XF86MonBrightnessUp, exec, brightnessctl s 5%+ -bindel = ,XF86MonBrightnessDown, exec, brightnessctl s 5%- +bindel = ,XF86MonBrightnessUp, exec, ~/.config/hypr/scripts/brightnesscontrol.sh -o i +bindel = ,XF86MonBrightnessDown, exec, ~/.config/hypr/scripts/brightnesscontrol.sh -o d # Requires playerctl bindl = , XF86AudioNext, exec, playerctl next diff --git a/Configs/.config/hypr/scripts/brightnesscontrol.sh b/Configs/.config/hypr/scripts/brightnesscontrol.sh new file mode 100755 index 0000000..32853ca --- /dev/null +++ b/Configs/.config/hypr/scripts/brightnesscontrol.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Print error message for invalid arguments +print_error() { + cat <<"EOF" +Usage: ./brightnesscontrol.sh +Valid actions are: + i -- ncrease brightness [+5%] + d -- ecrease brightness [-5%] +EOF +} + +brightness=$(brightnessctl -m | grep -o '[0-9]\+%' | head -c-2) + +# Handle options +while getopts o: opt; do + case "${opt}" in + o) + case $OPTARG in + i) # Increase brightness + if [[ $brightness -lt 10 ]]; then + brightnessctl set +1% + else + brightnessctl set +5% + fi + ;; + d) # Decrease brightness + if [[ $brightness -le 1 ]]; then + brightnessctl set 1% + elif [[ $brightness -le 10 ]]; then + brightnessctl set 1%- + else + brightnessctl set 5%- + fi + ;; + *) + print_error + ;; + esac + ;; + *) + print_error + ;; + esac +done diff --git a/Configs/.config/hypr/scripts/volumecontrol.sh b/Configs/.config/hypr/scripts/volumecontrol.sh new file mode 100755 index 0000000..a8ffde8 --- /dev/null +++ b/Configs/.config/hypr/scripts/volumecontrol.sh @@ -0,0 +1,94 @@ +#!/bin/bash + +# Define functions +print_error() { + cat <<"EOF" +Usage: ./volumecontrol.sh -[device] +...valid devices are... + i -- input device + o -- output device + p -- player application +...valid actions are... + i -- increase volume [+5] + d -- decrease volume [-5] + m -- mute [x] +EOF + exit 1 +} + +action_volume() { + case "${1}" in + i) + # Check current volume and increase only if below 100 + current_vol=$(pactl get-sink-volume @DEFAULT_SINK@ | awk '{print $5}' | sed 's/%//') + if [ "$current_vol" -lt 100 ]; then + new_vol=$((current_vol + 5)) + if [ "$new_vol" -gt 100 ]; then + new_vol=100 + fi + pactl set-sink-volume @DEFAULT_SINK@ "${new_vol}%" + fi + ;; + d) + # Decrease volume, ensuring it doesn't drop below 0% + current_vol=$(pactl get-sink-volume @DEFAULT_SINK@ | awk '{print $5}' | sed 's/%//') + new_vol=$((current_vol - 5)) + if [ "$new_vol" -lt 0 ]; then + new_vol=0 + fi + pactl set-sink-volume @DEFAULT_SINK@ "${new_vol}%" + ;; + esac +} + +select_output() { + if [ "$@" ]; then + desc="$*" + device=$(pactl list sinks | grep -C2 -F "Description: $desc" | grep Name | cut -d: -f2 | xargs) + if pactl set-default-sink "$device"; then + notify-send -r 91190 "Activated: $desc" + else + notify-send -r 91190 "Error activating $desc" + fi + else + pactl list sinks | grep -ie "Description:" | awk -F ': ' '{print $2}' | sort + fi +} + +# Evaluate device option +while getopts iops: DeviceOpt; do + case "${DeviceOpt}" in + i) + nsink=$(pactl list sources short | awk '{print $2}') + [ -z "${nsink}" ] && echo "ERROR: Input device not found..." && exit 0 + srce="--default-source" + ;; + o) + nsink=$(pactl list sinks short | awk '{print $2}') + [ -z "${nsink}" ] && echo "ERROR: Output device not found..." && exit 0 + srce="" + ;; + p) + nsink=$(playerctl --list-all | grep -w "${OPTARG}") + [ -z "${nsink}" ] && echo "ERROR: Player ${OPTARG} not active..." && exit 0 + # shellcheck disable=SC2034 + srce="${nsink}" + ;; + s) + # Select an output device + select_output "$@" + exit + ;; + *) print_error ;; + esac +done + +# Set default variables +shift $((OPTIND - 1)) + +# Execute action +case "${1}" in +i) action_volume i ;; +d) action_volume d ;; +*) print_error ;; +esac