--- rxvt-unicode/src/main.C 2005/02/04 11:41:23 1.134 +++ rxvt-unicode/src/main.C 2005/11/30 21:05:39 1.148 @@ -32,7 +32,6 @@ #include "../config.h" /* NECESSARY */ #include "rxvt.h" /* NECESSARY */ -#include "main.intpro" /* PROTOS for internal routines */ #include #include @@ -160,9 +159,6 @@ #ifdef USE_XIM im_ev (this, &rxvt_term::im_cb), #endif - sw_term (this, &rxvt_term::sig_term), - sw_int (this, &rxvt_term::sig_term), - sw_chld (this, &rxvt_term::sig_chld), termwin_ev (this, &rxvt_term::x_cb), vt_ev (this, &rxvt_term::x_cb), check_ev (this, &rxvt_term::check_cb), @@ -262,7 +258,7 @@ // TODO: free pixcolours, colours should become part of rxvt_display delete pix_colors_focused; -#ifdef OFF_FOCUS_FADING +#if OFF_FOCUS_FADING delete pix_colors_unfocused; #endif @@ -364,6 +360,55 @@ (*t)->emergency_cleanup (); } +#if ENABLE_FRILLS +static void +print_x_error (Display *dpy, XErrorEvent *event) +{ + char buffer[BUFSIZ]; + char mesg[BUFSIZ]; + char number[32]; + char *mtype = "XlibMessage"; + XGetErrorText(dpy, event->error_code, buffer, BUFSIZ); + XGetErrorDatabaseText(dpy, mtype, "XError", "X Error", mesg, BUFSIZ); + rxvt_warn ("An X Error occured, trying to continue after report.\n"); + rxvt_warn ("%s: %s\n", mesg, buffer); + XGetErrorDatabaseText(dpy, mtype, "MajorCode", "Request Major code %d", mesg, BUFSIZ); + rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->request_code); + sprintf(number, "%d", event->request_code); + XGetErrorDatabaseText(dpy, "XRequest", number, "", buffer, BUFSIZ); + rxvt_warn ("(which is %s)\n", buffer); + if (event->request_code >= 128) { + XGetErrorDatabaseText(dpy, mtype, "MinorCode", "Request Minor code %d", + mesg, BUFSIZ); + rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->minor_code); + } + if ((event->error_code == BadWindow) || + (event->error_code == BadPixmap) || + (event->error_code == BadCursor) || + (event->error_code == BadFont) || + (event->error_code == BadDrawable) || + (event->error_code == BadColor) || + (event->error_code == BadGC) || + (event->error_code == BadIDChoice) || + (event->error_code == BadValue) || + (event->error_code == BadAtom)) { + if (event->error_code == BadValue) + XGetErrorDatabaseText(dpy, mtype, "Value", "Value 0x%x", + mesg, BUFSIZ); + else if (event->error_code == BadAtom) + XGetErrorDatabaseText(dpy, mtype, "AtomID", "AtomID 0x%x", + mesg, BUFSIZ); + else + XGetErrorDatabaseText(dpy, mtype, "ResourceID", "ResourceID 0x%x", + mesg, BUFSIZ); + rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); + } + XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", + mesg, BUFSIZ); + rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); +} +#endif + int rxvt_xerror_handler (Display *display, XErrorEvent *event) { @@ -371,10 +416,13 @@ GET_R->allowedxerror = event->error_code; else { - //TODO: GET_R is most likely not the terminal which caused the error - //TODO: maybe just output the error and continue? + // GET_R is most likely not the terminal which caused the error, + // so just output the error and continue +#if ENABLE_FRILLS + print_x_error (display, event); +#else old_xerror_handler (display, event); - GET_R->destroy (); +#endif } return 0; @@ -389,22 +437,7 @@ _exit (EXIT_FAILURE); } -/* - * Catch a fatal signal and tidy up before quitting - */ -void -rxvt_term::sig_term (sig_watcher &w) -{ -#ifdef DEBUG_CMD - rxvt_warn ("caught signal %d, exiting.\n", w.signum); -#endif - rxvt_emergency_cleanup (); - signal (w.signum, SIG_DFL); - kill (getpid (), w.signum); -} - /*----------------------------------------------------------------------*/ -/* rxvt_init () */ bool rxvt_term::init (int argc, const char *const *argv) { @@ -476,6 +509,46 @@ return true; } +static struct sig_handlers +{ + sig_watcher sw_chld, 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)->destroy (); + break; + } + } + + /* + * Catch a fatal signal and tidy up before quitting + */ + void + sig_term (sig_watcher &w) + { +#ifdef DEBUG_CMD + rxvt_warn ("caught signal %d, exiting.\n", w.signum); +#endif + rxvt_emergency_cleanup (); + signal (w.signum, SIG_DFL); + kill (getpid (), w.signum); + } + + sig_handlers () + : sw_chld (this, &sig_handlers::sig_chld), + sw_term (this, &sig_handlers::sig_term), + sw_int (this, &sig_handlers::sig_term) + { + } +} sig_handlers; + void rxvt_init () { @@ -492,6 +565,10 @@ 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); + /* need to trap SIGURG for SVR4 (Unixware) rlogin */ /* signal (SIGURG, SIG_DFL); */ @@ -501,28 +578,6 @@ } /* ------------------------------------------------------------------------- * - * SIGNAL HANDLING & EXIT HANDLER * - * ------------------------------------------------------------------------- */ -/* - * Catch a SIGCHLD signal and exit if the direct child has died - */ - -void -rxvt_term::sig_chld (sig_watcher &w) -{ - // we are being called for every SIGCHLD, not just ours - int pid; - - while ((pid = waitpid (-1, NULL, WNOHANG)) > 0) - for (rxvt_term **t = termlist.begin (); t < termlist.end (); t++) - if (pid == (*t)->cmd_pid) - { - (*t)->destroy (); - break; - } -} - -/* ------------------------------------------------------------------------- * * MEMORY ALLOCATION WRAPPERS * * ------------------------------------------------------------------------- */ void * @@ -536,8 +591,7 @@ return p; } -/* INTPROTO */ -void * +void * rxvt_calloc (size_t number, size_t size) { void *p = calloc (number, size); @@ -548,7 +602,6 @@ return p; } -/* INTPROTO */ void * rxvt_realloc (void *ptr, size_t size) { @@ -662,16 +715,19 @@ parsed_geometry = 1; if (rs[Rs_geometry]) flags = XParseGeometry (rs[Rs_geometry], &x, &y, &w, &h); + if (flags & WidthValue) { TermWin.ncol = BOUND_POSITIVE_INT16 (w); szHint.flags |= USSize; } + if (flags & HeightValue) { TermWin.nrow = BOUND_POSITIVE_INT16 (h); szHint.flags |= USSize; } + if (flags & XValue) { szHint.x = x; @@ -682,6 +738,7 @@ szHint.win_gravity = NorthEastGravity; } } + if (flags & YValue) { szHint.y = y; @@ -790,13 +847,13 @@ #if 0 // TIOCSWINSZ⎈ is supposed to do this automatically and correctly if (cmd_pid) /* force through to the command */ - kill (cmd_pid, SIGWINCH); + kill (-cmd_pid, SIGWINCH); #endif } /*----------------------------------------------------------------------*/ /* set_fonts () - load and set the various fonts -/* + * * init = 1 - initialize * * fontname == FONT_UP - switch to bigger font @@ -904,7 +961,7 @@ rxvt_term::set_title (const char *str) { set_string_property (XA_WM_NAME, str); -#if ENABLE_FRILLS +#if ENABLE_EWMH set_utf8_property (xa[XA_NET_WM_NAME], str); #endif } @@ -913,7 +970,7 @@ rxvt_term::set_icon_name (const char *str) { set_string_property (XA_WM_ICON_NAME, str); -#if ENABLE_FRILLS +#if ENABLE_EWMH set_utf8_property (xa[XA_NET_WM_ICON_NAME], str); #endif } @@ -939,7 +996,7 @@ # ifndef NO_BRIGHTCOLOR pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; SET_PIXCOLOR (idx); - goto Done; + goto done; # endif } @@ -947,7 +1004,7 @@ { /* normal colors */ pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; SET_PIXCOLOR (idx); - goto Done; + goto done; } } @@ -977,10 +1034,11 @@ /* XSetWindowAttributes attr; */ /* Cursor cursor; */ -Done: -#ifdef OFF_FOCUS_FADING +done: + +#if OFF_FOCUS_FADING if (rs[Rs_fade]) - pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade])); + pix_colors_unfocused[idx] = pix_colors_focused[idx].fade (display, atoi (rs[Rs_fade]), pix_colors[Color_fade]); #endif /*TODO: handle Color_BD, scrollbar background, etc. */ @@ -1195,6 +1253,7 @@ if (width == 0 || height == 0) { XGetWindowAttributes (display->display, display->root, &wattr); + if (width == 0) width = wattr.width - szHint.base_width; if (height == 0) @@ -1498,11 +1557,13 @@ void rxvt_term::im_cb () { - int i, found, had_im; + int i; const char *p; char **s; char buf[IMBUFSIZ]; + SET_R (this); + im_destroy (); D_MAIN ((stderr, "rxvt_IMInstantiateCallback ()"));