blob: 69c734da9882172c4f0083f465e994ec0624d3ab (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
#!/bin/bash
# Created By: srdusr
# Created On: Tue 07 Mar 2023 15:06:47 PM CAT
# Project: Agnostic dropdown/scratchpad terminal that works on most window managers
## List of supported terminals with dropdown class
#supported_terminals=(
# "wezterm"
# "kitty"
# "alacritty"
#)
#
## Check if any of the supported terminals with dropdown class are running
#for term in "${supported_terminals[@]}"; do
# if pgrep -f "$term.*--class dropdown" > /dev/null; then
# my_term="$term"
# break
# fi
#done
#
## If none of the supported terminals are running, start the first available one
#if [ -z "$my_term" ]; then
# for term in "${supported_terminals[@]}"; do
# if command -v "$term" > /dev/null 2>&1; then
# my_term="$term"
# break
# fi
# done
# if [ -z "$my_term" ]; then
# echo "No supported terminal found."
# exit 1
# fi
#
# # Start the terminal with dropdown class
# case "$my_term" in
# "wezterm")
# wezterm start --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 &
# ;;
# "kitty")
# kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 &
# ;;
# "alacritty")
# alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 &
# ;;
# esac
#fi
#
## Get the window ID of the dropdown terminal
#id="$(xdo id -N dropdown)"
#
## Toggle the visibility of the dropdown terminal
#if [ -n "$id" ]; then
# if xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null; then
# # The dropdown window is visible, so hide it
# dimensions="$(xwininfo -id "$id" | awk '/Width:|Height:/ { printf("%s=%s;", tolower($1), $2) }')"
# xdo hide "$id" 2>/dev/null
# else
# # The dropdown window is hidden, so show it
# xdo show "$id"
# # Restore the dimensions of the window
# xdotool windowsize "$id" "$(echo "$dimensions" | tr ';' ' ')" 2>/dev/null
# fi
#fi
# Function to get window ID by window class name
get_window_id_by_class() {
local class="$1"
if command -v ydotool > /dev/null; then
ydotool search --classname "$class"
elif command -v xdotool > /dev/null; then
xdotool search --classname "$class"
fi
}
# List of supported terminals with dropdown class
supported_terminals=(
"wezterm"
"kitty"
"alacritty"
)
# Check if any of the supported terminals with dropdown class are running
for term in "${supported_terminals[@]}"; do
if pgrep -f "$term.*--class dropdown" > /dev/null; then
my_term="$term"
break
fi
done
# If none of the supported terminals are running, start the first available one
if [ -z "$my_term" ]; then
for term in "${supported_terminals[@]}"; do
if command -v "$term" > /dev/null 2>&1; then
my_term="$term"
break
fi
done
if [ -z "$my_term" ]; then
echo "No supported terminal found."
exit 1
fi
# Start the terminal with dropdown class
case "$my_term" in
"wezterm")
wezterm --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 &
;;
"kitty")
kitty --class dropdown tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 &
;;
"alacritty")
alacritty --class dropdown -e tmux new-session -A -s dropdown -e bash > /dev/null 2>&1 &
;;
esac
fi
# Get the window ID of the dropdown terminal using either ydotool or xdotool
id=$(get_window_id_by_class "dropdown")
# Toggle the visibility of the dropdown terminal
if [ -n "$id" ]; then
if command -v ydotool > /dev/null; then
mapped=$(ydotool windowmap --query "$id" | awk '{print $2}')
if [ "$mapped" = "true" ]; then
# The dropdown window is visible, so hide it
ydotool windowunmap "$id"
else
# The dropdown window is hidden, so show it
ydotool windowmap "$id"
fi
elif command -v xdotool > /dev/null; then
if xdotool getwindowfocus | grep -q "$id"; then
# The dropdown window is visible, so hide it
xdotool windowunmap "$id"
else
# The dropdown window is hidden, so show it
xdotool windowmap "$id"
fi
fi
fi
|