fix i3 auto-showing by detecting if window was tiled or floating before

hiding it
long-opts
angelic-sedition 10 years ago
parent a670eeb968
commit 7b63ec6685

@ -1,4 +1,10 @@
# Demos # 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. 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") ![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 ### Tiling with Floating Support
These window managers currently will work with '-a'. I will add a lot more. These window managers currently will work with '-a'. I will add a lot more.
- bspwm - bspwm
- i3 (partially) - i3
# Why not use wmctrl? # Why not use wmctrl?
Necessary features don't work on many window managers, including mine. Necessary features don't work on many window managers, including mine.

19
tdrop

@ -20,7 +20,7 @@ options:
-P cmd provide a post command to float the window if necessary -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') -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) -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) -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') --clear clear saved window id; useful accidentally make a window a dropdown (e.g. '$ tdrop --clear current')
--no-cancel don't cancel auto-showing --no-cancel don't cancel auto-showing
@ -123,6 +123,11 @@ wm_autodetect_settings() {
i3-msg floating enable && \ i3-msg floating enable && \
xdotool windowmove "$1" "$xoff" "$yoff" windowsize "$1" "$width" "$height" 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 fi
# for auto_show proper positioning # for auto_show proper positioning
@ -256,6 +261,12 @@ wid_toggle() {
# #
get_geometry() { get_geometry() {
# 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") wininfo=$(xwininfo -id "$1")
x=$(echo "$wininfo" | awk '/Absolute.*X/ {print $4}') x=$(echo "$wininfo" | awk '/Absolute.*X/ {print $4}')
y=$(echo "$wininfo" | awk '/Absolute.*Y/ {print $4}') y=$(echo "$wininfo" | awk '/Absolute.*Y/ {print $4}')
@ -268,6 +279,7 @@ get_geometry() {
y=$((y-rel_y)) y=$((y-rel_y))
fi fi
echo -e "X=$x\nY=$y" echo -e "X=$x\nY=$y"
fi
} }
set_geometry() { set_geometry() {
@ -317,11 +329,16 @@ auto_show() {
if [[ -z $no_hide ]]; then if [[ -z $no_hide ]]; then
wid=$(< /tmp/tdrop/auto_hidden/wid) wid=$(< /tmp/tdrop/auto_hidden/wid)
class=$(< /tmp/tdrop/auto_hidden/class) class=$(< /tmp/tdrop/auto_hidden/class)
was_floating=$(< /tmp/tdrop/auto_hidden/geometry)
if [[ $was_floating != false ]]; then
float_pre_command "$class" float_pre_command "$class"
fi
xdotool windowmap "$wid" xdotool windowmap "$wid"
if [[ $was_floating != false ]]; then
float_post_command "$wid" float_post_command "$wid"
set_geometry "$wid" set_geometry "$wid"
fi fi
fi
} }
# #

@ -52,7 +52,7 @@ Specify a window decoration/border size in the form <x decoration size>x<y decor
Specifies that the program is not a terminal or does not have the '-e' flag; takes no argument. If using 'tdrop current', this option will have no effect either way. (default: false) Specifies that the program is not a terminal or does not have the '-e' flag; takes no argument. If using 'tdrop current', this option will have no effect either way. (default: false)
.TP .TP
\fB\-a\fR, \fB \-\-auto-detect-wm\fR \fB\-a\fR, \fB \-\-auto-detect-wm\fR
If there are available settings for the detected window manager for the -p, -P, and/or -d options, automatically set them; takes no argument. User set settings will still override these. (default: false) If there are available settings for the detected window manager for the -p, -P, and/or -d options, automatically set them; takes no argument. User set settings will still override these. This can be used with 'tdrop <terminal>', '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 .TP
\fB \-\-clear\fR \fB \-\-clear\fR
Used to clear a saved window id for the given program or 'current' instead of creating a dropdown; takes no argument. 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: For example, this functionality can be used in a function:
.br .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: To use it in an alias when writing a commit message in an graphical $EDITOR started from a terminal:
.br .br
alias gc='hide_on_open git commit' 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. 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.

Loading…
Cancel
Save