Skip to content

Instantly share code, notes, and snippets.

@AlexCzar
Last active July 22, 2021 17:04
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexCzar/0c2cea33f88f41473773f1a78e5ef63a to your computer and use it in GitHub Desktop.
Save AlexCzar/0c2cea33f88f41473773f1a78e5ef63a to your computer and use it in GitHub Desktop.
Tabbed DropDown Alacritty for X11
#!/bin/sh
# Author: https://github.com/AlexCzar
# License: Apache 2.0
# This script can be used as a launcher for alacritty-inside-tabbed
# It monitors window manager events and when detects that tabbed has
# lost focus, script will minimize tabbed.
# If alacritty-in-tabbed is not running, it will launch it, if it is
# running but isn't focused, script will give it focus, if it is running
# and is focused, script will minimize it.
#
# The script should work in any POSIX compatible shell (at least according
# to ShellCheck), but was only tested on ZSH. In case something doesn't
# work as expected, please submit a PR or report the issue in a comment.
# TODO: get rid of mentions of tabbed to make script universal.
# TODO: investigate why are there always two copies of the script running
active_window_id=$(xprop -root 32x '\t$0' _NET_ACTIVE_WINDOW | cut -f 2)
active_window=$(xprop -id "$active_window_id" WM_CLASS)
case "$active_window" in
*tabbed* )
xdotool windowminimize "$active_window_id"
exit 0;
;;
* )
# find tabbed's window and make it active or if it's not running we'll launch it
wmctrl -vxR tabbed || tabbed -df alacritty --embed &
# sleep is needed to make sure WM has had time to finilize setting things up
# you might want to increase it on a slow machine, if window keeps disappearing
# when it shouldn't
sleep 0.5
tabbed_id=$(xdotool search --class tabbed)
# now we'll listen for WM events for tabbed window
xprop -spy -id "$tabbed_id" _NET_WM_STATE |
while read -r event; do
# check if the event is about tabbed losing focus
case "$event" in
*_NET_WM_STATE_FOCUSED* )
# it's still in focus, nothing to do, keep listening
:;;
* )
xdotool windowminimize "$tabbed_id"
exit 0;
;;
esac
done
;;
esac
@azarmadr
Copy link

43'rd line was causing me problems so i modified it to work
*_NET_WM_STATE_FOCUSED* )
to
*_NET_WM_STATE_[^:HIDDEN:]* )
nice gist by the way

@AlexCzar
Copy link
Author

Thaks for the feedback, I'll test that and if it works for me as well, will update the gist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment