From 15edcb024d4e549ec2725d3145e73532925d45af Mon Sep 17 00:00:00 2001 From: retrilzzy Date: Sun, 27 Apr 2025 23:06:42 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=20=D1=83=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B2=D1=83=D0=BA=D0=BE=D0=BC=20=D0=B8=20=D1=8F?= =?UTF-8?q?=D1=80=D0=BA=D0=BE=D1=81=D1=82=D1=8C=D1=8E=20=D1=81=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D0=B2=D0=B8=D0=B0=D1=82=D1=83=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Configs/.config/hypr/keybindings.conf | 8 +- .../.config/hypr/scripts/brightnesscontrol.sh | 45 +++++++++ Configs/.config/hypr/scripts/volumecontrol.sh | 94 +++++++++++++++++++ 3 files changed, 143 insertions(+), 4 deletions(-) create mode 100755 Configs/.config/hypr/scripts/brightnesscontrol.sh create mode 100755 Configs/.config/hypr/scripts/volumecontrol.sh 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