--- rxvt-unicode/src/main.C 2006/01/18 08:33:34 1.188 +++ rxvt-unicode/src/main.C 2006/01/20 10:27:08 1.191 @@ -50,10 +50,13 @@ vector rxvt_term::termlist; +// used to tell global functions which terminal instance is "active" +rxvt_t rxvt_current_term; + static char curlocale[128], savelocale[128]; bool -rxvt_set_locale (const char *locale) +rxvt_set_locale (const char *locale) NOTHROW { if (!locale || !strncmp (locale, curlocale, 128)) return false; @@ -64,14 +67,14 @@ } void -rxvt_push_locale (const char *locale) +rxvt_push_locale (const char *locale) NOTHROW { strcpy (savelocale, curlocale); rxvt_set_locale (locale); } void -rxvt_pop_locale () +rxvt_pop_locale () NOTHROW { rxvt_set_locale (savelocale); } @@ -171,6 +174,7 @@ #endif termwin_ev (this, &rxvt_term::x_cb), vt_ev (this, &rxvt_term::x_cb), + child_ev (this, &rxvt_term::child_cb), check_ev (this, &rxvt_term::check_cb), flush_ev (this, &rxvt_term::flush_cb), destroy_ev (this, &rxvt_term::destroy_cb), @@ -183,9 +187,6 @@ #ifdef KEYSYM_RESOURCE keyboard = new keyboard_manager; - - if (!keyboard) - rxvt_fatal ("out of memory, aborting.\n"); #endif } @@ -201,8 +202,6 @@ rxvt_term::~rxvt_term () { - HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); - termlist.erase (find (termlist.begin (), termlist.end(), this)); emergency_cleanup (); @@ -287,9 +286,12 @@ #endif } +// child has exited, usually destroys void -rxvt_term::child_exit () +rxvt_term::child_cb (child_watcher &w, int status) { + HOOK_INVOKE ((this, HOOK_CHILD_EXIT, DT_INT, status, DT_END)); + cmd_pid = 0; if (!OPTION (Opt_hold)) @@ -302,6 +304,9 @@ if (destroy_ev.active) return; + if (HOOK_INVOKE ((this, HOOK_DESTROY, DT_END))) + return; + #if ENABLE_OVERLAY scr_overlay_off (); #endif @@ -461,11 +466,6 @@ keyboard->register_done (); #endif -#ifdef HAVE_SCROLLBARS - if (OPTION (Opt_scrollBar)) - scrollBar.setIdle (); /* set existence for size calculations */ -#endif - #if ENABLE_PERL if (!rs[Rs_perl_ext_1]) rs[Rs_perl_ext_1] = "default"; @@ -479,6 +479,11 @@ } #endif +#ifdef HAVE_SCROLLBARS + if (OPTION (Opt_scrollBar)) + scrollBar.setIdle (); /* set existence for size calculations */ +#endif + pty = rxvt_new_ptytty (); create_windows (argc, argv); @@ -506,9 +511,6 @@ } #endif - XMapWindow (disp, vt); - XMapWindow (disp, parent[0]); - set_colorfgbg (); init_command (cmd_argv); @@ -522,27 +524,16 @@ HOOK_INVOKE ((this, HOOK_START, DT_END)); + XMapWindow (disp, vt); + XMapWindow (disp, parent[0]); + return true; } static struct sig_handlers { - sig_watcher sw_chld, sw_term, sw_int; + sig_watcher sw_term, sw_int; - void sig_chld (sig_watcher &w) - { - // we are being called for every SIGCHLD, find the corresponding term - int pid; - - while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) - for (rxvt_term **t = rxvt_term::termlist.begin (); t < rxvt_term::termlist.end (); t++) - if (pid == (*t)->cmd_pid) - { - (*t)->child_exit (); - break; - } - } - /* * Catch a fatal signal and tidy up before quitting */ @@ -558,8 +549,7 @@ } sig_handlers () - : sw_chld (this, &sig_handlers::sig_chld), - sw_term (this, &sig_handlers::sig_term), + : sw_term (this, &sig_handlers::sig_term), sw_int (this, &sig_handlers::sig_term) { } @@ -606,7 +596,6 @@ signal (SIGHUP, SIG_IGN); signal (SIGPIPE, SIG_IGN); - sig_handlers.sw_chld.start (SIGCHLD); sig_handlers.sw_term.start (SIGTERM); sig_handlers.sw_int.start (SIGINT); @@ -645,7 +634,7 @@ return p; } -void * +void * rxvt_realloc (void *ptr, size_t size) { void *p = realloc (ptr, size); @@ -1603,7 +1592,4 @@ } #endif /* USE_XIM */ -/*----------------------------------------------------------------------*/ -rxvt_t rxvt_current_term; - /*----------------------- end-of-file (C source) -----------------------*/