add support for turning current win into dropdown

long-opts
angelic-sedition 10 years ago
parent 3c4de4f7c0
commit 355cd4eb00

37
tdrop

@ -6,9 +6,9 @@ print_help() {
Also supports the ability to auto-hide and auto-show. For example, this can be used to automatically hide a window when opening something, e.g. image viewer, video player, etc. from it, and then re-show the window whenever the image view, video player, etc. is closed. Also supports the ability to auto-hide and auto-show. For example, this can be used to automatically hide a window when opening something, e.g. image viewer, video player, etc. from it, and then re-show the window whenever the image view, video player, etc. is closed.
Takes a terminal as an argument or one of auto_show, auto_hide, or toggle_auto_hide. 'toggle_auto_hide' toggles whether calling 'auto_hide' or 'auto_show' will have any effect. Takes a window as an argument or one of auto_show, auto_hide, or toggle_auto_hide. 'toggle_auto_hide' toggles whether calling 'auto_hide' or 'auto_show' will have any effect. 'current' will turn the current window into a dropdown.
usage: tdrop [options] <program> or <auto_show/auto_hide/toggle_auto_hide> usage: tdrop [options] <program or 'current'> or one of <auto_show/auto_hide/toggle_auto_hide>
options: options:
-h height specify a height for a newly created term (default: 100%) -h height specify a height for a newly created term (default: 100%)
-w width specify a width for a newly created term (default: 45%) -w width specify a width for a newly created term (default: 45%)
@ -18,7 +18,8 @@ options:
-n num num or extra text; only needed if want multiple dropdowns of same program (default: "") -n num num or extra text; only needed if want multiple dropdowns of same program (default: "")
-p cmd provide a pre command to float the window if necessary -p cmd provide a pre command to float the window if necessary
-P cmd provide a post command to float the window if necessary -P cmd provide a post command to float the window if necessary
-W the given program is not a terminal (or lacks an -e flag) (default: assume it IS terminal) -O cmd provide a one time command only for when a dropdown is created/initiated (useful for 'tdrop -c')
-W the given program is not a terminal (or lacks an -e flag) (default: assume it IS a terminal)
--no-cancel don't cancel auto-showing --no-cancel don't cancel auto-showing
(default is to prevent this when manually toggling a term after it is auto-hidden) (default is to prevent this when manually toggling a term after it is auto-hidden)
--help print help --help print help
@ -39,12 +40,13 @@ xoff=0
yoff=1 yoff=1
float_pre="" float_pre=""
float_post="" float_post=""
oneshot_post=""
session_name="" session_name=""
num="" num=""
normal_window=false normal_window=false
cancel_auto_show=true cancel_auto_show=true
term=${*:0-1} term=${*:0-1}
while getopts :h:w:x:y:s:n:p:P:-:W opt while getopts :h:w:x:y:s:n:p:P:O:-:W opt
do do
case $opt in case $opt in
h) height=$OPTARG;; h) height=$OPTARG;;
@ -55,6 +57,7 @@ do
n) num=$OPTARG;; n) num=$OPTARG;;
p) float_pre=$OPTARG;; p) float_pre=$OPTARG;;
P) float_post=$OPTARG;; P) float_post=$OPTARG;;
O) oneshot_post=$OPTARG;;
W) normal_window=true;; W) normal_window=true;;
-) -)
OPTION=$(echo "$OPTARG" | awk -F '=' '{print $1}') OPTION=$(echo "$OPTARG" | awk -F '=' '{print $1}')
@ -68,6 +71,7 @@ do
number) num=$OPTARG;; number) num=$OPTARG;;
pre-command) float_pre=$OPTARG;; pre-command) float_pre=$OPTARG;;
post-command) float_post=$OPTARG;; post-command) float_post=$OPTARG;;
oneshot-post) oneshot_post=$OPTARG;;
normal-window) normal_window=true;; normal-window) normal_window=true;;
no-cancel) cancel_auto_show=false;; no-cancel) cancel_auto_show=false;;
help) print_help;; help) print_help;;
@ -86,7 +90,9 @@ float_pre_command() {
} }
float_post_command() { float_post_command() {
if [[ -n $float_post ]]; then if [[ -n $oneshot_post ]] && [[ $1 == oneshot ]]; then
eval "$oneshot_post"
elif [[ -n $float_post ]]; then
eval "$float_post" eval "$float_post"
fi fi
} }
@ -121,13 +127,20 @@ win_create() {
xdotool windowmove "$wid" "$xoff" "$yoff" windowsize "$wid" "$width" "$height" xdotool windowmove "$wid" "$xoff" "$yoff" windowsize "$wid" "$width" "$height"
} }
current_create() {
# turns active window into a dropdown
wid=$(xdotool getactivewindow)
echo "$wid" > /tmp/tdrop/current"$num"
xprop -id "$(xprop -root _NET_ACTIVE_WINDOW | awk '{print $5}')" WM_CLASS | awk '{ gsub(/"/, ""); print $4}' > /tmp/tdrop/current"$num"_type
}
wid_toggle() { wid_toggle() {
mkdir -p /tmp/tdrop mkdir -p /tmp/tdrop
# get saved window id if already created # get saved window id if already created
wid=$(< /tmp/tdrop/"$term$num") wid=$(< /tmp/tdrop/"$term$num")
exists=true exists=true
if [[ -n $wid ]]; then if [[ -n $wid ]]; then
visibility=$(xwininfo -id "$wid" | awk '/Map State/ {print $3}') visibility=$(xwininfo -id "$wid" | awk '/Map State/ {print $3}')
if [[ -z $visibility ]]; then if [[ -z $visibility ]]; then
# window no longer exists # window no longer exists
exists=false exists=false
@ -137,7 +150,11 @@ wid_toggle() {
fi fi
if $exists && [[ $visibility != IsUnviewable ]]; then if $exists && [[ $visibility != IsUnviewable ]]; then
if [[ $visibility == IsUnMapped ]]; then if [[ $visibility == IsUnMapped ]]; then
float_pre_command "$term" if [[ $term == current ]]; then
float_pre_command "$(< /tmp/tdrop/current"$num"_type)"
else
float_pre_command "$term"
fi
xdotool windowmap "$wid" xdotool windowmap "$wid"
float_post_command float_post_command
else else
@ -147,12 +164,14 @@ wid_toggle() {
else else
# make it # make it
float_pre_command "$term" float_pre_command "$term"
if $normal_window; then if [[ $term == current ]]; then
current_create
elif $normal_window; then
win_create win_create
else else
term_create term_create
fi fi
float_post_command float_post_command oneshot
fi fi
} }

Loading…
Cancel
Save