--- rxvt-unicode/src/command.C 2006/01/28 20:33:31 1.288 +++ rxvt-unicode/src/command.C 2008/01/20 13:45:21 1.395 @@ -1,4 +1,4 @@ -/*--------------------------------*-C-*---------------------------------* +/*----------------------------------------------------------------------* * File: command.C *----------------------------------------------------------------------* * @@ -27,7 +27,8 @@ * Copyright (c) 2001 Marius Gedminas * - Ctrl/Mod4+Tab works like Meta+Tab (options) * Copyright (c) 2003 Rob McMullen - * Copyright (c) 2003-2006 Marc Lehmann + * Copyright (c) 2003-2007 Marc Lehmann + * Copyright (c) 2007 Emanuele Giaquinta * * 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 @@ -51,17 +52,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) @@ -98,7 +98,6 @@ XK_Shift_Lock, 0x21eb, XK_ISO_Lock, 0x21eb, - XK_ISO_Lock, 0x21eb, XK_Caps_Lock, 0x21ec, XK_Num_Lock, 0x21ed, XK_ISO_Level3_Shift, 0x21ee, @@ -202,7 +201,7 @@ int width = wcswidth (fname, wcslen (fname)); - max_it (width, 8+5); // for char + hey + max_it (width, 8+5); // for char + hex max_it (width, strlen (attr)); if (y >= 0) @@ -224,14 +223,21 @@ sprintf (buf, "%8x", ch); scr_overlay_set (0, y, buf); scr_overlay_set (9, y, '='); -# if !UNICODE3 +# if !UNICODE_3 if (ch >= 0x10000) 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,9 +300,8 @@ } #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; @@ -304,6 +309,11 @@ 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. @@ -492,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) @@ -503,7 +521,7 @@ } else { -# if ENABLE_OVERLAY +# if ISO_14755 scr_overlay_off (); # endif iso14755buf = 0; @@ -514,13 +532,13 @@ if (!(iso14755buf & ISO_14755_STARTED)) { iso14755buf |= ISO_14755_STARTED; -# if ENABLE_OVERLAY +# if ISO_14755 scr_overlay_new (0, -1, sizeof ("ISO 14755 mode") - 1, 1); scr_overlay_set (0, 0, "ISO 14755 mode"); # endif } #endif - + #ifdef PRINTPIPE if (keysym == XK_Print) { @@ -532,7 +550,38 @@ if (keysym >= 0xFF00 && keysym <= 0xFFFF) { { + bool kp = priv_modes & PrivMode_aplKP ? !shft : shft; newlen = 1; +#ifdef XK_KP_Home + static const KeySym keypadtrans[] = { + XK_KP_7, // XK_KP_Home + XK_KP_4, // XK_KP_Left + XK_KP_8, // XK_KP_Up + XK_KP_6, // XK_KP_Right + XK_KP_2, // XK_KP_Down +#ifndef UNSHIFTED_SCROLLKEYS + XK_KP_9, // XK_KP_Prior + XK_KP_3, // XK_KP_Next +#else + XK_Prior, + XK_Next, +#endif + XK_KP_1, // XK_KP_End + XK_KP_5, // XK_KP_Begin + }; + + if (IN_RANGE_INC (keysym, XK_KP_Home, XK_KP_Begin)) + { + unsigned int index = keysym - XK_KP_Home; + keysym = kp ? keypadtrans[index] : XK_Home + index; + } + else if (keysym == XK_KP_Insert) + keysym = kp ? XK_KP_0 : XK_Insert; +#ifndef NO_DELETE_KEY + else if (keysym == XK_KP_Delete) + keysym = kp ? XK_KP_Decimal : XK_Delete; +#endif +#endif switch (keysym) { #ifndef NO_BACKSPACE_KEY @@ -544,22 +593,12 @@ kbuf[1] = '\0'; } else - strcpy (kbuf, key_backspace); + strcpy (kbuf, rs[Rs_backspace_key]); break; #endif #ifndef NO_DELETE_KEY -# ifdef XK_KP_Prior - case XK_KP_Delete: - /* allow shift to override */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) - { - strcpy (kbuf, "\033On"); - break; - } - /* FALLTHROUGH */ -# endif case XK_Delete: - strcpy (kbuf, key_delete); + strcpy (kbuf, rs[Rs_delete_key]); break; #endif case XK_Tab: @@ -579,22 +618,6 @@ } break; -#ifdef XK_KP_Left - case XK_KP_Up: /* \033Ox or standard */ - case XK_KP_Down: /* \033Or or standard */ - case XK_KP_Right: /* \033Ov or standard */ - case XK_KP_Left: /* \033Ot or standard */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) - { - strcpy (kbuf, "\033OZ"); - kbuf[2] = "txvr"[keysym - XK_KP_Left]; - break; - } - else - /* translate to std. cursor key */ - keysym = XK_Left + (keysym - XK_KP_Left); - /* FALLTHROUGH */ -#endif case XK_Up: /* "\033[A" */ case XK_Down: /* "\033[B" */ case XK_Right: /* "\033[C" */ @@ -614,36 +637,16 @@ break; #ifndef UNSHIFTED_SCROLLKEYS -# ifdef XK_KP_Prior - case XK_KP_Prior: - /* allow shift to override */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) - { - strcpy (kbuf, "\033Oy"); - break; - } - /* FALLTHROUGH */ -# endif case XK_Prior: strcpy (kbuf, "\033[5~"); break; -# ifdef XK_KP_Next - case XK_KP_Next: - /* allow shift to override */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) - { - strcpy (kbuf, "\033Os"); - break; - } - /* FALLTHROUGH */ -# endif case XK_Next: strcpy (kbuf, "\033[6~"); break; #endif case XK_KP_Enter: /* allow shift to override */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) + if (kp) { strcpy (kbuf, "\033OM"); break; @@ -665,12 +668,6 @@ } break; -#ifdef XK_KP_Begin - case XK_KP_Begin: - strcpy (kbuf, "\033Ou"); - break; - -#endif case XK_KP_F1: /* "\033OP" */ case XK_KP_F2: /* "\033OQ" */ case XK_KP_F3: /* "\033OR" */ @@ -696,7 +693,7 @@ case XK_KP_8: /* "\033Ox" : "8" */ case XK_KP_9: /* "\033Oy" : "9" */ /* allow shift to override */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) + if (kp) { strcpy (kbuf, "\033Oj"); kbuf[2] += (keysym - XK_KP_Multiply); @@ -712,16 +709,6 @@ strcpy (kbuf, "\033[1~"); break; -#ifdef XK_KP_End - case XK_KP_Insert: - /* allow shift to override */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) - { - strcpy (kbuf, "\033Op"); - break; - } - /* FALLTHROUGH */ -#endif case XK_Insert: strcpy (kbuf, "\033[2~"); break; @@ -735,29 +722,9 @@ case XK_Select: strcpy (kbuf, "\033[4~"); break; -#ifdef XK_KP_End - case XK_KP_End: - /* allow shift to override */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) - { - strcpy (kbuf, "\033Oq"); - break; - } - /* FALLTHROUGH */ -#endif case XK_End: strcpy (kbuf, KS_END); break; -#ifdef XK_KP_Home - case XK_KP_Home: - /* allow shift to override */ - if ((priv_modes & PrivMode_aplKP) ? !shft : shft) - { - strcpy (kbuf, "\033Ow"); - break; - } - /* FALLTHROUGH */ -#endif case XK_Home: strcpy (kbuf, KS_HOME); break; @@ -869,7 +836,7 @@ if (len <= 0) return; /* not mapped */ - if (OPTION (Opt_scrollTtyKeypress)) + if (option (Opt_scrollTtyKeypress)) if (view_start) { view_start = 0; @@ -903,7 +870,83 @@ 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 ISO_14755 + 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 ISO_14755 + scr_overlay_off (); +# endif + if (iso14755buf & ISO_14755_51) + commit_iso14755 (); +#if ISO_14755 + else if (option (Opt_iso14755_52) && 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 @@ -943,11 +986,10 @@ { flush_ev.stop (); -#ifdef TRANSPARENT - if (want_full_refresh) +#ifdef HAVE_BG_PIXMAP + if (bgPixmap.check_clearChanged ()) { - want_full_refresh = 0; - scr_clear (); +// scr_clear (true); This needs to be researched further! scr_touch (false); } #endif @@ -1002,107 +1044,118 @@ display->flush (); } +/* checks wether a refresh is requested and starts the refresh timer */ void -rxvt_term::check_cb (check_watcher &w) +rxvt_term::refresh_check () { - make_current (); + if (want_refresh && !flush_ev.is_active ()) + flush_ev.start (1. / 60.); // refresh at max. 60 Hz normally display->flush (); - - if (want_refresh && !flush_ev.active) - flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally } void -rxvt_term::flush_cb (time_watcher &w) +rxvt_term::flush_cb (ev::timer &w, int revents) { make_current (); - refresh_limit = 1; refresh_count = 0; flush (); } #ifdef CURSOR_BLINK void -rxvt_term::cursor_blink_cb (time_watcher &w) +rxvt_term::cursor_blink_cb (ev::timer &w, int revents) { hidden_cursor = !hidden_cursor; want_refresh = 1; - - w.start (w.at + CURSOR_BLINK_INTERVAL); + refresh_check (); } #endif #ifdef TEXT_BLINK void -rxvt_term::text_blink_cb (time_watcher &w) +rxvt_term::text_blink_cb (ev::timer &w, int revents) { if (scr_refresh_rend (RS_Blink, RS_Blink)) { hidden_text = !hidden_text; want_refresh = 1; - w.start (w.at + TEXT_BLINK_INTERVAL); + refresh_check (); } + else + w.stop (); } #endif #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING void -rxvt_term::cont_scroll_cb (time_watcher &w) +rxvt_term::cont_scroll_cb (ev::timer &w, int revents) { - if ((scrollbar_isUp() || scrollbar_isDn()) && - scr_page (scrollbar_isUp() ? UP : DN, 1)) + if ((scrollbar_isUp () || scrollbar_isDn ()) + && scr_page (scrollbar_isUp () ? UP : DN, 1)) { want_refresh = 1; - w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); + refresh_check (); } + else + w.stop (); } #endif #ifdef SELECTION_SCROLLING void -rxvt_term::sel_scroll_cb (time_watcher &w) +rxvt_term::sel_scroll_cb (ev::timer &w, int revents) { if (scr_page (scroll_selection_dir, scroll_selection_lines)) { selection_extend (selection_save_x, selection_save_y, selection_save_state); want_refresh = 1; - w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); + refresh_check (); } + else + w.stop (); } #endif #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) void -rxvt_term::slip_wheel_cb (time_watcher &w) +rxvt_term::slip_wheel_cb (ev::timer &w, int revents) { - if (mouse_slip_wheel_speed == 0 - || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) - : scr_page (UP, mouse_slip_wheel_speed)) + if (scr_changeview (view_start - mouse_slip_wheel_speed)) { - if (view_start == top_row || view_start == 0) - mouse_slip_wheel_speed = 0; - want_refresh = 1; - w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); + refresh_check (); + } + + if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0) + { + mouse_slip_wheel_speed = 0; + w.stop (); } } #endif -#if HAVE_SCHED_YIELD +#if LINUX_YIELD_HACK static struct event_handler { - check_watcher cw_yield; - - void yield (check_watcher &w) + ev::prepare yield_ev; + + void yield_cb (ev::prepare &w, int revents) { - 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; @@ -1132,48 +1185,50 @@ } 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 (); } - + return false; } void -rxvt_term::pty_cb (io_watcher &w, short revents) +rxvt_term::pty_cb (ev::io &w, int revents) { make_current (); - if (revents & EVENT_READ) + if (revents & ev::READ) // loop, but don't allow a single term to monopolize us while (pty_fill ()) if (cmd_parse ()) break; - if (revents & EVENT_WRITE) + if (revents & ev::WRITE) pty_write (); + + refresh_check (); } void rxvt_term::pointer_unblank () { - XDefineCursor (xdisp, vt, TermWin_cursor); + XDefineCursor (dpy, vt, TermWin_cursor); recolour_cursor (); #ifdef POINTER_BLANK hidden_pointer = 0; - if (OPTION (Opt_pointerBlank)) - pointer_ev.start (NOW + pointerBlankDelay); + if (option (Opt_pointerBlank)) + pointer_ev.start (pointerBlankDelay); #endif } @@ -1181,17 +1236,17 @@ void rxvt_term::pointer_blank () { - if (!OPTION (Opt_pointerBlank)) + if (!option (Opt_pointerBlank)) return; - XDefineCursor (xdisp, vt, display->blank_cursor); - XFlush (xdisp); + XDefineCursor (dpy, vt, display->blank_cursor); + XFlush (dpy); hidden_pointer = 1; } void -rxvt_term::pointer_cb (time_watcher &w) +rxvt_term::pointer_cb (ev::timer &w, int revents) { make_current (); @@ -1204,10 +1259,18 @@ { int button_number, key_state = 0; int x, y; + int code = 32; - x = ev.x; - y = ev.y; - pixel_position (&x, &y); + x = Pixel2Col (ev.x); + y = Pixel2Row (ev.y); + if (ev.type == MotionNotify) + { + if (x == mouse_row && y == mouse_col) + return; + mouse_row = x; + mouse_col = y; + code += 32; + } if (MEvent.button == AnyButton) button_number = 3; @@ -1263,7 +1326,7 @@ #endif tt_printf ("\033[M%c%c%c", - (32 + button_number + key_state), + (code + button_number + key_state), (32 + x + 1), (32 + y + 1)); } @@ -1274,7 +1337,7 @@ { make_current (); - dLocal (Display *, xdisp); + dLocal (Display *, dpy); if (ev.xany.window == vt && SHOULD_INVOKE (HOOK_X_EVENT) @@ -1289,87 +1352,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); @@ -1394,7 +1382,7 @@ } #if ENABLE_EWMH else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) - XSendEvent (xdisp, ev.xclient.window = display->root, + XSendEvent (dpy, ev.xclient.window = display->root, False, SubstructureRedirectMask | SubstructureNotifyMask, &ev); #endif @@ -1412,10 +1400,6 @@ } break; - case MappingNotify: - XRefreshKeyboardMapping (&ev.xmapping); - break; - /* * XXX: this is not the _current_ arrangement * Here's my conclusion: @@ -1442,17 +1426,26 @@ 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: + /*fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n", + ev.xconfigure.window, parent[0], ev.xconfigure.width, ev.xconfigure.height, ev.xconfigure.x, ev.xconfigure.y, + szHint.width, szHint.height); */ if (ev.xconfigure.window == parent[0]) { - while (XCheckTypedWindowEvent (xdisp, ev.xconfigure.window, ConfigureNotify, &ev)) + while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev)) ; if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) @@ -1460,13 +1453,20 @@ seen_resize = 1; resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); } + else + { +#ifdef HAVE_BG_PIXMAP + if (bgPixmap.window_position_sensitive ()) + { + if (mapped) + update_background (); + else + bgPixmap.invalidate (); + } +#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)) - check_our_parents (); -#endif } break; @@ -1492,9 +1492,25 @@ break; case MapNotify: +#ifdef HAVE_BG_PIXMAP + /* This is needed spcifically to fix the case of no window manager or a + * non-reparenting window manager. In those cases we never get first + * ConfigureNotify. Also that speeds startup under normal WM, by taking + * care of multiplicity of ConfigureNotify events arriwing while WM does + * reparenting. + * We should not render background immidiately, as there could be several + * ConfigureNotify's to follow. Lets take care of all of them in one scoop + * by scheduling background redraw as soon as we can, but giving a short + * bit of time for ConfigureNotifies to arrive. + * We should render background PRIOR to drawing any text, but AFTER all + * of ConfigureNotifys for the best results. + */ + if (bgPixmap.flags & bgPixmap_t::isInvalid) + update_background_ev.start (0.025); +#endif mapped = 1; #ifdef TEXT_BLINK - text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); + text_blink_ev.start (); #endif HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); break; @@ -1507,26 +1523,24 @@ HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END)); break; -#ifdef TRANSPARENT - case ReparentNotify: - rootwin_cb (ev); - break; -#endif /* TRANSPARENT */ - case GraphicsExpose: case Expose: if (ev.xany.window == vt) { do - scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); - while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)); + { + scr_expose (ev.xexpose.x, ev.xexpose.y, + ev.xexpose.width, ev.xexpose.height, False); + } + while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)); ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; - while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)) - scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); + while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)) + { + scr_expose (ev.xexpose.x, ev.xexpose.y, + ev.xexpose.width, ev.xexpose.height, False); + } want_refresh = 1; } @@ -1534,21 +1548,16 @@ { XEvent unused_event; - while (XCheckTypedWindowEvent (xdisp, ev.xany.window, Expose, &unused_event)) + while (XCheckTypedWindowEvent (dpy, ev.xany.window, Expose, &unused_event)) ; - while (XCheckTypedWindowEvent (xdisp, ev.xany.window, GraphicsExpose, &unused_event)) + while (XCheckTypedWindowEvent (dpy, ev.xany.window, GraphicsExpose, &unused_event)) ; - if (isScrollbarWindow (ev.xany.window)) + if (scrollBar.state && ev.xany.window == scrollBar.win) { scrollBar.setIdle (); scrollbar_show (0); } - -#ifdef TRANSPARENT - if (am_transparent && ev.xany.window == parent[0]) - XClearWindow (xdisp, ev.xany.window); -#endif } break; @@ -1557,6 +1566,9 @@ if (hidden_pointer) pointer_unblank (); #endif + if ((priv_modes & PrivMode_MouseBtnEvent && ev.xbutton.state & (Button1Mask|Button2Mask|Button3Mask)) + || priv_modes & PrivMode_MouseAnyEvent) + mouse_report (ev.xbutton); if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) break; @@ -1567,10 +1579,10 @@ ; // nop else if (ev.xbutton.state & (Button1Mask | Button3Mask)) { - while (XCheckTypedWindowEvent (xdisp, vt, MotionNotify, &ev)) + while (XCheckTypedWindowEvent (dpy, vt, MotionNotify, &ev)) ; - XQueryPointer (xdisp, vt, + XQueryPointer (dpy, vt, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, @@ -1600,8 +1612,8 @@ /* don't clobber the current delay if we are * already in the middle of scrolling. */ - if (!sel_scroll_ev.active) - sel_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); + if (!sel_scroll_ev.is_active ()) + sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); /* save the event params so we can highlight * the selection in the pending-scroll loop @@ -1633,8 +1645,7 @@ /* we are within the text window, so we * shouldn't be scrolling */ - if (sel_scroll_ev.active) - sel_scroll_ev.stop(); + sel_scroll_ev.stop(); } #endif #ifdef MOUSE_THRESHOLD @@ -1642,13 +1653,13 @@ #endif } } - else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) + else if (scrollbar_isMotion () && ev.xany.window == scrollBar.win) { - while (XCheckTypedWindowEvent (xdisp, scrollBar.win, + while (XCheckTypedWindowEvent (dpy, scrollBar.win, MotionNotify, &ev)) ; - XQueryPointer (xdisp, scrollBar.win, + XQueryPointer (dpy, scrollBar.win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, @@ -1656,16 +1667,13 @@ scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, scrollbar_size ()); want_refresh = 1; - refresh_limit = 0; scrollbar_show (1); } break; } -skip_switch: ; - #if defined(CURSOR_BLINK) - if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) + if (option (Opt_cursorBlink) && ev.type == KeyPress) { if (hidden_cursor) { @@ -1673,12 +1681,12 @@ want_refresh = 1; } - cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); + cursor_blink_ev.again (); } #endif #if defined(POINTER_BLANK) - if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) + if (option (Opt_pointerBlank) && pointerBlankDelay > 0) { if (ev.type == MotionNotify || ev.type == ButtonPress @@ -1690,6 +1698,8 @@ pointer_blank (); } #endif + + refresh_check (); } void @@ -1700,18 +1710,18 @@ 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)) - cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); + if (option (Opt_cursorBlink)) + cursor_blink_ev.again (); #endif #if OFF_FOCUS_FADING if (rs[Rs_fade]) @@ -1720,6 +1730,16 @@ scr_recolour (); } #endif +#if ENABLE_FRILLS + if (option (Opt_urgentOnBell)) + { + if (XWMHints *h = XGetWMHints(dpy, parent[0])) + { + h->flags &= ~XUrgencyHint; + XSetWMHints (dpy, parent[0], h); + } + } +#endif } } @@ -1737,7 +1757,7 @@ if (iso14755buf) { iso14755buf = 0; -# if ENABLE_OVERLAY +# if ISO_14755 scr_overlay_off (); # endif } @@ -1747,8 +1767,9 @@ XUnsetICFocus (Input_Context); #endif #if CURSOR_BLINK - if (OPTION (Opt_cursorBlink)) + if (option (Opt_cursorBlink)) cursor_blink_ev.stop (); + hidden_cursor = 0; #endif #if OFF_FOCUS_FADING @@ -1761,12 +1782,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 ENABLE_TRANSPARENCY || 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 ENABLE_TRANSPARENCY switch (ev.type) { case PropertyNotify: @@ -1774,16 +1813,18 @@ * if user used some Esetroot compatible prog to set the root bg, * use the property to determine the pixmap. We use it later on. */ - if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] - && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) - return; + if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID] + || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID]) + { + bgPixmap.set_root_pixmap (); + update_background (); + } - /* FALLTHROUGH */ - case ReparentNotify: - if (OPTION (Opt_transparent) && check_our_parents () && am_transparent) - want_refresh = want_full_refresh = 1; break; } +# endif + + refresh_check (); } #endif @@ -1848,7 +1889,7 @@ #else MEvent.button = ev.button; mouse_report (ev); -#endif /* MOUSE_REPORT_DOUBLECLICK */ +#endif /* MOUSE_REPORT_DOUBLECLICK */ } else @@ -1906,7 +1947,7 @@ /* * Scrollbar window processing of button press */ - if (isScrollbarWindow (ev.window)) + if (scrollBar.state && ev.window == scrollBar.win) { scrollBar.setIdle (); /* @@ -1952,10 +1993,10 @@ } } else -#endif /* NO_SCROLLBAR_REPORT */ +#endif /* NO_SCROLLBAR_REPORT */ { - char upordown = 0; + char upordown = 0; if (scrollBar.style == R_SB_NEXT) { @@ -1971,10 +2012,12 @@ else if (scrollbarrxvt_dnButton (ev.y)) upordown = 1; /* down */ } + if (upordown) { #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - cont_scroll_ev.start (NOW + SCROLLBAR_INITIAL_DELAY); + if (!cont_scroll_ev.is_active ()) + cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); #endif if (scr_page (upordown < 0 ? UP : DN, 1)) { @@ -1988,7 +2031,7 @@ switch (ev.button) { case Button2: - switch (scrollbar_align) + switch (scrollBar.align) { case R_SB_ALIGN_TOP: csrO = 0; @@ -2010,7 +2053,7 @@ break; case Button1: - if (scrollbar_align == R_SB_ALIGN_CENTRE) + if (scrollBar.align == R_SB_ALIGN_CENTRE) csrO = ev.y - scrollBar.top; /* FALLTHROUGH */ @@ -2064,8 +2107,7 @@ } #ifdef SELECTION_SCROLLING - if (sel_scroll_ev.active) - sel_scroll_ev.stop(); + sel_scroll_ev.stop(); #endif if (ev.window == vt) @@ -2099,7 +2141,7 @@ #else /* MOUSE_REPORT_DOUBLECLICK */ MEvent.button = AnyButton; mouse_report (ev); -#endif /* MOUSE_REPORT_DOUBLECLICK */ +#endif /* MOUSE_REPORT_DOUBLECLICK */ return; } @@ -2121,7 +2163,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 & ModMetaMask ? Sel_Primary : Sel_Primary); + selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary); break; #ifdef MOUSE_WHEEL @@ -2135,7 +2177,7 @@ if (ev.state & ShiftMask) i = 1; - else if (OPTION (Opt_mouseWheelScrollPage)) + else if (option (Opt_mouseWheelScrollPage)) i = nrow - 1; else i = 5; @@ -2147,19 +2189,15 @@ if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; - if (slip_wheel_ev.at < NOW) - slip_wheel_ev.at = NOW + SCROLLBAR_CONTINUOUS_DELAY; - - slip_wheel_ev.start (); + if (!slip_wheel_ev.is_active ()) + slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY); } else - { # endif + { scr_page (v, i); scrollbar_show (1); -# ifdef MOUSE_SLIP_WHEELING } -# endif } break; #endif @@ -2167,480 +2205,6 @@ } } -#ifdef TRANSPARENT -#if TINTING -/* taken from aterm-0.4.2 */ - -typedef uint32_t RUINT32T; - -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; - RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; - unsigned int lower_lim_r, lower_lim_g, lower_lim_b; - unsigned int upper_lim_r, upper_lim_g, upper_lim_b; - int i; - - Visual *visual = term->visual; - - if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; - - /* for convenience */ - mask_r = visual->red_mask; - mask_g = visual->green_mask; - mask_b = visual->blue_mask; - - /* boring lookup table pre-initialization */ - switch (srcImage->bits_per_pixel) { - case 15: - if ((mask_r != 0x7c00) || - (mask_g != 0x03e0) || - (mask_b != 0x001f)) - return; - lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); - lookup_r = lookup; - lookup_g = lookup+32; - lookup_b = lookup+32+32; - sh_r = 10; - sh_g = 5; - sh_b = 0; - break; - case 16: - if ((mask_r != 0xf800) || - (mask_g != 0x07e0) || - (mask_b != 0x001f)) - return; - lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); - lookup_r = lookup; - lookup_g = lookup+32; - lookup_b = lookup+32+64; - sh_r = 11; - sh_g = 5; - sh_b = 0; - break; - case 24: - if ((mask_r != 0xff0000) || - (mask_g != 0x00ff00) || - (mask_b != 0x0000ff)) - return; - lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); - lookup_r = lookup; - lookup_g = lookup+256; - lookup_b = lookup+256+256; - sh_r = 16; - sh_g = 8; - sh_b = 0; - break; - case 32: - if ((mask_r != 0xff0000) || - (mask_g != 0x00ff00) || - (mask_b != 0x0000ff)) - return; - lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); - lookup_r = lookup; - lookup_g = lookup+256; - lookup_b = lookup+256+256; - sh_r = 16; - sh_g = 8; - sh_b = 0; - break; - default: - return; /* we do not support this color depth */ - } - - /* prepare limits for color transformation (each channel is handled separately) */ - if (shade < 0) { - shade = -shade; - if (shade < 0) shade = 0; - if (shade > 100) shade = 100; - - lower_lim_r = 65535-rm; - lower_lim_g = 65535-gm; - lower_lim_b = 65535-bm; - - lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); - lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); - lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); - - upper_lim_r = upper_lim_g = upper_lim_b = 65535; - } else { - if (shade < 0) shade = 0; - if (shade > 100) shade = 100; - - lower_lim_r = lower_lim_g = lower_lim_b = 0; - - upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); - upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); - upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); - } - - /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ - if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 )) - { - unsigned int tmp; - - tmp = lower_lim_r; - lower_lim_r = lower_lim_b; - lower_lim_b = tmp; - - tmp = upper_lim_r; - upper_lim_r = upper_lim_b; - upper_lim_b = tmp; - } - - /* fill our lookup tables */ - for (i = 0; i <= mask_r>>sh_r; i++) - { - RUINT32T tmp; - tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); - tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); - lookup_r[i] = (tmp/65535)<>sh_g; i++) - { - RUINT32T tmp; - tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); - tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); - lookup_g[i] = (tmp/65535)<>sh_b; i++) - { - RUINT32T tmp; - tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); - tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); - lookup_b[i] = (tmp/65535)<bits_per_pixel) - { - case 15: - { - unsigned short *p1, *pf, *p, *pl; - p1 = (unsigned short *) srcImage->data; - pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); - while (p1 < pf) - { - p = p1; - pl = p1 + srcImage->width; - for (; p < pl; p++) - { - *p = lookup_r[(*p & 0x7c00)>>10] | - lookup_g[(*p & 0x03e0)>> 5] | - lookup_b[(*p & 0x001f)]; - } - p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); - } - break; - } - case 16: - { - unsigned short *p1, *pf, *p, *pl; - p1 = (unsigned short *) srcImage->data; - pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); - while (p1 < pf) - { - p = p1; - pl = p1 + srcImage->width; - for (; p < pl; p++) - { - *p = lookup_r[(*p & 0xf800)>>11] | - lookup_g[(*p & 0x07e0)>> 5] | - lookup_b[(*p & 0x001f)]; - } - p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); - } - break; - } - case 24: - { - unsigned char *p1, *pf, *p, *pl; - p1 = (unsigned char *) srcImage->data; - pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); - while (p1 < pf) - { - p = p1; - pl = p1 + srcImage->width * 3; - for (; p < pl; p += 3) - { - p[0] = lookup_r[(p[0] & 0xff0000)>>16]; - p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; - p[2] = lookup_r[(p[2] & 0x0000ff)]; - } - p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); - } - break; - } - case 32: - { - RUINT32T *p1, *pf, *p, *pl; - p1 = (RUINT32T *) srcImage->data; - pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); - - while (p1 < pf) - { - p = p1; - pl = p1 + srcImage->width; - for (; p < pl; p++) - { - *p = lookup_r[(*p & 0xff0000)>>16] | - lookup_g[(*p & 0x00ff00)>> 8] | - lookup_b[(*p & 0x0000ff)] | - (*p & ~0xffffff); - } - p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); - } - break; - } - } - - free (lookup); -} -#endif - -/* - * Check our parents are still who we think they are. - * Do transparency updates if required - */ -int -rxvt_term::check_our_parents () -{ - int i, pchanged, aformat, have_pixmap, rootdepth; - unsigned long nitems, bytes_after; - Atom atype; - unsigned char *prop = NULL; - Window root, oldp, *list; - Pixmap rootpixmap = None; - XWindowAttributes wattr, wrootattr; - - pchanged = 0; - - if (!OPTION (Opt_transparent)) - return pchanged; /* Don't try any more */ - - XGetWindowAttributes (xdisp, display->root, &wrootattr); - rootdepth = wrootattr.depth; - - XGetWindowAttributes (xdisp, parent[0], &wattr); - - if (rootdepth != wattr.depth) - { - if (am_transparent) - { - pchanged = 1; - XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]); - am_transparent = am_pixmap_trans = 0; - } - - return pchanged; /* Don't try any more */ - } - - /* Get all X ops out of the queue so that our information is up-to-date. */ - XSync (xdisp, False); - - /* - * 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 (xdisp, 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 (xdisp, 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] -#endif - ) - have_pixmap = 0; - else - { - have_pixmap = 1; - rootpixmap = *(Pixmap *)prop; - XFree (prop); - } - - if (have_pixmap) - { - /* - * Copy display->root pixmap transparency - */ - int sx, sy, nx, ny; - unsigned int nw, nh; - Window cr; - XImage *image; - GC gc; - XGCValues gcvalue; - - XTranslateCoordinates (xdisp, 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 (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 (xdisp, False); - allowedxerror = -1; - image = XGetImage (xdisp, 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 (am_transparent && am_pixmap_trans) - { - pchanged = 1; - if (pixmap != None) - { - XFreePixmap (xdisp, pixmap); - pixmap = None; - } - } - - am_pixmap_trans = 0; - } - else - { - if (pixmap != None) - XFreePixmap (xdisp, 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 (this, rm, gm, bm); - - ShadeXImage (this, image, shade, rm, gm, bm); - } -#endif - - pixmap = XCreatePixmap (xdisp, vt, szHint.width, szHint.height, image->depth); - gc = XCreateGC (xdisp, vt, 0UL, &gcvalue); - XPutImage (xdisp, pixmap, gc, image, 0, 0, - nx, ny, image->width, image->height); - XFreeGC (xdisp, gc); - XDestroyImage (image); - XSetWindowBackgroundPixmap (xdisp, parent[0], pixmap); - XClearWindow (xdisp, parent[0]); - - if (!am_transparent || !am_pixmap_trans) - pchanged = 1; - - am_transparent = am_pixmap_trans = 1; - } - } - - if (am_pixmap_trans) - XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative); - else - { - unsigned int n; - /* - * InheritPixmap transparency - */ - for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) - { - oldp = parent[i]; - XQueryTree (xdisp, parent[i - 1], &root, - &parent[i], &list, &n); - XFree (list); - - if (parent[i] == display->root) - { - if (oldp != None) - pchanged = 1; - - break; - } - - if (oldp != parent[i]) - pchanged = 1; - } - - n = 0; - - if (pchanged) - { - for (; n < (unsigned int)i; n++) - { - XGetWindowAttributes (xdisp, 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]))) - { - XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]); - XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]); - am_transparent = 0; - /* XXX: also turn off Opt_transparent? */ - } - else - { - for (n = 0; n < (unsigned int)i; n++) - { - XSetWindowBackgroundPixmap (xdisp, parent[n], ParentRelative); - XClearWindow (xdisp, parent[n]); - } - - XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative); - am_transparent = 1; - } - - for (; i < (int) (sizeof (parent) / sizeof (Window)); i++) - parent[i] = None; - } - - if (scrollBar.win) - { - XSetWindowBackgroundPixmap (xdisp, scrollBar.win, ParentRelative); - scrollBar.setIdle (); - scrollbar_show (0); - } - - if (am_transparent) - { - want_refresh = want_full_refresh = 1; - if (am_pixmap_trans) - flush (); - } - - return pchanged; -} -#endif - /*}}} */ bool @@ -2698,13 +2262,16 @@ refresh_count++; - if (!OPTION (Opt_jumpScroll) - || (refresh_count >= refresh_limit * (nrow - 1))) + if (!option (Opt_jumpScroll) || refresh_count >= nrow - 1) { - refreshnow = true; refresh_count = 0; - ch = NOCHAR; - break; + + if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.) + { + refreshnow = true; + ch = NOCHAR; + break; + } } // scr_add_lines only works for nlines <= nrow - 1. @@ -2742,20 +2309,14 @@ /* * If there have been a lot of new lines, then update the screen - * What the heck I'll cheat and only refresh less than every page-full. - * the number of pages between refreshes is refresh_limit, which - * is incremented here because we must be doing flat-out scrolling. + * What the heck we'll cheat and only refresh less than every page-full. + * if skipScroll is enabled. */ if (refreshnow) { - if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) - refresh_limit++; - else - { - flag = true; - scr_refresh (); - want_refresh = 1; - } + flag = true; + scr_refresh (); + want_refresh = 1; } } @@ -2914,7 +2475,7 @@ break; /* done = 1 */ } } - + for (i = 0; i < len; i++) if (putc (buf[i], fd) == EOF) { @@ -2926,7 +2487,7 @@ pclose_printer (fd); } -#endif /* PRINTPIPE */ +#endif /* PRINTPIPE */ /*}}} */ /* *INDENT-OFF* */ @@ -2986,7 +2547,7 @@ case 0x9b: /* CSI */ process_csi_seq (); break; - case 0x9d: /* CSI */ + case 0x9d: /* OSC */ process_osc_seq (); break; #endif @@ -3086,7 +2647,7 @@ case '+': scr_charset_set (3, (unsigned int)cmd_getc ()); break; -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL case '6': scr_backindex (); break; @@ -3097,7 +2658,7 @@ case '8': scr_cursor (RESTORE); break; -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL case '9': scr_forwardindex (); break; @@ -3222,15 +2783,15 @@ unicode_t ch, priv, i; unsigned int nargs, p; int n, ndef; - int arg[ESC_ARGS]; + int arg[ESC_ARGS] = { }; - for (nargs = ESC_ARGS; nargs > 0;) - arg[--nargs] = 0; + nargs = 0; priv = 0; ch = cmd_getc (); if (ch >= '<' && ch <= '?') - { /* '<' '=' '>' '?' */ + { + /* '<' '=' '>' '?' */ priv = ch; ch = cmd_getc (); } @@ -3279,16 +2840,17 @@ case '>': if (ch == CSI_DA) /* secondary device attributes */ { - // first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt, - // 'U' for rxvt-unicode <= 7.2. + // first parameter is normally 0 for vt100, 1 for vt220, '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). + // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, 94 for urxvt <= 8.3, and 95 for later + // versions. // - tt_printf ("\033[>0;94;0c"); + tt_printf ("\033[>%d;95;0c", 'U'); } break; + case '?': if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') process_terminal_mode (ch, priv, nargs, arg); @@ -3423,7 +2985,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 */ @@ -3500,7 +3062,7 @@ scr_cursor (RESTORE); break; -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL case CSI_74: process_window_ops (arg, nargs); break; @@ -3517,7 +3079,7 @@ } /*}}} */ -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL /* ARGSUSED */ void rxvt_term::process_window_ops (const int *args, unsigned int nargs) @@ -3526,7 +3088,7 @@ XWindowAttributes wattr; Window wdummy; - dLocal (Display *, xdisp); + dLocal (Display *, dpy); if (nargs == 0) return; @@ -3537,22 +3099,22 @@ * commands */ case 1: /* deiconify window */ - XMapWindow (xdisp, parent[0]); + XMapWindow (dpy, parent[0]); break; case 2: /* iconify window */ - XIconifyWindow (xdisp, parent[0], display->screen); + XIconifyWindow (dpy, parent[0], display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (xdisp, 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 (xdisp, parent[0]); + XRaiseWindow (dpy, parent[0]); break; case 6: /* lower window */ - XLowerWindow (xdisp, parent[0]); + XLowerWindow (dpy, parent[0]); break; case 7: /* refresh window */ scr_touch (true); @@ -3569,23 +3131,22 @@ (unsigned int) (args[1] * fheight)); break; - /* * reports - some output format copied from XTerm */ case 11: /* report window state */ - XGetWindowAttributes (xdisp, 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 (xdisp, parent[0], &wattr); - XTranslateCoordinates (xdisp, 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 (xdisp, 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) */ @@ -3597,16 +3158,16 @@ case 20: /* report icon label */ { char *s; - XGetIconName (xdisp, 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 (xdisp, 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; @@ -3643,6 +3204,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 */ @@ -3652,10 +3215,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'; @@ -3716,9 +3276,15 @@ { if (str[0] == '?' && !str[1]) { - unsigned short r, g, b; - pix_colors_focused[color].get (this, 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); @@ -3735,9 +3301,13 @@ bool query = str[0] == '?' && !str[1]; int saveop = op; - dLocal (Display *, xdisp); + 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: @@ -3761,7 +3331,7 @@ const char *str = ""; if (prop - && XGetWindowProperty (xdisp, parent[0], + && XGetWindowProperty (dpy, parent[0], prop, 0, 1<<16, 0, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &value) == Success @@ -3769,7 +3339,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); } @@ -3783,7 +3353,7 @@ set_utf8_property (display->atom (str), eq + 1); } else - XDeleteProperty (xdisp, parent[0], + XDeleteProperty (dpy, parent[0], display->atom (str)); } break; @@ -3803,36 +3373,31 @@ if ((buf = strchr (name, ';')) != NULL) *buf++ = '\0'; - if (name[0] == '?' && !name[1]) - { - unsigned short r, g, b; - pix_colors_focused[color].get (this, 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 Rxvt_restoreFG: case XTerm_Color00: - process_color_seq (XTerm_Color00, Color_fg, str, resp); + process_color_seq (op, Color_fg, str, resp); break; + case Rxvt_restoreBG: 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: @@ -3843,55 +3408,66 @@ 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 +#if ENABLE_TRANSPARENCY case URxvt_Color_tint: - process_color_seq (URxvt_Color_tint, Color_tint, str, resp); - check_our_parents (); - if (am_transparent) - want_full_refresh = want_refresh = 1; + process_color_seq (op, Color_tint, str, resp); + { + bool changed = false; + + if (ISSET_PIXCOLOR (Color_tint)) + changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]); + else + changed = bgPixmap.unset_tint (); + + if (changed) + update_background (); + } + break; #endif +#if BG_IMAGE_FROM_FILE case Rxvt_Pixmap: - { - if (*str != ';') - { -#if XPM_BACKGROUND - scale_pixmap (""); /* reset to default scaling */ - set_bgPixmap (str); /* change pixmap */ - scr_touch (true); -#endif - } + if (!strcmp (str, "?")) + { + char str[256]; - int changed = 0; + sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ + min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767), + min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767)); + process_xterm_seq (XTerm_title, str, CHAR_ST); + } + else + { + int changed = 0; - while ((str = strchr (str, ';')) != NULL) - { - str++; -#if XPM_BACKGROUND - changed += scale_pixmap (str); -#endif - } + if (*str != ';') + { + /* reset to default scaling :*/ + bgPixmap.unset_geometry (); + if (bgPixmap.set_file (str)) /* change pixmap */ + changed++; + str = strchr (str, ';'); + if (str == NULL) + bgPixmap.set_defaultGeometry (); + } - if (changed) - { -#ifdef XPM_BACKGROUND - resize_pixmap (); - scr_touch (true); -#endif - } - } - break; + while (str) + { + str++; + if (bgPixmap.set_geometry (str)) + changed++; + str = strchr (str, ';'); + } - case Rxvt_restoreFG: - set_window_color (Color_fg, str); - break; - case Rxvt_restoreBG: - set_window_color (Color_bg, str); + if (changed) + update_background (); + } break; +#endif case XTerm_logfile: // TODO, when secure mode? @@ -3919,7 +3495,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 @@ -3935,16 +3511,15 @@ case URxvt_version: if (query) tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c", - URxvt_version, - rs[Rs_name], - VERSION[0], VERSION[2], + op, + rs[Rs_name], VERSION[0], VERSION[2], resp); break; -#if ENABLE_FRILLS +#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); @@ -3969,7 +3544,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 @@ -4017,12 +3592,10 @@ int state; static const struct - { - const int argval; - const unsigned long bit; - } - - argtopriv[] = { + { + const int argval; + const unsigned long bit; + } argtopriv[] = { { 1, PrivMode_aplCUR }, { 2, PrivMode_vt52 }, { 3, PrivMode_132 }, @@ -4048,9 +3621,8 @@ { 67, PrivMode_BackSpace }, #endif { 1000, PrivMode_MouseX11 }, - // 1001 Use Hilite Mouse Tracking. NYI, TODO - // 1002 Use Cell Motion Mouse Tracking. NYI, TODO - // 1003 Use All Motion Mouse Tracking. NYI, TODO + { 1002, PrivMode_MouseBtnEvent }, + { 1003, PrivMode_MouseAnyEvent }, { 1010, PrivMode_TtyOutputInh }, // rxvt extension { 1011, PrivMode_Keypress }, // rxvt extension // 1035 enable modifiers for alt, numlock NYI @@ -4095,7 +3667,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) @@ -4117,7 +3689,10 @@ break; case 3: /* 80/132 */ if (priv_modes & PrivMode_132OK) - set_widthheight (((state ? 132 : 80) * fwidth), height); + { + scr_poweron (); + set_widthheight (((state ? 132 : 80) * fwidth), 24 * fheight); + } break; case 4: /* smooth scrolling */ set_option (Opt_jumpScroll, !state); @@ -4134,7 +3709,7 @@ /* case 8: - auto repeat, can't do on a per window basis */ case 9: /* X10 mouse reporting */ if (state) /* orthogonal */ - priv_modes &= ~PrivMode_MouseX11; + priv_modes &= ~(PrivMode_MouseX11|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent); break; #ifdef scrollBar_esc case scrollBar_esc: @@ -4157,12 +3732,20 @@ /* case 67: - backspace key */ case 1000: /* X11 mouse reporting */ if (state) /* orthogonal */ - priv_modes &= ~PrivMode_MouseX10; + priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent); + break; + case 1002: + case 1003: + if (state) + { + priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseX11); + priv_modes &= arg[i] == 1003 ? ~PrivMode_MouseBtnEvent : ~PrivMode_MouseAnyEvent; + vt_emask_mouse = PointerMotionMask; + } + else + vt_emask_mouse = NoEventMask; + vt_select_input (); break; -#if 0 - case 1001: - break; /* X11 mouse highlighting */ -#endif case 1010: /* scroll to bottom on TTY output inhibit */ set_option (Opt_scrollTtyOutput, !state); break; @@ -4170,14 +3753,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; @@ -4315,7 +3898,7 @@ //case 50: // not variable spacing -#if ENABLE_FRILLS +#if !ENABLE_MINIMAL case 90: case 91: /* set bright fg color */ case 92: @@ -4349,7 +3932,8 @@ unicode_t ch, cmd = cmd_getc (); if (cmd == 'Q') - { /* query graphics */ + { + /* query graphics */ tt_printf ("\033G0\012"); /* no graphics */ return; } @@ -4409,7 +3993,7 @@ memcpy (v_buffer + v_buflen, data, len); v_buflen += len; - pty_ev.set (EVENT_READ | EVENT_WRITE); + pty_ev.set (ev::READ | ev::WRITE); } void rxvt_term::pty_write () @@ -4424,16 +4008,15 @@ { free (v_buffer); v_buffer = 0; - v_buflen = 0; - pty_ev.set (EVENT_READ); + pty_ev.set (ev::READ); return; } memmove (v_buffer, v_buffer + written, v_buflen); } else if (written != -1 || (errno != EAGAIN && errno != EINTR)) - pty_ev.set (EVENT_READ); + pty_ev.set (ev::READ); } /*----------------------- end-of-file (C source) -----------------------*/