--- rxvt-unicode/src/main.C 2007/11/18 02:45:26 1.260 +++ rxvt-unicode/src/main.C 2008/01/04 21:31:23 1.297 @@ -13,7 +13,7 @@ * Copyright (c) 1997,1998 Oezguer Kesim * Copyright (c) 1998-2001 Geoff Wing * - extensive modifications - * Copyright (c) 2003-2006 Marc Lehmann + * Copyright (c) 2003-2007 Marc Lehmann * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,9 +40,7 @@ #include #include -#ifdef HAVE_TERMIOS_H -# include -#endif +#include #ifdef HAVE_XSETLOCALE # define X_LOCALE @@ -154,49 +152,48 @@ #endif rxvt_term::rxvt_term () - : -#if ENABLE_TRANSPARENCY || ENABLE_PERL - rootwin_ev (this, &rxvt_term::rootwin_cb), -#endif +{ #if HAVE_BG_PIXMAP - update_background_ev(this, &rxvt_term::update_background_cb), -#endif -#ifdef HAVE_SCROLLBARS - scrollbar_ev (this, &rxvt_term::x_cb), + update_background_ev.set (this); #endif #ifdef CURSOR_BLINK - cursor_blink_ev (this, &rxvt_term::cursor_blink_cb), + cursor_blink_ev.set (this); cursor_blink_ev.set (0., CURSOR_BLINK_INTERVAL); #endif #ifdef TEXT_BLINK - text_blink_ev (this, &rxvt_term::text_blink_cb), + text_blink_ev.set (this); text_blink_ev.set (0., TEXT_BLINK_INTERVAL); #endif #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - cont_scroll_ev (this, &rxvt_term::cont_scroll_cb), + cont_scroll_ev.set (this); #endif #ifdef SELECTION_SCROLLING - sel_scroll_ev (this, &rxvt_term::sel_scroll_cb), + sel_scroll_ev.set (this); #endif #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) - slip_wheel_ev (this, &rxvt_term::slip_wheel_cb), + slip_wheel_ev.set (this); #endif -#ifdef POINTER_BLANK - pointer_ev (this, &rxvt_term::pointer_cb), +#if ENABLE_TRANSPARENCY || ENABLE_PERL + rootwin_ev.set (this), +#endif +#ifdef HAVE_SCROLLBARS + scrollbar_ev.set (this), #endif #ifdef USE_XIM - im_ev (this, &rxvt_term::im_cb), + im_ev.set (this), +#endif +#ifdef POINTER_BLANK + pointer_ev.set (this); #endif #ifndef NO_BELL - bell_ev (this, &rxvt_term::bell_cb), + bell_ev.set (this); #endif - termwin_ev (this, &rxvt_term::x_cb), - vt_ev (this, &rxvt_term::x_cb), - child_ev (this, &rxvt_term::child_cb), - prepare_ev (this, &rxvt_term::prepare_cb), - flush_ev (this, &rxvt_term::flush_cb), - destroy_ev (this, &rxvt_term::destroy_cb), - pty_ev (this, &rxvt_term::pty_cb), - incr_ev (this, &rxvt_term::incr_cb) -{ + child_ev.set (this); + flush_ev.set (this); + destroy_ev.set (this); + pty_ev.set (this); + incr_ev.set (this); + termwin_ev.set (this); + vt_ev.set (this); + cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; termlist.push_back (this); @@ -281,11 +278,10 @@ clear (); } - delete [] pix_colors_focused; -#if OFF_FOCUS_FADING - delete [] pix_colors_unfocused; +#ifdef HAVE_BG_PIXMAP + bgPixmap.destroy (); #endif - + display->flush (); /* ideally .put should do this */ displays.put (display); scr_release (); @@ -308,6 +304,9 @@ #ifdef KEYSYM_RESOURCE delete keyboard; #endif +#ifndef NO_RESOURCES + XrmDestroyDatabase (option_db); +#endif } // child has exited, usually destroys @@ -325,7 +324,7 @@ void rxvt_term::destroy () { - if (destroy_ev.active) + if (destroy_ev.is_active ()) return; HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); @@ -350,7 +349,7 @@ vt_ev.stop (display); } - prepare_ev.stop (); + flush_ev.stop (); pty_ev.stop (); #ifdef CURSOR_BLINK cursor_blink_ev.stop (); @@ -471,7 +470,7 @@ } /*----------------------------------------------------------------------*/ -bool +void rxvt_term::init (int argc, const char *const *argv, stringvec *envv) { this->envv = envv; @@ -480,8 +479,7 @@ set_locale (""); set_environ (envv); // few things in X do not call setlocale :( - if (!init_vars ()) - return false; + init_vars (); init_secondary (); @@ -520,12 +518,14 @@ if (option (Opt_transparent)) { bgPixmap.set_transparent (); + #ifdef HAVE_AFTERIMAGE if (rs [Rs_blurradius]) bgPixmap.set_blur_radius (rs [Rs_blurradius]); #endif if (ISSET_PIXCOLOR (Color_tint)) bgPixmap.set_tint (pix_colors_focused [Color_tint]); + if (rs [Rs_shade]) bgPixmap.set_shade (rs [Rs_shade]); @@ -536,11 +536,11 @@ #endif #ifdef BG_IMAGE_FROM_FILE - if (rs[Rs_backgroundPixmap] != NULL) + if (rs[Rs_backgroundPixmap]) { const char *p = rs[Rs_backgroundPixmap]; - if ((p = strchr (p, ';')) != NULL) + if ((p = strchr (p, ';')) != 0) { p++; bgPixmap.set_geometry (p); @@ -569,8 +569,6 @@ if (pty->pty >= 0) pty_ev.start (pty->pty, ev::READ); - prepare_ev.start (); - HOOK_INVOKE ((this, HOOK_START, DT_END)); #if ENABLE_XEMBED @@ -585,8 +583,6 @@ XMapWindow (dpy, vt); XMapWindow (dpy, parent[0]); - - return true; } static struct sig_handlers @@ -596,21 +592,23 @@ /* * Catch a fatal signal and tidy up before quitting */ - void - sig_term (ev::sig &w, int revents) - { - rxvt_emergency_cleanup (); - w.stop (); - kill (getpid (), w.signum); - } + void sig_term (ev::sig &w, int revents); sig_handlers () - : sw_term (this, &sig_handlers::sig_term), - sw_int (this, &sig_handlers::sig_term) { + sw_term.set (this); + sw_int .set (this); } } sig_handlers; +void +sig_handlers::sig_term (ev::sig &w, int revents) +{ + rxvt_emergency_cleanup (); + w.stop (); + kill (getpid (), w.signum); +} + char **rxvt_environ; // startup environment void @@ -618,7 +616,7 @@ { ptytty::init (); - if (!ev::ev_default_loop (0)) + if (!ev_default_loop (0)) rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); rxvt_environ = environ; @@ -626,8 +624,8 @@ signal (SIGHUP, SIG_IGN); signal (SIGPIPE, SIG_IGN); - sig_handlers.sw_term.start (SIGTERM); ev::ev_unref (); - sig_handlers.sw_int.start (SIGINT); ev::ev_unref (); + sig_handlers.sw_term.start (SIGTERM); ev_unref (); + sig_handlers.sw_int.start (SIGINT); ev_unref (); /* need to trap SIGURG for SVR4 (Unixware) rlogin */ /* signal (SIGURG, SIG_DFL); */ @@ -639,42 +637,6 @@ XrmInitialize (); } -/* ------------------------------------------------------------------------- * - * MEMORY ALLOCATION WRAPPERS * - * ------------------------------------------------------------------------- */ -void * -rxvt_malloc (size_t size) -{ - void *p = malloc (size); - - if (!p) - rxvt_fatal ("memory allocation failure. aborting.\n"); - - return p; -} - -void * -rxvt_calloc (size_t number, size_t size) -{ - void *p = calloc (number, size); - - if (!p) - rxvt_fatal ("memory allocation failure. aborting.\n"); - - return p; -} - -void * -rxvt_realloc (void *ptr, size_t size) -{ - void *p = realloc (ptr, size); - - if (!p) - rxvt_fatal ("memory allocation failure. aborting.\n"); - - return p; -} - /*----------------------------------------------------------------------*/ /* * window size/position calculations for XSizeHint and other storage. @@ -823,7 +785,7 @@ (void)ioctl (pty->pty, TIOCSWINSZ, &ws); #if 0 - // TIOCSWINSZ⎈ is supposed to do this automatically and correctly + // TIOCSWINSZ is supposed to do this automatically and correctly if (cmd_pid) /* force through to the command */ kill (-cmd_pid, SIGWINCH); #endif @@ -975,14 +937,15 @@ i = atoi (color); if (i >= 8 && i <= 15) - { /* bright colors */ - i -= 8; - pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i]; + { + /* bright colors */ + pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i - 8]; goto done; } if (i >= 0 && i <= 7) - { /* normal colors */ + { + /* normal colors */ pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i]; goto done; } @@ -997,8 +960,6 @@ pix_colors_focused[idx] = xcol; - /* XSetWindowAttributes attr; */ - /* Cursor cursor; */ done: /*TODO: handle Color_BD, scrollbar background, etc. */ @@ -1032,7 +993,7 @@ rxvt_term::set_colorfgbg () { unsigned int i; - const char *xpmb = "\0"; + const char *xpmb = ""; char fstr[sizeof ("default") + 1], bstr[sizeof ("default") + 1]; strcpy (fstr, "default"); @@ -1715,7 +1676,7 @@ { Window cr; XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); -/* fprintf( stderr, "origin is %+d%+d\n", x, y);*/ +/* fprintf (stderr, "origin is %+d%+d\n", x, y);*/ } Pixmap @@ -1732,49 +1693,47 @@ 0L, 1L, False, XA_PIXMAP, &atype, &aformat, &nitems, &bytes_after, &prop); if (result == Success && prop && atype == XA_PIXMAP) - { - return *(Pixmap *)prop; - } + return *(Pixmap *)prop; } + return None; } #ifdef HAVE_BG_PIXMAP # if TRACE_PIXMAPS # undef update_background -int rxvt_term::trace_update_background (const char* file, int line) +void +rxvt_term::trace_update_background (const char *file, int line) { fprintf (stderr, "%s:%d:update_background()\n", file, line); update_background (); } # endif -int + +void rxvt_term::update_background () { + if (update_background_ev.is_active ()) + return; + bgPixmap.invalidate (); - /* no chance of real time refresh if we are blurring! */ - if (bgPixmap.invalid_since + 0.5 < ev::now () && !(bgPixmap.flags & bgPixmap_t::blurNeeded)) + ev_tstamp to_wait = 0.5 - (ev::now () - bgPixmap.valid_since); + + if (to_wait <= 0.) bgPixmap.render (); else - { - update_background_ev.stop (); - - if (!bgPixmap.need_client_side_rendering()) - update_background_ev.start (.05); - else if (bgPixmap.flags & bgPixmap_t::blurNeeded) - update_background_ev.start (.20); /* very slow !!! */ - else - update_background_ev.start (.07); - } - - return 0; + update_background_ev.start (to_wait); } void rxvt_term::update_background_cb (ev::timer &w, int revents) { + make_current (); + + update_background_ev.stop (); bgPixmap.render (); + refresh_check (); } #endif /* HAVE_BG_PIXMAP */