summaryrefslogtreecommitdiffstats
path: root/roles
diff options
context:
space:
mode:
authorAhmed Abdelhalim <[email protected]>2026-02-09 21:58:35 +0100
committerAhmed Abdelhalim <[email protected]>2026-02-09 21:58:35 +0100
commit7d149e3763138de600661bf0acc6aa9ec283f4d3 (patch)
tree865b60361812ab1960272f4f03793f4a64edbecb /roles
parent3dfe41fd6dd5a0daf71308200b525b01eb8dae5e (diff)
Add volume controlling script with OSD (using mako)
Diffstat (limited to 'roles')
-rwxr-xr-xroles/hyprland/files/scripts/volume.sh85
-rw-r--r--roles/hyprland/tasks/main.yml2
-rw-r--r--roles/hyprland/templates/bindings.conf.j28
3 files changed, 91 insertions, 4 deletions
diff --git a/roles/hyprland/files/scripts/volume.sh b/roles/hyprland/files/scripts/volume.sh
new file mode 100755
index 00000000..c5ea8b6d
--- /dev/null
+++ b/roles/hyprland/files/scripts/volume.sh
@@ -0,0 +1,85 @@
+#!/bin/bash
+
+get_volume() {
+ local volume_status=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
+ if [[ "$volume_status" == *"MUTED"* ]]; then
+ muted=true
+ else
+ muted=false
+ fi
+ volume=$(echo "$volume_status" | cut -d' ' -f2 | awk '{printf "%d\n", $1 * 100}')
+}
+
+set_volume() {
+ local volume=$1
+ wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ $volume
+}
+
+mute_volume() {
+ wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
+}
+
+mute_mic() {
+ wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
+}
+
+notify() {
+ value="$1"
+ if $muted; then
+ notify-send -e \
+ -h string:x-canonical-private-synchronous:volume \
+ -u low \
+ "Volume" \
+ " \tmute"
+ else
+ notify-send -e \
+ -h string:x-canonical-private-synchronous:volume \
+ -u low \
+ "Volume" \
+ " \t$value%"
+ fi
+}
+
+
+STEP="${2:-1}"
+case "$1" in
+ "--get")
+ get_volume
+ notify $volume
+ ;;
+ "--set")
+ set_volume $STEP%
+ get_volume
+ notify $volume
+ ;;
+ "--inc")
+ set_volume $STEP%+
+ get_volume
+ notify $volume
+ ;;
+ "--dec")
+ set_volume $STEP%-
+ get_volume
+ notify $volume
+ ;;
+ "--toggle-mute-vol")
+ mute_volume
+ get_volume
+ notify $volume
+ ;;
+ "--toggle-mute-mic")
+ mute_mic
+ get_volume
+ notify $volume
+ ;;
+ *)
+ echo -e "Usage:"
+ echo -e " --get to get current volume value"
+ echo -e " --toggle-mute-vol to toggle mute output volume"
+ echo -e " --toggle-mute-mic to toggle mute input mic"
+ echo -e " --set [arg] to set current volume value to [arg]%"
+ echo -e " --inc [arg] to increment current volume value by [arg]%"
+ echo -e " --dec [arg] to decrement current volume value by [arg]%"
+ exit 0
+ ;;
+esac
diff --git a/roles/hyprland/tasks/main.yml b/roles/hyprland/tasks/main.yml
index fc8c0f29..180d12da 100644
--- a/roles/hyprland/tasks/main.yml
+++ b/roles/hyprland/tasks/main.yml
@@ -100,3 +100,5 @@
loop:
- src: "scripts/brightness.sh"
dest: "/etc/hypr/scripts/brightness.sh"
+ - src: "scripts/volume.sh"
+ dest: "/etc/hypr/scripts/volume.sh"
diff --git a/roles/hyprland/templates/bindings.conf.j2 b/roles/hyprland/templates/bindings.conf.j2
index 7ace0c99..a7739be4 100644
--- a/roles/hyprland/templates/bindings.conf.j2
+++ b/roles/hyprland/templates/bindings.conf.j2
@@ -65,10 +65,10 @@ binde = SUPER CONTROL, k, resizeactive, 0 -20
binde = SUPER CONTROL, l, resizeactive, 20 0
# Laptop multimedia keys for volume and LCD brightness
-bindel = ,XF86AudioRaiseVolume, exec, wpctl set-volume -l 1 @DEFAULT_AUDIO_SINK@ 1%+
-bindel = ,XF86AudioLowerVolume, exec, wpctl set-volume @DEFAULT_AUDIO_SINK@ 1%-
-bindel = ,XF86AudioMute, exec, wpctl set-mute @DEFAULT_AUDIO_SINK@ toggle
-bindel = ,XF86AudioMicMute, exec, wpctl set-mute @DEFAULT_AUDIO_SOURCE@ toggle
+bindel = ,XF86AudioRaiseVolume, exec, /etc/hypr/scripts/volume.sh --inc 1
+bindel = ,XF86AudioLowerVolume, exec, /etc/hypr/scripts/volume.sh --dec 1
+bindel = ,XF86AudioMute, exec, /etc/hypr/scripts/volume.sh --toggle-mute-vol
+bindel = ,XF86AudioMicMute, exec, /etc/hypr/scripts/volume.sh --toggle-mute-mic
bindel = ,XF86MonBrightnessUp, exec, /etc/hypr/scripts/brightness.sh --inc 5
bindel = ,XF86MonBrightnessDOWN, exec, /etc/hypr/scripts/brightness.sh --dec 5