Index: trunk/src/hid.h =================================================================== --- trunk/src/hid.h (revision 13550) +++ trunk/src/hid.h (revision 13551) @@ -355,11 +355,13 @@ /* Causes func_ to be called when some condition occurs on the file descriptor passed. Conditions include data for reading, writing, hangup, and errors. user_data_ can be anything, it's just passed - to func. */ + to func. If the watch function returns pcb_true, the watch is kept, else + it is removed. */ pcb_hidval_t(*watch_file) (int fd_, unsigned int condition_, - void (*func_) (pcb_hidval_t watch_, int fd_, unsigned int condition_, pcb_hidval_t user_data_), + pcb_bool (*func_) (pcb_hidval_t watch_, int fd_, unsigned int condition_, pcb_hidval_t user_data_), pcb_hidval_t user_data); - /* Use this to stop a file watch. */ + + /* Use this to stop a file watch; must not be called from within a GUI callback! */ void (*unwatch_file) (pcb_hidval_t watch_); /* Causes func_ to be called in the mainloop prior to blocking */ Index: trunk/src_plugins/extedit/extedit.c =================================================================== --- trunk/src_plugins/extedit/extedit.c (revision 13550) +++ trunk/src_plugins/extedit/extedit.c (revision 13551) @@ -82,7 +82,7 @@ pcb_hidval_t wid; } extedit_wait_t; -void extedit_fd_watch(pcb_hidval_t watch, int fd, unsigned int condition, pcb_hidval_t user_data) +pcb_bool extedit_fd_watch(pcb_hidval_t watch, int fd, unsigned int condition, pcb_hidval_t user_data) { char tmp[128]; int res; @@ -90,13 +90,15 @@ /* excess callbacks */ if (!ctx->stay) - return; + return pcb_true; res = fread(tmp, 1, sizeof(tmp), ctx->fc); if (res <= 0) { pcb_gui->unwatch_file(ctx->wid); ctx->stay = 0; + return pcb_false; } + return pcb_true; } /* Invoke the child process, display a "progress bar" or some other indication Index: trunk/src_plugins/hid_lesstif/main.c =================================================================== --- trunk/src_plugins/hid_lesstif/main.c (revision 13550) +++ trunk/src_plugins/hid_lesstif/main.c (revision 13551) @@ -3308,7 +3308,7 @@ typedef struct { - void (*func) (pcb_hidval_t, int, unsigned int, pcb_hidval_t); + pcb_bool (*func) (pcb_hidval_t, int, unsigned int, pcb_hidval_t); pcb_hidval_t user_data; int fd; XtInputId id; @@ -3340,8 +3340,8 @@ pcb_condition |= PCB_WATCH_HANGUP; x.ptr = (void *) watch; - watch->func(x, watch->fd, pcb_condition, watch->user_data); - + if (!watch->func(x, watch->fd, pcb_condition, watch->user_data)) + lesstif_unwatch_file(x); return; } Index: trunk/src_plugins/lib_gtk_common/util_watch.c =================================================================== --- trunk/src_plugins/lib_gtk_common/util_watch.c (revision 13550) +++ trunk/src_plugins/lib_gtk_common/util_watch.c (revision 13551) @@ -27,7 +27,7 @@ #include "conf_core.h" typedef struct { - void (*func) (pcb_hidval_t, int, unsigned int, pcb_hidval_t); + pcb_bool (*func) (pcb_hidval_t, int, unsigned int, pcb_hidval_t); pcb_hidval_t user_data; int fd; GIOChannel *channel; @@ -42,6 +42,7 @@ unsigned int pcb_condition = 0; pcb_hidval_t x; GuiWatch *watch = (GuiWatch *) data; + pcb_bool res; if (condition & G_IO_IN) pcb_condition |= PCB_WATCH_READABLE; @@ -53,11 +54,11 @@ pcb_condition |= PCB_WATCH_HANGUP; x.ptr = (void *) watch; - watch->func(x, watch->fd, pcb_condition, watch->user_data); + res = watch->func(x, watch->fd, pcb_condition, watch->user_data); watch->com->mode_cursor_main(-1); - return TRUE; /* Leave watch on */ + return res; } pcb_hidval_t pcb_gtk_watch_file(pcb_gtk_common_t *com, int fd, unsigned int condition,