From 7b63ec66851fd6ecfdff05718230ebcd17708827 Mon Sep 17 00:00:00 2001 From: angelic-sedition Date: Tue, 17 Feb 2015 22:19:30 -0500 Subject: [PATCH] fix i3 auto-showing by detecting if window was tiled or floating before hiding it --- README.md | 8 +++++++- tdrop | 47 ++++++++++++++++++++++++++++++++--------------- tdrop.groff | 8 +++++--- 3 files changed, 44 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b37c544..60fe60b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ # Demos + + + + + + A basic demo using tdrop to create a dropdown/scratchpad on the fly with a hotkey. I set the height to be less than max with tdrop to make it more obvious which is the dropdown at which time. First apvlv is turned into a dropdown. Then it is cleared and zathura is turned into a dropdown. One can also have multiple hotkeys to create multiple dropdowns on the fly at a time. ![Alt text](http://angelic-sedition.github.io/tdrop/assets/on_the_fly.gif "On the fly creation") @@ -58,7 +64,7 @@ It is a simple matter to add new ones to this list. If your dropdown moves out o ### Tiling with Floating Support These window managers currently will work with '-a'. I will add a lot more. - bspwm -- i3 (partially) +- i3 # Why not use wmctrl? Necessary features don't work on many window managers, including mine. diff --git a/tdrop b/tdrop index 24f77e8..cbf8166 100755 --- a/tdrop +++ b/tdrop @@ -20,7 +20,7 @@ options: -P cmd provide a post command to float the window if necessary -O cmd provide a one time command only for when a dropdown is created/initiated (useful for 'tdrop -c') -d XxY give decoration/border size to accurately save position; only applicable with auto_show; on applicable with a few window managers (e.g. blackbox) - -a automatically detect window manager and if settings exist for it, automatically set -p, -P, and -d values as necessary (default: false) + -a automatically detect window manager and if settings exist for it, automatically set -p, -P, and -d values as necessary; this can have affect when used with a terminal or with auto_show or auto_hide (default: false) -W the given program is not a terminal (or lacks an -e flag) (default: assume it IS a terminal) --clear clear saved window id; useful accidentally make a window a dropdown (e.g. '$ tdrop --clear current') --no-cancel don't cancel auto-showing @@ -123,6 +123,11 @@ wm_autodetect_settings() { i3-msg floating enable && \ xdotool windowmove "$1" "$xoff" "$yoff" windowsize "$1" "$width" "$height" } + # function to check if floating when auto-hiding so restores properly (prevent floating a previously tiled window) + is_floating() { + # do you even sed? + i3-msg -t get_tree | awk 'gsub(/{"id"/, "\n{\"id\"")' | awk '/focused":true.*floating":"user_on/ {print $1}' + } fi # for auto_show proper positioning @@ -256,18 +261,25 @@ wid_toggle() { # get_geometry() { - wininfo=$(xwininfo -id "$1") - x=$(echo "$wininfo" | awk '/Absolute.*X/ {print $4}') - y=$(echo "$wininfo" | awk '/Absolute.*Y/ {print $4}') - rel_x=$(echo "$wininfo" | awk '/Relative.*X/ {print $4}') - rel_y=$(echo "$wininfo" | awk '/Relative.*Y/ {print $4}') - if [[ $x -ne $rel_x ]]; then - x=$((x-rel_x)) - fi - if [[ $y -ne $rel_y ]]; then - y=$((y-rel_y)) + # so that won't float a tiled window later when showing + if [[ -n $(type is_floating) ]] && [[ -z $(is_floating) ]]; then + # window is not floating; don't bother saving geometry + # this is going to be eval'd in set_geometry.. maybe not best/ most explicit way to do this but funny to me + echo "false" + else + wininfo=$(xwininfo -id "$1") + x=$(echo "$wininfo" | awk '/Absolute.*X/ {print $4}') + y=$(echo "$wininfo" | awk '/Absolute.*Y/ {print $4}') + rel_x=$(echo "$wininfo" | awk '/Relative.*X/ {print $4}') + rel_y=$(echo "$wininfo" | awk '/Relative.*Y/ {print $4}') + if [[ $x -ne $rel_x ]]; then + x=$((x-rel_x)) + fi + if [[ $y -ne $rel_y ]]; then + y=$((y-rel_y)) + fi + echo -e "X=$x\nY=$y" fi - echo -e "X=$x\nY=$y" } set_geometry() { @@ -317,10 +329,15 @@ auto_show() { if [[ -z $no_hide ]]; then wid=$(< /tmp/tdrop/auto_hidden/wid) class=$(< /tmp/tdrop/auto_hidden/class) - float_pre_command "$class" + was_floating=$(< /tmp/tdrop/auto_hidden/geometry) + if [[ $was_floating != false ]]; then + float_pre_command "$class" + fi xdotool windowmap "$wid" - float_post_command "$wid" - set_geometry "$wid" + if [[ $was_floating != false ]]; then + float_post_command "$wid" + set_geometry "$wid" + fi fi } diff --git a/tdrop.groff b/tdrop.groff index 180f6f5..9046055 100644 --- a/tdrop.groff +++ b/tdrop.groff @@ -52,7 +52,7 @@ Specify a window decoration/border size in the form x', 'tdrop auto_hide', and 'tdrop auto_show'. For 'auto_hide', if the window manager is supported, it will check if the current window is tiled so that it is not changed to floating when auto-showing. (default: false) .TP \fB \-\-clear\fR Used to clear a saved window id for the given program or 'current' instead of creating a dropdown; takes no argument. @@ -114,13 +114,15 @@ Tdrop provides the functionality to get programs/terminals out of the way when o For example, this functionality can be used in a function: .br -hide_on_open() { tdrop auto_hide; "$@" && tdrop auto_show } +hide_on_open() { tdrop -a auto_hide; "$@" && tdrop -a auto_show } To use it in an alias when writing a commit message in an graphical $EDITOR started from a terminal: .br alias gc='hide_on_open git commit' -This will hide the terminal window when opening the editor and then show it once the editor is closed. It should also maintain the window's position and size when showing it. If the window moves down and to the right every time it is auto-hidden and then shown again, the user may need to specify a '-d' value. Alternatively, if one already exists for the user's window manager, '-a' can be used to automatically set it. The '-p' and '-P' options are also used with auto_show and can be set automatically with '-a' if tested settings exist for the current window manager +This will hide the terminal window when opening the editor and then show it once the editor is closed. It should also maintain the window's position and size when showing it. If the window moves down and to the right every time it is auto-hidden and then shown again, the user may need to specify a '-d' value. Alternatively, if one already exists for the user's window manager, '-a' can be used to automatically set it. The '-p' and '-P' options are also used with auto_show and can be set automatically with '-a' if tested settings exist for the current window manager. + +Note that for tiled window managers that support 'tdrop -a auto_show' there will be problems when auto-hiding from a tiled window. When re-showing the window, it will be floating (since geometry is by default saved and restored). To keep it tiled, also use 'tdrop -a auto_hide' if your window manager is supported. This will check if a window is floating or tiled and keep it that way. This functionality might lead to some unwanted "re-shows" of dropdown. Consider a situation in which one opens an image viewer from a dropdown and leaves it open for a while, resuming normal use of the dropdown. When the image viewer is closed, the dropdown appears, unwanted. Tdrop is smart about this and won't "re-show" a dropdown if it has been manually toggled since an auto-hide. If you don't want this check to happen, use '--no-cancel' in your dropdown key binding.