--- rxvt-unicode/src/main.C 2004/03/06 00:05:01 1.51 +++ rxvt-unicode/src/main.C 2004/04/08 20:31:45 1.66 @@ -1,5 +1,5 @@ -/*--------------------------------*-C-*---------------------------------*; - * File: main.c +/*--------------------------------*-C-*---------------------------------* + * File: main.C *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. @@ -46,21 +46,25 @@ #include +vector rxvt_term::termlist; + static char curlocale[128]; -void +bool rxvt_set_locale (const char *locale) { - if (locale && STRNCMP (locale, curlocale, 128)) - { - STRNCPY (curlocale, locale, 128); - setlocale (LC_CTYPE, curlocale); - } + if (!locale || !STRNCMP (locale, curlocale, 128)) + return false; + + STRNCPY (curlocale, locale, 128); + setlocale (LC_CTYPE, curlocale); + return true; } +#if ENABLE_COMBINING class rxvt_composite_vec rxvt_composite; -text_t rxvt_composite_vec::compose (uint32_t c1, uint32_t c2) +text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2) { compose_char *cc; @@ -96,7 +100,7 @@ return v.size () - 1 + COMPOSE_LO; } -int rxvt_composite_vec::expand (uint32_t c, wchar_t *r) +int rxvt_composite_vec::expand (unicode_t c, wchar_t *r) { compose_char *cc = (*this)[c]; @@ -119,8 +123,8 @@ return len; } +#endif -extern struct rxvt_composite_vec rxvt_composite; void * rxvt_term::operator new (size_t s) { @@ -165,10 +169,14 @@ incr_ev (this, &rxvt_term::incr_cb) { cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; + + termlist.push_back (this); } rxvt_term::~rxvt_term () { + termlist.erase (find (termlist.begin (), termlist.end(), this)); + if (cmd_fd >= 0) close (cmd_fd); @@ -183,6 +191,37 @@ if (display) { + selection_clear (); + +#ifdef MENUBAR + if (menubarGC) XFreeGC (display->display, menubarGC); +#endif +#ifdef XTERM_SCROLLBAR + if (xscrollbarGC) XFreeGC (display->display, xscrollbarGC); + if (ShadowGC) XFreeGC (display->display, ShadowGC); +#endif +#ifdef PLAIN_SCROLLBAR + if (pscrollbarGC) XFreeGC (display->display, pscrollbarGC); +#endif +#ifdef NEXT_SCROLLBAR + if (blackGC) XFreeGC (display->display, blackGC); + if (whiteGC) XFreeGC (display->display, whiteGC); + if (grayGC) XFreeGC (display->display, grayGC); + if (darkGC) XFreeGC (display->display, darkGC); + if (stippleGC) XFreeGC (display->display, stippleGC); + if (dimple) XFreePixmap (display->display, dimple); + if (upArrow) XFreePixmap (display->display, upArrow); + if (downArrow) XFreePixmap (display->display, downArrow); + if (upArrowHi) XFreePixmap (display->display, upArrowHi); + if (downArrowHi) XFreePixmap (display->display, downArrowHi); +#endif +#if defined(MENUBAR) || defined(RXVT_SCROLLBAR) + if (topShadowGC) XFreeGC (display->display, topShadowGC); + if (botShadowGC) XFreeGC (display->display, botShadowGC); + if (scrollbarGC) XFreeGC (display->display, scrollbarGC); +#endif + if (TermWin.gc) XFreeGC (display->display, TermWin.gc); + #if defined(MENUBAR) && (MENUBAR_MAX > 1) delete menuBar.drawable; //if (menuBar.win) @@ -202,12 +241,20 @@ scr_release (); + /* clear all resources */ + for (int i = 0; i < allocated.size (); i++) + free (allocated[i]); + + free (selection.text); + // TODO: manage env vars in child only(!) free (env_windowid); free (env_display); free (env_term); free (env_colorfgbg); free (locale); +#if 0 free (codeset); +#endif delete envv; delete argv; @@ -258,55 +305,14 @@ /*----------------------------------------------------------------------*/ /* rxvt_init () */ -/* LIBPROTO */ -rxvt_t -rxvt_init (int argc, const char *const *argv) -{ - SET_R (new rxvt_term); - - if (!GET_R->init_vars () || !GET_R->init (argc, argv)) - { - delete GET_R; - SET_R (0); - } - - return GET_R; -} - -static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); - -void -rxvt_init_signals () -{ - /* install exit handler for cleanup */ -#if 0 -#ifdef HAVE_ATEXIT - atexit (rxvt_clean_exit); -#else -#endif -#endif - - struct sigaction sa; - - sigfillset (&sa.sa_mask); - sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; - sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); - sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); - sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); - sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); - sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); - sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); - - /* need to trap SIGURG for SVR4 (Unixware) rlogin */ - /* signal (SIGURG, SIG_DFL); */ - - old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); - //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); -} - bool rxvt_term::init (int argc, const char *const *argv) { + SET_R (this); + + if (!init_vars ()) + return false; + /* * Save and then give up any super-user privileges * If we need privileges in any area then we must specifically request it. @@ -371,26 +377,65 @@ return true; } +static int (*old_xerror_handler) (Display *dpy, XErrorEvent *event); + +void +rxvt_init_signals () +{ + /* install exit handler for cleanup */ +#if 0 +#ifdef HAVE_ATEXIT + atexit (rxvt_clean_exit); +#else +#endif +#endif + + struct sigaction sa; + + sigfillset (&sa.sa_mask); + sa.sa_flags = SA_NOCLDSTOP | SA_RESTART; + sa.sa_handler = SIG_IGN; sigaction (SIGHUP , &sa, 0); + sa.sa_handler = SIG_IGN; sigaction (SIGPIPE, &sa, 0); + sa.sa_handler = rxvt_Exit_signal; sigaction (SIGINT , &sa, 0); + sa.sa_handler = rxvt_Exit_signal; sigaction (SIGQUIT, &sa, 0); + sa.sa_handler = rxvt_Exit_signal; sigaction (SIGTERM, &sa, 0); + sa.sa_handler = rxvt_Child_signal; sigaction (SIGCHLD, &sa, 0); + + /* need to trap SIGURG for SVR4 (Unixware) rlogin */ + /* signal (SIGURG, SIG_DFL); */ + + old_xerror_handler = XSetErrorHandler ((XErrorHandler) rxvt_xerror_handler); + //XSetIOErrorHandler ((XErrorHandler) rxvt_xioerror_handler); +} + /* ------------------------------------------------------------------------- * * SIGNAL HANDLING & EXIT HANDLER * * ------------------------------------------------------------------------- */ /* * Catch a SIGCHLD signal and exit if the direct child has died */ + +void rxvt_term::child_exited (int pid) +{ + for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) + if (pid == (*t)->cmd_pid) + { + (*t)->destroy (); + break; + } +} + /* ARGSUSED */ /* EXTPROTO */ RETSIGTYPE rxvt_Child_signal (int sig __attribute__ ((unused))) { int pid, save_errno = errno; - while ((pid = waitpid (-1, NULL, WNOHANG)) == -1 && errno == EINTR) - ; - errno = save_errno; -#if 0 - if (pid == cmd_pid) - exit (EXIT_SUCCESS); -#endif + while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) + rxvt_term::child_exited (pid); + + errno = save_errno; } /* @@ -402,7 +447,7 @@ { signal (sig, SIG_DFL); #ifdef DEBUG_CMD - rxvt_print_error ("signal %d", sig); + rxvt_warn ("caught signal %d, exiting.\n", sig); #endif rxvt_clean_exit (); kill (getpid (), sig); @@ -687,6 +732,7 @@ } } } + /* TODO: BOUNDS */ TermWin.width = TermWin.ncol * TermWin.fwidth; TermWin.height = TermWin.nrow * TermWin.fheight; @@ -838,32 +884,36 @@ void rxvt_term::set_title (const char *str) { -#ifndef SMART_WINDOW_TITLE - XStoreName (display->display, TermWin.parent[0], str); -#else +#ifdef SMART_WINDOW_TITLE char *name; - if (XFetchName (display->display, TermWin.parent[0], &name) == 0) + if (!XFetchName (display->display, TermWin.parent[0], &name)) name = NULL; + if (name == NULL || STRCMP (name, str)) +#endif XStoreName (display->display, TermWin.parent[0], str); + +#ifdef SMART_WINDOW_TITLE if (name) XFree (name); #endif } void -rxvt_term::set_iconName (const char *str) +rxvt_term::set_icon_name (const char *str) { -#ifndef SMART_WINDOW_TITLE - XSetIconName (display->display, TermWin.parent[0], str); -#else +#ifdef SMART_WINDOW_TITLE char *name; - if (XGetIconName (display->display, TermWin.parent[0], &name)) + if (!XGetIconName (display->display, TermWin.parent[0], &name)) name = NULL; + if (name == NULL || STRCMP (name, str)) +#endif XSetIconName (display->display, TermWin.parent[0], str); + +#ifdef SMART_WINDOW_TITLE if (name) XFree (name); #endif @@ -900,8 +950,10 @@ goto Done; } } + if (!rXParseAllocColor (& xcol, color)) return; + /* XStoreColor (display->display, XCMAP, XColor*); */ /* @@ -934,8 +986,7 @@ set_colorfgbg (); recolour_cursor (); - /* the only reasonable way to enforce a clean update */ - scr_poweron (); + scr_touch (true); } #else @@ -945,14 +996,12 @@ void rxvt_term::recolour_cursor () { -#if TODO - rxvt_color xcol[2]; + XColor xcol[2]; - xcol[0] = PixColors[Color_pointer]; - xcol[1] = PixColors[Color_bg]; + xcol[0].pixel = ISSET_PIXCOLOR (Color_pointer_fg) ? PixColors[Color_pointer_fg] : PixColors[Color_fg]; + xcol[1].pixel = ISSET_PIXCOLOR (Color_pointer_bg) ? PixColors[Color_pointer_bg] : PixColors[Color_bg]; XQueryColors (display->display, XCMAP, xcol, 2); - XRecolorCursor (display->display, TermWin_cursor, & (xcol[0]), & (xcol[1])); -#endif + XRecolorCursor (display->display, TermWin_cursor, xcol + 0, xcol + 1); } /*----------------------------------------------------------------------*/ @@ -1011,7 +1060,7 @@ { if (!screen_in_out->set (display, colour)) { - rxvt_print_error ("can't allocate colour: %s", colour); + rxvt_warn ("can't get colour '%s', continuing without.\n", colour); return false; } @@ -1388,7 +1437,7 @@ if (Input_Context == NULL) { - rxvt_print_error ("failed to create input context"); + rxvt_warn ("failed to create input context, continuing without XIM.\n"); display->put_xim (input_method); return false; }