--- rxvt-unicode/src/main.C 2007/08/13 22:41:34 1.241 +++ rxvt-unicode/src/main.C 2007/12/18 11:15:24 1.289 @@ -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,12 +40,15 @@ #include #include -#ifdef TTY_GID_SUPPORT -# include -#endif +#include -#ifdef HAVE_TERMIOS_H -# include +#ifdef HAVE_XSETLOCALE +# define X_LOCALE +# include +#else +# ifdef HAVE_SETLOCALE +# include +# endif #endif vector rxvt_term::termlist; @@ -90,7 +93,7 @@ text_t rxvt_composite_vec::compose (unicode_t c1, unicode_t c2) { compose_char *cc; - + // break compose chains, as stupid readline really likes to duplicate // composing characters for some reason near the end of a line. cc = (*this)[c1]; @@ -149,49 +152,48 @@ #endif rxvt_term::rxvt_term () - : -#if ENABLE_TRANSPARENCY || ENABLE_PERL - rootwin_ev (this, &rxvt_term::rootwin_cb), -#endif -#if ENABLE_TRANSPARENCY - check_our_parents_ev(this, &rxvt_term::check_our_parents_cb), -#endif -#ifdef HAVE_SCROLLBARS - scrollbar_ev (this, &rxvt_term::x_cb), +{ +#if HAVE_BG_PIXMAP + 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 -#ifndef NO_BELL - bell_ev (this, &rxvt_term::bell_cb), +#ifdef POINTER_BLANK + pointer_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), - check_ev (this, &rxvt_term::check_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) -{ +#ifndef NO_BELL + bell_ev.set (this); +#endif + 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); @@ -203,7 +205,8 @@ // clean up the most important stuff, do *not* call x or free mem etc. // for use before an emergency exit -void rxvt_term::emergency_cleanup () +void +rxvt_term::emergency_cleanup () { if (cmd_pid) kill (-cmd_pid, SIGHUP); @@ -280,6 +283,10 @@ delete [] pix_colors_unfocused; #endif +#ifdef HAVE_BG_PIXMAP + bgPixmap.destroy (); +#endif + display->flush (); /* ideally .put should do this */ displays.put (display); scr_release (); @@ -302,11 +309,14 @@ #ifdef KEYSYM_RESOURCE delete keyboard; #endif +#ifndef NO_RESOURCES + XrmDestroyDatabase (option_db); +#endif } // child has exited, usually destroys void -rxvt_term::child_cb (child_watcher &w, int status) +rxvt_term::child_cb (ev::child &w, int status) { HOOK_INVOKE ((this, HOOK_CHILD_EXIT, DT_INT, status, DT_END)); @@ -319,7 +329,7 @@ void rxvt_term::destroy () { - if (destroy_ev.active) + if (destroy_ev.is_active ()) return; HOOK_INVOKE ((this, HOOK_DESTROY, DT_END)); @@ -344,7 +354,7 @@ vt_ev.stop (display); } - check_ev.stop (); + flush_ev.stop (); pty_ev.stop (); #ifdef CURSOR_BLINK cursor_blink_ev.stop (); @@ -362,11 +372,11 @@ pointer_ev.stop (); #endif - destroy_ev.start (0); + destroy_ev.start (); } void -rxvt_term::destroy_cb (time_watcher &w) +rxvt_term::destroy_cb (ev::idle &w, int revents) { make_current (); @@ -430,7 +440,7 @@ mesg, BUFSIZ); rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->resourceid); } - XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", + XGetErrorDatabaseText(dpy, mtype, "ErrorSerial", "Error Serial #%d", mesg, BUFSIZ); rxvt_warn (strncat (mesg, "\n", BUFSIZ), event->serial); } @@ -465,7 +475,7 @@ } /*----------------------------------------------------------------------*/ -bool +void rxvt_term::init (int argc, const char *const *argv, stringvec *envv) { this->envv = envv; @@ -474,8 +484,7 @@ set_locale (""); set_environ (envv); // few things in X do not call setlocale :( - if (!init_vars ()) - return false; + init_vars (); init_secondary (); @@ -508,22 +517,20 @@ #endif #ifdef HAVE_BG_PIXMAP { - bool changed = false; bgPixmap.set_target (this); #ifdef ENABLE_TRANSPARENCY if (option (Opt_transparent)) { bgPixmap.set_transparent (); -#ifdef HAVE_AFTERIMAGE +#ifdef HAVE_AFTERIMAGE if (rs [Rs_blurradius]) bgPixmap.set_blur_radius (rs [Rs_blurradius]); -#endif +#endif if (ISSET_PIXCOLOR (Color_tint)) bgPixmap.set_tint (pix_colors_focused [Color_tint]); if (rs [Rs_shade]) bgPixmap.set_shade (rs [Rs_shade]); - changed = true; bgPixmap.set_root_pixmap (); XSelectInput (dpy, display->root, PropertyChangeMask); @@ -531,7 +538,7 @@ } #endif -#ifdef XPM_BACKGROUND +#ifdef BG_IMAGE_FROM_FILE if (rs[Rs_backgroundPixmap] != NULL) { const char *p = rs[Rs_backgroundPixmap]; @@ -544,14 +551,11 @@ else bgPixmap.set_defaultGeometry (); - changed = bgPixmap.set_file (rs[Rs_backgroundPixmap]); + if (bgPixmap.set_file (rs[Rs_backgroundPixmap])) + if (!bgPixmap.window_position_sensitive ()) + update_background (); } #endif - if (changed) - { - bgPixmap.render (); - scr_touch (true); - } } #endif @@ -566,9 +570,7 @@ free (cmd_argv); if (pty->pty >= 0) - pty_ev.start (pty->pty, EVENT_READ); - - check_ev.start (); + pty_ev.start (pty->pty, ev::READ); HOOK_INVOKE ((this, HOOK_START, DT_END)); @@ -584,32 +586,32 @@ XMapWindow (dpy, vt); XMapWindow (dpy, parent[0]); - - return true; } static struct sig_handlers { - sig_watcher sw_term, sw_int; - + ev::sig sw_term, sw_int; + /* * Catch a fatal signal and tidy up before quitting */ - void - sig_term (sig_watcher &w) - { - rxvt_emergency_cleanup (); - signal (w.signum, SIG_DFL); - 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 @@ -617,13 +619,16 @@ { ptytty::init (); + if (!ev_default_loop (0)) + rxvt_fatal ("cannot initialise libev (bad value for LIBEV_METHODS?)\n"); + rxvt_environ = environ; signal (SIGHUP, SIG_IGN); signal (SIGPIPE, SIG_IGN); - sig_handlers.sw_term.start (SIGTERM); - sig_handlers.sw_int.start (SIGINT); + 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); */ @@ -635,42 +640,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. @@ -819,7 +788,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 @@ -903,19 +872,21 @@ resize_all_windows (0, 0, 0); scr_remap_chars (); scr_touch (true); - } + } return true; } -void rxvt_term::set_string_property (Atom prop, const char *str, int len) +void +rxvt_term::set_string_property (Atom prop, const char *str, int len) { XChangeProperty (dpy, parent[0], prop, XA_STRING, 8, PropModeReplace, (const unsigned char *)str, len >= 0 ? len : strlen (str)); } -void rxvt_term::set_utf8_property (Atom prop, const char *str, int len) +void +rxvt_term::set_utf8_property (Atom prop, const char *str, int len) { wchar_t *ws = rxvt_mbstowcs (str, len); char *s = rxvt_wcstoutf8 (ws); @@ -949,13 +920,13 @@ #endif } -#ifdef XTERM_COLOR_CHANGE void rxvt_term::set_window_color (int idx, const char *color) { +#ifdef XTERM_COLOR_CHANGE rxvt_color xcol; int i; - + if (color == NULL || *color == '\0') return; @@ -969,14 +940,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; } @@ -991,20 +963,15 @@ pix_colors_focused[idx] = xcol; - /* XSetWindowAttributes attr; */ - /* Cursor cursor; */ done: /*TODO: handle Color_BD, scrollbar background, etc. */ update_fade_color (idx); recolour_cursor (); scr_recolour (); +#endif /* XTERM_COLOR_CHANGE */ } -#else -# define set_window_color (idx,color) ((void)0) -#endif /* XTERM_COLOR_CHANGE */ - void rxvt_term::recolour_cursor () { @@ -1029,7 +996,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"); @@ -1045,7 +1012,7 @@ if (pix_colors[Color_bg] == pix_colors[i]) { sprintf (bstr, "%d", (i - Color_Black)); -#ifdef XPM_BACKGROUND +#ifdef BG_IMAGE_FROM_FILE xpmb = "default;"; #endif break; @@ -1151,11 +1118,12 @@ window_vt_x, window_vt_y, width, height); - scr_clear (); -#ifdef XPM_BACKGROUND - /* TODO: should that really be here ? */ - bgPixmap.render (); +#ifdef HAVE_BG_PIXMAP + if (bgPixmap.window_size_sensitive ()) + update_background (); #endif + + scr_clear (); } if (fix_screen || old_height == 0) @@ -1165,8 +1133,9 @@ //scr_touch (false); #ifdef HAVE_BG_PIXMAP - if (bgPixmap.pixmap) - scr_touch (false); +// TODO: this don't seem to have any effect - do we still need it ? If so - in which case exactly ? +// if (bgPixmap.pixmap) +// scr_touch (false); #endif #ifdef USE_XIM @@ -1347,7 +1316,7 @@ } else str = (void *)text->string.wide_char; - + HOOK_INVOKE ((term, HOOK_XIM_PREEDIT_DRAW, DT_INT, call_data->caret, DT_INT, call_data->chg_first, @@ -1676,7 +1645,7 @@ { im_set_size (preedit_rect); preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); - + XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); } @@ -1703,6 +1672,80 @@ XFree (preedit_attr); } -#endif /* USE_XIM */ +#endif /* USE_XIM */ + +void +rxvt_term::get_window_origin (int &x, int &y) +{ + Window cr; + XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); +/* fprintf (stderr, "origin is %+d%+d\n", x, y);*/ +} + +Pixmap +rxvt_term::get_pixmap_property (int prop_id) +{ + if (prop_id > 0 && prop_id < NUM_XA) + if (xa[prop_id]) + { + int aformat; + unsigned long nitems, bytes_after; + Atom atype; + unsigned char *prop = NULL; + int result = XGetWindowProperty (dpy, display->root, xa[prop_id], + 0L, 1L, False, XA_PIXMAP, &atype, &aformat, + &nitems, &bytes_after, &prop); + if (result == Success && prop && atype == XA_PIXMAP) + { + 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) +{ + fprintf (stderr, "%s:%d:update_background()\n", file, line); + update_background (); +} +# endif + +int +rxvt_term::update_background () +{ + 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)) + bgPixmap.render (); + else + { + ev_tstamp refresh; + update_background_ev.stop (); + + if (!bgPixmap.need_client_side_rendering ()) + refresh = .05; + else if (bgPixmap.flags & bgPixmap_t::blurNeeded) + refresh = .20; /* very slow !!! */ + else + refresh = .07; + update_background_ev.start (refresh); + } + + return 0; +} + +void +rxvt_term::update_background_cb (ev::timer &w, int revents) +{ + make_current (); + bgPixmap.render (); + refresh_check (); +} + +#endif /* HAVE_BG_PIXMAP */ /*----------------------- end-of-file (C source) -----------------------*/