--- rxvt-unicode/src/command.C 2006/01/23 23:33:58 1.280 +++ rxvt-unicode/src/command.C 2007/06/08 20:04:12 1.324 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: command.C *----------------------------------------------------------------------* * @@ -51,17 +51,16 @@ #include "version.h" #include "command.h" -#if HAVE_SCHED_YIELD -#undef HAVE_SCHED_YIELD // disabled for the time being -//# include -#endif - #ifdef KEYSYM_RESOURCE # include "keyboard.h" #endif #include +#if LINUX_YIELD_HACK +# include +#endif + /*----------------------------------------------------------------------*/ #define IS_CONTROL(ch) !((ch) & 0xffffff60UL) @@ -229,9 +228,16 @@ ch = 0xfffd; # endif scr_overlay_set (11, y, ch, r); - scr_overlay_set (12, y, NOCHAR, r); + + if (WCWIDTH (ch) >= 2) + scr_overlay_set (12, y, NOCHAR, r); } +// { +// char buf[4+4+3+1]; +// snprintf (buf, sizeof (buf), "(%.4d|%.4d)", x, y); +// scr_overlay_set (0, 0, buf); +// } scr_overlay_set (0, len , attr); scr_overlay_set (0, len + 1, fname); @@ -294,19 +300,20 @@ } #endif -/*{{{ Convert the keypress event into a string */ void -rxvt_term::lookup_key (XKeyEvent &ev) +rxvt_term::key_press (XKeyEvent &ev) { int ctrl, meta, shft, len; unsigned int newlen; KeySym keysym; -#ifdef DEBUG_CMD - static int debug_key = 1; /* accessible by a debugger only */ -#endif int valid_keysym; char kbuf[KBUFSZ]; +#if ISO_14755 + if (iso14755buf & ISO_14755_52) + return; +#endif + /* * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an * escape sequence to toggle the Keypad. @@ -495,6 +502,14 @@ # endif return; } + else if (keysym == XK_BackSpace) + { + iso14755buf = ((iso14755buf & ISO_14755_MASK) >> 4) | ISO_14755_51; +# if ISO_14755 + iso14755_51 (iso14755buf & ISO_14755_MASK); +# endif + return; + } else if ((hv = hex_keyval (ev)) >= 0) { iso14755buf = ((iso14755buf << 4) & ISO_14755_MASK) @@ -872,7 +887,7 @@ if (len <= 0) return; /* not mapped */ - if (OPTION (Opt_scrollTtyKeypress)) + if (option (Opt_scrollTtyKeypress)) if (view_start) { view_start = 0; @@ -904,19 +919,85 @@ tt_write (&ch, 1); } -#if defined(DEBUG_CMD) - /* Display keyboard buffer contents */ - unsigned char *p; - int i; - - fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len); - for (i = 0, p = kbuf; i < len; i++, p++) - fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p); - fprintf (stderr, "'\n"); -#endif /* DEBUG_CMD */ tt_write (kbuf, (unsigned int)len); } -/*}}} */ + +void +rxvt_term::key_release (XKeyEvent &ev) +{ +#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL + KeySym keysym; + + keysym = XLookupKeysym (&ev, ev.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ +#endif + +#if ENABLE_FRILLS || ISO_14755 + // ISO 14755 support + if (iso14755buf) + if (iso14755buf & ISO_14755_52) + { +# if ENABLE_OVERLAY + scr_overlay_off (); +# endif +# if ISO_14755 + // iso14755 part 5.2 handling: release time + // first: controls + if ((ev.state & ControlMask) + && ((keysym >= 0x40 && keysym <= 0x5f) + || (keysym >= 0x61 && keysym <= 0x7f))) + { + iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f); + commit_iso14755 (); + + return; + } + + for (unsigned short *i = iso14755_symtab; i[0]; i+= 2) + if (i[0] == keysym) + { + iso14755buf = ISO_14755_51 | i[1]; + commit_iso14755 (); + + return; + } + + scr_bell (); +# endif + iso14755buf = 0; + + return; + } + else if ((ev.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask)) + { +# if ENABLE_OVERLAY + scr_overlay_off (); +# endif + if (iso14755buf & ISO_14755_51) + commit_iso14755 (); +#if ISO_14755 + else if (iso14755buf & ISO_14755_STARTED) + { + iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair + + scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1); + scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE"); + } +# endif + else + iso14755buf = 0; + } +#endif + + if (HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END))) + return; + +#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) + if (!(ev.state & ControlMask)) + slip_wheel_ev.stop (); + else if (keysym == XK_Control_L || keysym == XK_Control_R) + mouse_slip_wheel_speed = 0; +#endif +} #if defined (KEYSYM_RESOURCE) unsigned int @@ -1103,19 +1184,26 @@ } #endif -#if HAVE_SCHED_YIELD +#if LINUX_YIELD_HACK static struct event_handler { - check_watcher cw_yield; + check_watcher yield_ev; - void yield (check_watcher &w) + void yield_cb (check_watcher &w) { - sched_yield (); + // this should really be sched_yield(), but the linux guys thought + // that giving a process calling sched_yield () less cpu time than + // ones with high nice levels is a useful thing to do. It surely is is + // allowed by the sus... as is returning ENOSYS. + + struct timespec ts = { 0, 0 }; + nanosleep (&ts, 0); + w.stop (); } event_handler () - : cw_yield (this, &event_handler::yield) + : yield_ev (this, &event_handler::yield_cb) { } } event_handler; @@ -1145,16 +1233,16 @@ } else if (r < 0 && (errno == EAGAIN || errno == EINTR)) { -#if HAVE_SCHED_YIELD +#if LINUX_YIELD_HACK if (display->is_local) - event_handler.cw_yield.start (); + event_handler.yield_ev.start (); #endif } else { pty_ev.stop (); - if (!OPTION (Opt_hold)) + if (!option (Opt_hold)) destroy (); } @@ -1179,13 +1267,13 @@ void rxvt_term::pointer_unblank () { - XDefineCursor (display->display, vt, TermWin_cursor); + XDefineCursor (dpy, vt, TermWin_cursor); recolour_cursor (); #ifdef POINTER_BLANK hidden_pointer = 0; - if (OPTION (Opt_pointerBlank)) + if (option (Opt_pointerBlank)) pointer_ev.start (NOW + pointerBlankDelay); #endif } @@ -1194,11 +1282,11 @@ void rxvt_term::pointer_blank () { - if (!OPTION (Opt_pointerBlank)) + if (!option (Opt_pointerBlank)) return; - XDefineCursor (display->display, vt, display->blank_cursor); - XFlush (display->display); + XDefineCursor (dpy, vt, display->blank_cursor); + XFlush (dpy); hidden_pointer = 1; } @@ -1281,23 +1369,13 @@ (32 + y + 1)); } -#ifdef USING_W11LIB -void -rxvt_W11_process_x_event (XEvent *ev) -{ - rxvt_t *r = rxvt_get_r (); - - x_cb (*ev); -} -#endif - /*{{{ process an X event */ void rxvt_term::x_cb (XEvent &ev) { make_current (); - dDisp; + dLocal (Display *, dpy); if (ev.xany.window == vt && SHOULD_INVOKE (HOOK_X_EVENT) @@ -1312,87 +1390,12 @@ switch (ev.type) { case KeyPress: -#if ISO_14755 - if (!(iso14755buf & ISO_14755_52)) -#endif - lookup_key (ev.xkey); - + key_press (ev.xkey); break; case KeyRelease: - { -#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL - KeySym keysym; - - keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ -#endif - -#if ENABLE_FRILLS || ISO_14755 - // ISO 14755 support - if (iso14755buf) - if (iso14755buf & ISO_14755_52) - { -# if ENABLE_OVERLAY - scr_overlay_off (); -# endif -# if ISO_14755 - // iso14755 part 5.2 handling: release time - // first: controls - if ((ev.xkey.state & ControlMask) - && ((keysym >= 0x40 && keysym <= 0x5f) - || (keysym >= 0x61 && keysym <= 0x7f))) - { - iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f); - commit_iso14755 (); - goto skip_switch; - } - - for (unsigned short *i = iso14755_symtab; i[0]; i+= 2) - if (i[0] == keysym) - { - iso14755buf = ISO_14755_51 | i[1]; - commit_iso14755 (); - goto skip_switch; - } - - scr_bell (); -# endif - iso14755buf = 0; - break; - } - else if ((ev.xkey.state & (ShiftMask | ControlMask)) != (ShiftMask | ControlMask)) - { -# if ENABLE_OVERLAY - scr_overlay_off (); -# endif - if (iso14755buf & ISO_14755_51) - commit_iso14755 (); -#if ISO_14755 - else if (iso14755buf & ISO_14755_STARTED) - { - iso14755buf = ISO_14755_52; // iso14755 part 5.2: remember empty begin/end pair - - scr_overlay_new (0, -1, sizeof ("KEYCAP PICTURE INSERT MODE") - 1, 1); - scr_overlay_set (0, 0, "KEYCAP PICTURE INSERT MODE"); - } -# endif - else - iso14755buf = 0; - } -#endif - - if (ev.xany.window == vt - && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END))) - break; - -#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) - if (!(ev.xkey.state & ControlMask)) - slip_wheel_ev.stop (); - else if (keysym == XK_Control_L || keysym == XK_Control_R) - mouse_slip_wheel_speed = 0; -#endif - break; - } + key_release (ev.xkey); + break; case ButtonPress: button_press (ev.xbutton); @@ -1417,7 +1420,7 @@ } #if ENABLE_EWMH else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) - XSendEvent (disp, ev.xclient.window = display->root, + XSendEvent (dpy, ev.xclient.window = display->root, False, SubstructureRedirectMask | SubstructureNotifyMask, &ev); #endif @@ -1465,29 +1468,42 @@ break; case FocusIn: - focus_in (); + if (ev.xfocus.detail != NotifyInferior + && ev.xfocus.detail != NotifyPointer + && ev.xfocus.mode != NotifyGrab) + focus_in (); break; case FocusOut: - focus_out (); + if (ev.xfocus.detail != NotifyInferior + && ev.xfocus.detail != NotifyPointer + && ev.xfocus.mode != NotifyGrab) + focus_out (); break; case ConfigureNotify: if (ev.xconfigure.window == parent[0]) { - while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)) + while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev)) ; if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) { seen_resize = 1; resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); +#ifdef XPM_BACKGROUND + if (!option(Opt_transparent) && bgPixmap.auto_resize) + { + resize_pixmap (); + scr_touch (true); + } +#endif } HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); -#ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ - if (OPTION (Opt_transparent)) +#ifdef TRANSPARENT + if (option (Opt_transparent)) check_our_parents (); #endif } @@ -1543,11 +1559,11 @@ do scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); - while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)); + while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)); ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; - while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)) + while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)) scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); @@ -1557,9 +1573,9 @@ { XEvent unused_event; - while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) + while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event)) ; - while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) + while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event)) ; if (isScrollbarWindow (ev.xany.window)) @@ -1570,7 +1586,7 @@ #ifdef TRANSPARENT if (am_transparent && ev.xany.window == parent[0]) - XClearWindow (disp, ev.xany.window); + XClearWindow (dpy, ev.xany.window); #endif } break; @@ -1590,10 +1606,10 @@ ; // nop else if (ev.xbutton.state & (Button1Mask | Button3Mask)) { - while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev)) + while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev)) ; - XQueryPointer (disp, vt, + XQueryPointer (dpy, vt, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, @@ -1667,11 +1683,11 @@ } else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) { - while (XCheckTypedWindowEvent (disp, scrollBar.win, + while (XCheckTypedWindowEvent (dpy, scrollBar.win, MotionNotify, &ev)) ; - XQueryPointer (disp, scrollBar.win, + XQueryPointer (dpy, scrollBar.win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, @@ -1685,10 +1701,8 @@ break; } -skip_switch: ; - #if defined(CURSOR_BLINK) - if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) + if (option (Opt_cursorBlink) && ev.type == KeyPress) { if (hidden_cursor) { @@ -1701,7 +1715,7 @@ #endif #if defined(POINTER_BLANK) - if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) + if (option (Opt_pointerBlank) && pointerBlankDelay > 0) { if (ev.type == MotionNotify || ev.type == ButtonPress @@ -1723,17 +1737,17 @@ focus = 1; want_refresh = 1; - HOOK_INVOKE ((this, HOOK_FOCUS_OUT, DT_END)); + HOOK_INVOKE ((this, HOOK_FOCUS_IN, DT_END)); #if USE_XIM if (Input_Context != NULL) { - IMSetStatusPosition (); + IMSetPosition (); XSetICFocus (Input_Context); } #endif #if CURSOR_BLINK - if (OPTION (Opt_cursorBlink)) + if (option (Opt_cursorBlink)) cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); #endif #if OFF_FOCUS_FADING @@ -1743,6 +1757,19 @@ scr_recolour (); } #endif +#if ENABLE_FRILLS + if (option (Opt_urgentOnBell)) + { + XWMHints *h; + + h = XGetWMHints(dpy, parent[0]); + if (h != NULL) + { + h->flags &= ~XUrgencyHint; + XSetWMHints(dpy, parent[0], h); + } + } +#endif } } @@ -1770,7 +1797,7 @@ XUnsetICFocus (Input_Context); #endif #if CURSOR_BLINK - if (OPTION (Opt_cursorBlink)) + if (option (Opt_cursorBlink)) cursor_blink_ev.stop (); hidden_cursor = 0; #endif @@ -1784,12 +1811,30 @@ } } -#if TRANSPARENT +void +rxvt_term::update_fade_color (unsigned int idx) +{ +#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 +} + +#if TRANSPARENT || ENABLE_PERL void rxvt_term::rootwin_cb (XEvent &ev) { make_current (); + if (SHOULD_INVOKE (HOOK_ROOT_EVENT) + && HOOK_INVOKE ((this, HOOK_ROOT_EVENT, DT_XEVENT, &ev, DT_END))) + return; + +# if TRANSPARENT switch (ev.type) { case PropertyNotify: @@ -1803,10 +1848,11 @@ /* FALLTHROUGH */ case ReparentNotify: - if (OPTION (Opt_transparent) && check_our_parents () && am_transparent) - want_refresh = want_full_refresh = 1; + if (option (Opt_transparent)) + check_our_parents (); break; } +# endif } #endif @@ -2144,7 +2190,7 @@ case Button2: if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? - selection_request (ev.time, ev.state & ShiftMask ? Sel_Clipboard : Sel_Primary); + selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary); break; #ifdef MOUSE_WHEEL @@ -2158,7 +2204,7 @@ if (ev.state & ShiftMask) i = 1; - else if (OPTION (Opt_mouseWheelScrollPage)) + else if (option (Opt_mouseWheelScrollPage)) i = nrow - 1; else i = 5; @@ -2191,12 +2237,12 @@ } #ifdef TRANSPARENT -#if TINTING +#if TINTING && !defined(HAVE_AFTERIMAGE) /* taken from aterm-0.4.2 */ typedef uint32_t RUINT32T; -void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm) +void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) { int sh_r, sh_g, sh_b; RUINT32T mask_r, mask_g, mask_b; @@ -2205,7 +2251,7 @@ unsigned int upper_lim_r, upper_lim_g, upper_lim_b; int i; - Visual *visual = display->visual; + Visual *visual = term->visual; if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; @@ -2429,6 +2475,16 @@ int rxvt_term::check_our_parents () { +#if TRANSPARENT || ENABLE_PERL + check_our_aprents_ev.stop(); + check_our_aprents_ev.start(NOW + 1./3.); +#endif + return 0; +} + +void +rxvt_term::check_our_parents_cb (time_watcher &w) +{ int i, pchanged, aformat, have_pixmap, rootdepth; unsigned long nitems, bytes_after; Atom atype; @@ -2436,52 +2492,64 @@ Window root, oldp, *list; Pixmap rootpixmap = None; XWindowAttributes wattr, wrootattr; - dDisp; + int sx, sy; + Window cr; pchanged = 0; - if (!OPTION (Opt_transparent)) - return pchanged; /* Don't try any more */ + if (!option (Opt_transparent)) + return /*pchanged*/; /* Don't try any more */ - XGetWindowAttributes (disp, display->root, &wrootattr); + XGetWindowAttributes (dpy, display->root, &wrootattr); rootdepth = wrootattr.depth; - XGetWindowAttributes (disp, parent[0], &wattr); + XGetWindowAttributes (dpy, parent[0], &wattr); if (rootdepth != wattr.depth) { if (am_transparent) { pchanged = 1; - XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]); + XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); am_transparent = am_pixmap_trans = 0; } - return pchanged; /* Don't try any more */ + return /*pchanged*/; /* Don't try any more */ } /* Get all X ops out of the queue so that our information is up-to-date. */ - XSync (disp, False); + XSync (dpy, False); + + XTranslateCoordinates (dpy, parent[0], display->root, + 0, 0, &sx, &sy, &cr); + /* check if we are outside of the visible part of the virtual screen : */ + if( sx + (int)szHint.width <= 0 || sy + (int)szHint.height <= 0 + || sx >= wrootattr.width || sy >= wrootattr.height ) + return /* 0 */ ; /* * Make the frame window set by the window manager have * the root background. Some window managers put multiple nested frame * windows for each client, so we have to take care about that. */ i = (xa[XA_XROOTPMAP_ID] - && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID], + && XGetWindowProperty (dpy, display->root, xa[XA_XROOTPMAP_ID], 0L, 1L, False, XA_PIXMAP, &atype, &aformat, &nitems, &bytes_after, &prop) == Success); if (!i || prop == NULL) i = (xa[XA_ESETROOT_PMAP_ID] - && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID], + && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], 0L, 1L, False, XA_PIXMAP, &atype, &aformat, &nitems, &bytes_after, &prop) == Success); if (!i || prop == NULL #if TINTING - || !rs[Rs_color + Color_tint] + || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL +#ifdef HAVE_AFTERIMAGE + && original_asim == NULL && rs[Rs_blurradius] == NULL +#endif + ) #endif ) have_pixmap = 0; @@ -2494,55 +2562,199 @@ if (have_pixmap) { + Bool success = False ; + GC gc; + XGCValues gcvalue; +#ifdef HAVE_AFTERIMAGE + { + Pixmap tmp_pmap = None ; + ShadingInfo shade; + ARGB32 tint ; + unsigned int pmap_w = 0, pmap_h = 0; + + if (get_drawable_size( rootpixmap, &pmap_w, &pmap_h )) + { + int root_x = 0, root_y = 0; + + shade.shading = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100; + if (ISSET_PIXCOLOR (Color_tint)) + { + rgba c; + pix_colors_focused [Color_tint].get (c); + shade.tintColor.red = c.r; + shade.tintColor.green = c.g; + shade.tintColor.blue = c.b; + } + else + shade.tintColor.red = shade.tintColor.green = shade.tintColor.blue = 0xFFFF; + tint = shading2tint32( &shade ); + gc = XCreateGC (dpy, vt, 0UL, &gcvalue); + if (GetWinPosition (parent[0], &root_x, &root_y) ) + { + ASImageLayer *layers = create_image_layers( 2 ); + ASImage *merged_im = NULL; + int back_x, back_y, back_w, back_h; + /* merge_layers does good job at tiling background appropriately, + so all we need is to cut out smallest possible piece : */ +#define MAKE_ROOTPMAP_GEOM(xy,wh,widthheight) \ + do{ while( root_##xy < 0 ) root_##xy += (int)wrootattr.widthheight; \ + back_##xy = root_##xy % pmap_##wh; /* that gives us left side of the closest tile : */ \ + if( pmap_##wh >= back_##xy + szHint.widthheight ) \ + back_##wh = szHint.widthheight;/* background is large - limit it by our size */ \ + else \ + { /* small background - need the whole of it for successfull tiling :*/ \ + back_##xy = 0; \ + back_##wh = pmap_##wh; \ + }}while(0) + + MAKE_ROOTPMAP_GEOM(x,w,width); + MAKE_ROOTPMAP_GEOM(y,h,height); + + layers[0].im = pixmap2asimage (display->asv, rootpixmap, back_x, back_y, back_w, back_h, AllPlanes, ASA_ASImage, 100); + layers[0].clip_x = (back_w == pmap_w)?root_x:0; + layers[0].clip_y = (back_h == pmap_h)?root_y:0; + layers[0].clip_width = szHint.width; + layers[0].clip_height = szHint.height; + layers[0].tint = tint; + if (rs[Rs_blurradius] && layers[0].im) + { + double r = atof(rs[Rs_blurradius]); + ASImage* tmp = blur_asimage_gauss(display->asv, layers[0].im, r, r, 0xFFFFFFFF, ASA_ASImage, 100, ASIMAGE_QUALITY_DEFAULT ); + if( tmp ) + { + destroy_asimage( &layers[0].im ); + layers[0].im = tmp; + } + } + if (original_asim != NULL) + { + int fore_w, fore_h; + layers[1].im = original_asim; + if( bgPixmap.auto_resize ) + { + fore_w = szHint.width; + fore_h = szHint.height; + } + else + { + fore_w = bgPixmap.w; + fore_h = bgPixmap.h; + } + if (fore_w != original_asim->width + || fore_h != original_asim->height) + { + layers[1].im = scale_asimage( display->asv, + original_asim, + fore_w, fore_h, + ASA_ASImage, 100, + ASIMAGE_QUALITY_DEFAULT ); + } + + layers[1].clip_width = szHint.width; + layers[1].clip_height = szHint.height; + + if (rs[Rs_blendtype]) + { + layers[1].merge_scanlines = blend_scanlines_name2func(rs[Rs_blendtype]); + if( layers[1].merge_scanlines == NULL ) + layers[1].merge_scanlines = alphablend_scanlines; + } + } + merged_im = merge_layers( display->asv, layers, layers[1].im?2:1, + szHint.width, szHint.height, + ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT ); + if (layers[1].im != original_asim) + destroy_asimage( &(layers[1].im) ); + destroy_asimage( &(layers[0].im) ); + if (merged_im != NULL) + { + tmp_pmap = asimage2pixmap( display->asv, DefaultRootWindow(dpy), merged_im, gc, True ); + destroy_asimage( &merged_im ); + } + free( layers ); + } + } + if (tmp_pmap != None) + { + success = True; + if (pixmap != None) + XFreePixmap (dpy, pixmap); + pixmap = tmp_pmap; + } + } +#else /* HAVE_AFTERIMAGE */ + { /* * Copy display->root pixmap transparency */ - int sx, sy, nx, ny; - unsigned int nw, nh; - Window cr; - XImage *image; - GC gc; - XGCValues gcvalue; + int nx, ny; + unsigned int nw, nh; + XImage *image; + + nw = (unsigned int)szHint.width; + nh = (unsigned int)szHint.height; + nx = ny = 0; - XTranslateCoordinates (disp, parent[0], display->root, - 0, 0, &sx, &sy, &cr); - nw = (unsigned int)szHint.width; - nh = (unsigned int)szHint.height; - nx = ny = 0; + if (sx < 0) + { + nw += sx; + nx = -sx; + sx = 0; + } - if (sx < 0) - { - nw += sx; - nx = -sx; - sx = 0; - } + if (sy < 0) + { + nh += sy; + ny = -sy; + sy = 0; + } - if (sy < 0) - { - nh += sy; - ny = -sy; - sy = 0; - } + min_it (nw, (unsigned int) (wrootattr.width - sx)); + min_it (nh, (unsigned int) (wrootattr.height - sy)); + + XSync (dpy, False); + allowedxerror = -1; + image = XGetImage (dpy, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); + + /* XXX: handle BadMatch - usually because we're outside the pixmap */ + /* XXX: may need a delay here? */ + allowedxerror = 0; + if (image != NULL) + { + if (pixmap != None) + XFreePixmap (dpy, pixmap); - min_it (nw, (unsigned int) (wrootattr.width - sx)); - min_it (nh, (unsigned int) (wrootattr.height - sy)); +#if TINTING + if (ISSET_PIXCOLOR (Color_tint)) + { + int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100; - XSync (disp, False); - allowedxerror = -1; - image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); + rgba c; + pix_colors_focused [Color_tint].get (c); + ShadeXImage (this, image, shade, c.r, c.g, c.b); + } +#endif - /* XXX: handle BadMatch - usually because we're outside the pixmap */ - /* XXX: may need a delay here? */ - allowedxerror = 0; + pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, image->depth); + gc = XCreateGC (dpy, vt, 0UL, &gcvalue); + XPutImage (dpy, pixmap, gc, image, 0, 0, + nx, ny, image->width, image->height); + XDestroyImage (image); + success = True ; + } + } +#endif /* HAVE_AFTERIMAGE */ + if (gc != NULL) + XFreeGC (dpy, gc); - if (image == NULL) + if (!success) { if (am_transparent && am_pixmap_trans) { pchanged = 1; if (pixmap != None) { - XFreePixmap (disp, pixmap); + XFreePixmap (dpy, pixmap); pixmap = None; } } @@ -2551,30 +2763,8 @@ } else { - if (pixmap != None) - XFreePixmap (disp, pixmap); - -#if TINTING - if (ISSET_PIXCOLOR (Color_tint)) - { - unsigned short rm, gm, bm; - int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100; - - pix_colors_focused[Color_tint].get (display, rm, gm, bm); - - ShadeXImage (display, image, shade, rm, gm, bm); - } -#endif - - pixmap = XCreatePixmap (disp, vt, - szHint.width, szHint.height, image->depth); - gc = XCreateGC (disp, vt, 0UL, &gcvalue); - XPutImage (disp, pixmap, gc, image, 0, 0, - nx, ny, image->width, image->height); - XFreeGC (disp, gc); - XDestroyImage (image); - XSetWindowBackgroundPixmap (disp, parent[0], pixmap); - XClearWindow (disp, parent[0]); + XSetWindowBackgroundPixmap (dpy, parent[0], pixmap); + XClearWindow (dpy, parent[0]); if (!am_transparent || !am_pixmap_trans) pchanged = 1; @@ -2584,7 +2774,7 @@ } if (am_pixmap_trans) - XSetWindowBackgroundPixmap (disp, vt, ParentRelative); + XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); else { unsigned int n; @@ -2594,8 +2784,7 @@ for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) { oldp = parent[i]; - XQueryTree (disp, parent[i - 1], &root, - &parent[i], &list, &n); + XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n); XFree (list); if (parent[i] == display->root) @@ -2613,22 +2802,21 @@ n = 0; if (pchanged) - { - for (; n < (unsigned int)i; n++) - { - XGetWindowAttributes (disp, parent[n], &wattr); - if (wattr.depth != rootdepth || wattr.c_class == InputOnly) - { - n = (int) (sizeof (parent) / sizeof (Window)) + 1; - break; - } - } - } + for (; n < (unsigned int)i; n++) + { + XGetWindowAttributes (dpy, parent[n], &wattr); + + if (wattr.depth != rootdepth || wattr.c_class == InputOnly) + { + n = (int) (sizeof (parent) / sizeof (Window)) + 1; + break; + } + } - if (n > (int) (sizeof (parent) / sizeof (parent[0]))) + if (n > (sizeof (parent) / sizeof (parent[0]))) { - XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]); - XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]); + XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]); + XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); am_transparent = 0; /* XXX: also turn off Opt_transparent? */ } @@ -2636,11 +2824,11 @@ { for (n = 0; n < (unsigned int)i; n++) { - XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative); - XClearWindow (disp, parent[n]); + XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative); + XClearWindow (dpy, parent[n]); } - XSetWindowBackgroundPixmap (disp, vt, ParentRelative); + XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); am_transparent = 1; } @@ -2650,7 +2838,7 @@ if (scrollBar.win) { - XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative); + XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); scrollBar.setIdle (); scrollbar_show (0); } @@ -2662,7 +2850,7 @@ flush (); } - return pchanged; +// return pchanged; } #endif @@ -2723,7 +2911,7 @@ refresh_count++; - if (!OPTION (Opt_jumpScroll) + if (!option (Opt_jumpScroll) || (refresh_count >= refresh_limit * (nrow - 1))) { refreshnow = true; @@ -2773,11 +2961,12 @@ */ if (refreshnow) { - if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) + if (option (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) refresh_limit++; else { flag = true; + //TODO: due to popular request, implement "skipscroll" option here scr_refresh (); want_refresh = 1; } @@ -3111,7 +3300,7 @@ case '+': scr_charset_set (3, (unsigned int)cmd_getc ()); break; -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL case '6': scr_backindex (); break; @@ -3122,7 +3311,7 @@ case '8': scr_cursor (RESTORE); break; -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL case '9': scr_forwardindex (); break; @@ -3294,13 +3483,6 @@ if (arg[p] == -1) arg[p] = ndef; -#ifdef DEBUG_CMD - fprintf (stderr, "CSI "); - for (p = 0; p < nargs; p++) - fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : ""); - fprintf (stderr, "%c\n", ch); -#endif - /* * private mode handling */ @@ -3310,7 +3492,16 @@ { case '>': if (ch == CSI_DA) /* secondary device attributes */ - tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); + { + // first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt, + // 'U' for rxvt-unicode != 7.[34] (where it was broken). + // + // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt + // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, and 94 for later versions, to signify + // that we do not support xterm mouse reporting (should be 95 when we do). + // + tt_printf ("\033[>%d;94;0c", 'U'); + } break; case '?': if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') @@ -3446,7 +3637,7 @@ scr_report_position (); break; case 7: /* unofficial extension */ - if (OPTION (Opt_insecure)) + if (option (Opt_insecure)) tt_printf ("%-.250s\012", rs[Rs_display_name]); break; case 8: /* unofficial extension */ @@ -3523,7 +3714,7 @@ scr_cursor (RESTORE); break; -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL case CSI_74: process_window_ops (arg, nargs); break; @@ -3540,7 +3731,7 @@ } /*}}} */ -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL /* ARGSUSED */ void rxvt_term::process_window_ops (const int *args, unsigned int nargs) @@ -3548,7 +3739,8 @@ int x, y; XWindowAttributes wattr; Window wdummy; - dDisp; + + dLocal (Display *, dpy); if (nargs == 0) return; @@ -3559,22 +3751,22 @@ * commands */ case 1: /* deiconify window */ - XMapWindow (disp, parent[0]); + XMapWindow (dpy, parent[0]); break; case 2: /* iconify window */ - XIconifyWindow (disp, parent[0], display->screen); + XIconifyWindow (dpy, parent[0], display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (disp, parent[0], args[1], args[2]); + XMoveWindow (dpy, parent[0], args[1], args[2]); break; case 4: /* set size (pixels) */ set_widthheight ((unsigned int)args[2], (unsigned int)args[1]); break; case 5: /* raise window */ - XRaiseWindow (disp, parent[0]); + XRaiseWindow (dpy, parent[0]); break; case 6: /* lower window */ - XLowerWindow (disp, parent[0]); + XLowerWindow (dpy, parent[0]); break; case 7: /* refresh window */ scr_touch (true); @@ -3591,23 +3783,22 @@ (unsigned int) (args[1] * fheight)); break; - /* * reports - some output format copied from XTerm */ case 11: /* report window state */ - XGetWindowAttributes (disp, parent[0], &wattr); + XGetWindowAttributes (dpy, parent[0], &wattr); tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); break; case 13: /* report window position */ - XGetWindowAttributes (disp, parent[0], &wattr); - XTranslateCoordinates (disp, parent[0], wattr.root, + XGetWindowAttributes (dpy, parent[0], &wattr); + XTranslateCoordinates (dpy, parent[0], wattr.root, -wattr.border_width, -wattr.border_width, &x, &y, &wdummy); tt_printf ("\033[3;%d;%dt", x, y); break; case 14: /* report window size (pixels) */ - XGetWindowAttributes (disp, parent[0], &wattr); + XGetWindowAttributes (dpy, parent[0], &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; case 18: /* report text area size (chars) */ @@ -3619,16 +3810,16 @@ case 20: /* report icon label */ { char *s; - XGetIconName (disp, parent[0], &s); - tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ + XGetIconName (dpy, parent[0], &s); + tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } break; case 21: /* report window title */ { char *s; - XFetchName (disp, parent[0], &s); - tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ + XFetchName (dpy, parent[0], &s); + tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } break; @@ -3665,6 +3856,8 @@ } else if (ch == C0_BEL || ch == CHAR_ST) break; + else if (ch == C0_SYN) + ch = cmd_get8 (); else if (ch < 0x20) return NULL; /* other control character - exit */ @@ -3674,10 +3867,7 @@ // stop at some sane length return NULL; - if (ch == C0_SYN) - string[n++] = cmd_get8 (); - else - string[n++] = ch; + string[n++] = ch; } string[n++] = '\0'; @@ -3738,9 +3928,15 @@ { if (str[0] == '?' && !str[1]) { - unsigned short r, g, b; - pix_colors_focused[color].get (display, r, g, b); - tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); + rgba c; + pix_colors_focused[color].get (c); + +#if XFT + if (c.a != rgba::MAX_CC) + tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp); + else +#endif + tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, c.r, c.g, c.b, resp); } else set_window_color (color, str); @@ -3756,9 +3952,14 @@ char *buf, *name; bool query = str[0] == '?' && !str[1]; int saveop = op; - dDisp; + + dLocal (Display *, dpy); assert (str != NULL); + + if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_INT, op, DT_STR, str, DT_END))) + return; + switch (op) { case XTerm_name: @@ -3782,7 +3983,7 @@ const char *str = ""; if (prop - && XGetWindowProperty (disp, parent[0], + && XGetWindowProperty (dpy, parent[0], prop, 0, 1<<16, 0, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &value) == Success @@ -3790,7 +3991,7 @@ && actual_format == 8) str = (const char *)(value); - tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); + tt_printf ("\033]%d;%s%c", op, str, resp); XFree (value); } @@ -3804,7 +4005,7 @@ set_utf8_property (display->atom (str), eq + 1); } else - XDeleteProperty (disp, parent[0], + XDeleteProperty (dpy, parent[0], display->atom (str)); } break; @@ -3824,36 +4025,29 @@ if ((buf = strchr (name, ';')) != NULL) *buf++ = '\0'; - if (name[0] == '?' && !name[1]) - { - unsigned short r, g, b; - pix_colors_focused[color].get (display, r, g, b); - tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp); - } - else - set_window_color (color, name); + process_color_seq (op, color, name, resp); } break; case XTerm_Color00: - process_color_seq (XTerm_Color00, Color_fg, str, resp); + process_color_seq (op, Color_fg, str, resp); break; case XTerm_Color01: - process_color_seq (XTerm_Color01, Color_bg, str, resp); + process_color_seq (op, Color_bg, str, resp); break; #ifndef NO_CURSORCOLOR case XTerm_Color_cursor: - process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); + process_color_seq (op, Color_cursor, str, resp); break; #endif case XTerm_Color_pointer_fg: - process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); + process_color_seq (op, Color_pointer_fg, str, resp); break; case XTerm_Color_pointer_bg: - process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); + process_color_seq (op, Color_pointer_bg, str, resp); break; #ifndef NO_BOLD_UNDERLINE_REVERSE case XTerm_Color_RV: - process_color_seq (XTerm_Color_RV, Color_RV, str, resp); + process_color_seq (op, Color_RV, str, resp); break; case Rxvt_Color_BD: case URxvt_Color_BD: @@ -3864,15 +4058,18 @@ process_color_seq (op, Color_UL, str, resp); break; case URxvt_Color_IT: - process_color_seq (URxvt_Color_IT, Color_IT, str, resp); + process_color_seq (op, Color_IT, str, resp); break; #endif #if TRANSPARENT && TINTING case URxvt_Color_tint: - process_color_seq (URxvt_Color_tint, Color_tint, str, resp); + process_color_seq (op, Color_tint, str, resp); + check_our_parents (); + if (am_transparent) want_full_refresh = want_refresh = 1; + break; #endif @@ -3904,6 +4101,11 @@ scr_touch (true); #endif } +#if TRANSPARENT && defined(HAVE_AFTERIMAGE) + if (option(Opt_transparent)) + check_our_parents (); +#endif + } break; @@ -3940,7 +4142,7 @@ #endif if (query) tt_printf ("\33]%d;%-.250s%c", saveop, - OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc + option (Opt_insecure) && fontset[op - URxvt_font]->fontdesc ? fontset[op - URxvt_font]->fontdesc : "", resp); else @@ -3953,10 +4155,18 @@ } break; -#if ENABLE_FRILLS + case URxvt_version: + if (query) + tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c", + op, + rs[Rs_name], VERSION[0], VERSION[2], + resp); + break; + +#if !ENABLE_MINIMAL case URxvt_locale: if (query) - tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp); + tt_printf ("\33]%d;%-.250s%c", op, option (Opt_insecure) ? locale : "", resp); else { set_locale (str); @@ -3981,7 +4191,7 @@ #if ENABLE_PERL case URxvt_perl: - if (HOOK_INVOKE ((this, HOOK_OSC_SEQ, DT_STR, str, DT_END))) + if (HOOK_INVOKE ((this, HOOK_OSC_SEQ_PERL, DT_STR, str, DT_END))) ; // no responses yet break; #endif @@ -4107,7 +4317,7 @@ #endif case 1048: /* alternative cursor save */ case 1049: - if (OPTION (Opt_secondaryScreen)) + if (option (Opt_secondaryScreen)) if (mode == 0) scr_cursor (RESTORE); else if (mode == 1) @@ -4182,14 +4392,14 @@ set_option (Opt_scrollTtyKeypress, state); break; case 1047: /* secondary screen w/ clearing last */ - if (OPTION (Opt_secondaryScreen)) + if (option (Opt_secondaryScreen)) if (current_screen != PRIMARY) scr_erase_screen (2); scr_change_screen (state); break; case 1049: /* secondary screen w/ clearing first */ scr_change_screen (state); - if (OPTION (Opt_secondaryScreen)) + if (option (Opt_secondaryScreen)) if (current_screen != PRIMARY) scr_erase_screen (2); break; @@ -4327,7 +4537,7 @@ //case 50: // not variable spacing -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL case 90: case 91: /* set bright fg color */ case 92: