diff options
Diffstat (limited to 'dropdown')
| -rwxr-xr-x | dropdown | 46 |
1 files changed, 20 insertions, 26 deletions
@@ -67,6 +67,7 @@ + # List of supported terminals with dropdown class supported_terminals=( "wezterm" @@ -74,26 +75,6 @@ supported_terminals=( "alacritty" ) -# Function to check if the terminal is running and visible -is_terminal_visible() { - local id="$(xdotool search --class "$1" | head -1)" - [ -n "$id" ] && xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null -} - -# Function to toggle the visibility of the dropdown terminal -toggle_dropdown() { - local id="$(xdotool search --class dropdown | head -1)" - if [ -n "$id" ]; then - if xwininfo -id "$id" | grep "Map State: IsViewable" > /dev/null; 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 -} - # 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 @@ -129,16 +110,29 @@ if [ -z "$my_term" ]; then esac fi +# Function to toggle the visibility of the dropdown terminal +toggle_dropdown() { + local id="$(xdotool search --class dropdown | head -1)" + if [ -n "$id" ]; then + local state="$(xprop -id "$id" | grep "_NET_WM_STATE_HIDDEN")" + if [ -n "$state" ]; then + # The dropdown window is hidden, so show it + wmctrl -i -r "$id" -b remove,hidden + else + # The dropdown window is visible, so hide it + wmctrl -i -r "$id" -b add,hidden + fi + fi +} + # Check if the script is already running and exit if it is if pgrep -x "$(basename "$0")" | grep -v $$ > /dev/null; then exit 1 fi -# Toggle the dropdown terminal visibility +# Attempt to toggle the dropdown terminal toggle_dropdown -# Set up a listener to hide the dropdown terminal when it loses focus -dropdown_id="$(xdotool search --class dropdown | head -1)" -if [ -n "$dropdown_id" ]; then - xdotool behave $dropdown_id focus-out exec "xdotool windowunmap $dropdown_id" -fi +# Sometimes, it may fail to toggle, so we add a slight delay and try again +sleep 0.1 +toggle_dropdown |
