--- rxvt-unicode/src/command.C 2007/09/09 10:14:40 1.351 +++ rxvt-unicode/src/command.C 2007/12/14 05:25:23 1.381 @@ -27,7 +27,7 @@ * 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 * * 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 @@ -549,7 +549,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 @@ -565,16 +596,6 @@ break; #endif #ifndef NO_DELETE_KEY -# ifdef XK_KP_Delete - 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, rs[Rs_delete_key]); break; @@ -596,22 +617,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" */ @@ -631,36 +636,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; @@ -682,12 +667,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" */ @@ -713,7 +692,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); @@ -729,16 +708,6 @@ strcpy (kbuf, "\033[1~"); break; -#ifdef XK_KP_Insert - 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; @@ -752,29 +721,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; @@ -1036,11 +985,10 @@ { flush_ev.stop (); -#ifdef ENABLE_TRANSPARENCY - 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 @@ -1095,19 +1043,16 @@ 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 (); - - display->flush (); - - if (want_refresh && !flush_ev.active) - flush_ev.start (NOW + 1. / 60.); // refresh at max. 60 hz normally + if (want_refresh && !flush_ev.is_active ()) + flush_ev.start (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 (); @@ -1117,67 +1062,73 @@ #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 @@ -1185,9 +1136,9 @@ #if LINUX_YIELD_HACK static struct event_handler { - check_watcher yield_ev; + ev::prepare yield_ev; - void yield_cb (check_watcher &w) + void yield_cb (ev::prepare &w, int revents) { // this should really be sched_yield(), but the linux guys thought // that giving a process calling sched_yield () less cpu time than @@ -1248,17 +1199,17 @@ } 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 (); } @@ -1272,7 +1223,7 @@ hidden_pointer = 0; if (option (Opt_pointerBlank)) - pointer_ev.start (NOW + pointerBlankDelay); + pointer_ev.start (pointerBlankDelay); #endif } @@ -1290,7 +1241,7 @@ } void -rxvt_term::pointer_cb (time_watcher &w) +rxvt_term::pointer_cb (ev::timer &w, int revents) { make_current (); @@ -1303,10 +1254,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; @@ -1362,7 +1321,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)); } @@ -1476,9 +1435,9 @@ break; case ConfigureNotify: -/* fprintf (stderr, "ConfigureNotify for %X, parent is %X, geom is %dx%d%+d%+d, old geom was %dx%d\n", + /* 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);*/ + szHint.width, szHint.height); */ if (ev.xconfigure.window == parent[0]) { while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev)) @@ -1491,8 +1450,8 @@ } else { -#ifdef ENABLE_TRANSPARENCY - if (option (Opt_transparent)) +#ifdef HAVE_BG_PIXMAP + if (bgPixmap.window_position_sensitive ()) update_background (); #endif } @@ -1524,7 +1483,7 @@ case MapNotify: 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; @@ -1537,26 +1496,24 @@ HOOK_INVOKE ((this, HOOK_UNMAP_NOTIFY, DT_XEVENT, &ev, DT_END)); break; -#ifdef ENABLE_TRANSPARENCY - case ReparentNotify: - rootwin_cb (ev); - break; -#endif /* ENABLE_TRANSPARENCY */ - 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); + { + 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 (dpy, vt, ev.xany.type, &ev)) - scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); + { + scr_expose (ev.xexpose.x, ev.xexpose.y, + ev.xexpose.width, ev.xexpose.height, False); + } want_refresh = 1; } @@ -1582,6 +1539,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; @@ -1625,8 +1585,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 @@ -1658,8 +1618,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 @@ -1695,7 +1654,7 @@ want_refresh = 1; } - cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); + cursor_blink_ev.again (); } #endif @@ -1712,6 +1671,8 @@ pointer_blank (); } #endif + + refresh_check (); } void @@ -1733,7 +1694,7 @@ #endif #if CURSOR_BLINK if (option (Opt_cursorBlink)) - cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); + cursor_blink_ev.again (); #endif #if OFF_FOCUS_FADING if (rs[Rs_fade]) @@ -1745,13 +1706,10 @@ #if ENABLE_FRILLS if (option (Opt_urgentOnBell)) { - XWMHints *h; - - h = XGetWMHints(dpy, parent[0]); - if (h != NULL) + if (XWMHints *h = XGetWMHints(dpy, parent[0])) { h->flags &= ~XUrgencyHint; - XSetWMHints(dpy, parent[0], h); + XSetWMHints (dpy, parent[0], h); } } #endif @@ -1784,6 +1742,7 @@ #if CURSOR_BLINK if (option (Opt_cursorBlink)) cursor_blink_ev.stop (); + hidden_cursor = 0; #endif #if OFF_FOCUS_FADING @@ -1836,6 +1795,8 @@ break; } # endif + + refresh_check (); } #endif @@ -1900,7 +1861,7 @@ #else MEvent.button = ev.button; mouse_report (ev); -#endif /* MOUSE_REPORT_DOUBLECLICK */ +#endif /* MOUSE_REPORT_DOUBLECLICK */ } else @@ -2004,10 +1965,10 @@ } } else -#endif /* NO_SCROLLBAR_REPORT */ +#endif /* NO_SCROLLBAR_REPORT */ { - char upordown = 0; + char upordown = 0; if (scrollBar.style == R_SB_NEXT) { @@ -2023,10 +1984,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)) { @@ -2116,8 +2079,7 @@ } #ifdef SELECTION_SCROLLING - if (sel_scroll_ev.active) - sel_scroll_ev.stop(); + sel_scroll_ev.stop(); #endif if (ev.window == vt) @@ -2151,7 +2113,7 @@ #else /* MOUSE_REPORT_DOUBLECLICK */ MEvent.button = AnyButton; mouse_report (ev); -#endif /* MOUSE_REPORT_DOUBLECLICK */ +#endif /* MOUSE_REPORT_DOUBLECLICK */ return; } @@ -2199,10 +2161,8 @@ 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 { @@ -2280,7 +2240,7 @@ { refresh_count = 0; - if (!option (Opt_skipScroll) || io_manager::now () > NOW + 1. / 60.) + if (!option (Opt_skipScroll) || ev_time () > ev::now () + 1. / 60.) { refreshnow = true; ch = NOCHAR; @@ -2351,6 +2311,8 @@ } } + refresh_check (); + return flag; } @@ -2501,7 +2463,7 @@ pclose_printer (fd); } -#endif /* PRINTPIPE */ +#endif /* PRINTPIPE */ /*}}} */ /* *INDENT-OFF* */ @@ -2804,7 +2766,8 @@ priv = 0; ch = cmd_getc (); if (ch >= '<' && ch <= '?') - { /* '<' '=' '>' '?' */ + { + /* '<' '=' '>' '?' */ priv = ch; ch = cmd_getc (); } @@ -2857,10 +2820,10 @@ // '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[>%d;94;0c", 'U'); + tt_printf ("\033[>%d;95;0c", 'U'); } break; case '?': @@ -3437,7 +3400,7 @@ break; #endif -#if XPM_BACKGROUND +#if BG_IMAGE_FROM_FILE case Rxvt_Pixmap: if (!strcmp (str, "?")) { @@ -3634,9 +3597,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 @@ -3720,7 +3682,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: @@ -3743,12 +3705,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; @@ -3935,7 +3905,8 @@ unicode_t ch, cmd = cmd_getc (); if (cmd == 'Q') - { /* query graphics */ + { + /* query graphics */ tt_printf ("\033G0\012"); /* no graphics */ return; } @@ -3995,7 +3966,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 () @@ -4010,16 +3981,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) -----------------------*/