mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-06-30 11:02:48 -05:00
Add a general way to request an immediate top-level callback.
This is a little like schedule_timer, in that the callback you provide will be run from the top-level message loop of whatever application you're in; but unlike the timer mechanism, it will happen _immediately_. The aim is to provide a general way to avoid re-entrance of code, in cases where just _doing_ the thing you want done is liable to trigger a confusing recursive call to the function in which you came to the decision to do it; instead, you just request a top-level callback at the message loop's earliest convenience, and do it then. [originally from svn r10019]
This commit is contained in:
@ -95,6 +95,7 @@ struct gui_data {
|
||||
int busy_status;
|
||||
guint term_paste_idle_id;
|
||||
guint term_exit_idle_id;
|
||||
guint toplevel_callback_idle_id;
|
||||
int alt_keycode;
|
||||
int alt_digits;
|
||||
char *wintitle;
|
||||
@ -1399,6 +1400,25 @@ void notify_remote_exit(void *frontend)
|
||||
inst->term_exit_idle_id = gtk_idle_add(idle_exit_func, inst);
|
||||
}
|
||||
|
||||
static gint idle_toplevel_callback_func(gpointer data)
|
||||
{
|
||||
struct gui_data *inst = (struct gui_data *)data;
|
||||
|
||||
run_toplevel_callbacks();
|
||||
|
||||
gtk_idle_remove(inst->toplevel_callback_idle_id);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void notify_toplevel_callback(void *frontend)
|
||||
{
|
||||
struct gui_data *inst = (struct gui_data *)frontend;
|
||||
|
||||
inst->toplevel_callback_idle_id =
|
||||
gtk_idle_add(idle_toplevel_callback_func, inst);
|
||||
}
|
||||
|
||||
static gint timer_trigger(gpointer data)
|
||||
{
|
||||
unsigned long now = GPOINTER_TO_LONG(data);
|
||||
@ -3858,6 +3878,8 @@ int pt_main(int argc, char **argv)
|
||||
|
||||
inst->eventlogstuff = eventlogstuff_new();
|
||||
|
||||
request_callback_notifications(notify_toplevel_callback, inst);
|
||||
|
||||
inst->term = term_init(inst->conf, &inst->ucsdata, inst);
|
||||
inst->logctx = log_init(inst, inst->conf);
|
||||
term_provide_logctx(inst->term, inst->logctx);
|
||||
|
@ -1118,6 +1118,8 @@ int main(int argc, char **argv)
|
||||
|
||||
net_pending_errors();
|
||||
|
||||
run_toplevel_callbacks();
|
||||
|
||||
if ((!connopen || !back->connected(backhandle)) &&
|
||||
bufchain_size(&stdout_data) == 0 &&
|
||||
bufchain_size(&stderr_data) == 0)
|
||||
|
@ -536,6 +536,8 @@ static int ssh_sftp_do_select(int include_stdin, int no_fds_ok)
|
||||
|
||||
sfree(fdlist);
|
||||
|
||||
run_toplevel_callbacks();
|
||||
|
||||
return FD_ISSET(0, &rset) ? 1 : 0;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user