adds multi device support for volume keybinds
This commit is contained in:
		| @@ -28,9 +28,9 @@ bindd = $mainMod, G, Remove gaps between window, exec, hyprctl --batch "keyword | ||||
|  | ||||
| # ======= Volume Control ======= | ||||
|  | ||||
| bindel = , XF86AudioRaiseVolume, exec, pactl set-sink-volume @DEFAULT_SINK@ +5% && pactl get-sink-volume @DEFAULT_SINK@ | grep -oP '\d+(?=%)' | awk '{if($1>100) system("pactl set-sink-volume @DEFAULT_SINK@ 100%")}' # Raise Volume | ||||
| bindel = , XF86AudioLowerVolume, exec, pactl set-sink-volume @DEFAULT_SINK@ -5% # Lower Volume | ||||
| bindel = , XF86AudioMute, exec, amixer sset Master toggle | sed -En '/\[on\]/ s/.*\[([0-9]+)%\].*/\1/ p; /\[off\]/ s/.*/0/p' | head -1 > /tmp/$HYPRLAND_INSTANCE_SIGNATURE.wob	#Mutes player audio | ||||
| bindel = , XF86AudioRaiseVolume, exec, ~/.config/hypr/scripts/volume-helper.sh up | ||||
| bindel = , XF86AudioLowerVolume, exec, ~/.config/hypr/scripts/volume-helper.sh down | ||||
| bindel = , XF86AudioMute, exec, ~/.config/hypr/scripts/volume-helper.sh toggle | ||||
|  | ||||
| # ======= Playback Control ======= | ||||
|  | ||||
|   | ||||
							
								
								
									
										80
									
								
								.config/hypr/scripts/volume-helper.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										80
									
								
								.config/hypr/scripts/volume-helper.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,80 @@ | ||||
| #!/bin/bash | ||||
| # | ||||
| # volume-helper.sh — Unified volume control script for Hyprland using pactl | ||||
| # | ||||
| # Purpose: | ||||
| # Many systems have multiple audio output devices (sinks), such as onboard | ||||
| # audio and an external device (e.g. M-Audio M-Track). This script adjusts the | ||||
| # volume of both: | ||||
| # | ||||
| #   - The default sink (`@DEFAULT_SINK@`) | ||||
| #   - A second sink (identified by partial name, e.g., "M-Track") | ||||
| # | ||||
| # Supports: | ||||
| #   - up       → Increase volume by 5% (defined by STEP, capped at MAX_VOLUME) | ||||
| #   - down     → Decrease volume by 5% | ||||
| #   - mute     → Mute all sinks | ||||
| #   - unmute   → Unmute all sinks | ||||
| #   - toggle   → Toggle mute state of all sinks | ||||
| # | ||||
| # Do NOT run this with sudo! pactl must run in your user session. | ||||
| # | ||||
|  | ||||
| MAX_VOLUME=140 | ||||
| STEP=5 | ||||
|  | ||||
| # Secondary sink (e.g. M-Track 2X2) | ||||
| SECOND_SINK=$(pactl list short sinks | grep "M-Track" | awk '{print $1}') | ||||
| DEFAULT_SINK="@DEFAULT_SINK@" | ||||
|  | ||||
| adjust_volume() { | ||||
|     local sink=$1 | ||||
|     local direction=$2 | ||||
|  | ||||
|     if [[ "$direction" == "up" ]]; then | ||||
|         pactl set-sink-volume "$sink" +${STEP}% | ||||
|         VOL=$(pactl get-sink-volume "$sink" | grep -oP '\d+(?=%)' | sort -nr | head -1) | ||||
|         if [ "$VOL" -gt "$MAX_VOLUME" ]; then | ||||
|             pactl set-sink-volume "$sink" "$MAX_VOLUME"% | ||||
|         fi | ||||
|     elif [[ "$direction" == "down" ]]; then | ||||
|         pactl set-sink-volume "$sink" -${STEP}% | ||||
|     fi | ||||
| } | ||||
|  | ||||
| toggle_mute() { | ||||
|     local sink=$1 | ||||
|     pactl set-sink-mute "$sink" "$2" | ||||
| } | ||||
|  | ||||
| # Process action | ||||
| case "$1" in | ||||
|     up) | ||||
|         adjust_volume "$DEFAULT_SINK" up | ||||
|         [[ -n "$SECOND_SINK" ]] && adjust_volume "$SECOND_SINK" up | ||||
|         ;; | ||||
|     down) | ||||
|         adjust_volume "$DEFAULT_SINK" down | ||||
|         [[ -n "$SECOND_SINK" ]] && adjust_volume "$SECOND_SINK" down | ||||
|         ;; | ||||
|     mute) | ||||
|         toggle_mute "$DEFAULT_SINK" 1 | ||||
|         [[ -n "$SECOND_SINK" ]] && toggle_mute "$SECOND_SINK" 1 | ||||
|         ;; | ||||
|     unmute) | ||||
|         toggle_mute "$DEFAULT_SINK" 0 | ||||
|         [[ -n "$SECOND_SINK" ]] && toggle_mute "$SECOND_SINK" 0 | ||||
|         ;; | ||||
|     toggle) | ||||
|         CURRENT_STATE=$(pactl get-sink-mute "$DEFAULT_SINK" | grep -oE "yes|no") | ||||
|         if [[ "$CURRENT_STATE" == "yes" ]]; then | ||||
|             "$0" unmute | ||||
|         else | ||||
|             "$0" mute | ||||
|         fi | ||||
|         ;; | ||||
|     *) | ||||
|         echo "Usage: $0 up|down|mute|unmute|toggle" | ||||
|         exit 1 | ||||
|         ;; | ||||
| esac | ||||
		Reference in New Issue
	
	Block a user