diff options
| -rwxr-xr-x | dropdown | 126 |
1 files changed, 96 insertions, 30 deletions
@@ -63,17 +63,81 @@ # 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 -} +## 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 [ "$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 [ "$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 [ "$id" != "" ]; then +# if command -v ydotool >/dev/null; then +# if ydotool windowvisible "$id"; 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 # List of supported terminals with dropdown class supported_terminals=( @@ -106,7 +170,7 @@ if [ -z "$my_term" ]; then # 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 & + 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 & @@ -117,27 +181,29 @@ if [ -z "$my_term" ]; then esac fi -# Get the window ID of the dropdown terminal using either ydotool or xdotool -id=$(get_window_id_by_class "dropdown") +# Function to toggle the visibility of the dropdown terminal +toggle_dropdown() { + # Get the window ID of the dropdown terminal + id="$(wmctrl -l | grep "dropdown" | awk '{print $1}')" -# 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 + # Toggle the visibility of the dropdown terminal + if [ -n "$id" ]; then + state="$(wmctrl -l -G -p -x | grep "$id" | awk '{print $4}')" + if [ "$state" = "-1" ]; then # 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" + wmctrl -i -r "$id" -b remove,hidden else - # The dropdown window is hidden, so show it - xdotool windowmap "$id" + # The dropdown window is visible, so hide it + wmctrl -i -r "$id" -b add,hidden fi fi +} + +# Check if wmctrl is available +if command -v wmctrl > /dev/null 2>&1; then + toggle_dropdown +else + echo "Window manipulation requires wmctrl. Install it and try again." + exit 1 fi + |
