Skip to content

Commit be6cf55

Browse files
author
Philip Waritschlager
committed
bugfix spam close/create
1 parent 3f936fe commit be6cf55

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tkbash

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ show_help() {
7777
echo -e "\t${COLOR_BOLD}--show${COLOR_RESET}"
7878
echo -e "\t\tSet the window visible by re-attaching it to the Winodow Manager."
7979
echo -e "\t${COLOR_BOLD}--close, --exit, --quit, --destroy${COLOR_RESET}"
80-
echo -e "\t\tClose the window programmatically. This is equal to the user pressing the X button or pressing alt+f4."
80+
echo -e "\t\tClose the window programmatically. This is equal to the user pressing the X button or pressing alt+f4. Waits until closing operations finished (including --onclose commands)."
8181
echo -e "\t${COLOR_BOLD}--hotkey, --bind, --shortcut${COLOR_RESET}"
8282
echo -e "\t\tAdd an action to be executed when a key (\"sequence\") is pressed. Possible sequences: See https://www.tcl.tk/man/tcl8.4/TkCmd/bind.htm#M5. Specify the commands to be executed use the --command option. Example: \"tkbash mygui --hotkey Escape --command 'echo You pressed Escape.'\" Also see --command note below."
8383
echo -e "\t${COLOR_BOLD}--onclose, --onexit${COLOR_RESET}"
@@ -358,6 +358,7 @@ fi
358358
if ! [[ -p "$WISH_PIPE" ]]; then
359359
# gui does not exist yet. initialize stuff
360360
# set up new pipe
361+
[[ -f "$WISH_PIPE" ]] && rm "$WISH_PIPE" # can happen unintentionally (multiple calls interfering with each other)
361362
mkfifo "$WISH_PIPE"
362363
WISH_PIPE_HELPER=${WISH_PIPE}_
363364
mkfifo "$WISH_PIPE_HELPER"
@@ -483,7 +484,10 @@ handle_window_commands() {
483484
[ -n "$ICONIFY" ] && wish_exec "wm iconify .w"
484485
[ -n "$HIDE" ] && wish_exec "wm withdraw .w"
485486
[ -n "$SHOW" ] && wish_exec "wm deiconify .w"
486-
[ -n "$CLOSE" ] && wish_exec "onexit"
487+
if [ -n "$CLOSE" ]; then
488+
wish_exec "onexit"
489+
while [ -p "$WISH_PIPE" ]; do sleep 0.2; done # wait for pipe to disappear = everything cleaned up. prevents mess when bulk statements with close/create window
490+
fi
487491
if [ -n "$HOTKEY" ]; then
488492
[ ! -v COMMAND ] && echo "hotkey command also needs the --command option." && die 23
489493
wish_exec "bind .w <$(tcl_esc "$HOTKEY")> \"onaction onhotkey$(tcl_esc "$HOTKEY")\""

0 commit comments

Comments
 (0)