Add a --map-hook flag

Addresses #17.
break
noctuid 9 years ago
parent 13a658fde0
commit 70c78039cf

@ -15,6 +15,7 @@ A demo showing tdrop's ability to auto-hide windows when opening things from the
- Allows for auto-hiding a dropdown when opening programs from it
- Can automatically start programs and tmux or tmuxinator sessions
- Supports automatic resizing based on the current monitor
- Has hooks for executing user commands
## Requirements
- xprop
@ -58,7 +59,9 @@ Some window managers allow querying what the current monitor is (e.g. bspwm and
See the manpage for more information.
### Hooks
Tdrop provides a `--create-hook` flag that can be used to run a command after first creating the dropdown. A `$1` in the given command will be replaced with the window id for the dropdown (in this case the command will of course need to be in single quotes or the dollar sign escaped). For example, to set a dropdown as always on top, `-c 'wmctrl -i -r $1 -b add,above'` could be added to a tdrop command.
Tdrop provides a `--create-hook` flag that can be used to run a command after first creating a dropdown. This hook will run for a normal dropdown or when the current window is turned into a dropdown. There is also a `--map-hook` flag that will run a command every time a dropdown is mapped. This hook will run when first creating a normal dropdown but not when turning the current window into a dropdown (since it is initially unmapped not mapped).
A `$1` in the given command will be replaced with the window id for the dropdown (in this case the command will of course need to be in single quotes or the dollar sign escaped). For example, to set a dropdown as always on top, `--map-hook 'wmctrl -i -r $1 -b add,above'` could be added to a tdrop command.
I plan to remove the current `-p`, `-P`, `-M`, and `-O` flags and replace them with generic hooks. Currently these options are only useful for dealing with floating/moving/resizing as they override settings made by `-a`. After this change, the new settings will still be able to be used for this purpose, but the idea is to have tdrop deal with these things automatically using `-a`. I will also provide a way to have the settings for another window manager be used as a simpler initial workaround for tdrop not yet having settings for some window manager.

13
tdrop

@ -58,6 +58,7 @@ map_post=""
unmap_post=""
oneshot_post=""
create_hook=""
map_hook=""
dec_fix=""
program_flags=""
clearwid=false
@ -105,6 +106,7 @@ do
post-unmap) unmap_post=$OPTARG;;
oneshot-post) oneshot_post=$OPTARG;;
create-hook) create_hook=$OPTARG;;
map-hook) map_hook=$OPTARG;;
decoration-fix) dec_fix=$OPTARG;;
program-flags) program_flags=$OPTARG;;
auto-detect-wm) auto_detect_wm=true;;
@ -456,6 +458,12 @@ run_create_hook() {
fi
}
run_map_hook() {
if [[ -n $map_hook ]]; then
eval "$map_hook"
fi
}
maybe_cancel_auto_show() {
if $cancel_auto_show && \
[[ $1 == $(cat /tmp/tdrop/auto_hidden/wid 2> /dev/null) ]]; then
@ -575,6 +583,7 @@ wid_toggle() {
# combine mapping with resizing/moving when possible to reduce flicker
map_post_command "$wid"
fi
run_map_hook "$wid"
maybe_cancel_auto_show "$wid"
if ! $focused_window_exists; then
# need to use dropdown as active window to get monitor info
@ -611,9 +620,12 @@ wid_toggle() {
if [[ $program == current ]]; then
wid=$(current_create)
xdotool windowunmap "$wid"
run_create_hook "$wid"
else
wid=$(program_start)
map_post_command oneshot "$wid"
run_create_hook "$wid"
run_map_hook "$wid"
# update window dimensions if necessary
if ! $focused_window_exists; then
width=${original_width:-$width}
@ -622,7 +634,6 @@ wid_toggle() {
set_geometry_for_monitor "$wid"
fi
fi
run_create_hook "$wid"
fi
}

@ -51,6 +51,9 @@ Specify a post command to execute only when first creating or initiating a dropd
\fB-c\fR, \fB --create-hook\fR
Specify a command to execute after first creating or initializing a dropdown. Unlike the previous options, this will not override the post or pre commands and can be used for purposes other than floating a window. One possible usage is to set certain window properties for the dropdown. This command can contain a '$1' (single quoted or escaped) which will be replaced with the window id of the dropdown. (default: none)
.TP
\fB --map-hook\fR
Specify a command to execute after every time the dropdown is mapped. This will be run when first creating/mapping a window for a normal dropdown but will not be run when turning the current window into a dropdown (since in this case the window will be unmapped). Like with --create-hook, the command can contain a '$1'. (default: none)
.TP
\fB\-d\fR, \fB \-\-decoration-fix\fR
Specify a window decoration/border size in the form <x decoration size>x<y decoration size> to be taken into account when saving window position. This should not be necessary for most window managers and is only used with 'auto_show', e.g. 'tdrop -d 1x22 auto_show' for blackbox. (default: none)
.TP

Loading…
Cancel
Save