TheRepoClub-DotFiles/localbin/.local/bin/dropdown_pavucontrol
2022-10-27 19:06:10 +01:00

98 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
#-*-coding:utf-8 -*-
#Auto updated?
# Yes
#File:
# dropdown_pavucontrol
#Author:
# The-Repo-Club [wayne6324@gmail.com]
#Github:
# https://github.com/The-Repo-Club/
#
#Created:
# Thu 27 October 2022, 06:11:40 PM [GMT+1]
#Modified:
# Thu 27 October 2022, 06:44:32 PM [GMT+1]
#
#Description:
# <Todo>
#
#Dependencies:
# alacritty
#
# shellcheck disable=all
# Controls a dropdown pavucontrol for use in i3wm
DISPLAY_WIDTH=1920
TERMINAL_WIDTH=1200
TERMINAL_HEIGHT=500
TERMINAL=pavucontrol # Change this to whatever pavucontrol emulator you want
# Temporary file to record the pavucontrol state
TERMINAL_STATE=/tmp/dropdown_pavucontrol_state
# Adjust the sleep time and step size as necessary to make the animation smooth
STEP_SIZE=50
SLEEP_TIME=0.02
usage() {
echo "Open/closes a dropdown pavucontrol"
echo "Usage: dropdown_pavucontrol <start|open|close|toggle>"
}
term_launch() {
$TERMINAL &
local term_pid=$!
# Wait for pavucontrol to open
xdotool search --sync --pid $term_pid >/dev/null
i3-msg -q mark dropdown_pavucontrol # Mark the pavucontrol so we can identify it
i3-msg -q [con_mark=dropdown_pavucontrol] move scratchpad
echo "closed" >$TERMINAL_STATE
}
term_open() {
if [ "$(cat $TERMINAL_STATE)" == "closed" ]; then
echo "animating" >$TERMINAL_STATE
i3-msg -q [con_mark=dropdown_pavucontrol] scratchpad show
i3-msg -q resize set $TERMINAL_WIDTH $TERMINAL_HEIGHT
i3-msg -q move absolute position $(((DISPLAY_WIDTH - TERMINAL_WIDTH) / 2)) 30
i3-msg -q move up $((TERMINAL_HEIGHT - 1))
for i in $(seq 1 $STEP_SIZE $TERMINAL_HEIGHT); do
i3-msg -q [con_mark=dropdown_pavucontrol] move down $STEP_SIZE
sleep $SLEEP_TIME
done
echo "open" >$TERMINAL_STATE
fi
}
term_close() {
if [ "$(cat $TERMINAL_STATE)" == "open" ]; then
echo "animating" >$TERMINAL_STATE
i3-msg -q [con_mark=dropdown_pavucontrol] focus
for i in $(seq 1 $STEP_SIZE $TERMINAL_HEIGHT); do
i3-msg -q [con_mark=dropdown_pavucontrol] move up $STEP_SIZE
sleep $SLEEP_TIME
done
i3-msg -q [con_mark=dropdown_pavucontrol] scratchpad show
echo "closed" >$TERMINAL_STATE
fi
}
term_toggle() {
case "$(cat $TERMINAL_STATE)" in
open) term_close ;;
closed) term_open ;;
*) ;;
esac
}
case $1 in
start) term_launch ;;
open) term_open ;;
close) term_close ;;
toggle) term_toggle ;;
*) usage ;;
esac