mirror of
https://github.com/The-Repo-Club/DotFiles.git
synced 2024-11-25 00:38:20 -05:00
105 lines
2.6 KiB
Bash
Executable File
105 lines
2.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
#-*-coding:utf-8 -*-
|
|
#Auto updated?
|
|
# Yes
|
|
#File:
|
|
# dropdown_btop
|
|
#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:
|
|
# Fri 28 October 2022, 04:08:33 PM [GMT+1]
|
|
#
|
|
#Description:
|
|
# <Todo>
|
|
#
|
|
#Dependencies:
|
|
# alacritty
|
|
#
|
|
# shellcheck disable=all
|
|
|
|
# Controls a dropdown btop for use in i3wm
|
|
|
|
DISPLAY_WIDTH=1920
|
|
TERMINAL_WIDTH=1200
|
|
TERMINAL_HEIGHT=500
|
|
|
|
TERMINAL=alacritty # Change this to whatever btop emulator you want
|
|
|
|
# Temporary file to record the btop 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 btop"
|
|
echo "Usage: dropdown_btop <start|open|close|toggle>"
|
|
}
|
|
|
|
term_launch() {
|
|
$TERMINAL --class=dropdown-terminal -e btop &
|
|
local term_pid=$!
|
|
# Wait for btop to open
|
|
xdotool search --sync --pid $term_pid >/dev/null
|
|
i3-msg -q mark dropdown_btop # Mark the btop so we can identify it
|
|
i3-msg -q [con_mark=dropdown_btop] move scratchpad
|
|
echo "closed" >$TERMINAL_STATE
|
|
}
|
|
|
|
term_open() {
|
|
if [ "$(cat $TERMINAL_STATE)" == "closed" ]; then
|
|
echo "animating" >$TERMINAL_STATE
|
|
i3-msg -q [con_mark=dropdown_btop] 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_btop] 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_btop] focus
|
|
for i in $(seq 1 $STEP_SIZE $TERMINAL_HEIGHT); do
|
|
i3-msg -q [con_mark=dropdown_btop] move up $STEP_SIZE
|
|
sleep $SLEEP_TIME
|
|
done
|
|
i3-msg -q [con_mark=dropdown_btop] scratchpad show
|
|
echo "closed" >$TERMINAL_STATE
|
|
fi
|
|
}
|
|
|
|
term_toggle() {
|
|
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
|
|
}
|
|
|
|
case $1 in
|
|
start) term_launch ;;
|
|
open) term_open ;;
|
|
close) term_close ;;
|
|
toggle) term_toggle ;;
|
|
*) usage ;;
|
|
esac |