--- rxvt-unicode/src/main.C 2006/02/18 14:14:43 1.223 +++ rxvt-unicode/src/main.C 2007/11/11 17:10:45 1.257 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: main.C *----------------------------------------------------------------------* * @@ -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" @@ -58,10 +63,15 @@ bool rxvt_set_locale (const char *locale) NOTHROW { - if (!locale || !strncmp (locale, curlocale, 128)) + int size = strlen (locale) + 1; + + if (size > sizeof (curlocale)) + rxvt_fatal ("locale string too long, aborting.\n"); + + if (!locale || !memcmp (locale, curlocale, size)) return false; - strncpy (curlocale, locale, 128); + memcpy (curlocale, locale, size); setlocale (LC_CTYPE, curlocale); return true; } @@ -85,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]; @@ -145,9 +155,12 @@ rxvt_term::rxvt_term () : -#if TRANSPARENT +#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), #endif @@ -172,13 +185,13 @@ #ifdef USE_XIM im_ev (this, &rxvt_term::im_cb), #endif -#ifndef NO_BELL +#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), + 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), @@ -195,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); @@ -267,9 +281,9 @@ clear (); } - delete pix_colors_focused; + delete [] pix_colors_focused; #if OFF_FOCUS_FADING - delete pix_colors_unfocused; + delete [] pix_colors_unfocused; #endif displays.put (display); @@ -298,13 +312,13 @@ // 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)); cmd_pid = 0; - if (!OPTION (Opt_hold)) + if (!option (Opt_hold)) destroy (); } @@ -328,7 +342,7 @@ #if HAVE_SCROLLBARS scrollbar_ev.stop (display); #endif -#if TRANSPARENT +#if ENABLE_TRANSPARENCY || ENABLE_PERL rootwin_ev.stop (display); #endif incr_ev.stop (); @@ -336,7 +350,7 @@ vt_ev.stop (display); } - check_ev.stop (); + prepare_ev.stop (); pty_ev.stop (); #ifdef CURSOR_BLINK cursor_blink_ev.stop (); @@ -354,11 +368,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::check &w, int revents) { make_current (); @@ -422,7 +436,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); } @@ -478,7 +492,7 @@ #endif #ifdef HAVE_SCROLLBARS - if (OPTION (Opt_scrollBar)) + if (option (Opt_scrollBar)) scrollBar.setIdle (); /* set existence for size calculations */ #endif @@ -495,16 +509,55 @@ #endif #ifdef HAVE_SCROLLBARS - if (OPTION (Opt_scrollBar)) + if (option (Opt_scrollBar)) resize_scrollbar (); /* create and map scrollbar */ #endif -#ifdef TRANSPARENT - if (OPTION (Opt_transparent)) - { - XSelectInput (dpy, display->root, PropertyChangeMask); - check_our_parents (); - rootwin_ev.start (display, display->root); - } +#ifdef HAVE_BG_PIXMAP + { + bgPixmap.set_target (this); + +#ifdef ENABLE_TRANSPARENCY + 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]); + + bgPixmap.set_root_pixmap (); + XSelectInput (dpy, display->root, PropertyChangeMask); + rootwin_ev.start (display, display->root); + } +#endif + +#ifdef BG_IMAGE_FROM_FILE + if (rs[Rs_backgroundPixmap] != NULL) + { + const char *p = rs[Rs_backgroundPixmap]; + + if ((p = strchr (p, ';')) != NULL) + { + p++; + bgPixmap.set_geometry (p); + } + else + bgPixmap.set_defaultGeometry (); + + if (bgPixmap.set_file (rs[Rs_backgroundPixmap])) + if (!bgPixmap.window_position_sensitive ()) + update_background (); + } +#endif + } +#endif + +#if ENABLE_PERL + rootwin_ev.start (display, display->root); #endif set_colorfgbg (); @@ -514,9 +567,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)); @@ -538,16 +591,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); } @@ -565,13 +618,16 @@ { ptytty::init (); + if (!ev::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::ev_unref (); + sig_handlers.sw_int.start (SIGINT); ev::ev_unref (); /* need to trap SIGURG for SVR4 (Unixware) rlogin */ /* signal (SIGURG, SIG_DFL); */ @@ -621,7 +677,7 @@ /*----------------------------------------------------------------------*/ /* - * window size/position calculcations for XSizeHint and other storage. + * window size/position calculations for XSizeHint and other storage. * if width/height are non-zero then override calculated width/height */ void @@ -703,7 +759,7 @@ sb_w = scrollbar_TotalWidth (); szHint.base_width += sb_w; - if (!OPTION (Opt_scrollBar_right)) + if (!option (Opt_scrollBar_right)) window_vt_x += sb_w; } @@ -734,7 +790,7 @@ szHint.height = szHint.base_height + height; } - if (scrollBar.state && OPTION (Opt_scrollBar_right)) + if (scrollBar.state && option (Opt_scrollBar_right)) window_sb_x = szHint.width - sb_w; if (recalc_x) @@ -806,7 +862,8 @@ prop = (*fs)[1]->properties (); prop.height += lineSpace; - fs->set_prop (prop); + + fs->set_prop (prop, false); fwidth = prop.width; fheight = prop.height; @@ -825,17 +882,20 @@ rxvt_fontprop prop2 = prop; if (res) - prop2.weight = prop2.slant = rxvt_fontprop::unset; + { + fs->populate (res); + fs->set_prop (prop2, false); + } else { - res = fontset[0]->fontdesc; + fs->populate (fontset[0]->fontdesc); if (SET_STYLE (0, style) & RS_Bold) prop2.weight = rxvt_fontprop::bold; if (SET_STYLE (0, style) & RS_Italic) prop2.slant = rxvt_fontprop::italic; + + fs->set_prop (prop2, true); } - fs->populate (res); - fs->set_prop (prop2); } #else fontset[style] = fontset[0]; @@ -847,19 +907,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); @@ -893,13 +955,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; @@ -938,25 +1000,13 @@ /* XSetWindowAttributes attr; */ /* Cursor cursor; */ done: - -#if OFF_FOCUS_FADING - if (rs[Rs_fade]) - { - rgba c; - pix_colors [Color_fade].get (c); - pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c); - } -#endif - /*TODO: handle Color_BD, scrollbar background, etc. */ + update_fade_color (idx); recolour_cursor (); scr_recolour (); -} - -#else -# define set_window_color (idx,color) ((void)0) #endif /* XTERM_COLOR_CHANGE */ +} void rxvt_term::recolour_cursor () @@ -998,7 +1048,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; @@ -1104,10 +1154,12 @@ window_vt_x, window_vt_y, width, height); - scr_clear (); -#ifdef XPM_BACKGROUND - resize_pixmap (); +#ifdef HAVE_BG_PIXMAP + if (bgPixmap.window_size_sensitive ()) + update_background (); #endif + + scr_clear (); } if (fix_screen || old_height == 0) @@ -1116,9 +1168,10 @@ // TODO, with nvidia-8178, resizes kill the alpha channel, report if not fixed in newer version //scr_touch (false); -#ifdef XPM_BACKGROUND - if (pixmap) - scr_touch (false); +#ifdef HAVE_BG_PIXMAP +// 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 @@ -1299,7 +1352,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, @@ -1628,7 +1681,7 @@ { im_set_size (preedit_rect); preedit_attr = XVaCreateNestedList (0, XNArea, &preedit_rect, NULL); - + XSetICValues (Input_Context, XNPreeditAttributes, preedit_attr, NULL); } @@ -1657,4 +1710,65 @@ } #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 +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) -----------------------*/