#!/usr/bin/env bash #-*-coding:utf-8 -*- #Auto updated? # Yes #File: # dropdown_terminal #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: # Tue 08 November 2022, 03:33:27 PM [GMT] # #Description: # # #Dependencies: # alacritty xdotools # # shellcheck disable=all # Controls a dropdown terminal for use in i3wm DISPLAY_WIDTH=1920 TERMINAL_WIDTH=1200 TERMINAL_HEIGHT=500 TERMINAL=alacritty # Change this to whatever terminal emulator you want # Temporary file to record the terminal state TERMINAL_STATE=/tmp/dropdown_terminal_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 terminal" echo "Usage: dropdown_terminal " } term_launch() { $TERMINAL --class=dropdown-terminal & local term_pid=$! # Wait for terminal to open xdotool search --sync --pid $term_pid >/dev/null i3-msg -q mark dropdown_terminal # Mark the terminal so we can identify it i3-msg -q [con_mark=dropdown_terminal] move scratchpad echo "closed" >$TERMINAL_STATE } term_open() { if [ "$(cat $TERMINAL_STATE)" == "closed" ]; then CHECK=$(xdotool getmouselocation --shell | awk -F= 'NR==1{print $2}') if [ $CHECK -ge "1920" ]; then DISPLAY_WIDTH=$(DISPLAY_WIDTH * 2) fi echo "animating" >$TERMINAL_STATE i3-msg -q [con_mark=dropdown_terminal] 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_terminal] 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_terminal] focus for i in $(seq 1 $STEP_SIZE $TERMINAL_HEIGHT); do i3-msg -q [con_mark=dropdown_terminal] move up $STEP_SIZE sleep $SLEEP_TIME done i3-msg -q [con_mark=dropdown_terminal] 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