--- rxvt-unicode/src/main.C 2007/08/13 22:41:34 1.241 +++ rxvt-unicode/src/main.C 2007/11/24 11:06:13 1.264 @@ -40,14 +40,19 @@ #include #include -#ifdef TTY_GID_SUPPORT -# include -#endif - #ifdef HAVE_TERMIOS_H # include #endif +#ifdef HAVE_XSETLOCALE +# define X_LOCALE +# include +#else +# ifdef HAVE_SETLOCALE +# include +# endif +#endif + vector rxvt_term::termlist; // used to tell global functions which terminal instance is "active" @@ -90,7 +95,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]; @@ -153,8 +158,8 @@ #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), +#if HAVE_BG_PIXMAP + update_background_ev(this, &rxvt_term::update_background_cb), #endif #ifdef HAVE_SCROLLBARS scrollbar_ev (this, &rxvt_term::x_cb), @@ -178,19 +183,19 @@ pointer_ev (this, &rxvt_term::pointer_cb), #endif #ifdef USE_XIM - im_ev (this, &rxvt_term::im_cb), + im_ev (this, &rxvt_term::im_cb), #endif -#ifndef NO_BELL - bell_ev (this, &rxvt_term::bell_cb), +#ifndef NO_BELL + bell_ev (this, &rxvt_term::bell_cb), #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), + 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) + pty_ev (this, &rxvt_term::pty_cb), + incr_ev (this, &rxvt_term::incr_cb) { cmdbuf_ptr = cmdbuf_endp = cmdbuf_base; @@ -203,7 +208,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 +286,9 @@ delete [] pix_colors_unfocused; #endif +#ifdef HAVE_BG_PIXMAP + bgPixmap.destroy (); +#endif displays.put (display); scr_release (); @@ -302,11 +311,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)); @@ -344,7 +356,7 @@ vt_ev.stop (display); } - check_ev.stop (); + prepare_ev.stop (); pty_ev.stop (); #ifdef CURSOR_BLINK cursor_blink_ev.stop (); @@ -362,11 +374,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 +442,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); } @@ -508,22 +520,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 +541,7 @@ } #endif -#ifdef XPM_BACKGROUND +#ifdef BG_IMAGE_FROM_FILE if (rs[Rs_backgroundPixmap] != NULL) { const char *p = rs[Rs_backgroundPixmap]; @@ -544,14 +554,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 +573,9 @@ free (cmd_argv); if (pty->pty >= 0) - pty_ev.start (pty->pty, EVENT_READ); + pty_ev.start (pty->pty, ev::READ); - check_ev.start (); + prepare_ev.start (); HOOK_INVOKE ((this, HOOK_START, DT_END)); @@ -590,16 +597,16 @@ 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) + sig_term (ev::sig &w, int revents) { rxvt_emergency_cleanup (); - signal (w.signum, SIG_DFL); + w.stop (); kill (getpid (), w.signum); } @@ -617,13 +624,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); */ @@ -903,19 +913,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 +961,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; @@ -999,12 +1011,9 @@ 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 () { @@ -1045,7 +1054,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 +1160,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 +1175,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 +1358,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 +1687,7 @@ { im_set_size (preedit_rect); preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); - + XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); } @@ -1703,6 +1714,75 @@ 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 + { + 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; +} + +void +rxvt_term::update_background_cb (ev::timer &w, int revents) +{ + bgPixmap.render (); +} + +#endif /* HAVE_BG_PIXMAP */ /*----------------------- end-of-file (C source) -----------------------*/