From 13a658fde0fed5264bf1008f728f8ad55cd159fb Mon Sep 17 00:00:00 2001 From: noctuid Date: Wed, 4 May 2016 22:42:32 -0400 Subject: [PATCH] Add a --create-hook option that won't override -a Addresses #17. --- README.md | 5 +++++ tdrop | 14 +++++++++++++- tdrop.groff | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 06af67f..0d86662 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,11 @@ 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. + +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. + ### Auto-hiding In addition to creating dropdowns, tdrop can automatically hide a window and later un-hide it. For example, if gvim is opened to write a git commit message from the terminal, tdrop can automatically hide the terminal (dropdown or not) and restore it after the user is finished writing the commit message: diff --git a/tdrop b/tdrop index 3e48bfb..fe861ae 100755 --- a/tdrop +++ b/tdrop @@ -26,6 +26,8 @@ options: -f specify flags/options to be used when creating the term or window (e.g. -f '--title mytitle'; default: none). caution: if there is a tmux/tmuxinator session specified (with -s), the option to execute a program (usually -e for terminal programs) is implicitly added by tdrop! -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) -m for use with multiple monitors and only with dropdowns (not for auto_show or auto_hide); convert percentages used for width or height to values relative to the size of the current monitor and force reszing of the dropdown when the monitor changes (default: false) + -c cmd provide a command to be run after first creating the dropdown + (e.g. to set some window property) --clear clear saved window id; useful accidentally make a window a dropdown (e.g. '$ tdrop --clear current') --no-cancel don't cancel auto-showing (default is to prevent this when manually toggling a term after it is auto-hidden) @@ -55,13 +57,14 @@ map_pre="" map_post="" unmap_post="" oneshot_post="" +create_hook="" dec_fix="" program_flags="" clearwid=false cancel_auto_show=true auto_detect_wm=false monitor_aware=false -while getopts :h:w:x:y:s:n:p:P:M:O:d:f:-:am opt +while getopts :h:w:x:y:s:n:p:P:M:O:c:d:f:-:am opt do case $opt in h) height=$OPTARG;; @@ -74,6 +77,7 @@ do P) map_post=$OPTARG;; M) unmap_post=$OPTARG;; O) oneshot_post=$OPTARG;; + c) create_hook=$OPTARG;; d) dec_fix=$OPTARG;; f) program_flags=$OPTARG;; a) auto_detect_wm=true;; @@ -100,6 +104,7 @@ do post-command) map_post=$OPTARG;; post-unmap) unmap_post=$OPTARG;; oneshot-post) oneshot_post=$OPTARG;; + create-hook) create_hook=$OPTARG;; decoration-fix) dec_fix=$OPTARG;; program-flags) program_flags=$OPTARG;; auto-detect-wm) auto_detect_wm=true;; @@ -445,6 +450,12 @@ unmap_post_command() { fi } +run_create_hook() { + if [[ -n $create_hook ]]; then + eval "$create_hook" + fi +} + maybe_cancel_auto_show() { if $cancel_auto_show && \ [[ $1 == $(cat /tmp/tdrop/auto_hidden/wid 2> /dev/null) ]]; then @@ -611,6 +622,7 @@ wid_toggle() { set_geometry_for_monitor "$wid" fi fi + run_create_hook "$wid" fi } diff --git a/tdrop.groff b/tdrop.groff index 96e06af..f19b055 100644 --- a/tdrop.groff +++ b/tdrop.groff @@ -48,6 +48,9 @@ Specify a command to execute after unmapping a dropdown. This can be used with w \fB\-O\fR, \fB \-\-oneshot-post\fR Specify a post command to execute only when first creating or initiating a dropdown. This can be used when turning the current window into a dropdown to float and resize it. (default: none) .TP +\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\-d\fR, \fB \-\-decoration-fix\fR Specify a window decoration/border size in the form x 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