TheRepoClub-DotFiles/localbin/.local/bin/dropdown_pavucontrol

109 lines
2.8 KiB
Plaintext
Raw Normal View History

2022-10-27 14:06:10 -04:00
#!/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:
2022-11-08 10:34:00 -05:00
# Tue 08 November 2022, 03:33:17 PM [GMT]
2022-10-27 14:06:10 -04:00
#
#Description:
# <Todo>
#
#Dependencies:
2022-11-08 10:34:00 -05:00
# alacritty xdotools
2022-10-27 14:06:10 -04:00
#
# 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
2022-11-08 10:34:00 -05:00
CHECK=$(xdotool getmouselocation --shell | awk -F= 'NR==1{print $2}')
if [ $CHECK -ge "1920" ]; then
DISPLAY_WIDTH=$(DISPLAY_WIDTH * 2)
fi
2022-10-27 14:06:10 -04:00
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() {
2022-10-28 11:36:45 -04:00
cmdList=$(i3-msg -t get_marks)
me=$(basename "$0")
if [[ ${cmdList[*]} =~ $me ]]; then
case "$(cat $TERMINAL_STATE)" in
open) term_close ;;
closed) term_open ;;
*) ;;
esac
else
$me "start"
$me "toggle"
fi
2022-10-27 14:06:10 -04:00
}
case $1 in
start) term_launch ;;
open) term_open ;;
close) term_close ;;
toggle) term_toggle ;;
*) usage ;;
esac