diff --git a/tdrop b/tdrop index f64d2fd..5507c33 100755 --- a/tdrop +++ b/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. - 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] or +usage: tdrop [options] or one of options: -h height specify a height for a newly created term (default: 100%) -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: "") -p cmd provide a pre 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 (default is to prevent this when manually toggling a term after it is auto-hidden) --help print help @@ -39,12 +40,13 @@ xoff=0 yoff=1 float_pre="" float_post="" +oneshot_post="" session_name="" num="" normal_window=false cancel_auto_show=true 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 case $opt in h) height=$OPTARG;; @@ -55,6 +57,7 @@ do n) num=$OPTARG;; p) float_pre=$OPTARG;; P) float_post=$OPTARG;; + O) oneshot_post=$OPTARG;; W) normal_window=true;; -) OPTION=$(echo "$OPTARG" | awk -F '=' '{print $1}') @@ -68,6 +71,7 @@ do number) num=$OPTARG;; pre-command) float_pre=$OPTARG;; post-command) float_post=$OPTARG;; + oneshot-post) oneshot_post=$OPTARG;; normal-window) normal_window=true;; no-cancel) cancel_auto_show=false;; help) print_help;; @@ -86,7 +90,9 @@ float_pre_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" fi } @@ -121,13 +127,20 @@ win_create() { 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() { mkdir -p /tmp/tdrop # get saved window id if already created wid=$(< /tmp/tdrop/"$term$num") exists=true 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 # window no longer exists exists=false @@ -137,7 +150,11 @@ wid_toggle() { fi if $exists && [[ $visibility != IsUnviewable ]]; 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" float_post_command else @@ -147,12 +164,14 @@ wid_toggle() { else # make it float_pre_command "$term" - if $normal_window; then + if [[ $term == current ]]; then + current_create + elif $normal_window; then win_create else term_create fi - float_post_command + float_post_command oneshot fi }