dotfiles/.config/scripts/volume.sh
Sarthak b5a252c480 control centre, notification overhaul, and cleanup
One centred rofi panel (super+x, or the gear in the bar) now drives network,
bluetooth, audio, WireGuard, display, notifications, clipboard, emoji,
screenshots, wallpaper, the particle layer, the bar and power. The separate
per-function menus are gone.

dunst: icons and images were disabled outright (icon_position=off,
max_icon_size=0). Now icons resolve through Papirus, images render, progress
bars are styled, notifications gap and stack, and fullscreen windows are not
covered unless the message is critical. Volume up/down never notified at all;
they now show a stacking OSD with a progress bar.

Removed things that were broken or belonged to whoever this rice came from:
- vpn-launcher.sh (mullvad/openvpn) and dc-multivpn
- audio/bluetooth/network/power rofi menus, folded into the control centre
- untar-all, unzip-all, resetxdgportal (unreferenced)
- a sxhkd binding hardcoded to /home/sarthak/projects/scribe
- clipboard-manager.sh keyed off XDG_SESSION_TYPE, which is 'tty' here, so it
  only ever printed a Russian error; rewritten on greenclip
- toggle-bar.sh was bound to super+b but did not exist; written

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Cn3dHfbgNYdbZvzb1b3GQt
2026-09-04 00:48:26 +05:30

144 lines
2.9 KiB
Bash
Executable file

#!/usr/bin/env bash
# SESSION_TYPE="$XDG_SESSION_TYPE"
SESSION_TYPE="x11"
ENABLED_COLOR="#A3BE8C"
DISABLED_COLOR="#D35F5E"
print_error() {
echo "Usage: $0 --device <input|output> --action <increase|decrease|toggle> [--status] [--enabled-color] [--disabled-color]"
exit 1
}
notify_vol() {
vol=$(get_volume)
local icon label
if [[ "${device}" == "input" ]]; then icon="󰍬"; label="Microphone"; else icon="󰕾"; label="Volume"; fi
notify-send -a osd -u low \
-h "int:value:${vol}" \
-h "string:x-dunst-stack-tag:osd-${device}" \
"${icon} ${label} ${vol}%"
}
get_volume() {
if [[ "${srce}" == "--default-source" ]]; then
pamixer "${srce}" --get-volume
else
pamixer --get-volume
fi
}
print_status() {
local vol=$(get_volume)
if [[ "${device}" == "output" ]]; then
if [[ $(pamixer --get-mute) == "true" ]]; then
local icon="$vol%"
local color=$DISABLED_COLOR
elif [[ "$vol" -le 30 ]]; then
local icon="$vol%"
local color=$ENABLED_COLOR
elif [[ "$vol" -le 60 ]]; then
local icon="$vol%"
local color=$ENABLED_COLOR
elif [[ "$vol" -le 80 ]]; then
local icon="$vol%"
local color=$ENABLED_COLOR
else
local icon="$vol%"
local color=$ENABLED_COLOR
fi
elif [[ "${device}" == "input" ]]; then
if [[ $(pamixer "${srce}" --get-mute) == "true" ]]; then
local icon="$vol%"
local color=$DISABLED_COLOR
else
local icon="$vol%"
local color=$ENABLED_COLOR
fi
fi
if [[ "$SESSION_TYPE" == "wayland" ]]; then
echo "<span color=\"$color\">$icon</span>"
elif [[ "$SESSION_TYPE" == "x11" ]]; then
echo "%{F$color}$icon%{F-}"
fi
}
action_volume() {
case "${action}" in
increase)
pamixer "${srce}" -i 2
notify_vol
;;
decrease)
pamixer "${srce}" -d 2
notify_vol
;;
toggle)
pamixer "${srce}" -t
notify_mute
exit 0
;;
*)
print_error
;;
esac
}
notify_mute() {
local icon label
if [[ "${device}" == "input" ]]; then label="Microphone"; else label="Volume"; fi
if [[ $(pamixer "${srce}" --get-mute) == "true" ]]; then
[[ "${device}" == "input" ]] && icon="󰍭" || icon="󰝟"
notify-send -a osd -u low -h "string:x-dunst-stack-tag:osd-${device}" "${icon} ${label} muted"
else
notify_vol
fi
}
# Parse arguments
while [[ "$#" -gt 0 ]]; do
case $1 in
--device)
device="$2"
shift
;;
--action)
action="$2"
shift
;;
--enabled-color)
ENABLED_COLOR="$2"
shift
;;
--disabled-color)
DISABLED_COLOR="$2"
shift
;;
--status) status=true ;;
*) print_error ;;
esac
shift
done
case "${device}" in
input) srce="--default-source" ;;
output) srce="" ;;
*) print_error ;;
esac
if [[ -z "${device}" ]]; then
print_error
fi
if [[ "$status" == true ]]; then
print_status
exit 0
fi
if [[ -z "${action}" ]]; then
print_error
fi
# Execute action
action_volume