--- rxvt-unicode/src/command.C 2007/11/24 11:06:12 1.367 +++ rxvt-unicode/src/command.C 2008/02/16 13:36:10 1.408 @@ -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 @@ -200,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) @@ -222,7 +223,7 @@ 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 @@ -280,8 +281,8 @@ iso14755buf = 0; } -int -rxvt_term::hex_keyval (XKeyEvent &ev) +static int +hex_keyval (XKeyEvent &ev) { // check wether this event corresponds to a hex digit // if the modifiers had not been pressed. @@ -299,11 +300,46 @@ } #endif +static inline KeySym +translate_keypad (KeySym keysym, bool kp) +{ +#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 + return keysym; +} + void rxvt_term::key_press (XKeyEvent &ev) { int ctrl, meta, shft, len; - unsigned int newlen; KeySym keysym; int valid_keysym; char kbuf[KBUFSZ]; @@ -548,40 +584,10 @@ 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 - }; + unsigned int newlen = 1; - 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) + switch (translate_keypad (keysym, kp)) { #ifndef NO_BACKSPACE_KEY case XK_BackSpace: @@ -790,7 +796,6 @@ if (newlen) len = strlen (kbuf); - } /* * Pass meta for all function keys, if 'meta' option set @@ -1043,15 +1048,14 @@ display->flush (); } +/* checks wether a refresh is requested and starts the refresh timer */ void -rxvt_term::prepare_cb (ev::prepare &w, int revents) +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 (1. / 60.); // refresh at max. 60 hz normally } void @@ -1069,6 +1073,7 @@ { hidden_cursor = !hidden_cursor; want_refresh = 1; + refresh_check (); } #endif @@ -1080,7 +1085,10 @@ { hidden_text = !hidden_text; want_refresh = 1; + refresh_check (); } + else + w.stop (); } #endif @@ -1088,9 +1096,12 @@ void rxvt_term::cont_scroll_cb (ev::timer &w, int revents) { - if ((scrollbar_isUp() || scrollbar_isDn()) && - scr_page (scrollbar_isUp() ? UP : DN, 1)) - want_refresh = 1; + if ((scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN) + && scr_page (scrollBar.state == STATE_UP ? UP : DN, 1)) + { + want_refresh = 1; + refresh_check (); + } else w.stop (); } @@ -1104,6 +1115,7 @@ { selection_extend (selection_save_x, selection_save_y, selection_save_state); want_refresh = 1; + refresh_check (); } else w.stop (); @@ -1114,17 +1126,17 @@ void 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; + refresh_check (); + } + + if (view_start == top_row || view_start == 0 || mouse_slip_wheel_speed == 0) + { + mouse_slip_wheel_speed = 0; + w.stop (); } - else - w.stop (); } #endif @@ -1206,6 +1218,8 @@ if (revents & ev::WRITE) pty_write (); + + refresh_check (); } void @@ -1430,9 +1444,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)) @@ -1447,9 +1461,15 @@ { #ifdef HAVE_BG_PIXMAP if (bgPixmap.window_position_sensitive ()) - update_background (); + { + if (mapped) + update_background (); + else + bgPixmap.invalidate (); + } #endif } + HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); } break; @@ -1476,9 +1496,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 (TEXT_BLINK_INTERVAL); + text_blink_ev.start (); #endif HOOK_INVOKE ((this, HOOK_MAP_NOTIFY, DT_XEVENT, &ev, DT_END)); break; @@ -1509,6 +1545,7 @@ scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); } + want_refresh = 1; } else @@ -1520,9 +1557,9 @@ 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.state = STATE_IDLE; scrollbar_show (0); } } @@ -1579,7 +1616,7 @@ /* don't clobber the current delay if we are * already in the middle of scrolling. */ - if (!sel_scroll_ev.active) + if (!sel_scroll_ev.is_active ()) sel_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_DELAY); /* save the event params so we can highlight @@ -1612,8 +1649,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 @@ -1621,7 +1657,7 @@ #endif } } - else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) + else if (scrollBar.state == STATE_MOTION && ev.xany.window == scrollBar.win) { while (XCheckTypedWindowEvent (dpy, scrollBar.win, MotionNotify, &ev)) @@ -1666,6 +1702,8 @@ pointer_blank (); } #endif + + refresh_check (); } void @@ -1687,7 +1725,7 @@ #endif #if CURSOR_BLINK if (option (Opt_cursorBlink)) - cursor_blink_ev.start (CURSOR_BLINK_INTERVAL, CURSOR_BLINK_INTERVAL); + cursor_blink_ev.again (); #endif #if OFF_FOCUS_FADING if (rs[Rs_fade]) @@ -1785,9 +1823,12 @@ bgPixmap.set_root_pixmap (); update_background (); } + break; } # endif + + refresh_check (); } #endif @@ -1910,9 +1951,16 @@ /* * Scrollbar window processing of button press */ - if (isScrollbarWindow (ev.window)) + if (scrollBar.state && ev.window == scrollBar.win) { - scrollBar.setIdle (); + page_dirn direction = NO_DIR; + + if (scrollBar.upButton (ev.y)) + direction = UP; /* up */ + else if (scrollBar.dnButton (ev.y)) + direction = DN; /* down */ + + scrollBar.state = STATE_IDLE; /* * Rxvt-style scrollbar: * move up if mouse is above slider @@ -1931,15 +1979,9 @@ * arrow buttons - send up/down * click on scrollbar - send pageup/down */ - if ((scrollBar.style == R_SB_NEXT - && scrollbarnext_upButton (ev.y)) - || (scrollBar.style == R_SB_RXVT - && scrollbarrxvt_upButton (ev.y))) + if (direction == UP) tt_printf ("\033[A"); - else if ((scrollBar.style == R_SB_NEXT - && scrollbarnext_dnButton (ev.y)) - || (scrollBar.style == R_SB_RXVT - && scrollbarrxvt_dnButton (ev.y))) + else if (direction == DN) tt_printf ("\033[B"); else switch (ev.button) @@ -1957,42 +1999,26 @@ } else #endif /* NO_SCROLLBAR_REPORT */ - { - char upordown = 0; - - if (scrollBar.style == R_SB_NEXT) - { - if (scrollbarnext_upButton (ev.y)) - upordown = -1; /* up */ - else if (scrollbarnext_dnButton (ev.y)) - upordown = 1; /* down */ - } - else if (scrollBar.style == R_SB_RXVT) - { - if (scrollbarrxvt_upButton (ev.y)) - upordown = -1; /* up */ - else if (scrollbarrxvt_dnButton (ev.y)) - upordown = 1; /* down */ - } - if (upordown) + if (direction != NO_DIR) { #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - cont_scroll_ev.start (SCROLLBAR_INITIAL_DELAY, SCROLLBAR_CONTINUOUS_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)) + if (scr_page (direction, 1)) { - if (upordown < 0) - scrollBar.setUp (); + if (direction == UP) + scrollBar.state = STATE_UP; else - scrollBar.setDn (); + scrollBar.state = STATE_DOWN; } } else switch (ev.button) { case Button2: - switch (scrollbar_align) + switch (scrollBar.align) { case R_SB_ALIGN_TOP: csrO = 0; @@ -2010,11 +2036,11 @@ || scrollbar_below_slider (ev.y)) scr_move_to (scrollbar_position (ev.y) - csrO, scrollbar_size ()); - scrollBar.setMotion (); + scrollBar.state = STATE_MOTION; break; case Button1: - if (scrollbar_align == R_SB_ALIGN_CENTRE) + if (scrollBar.align == R_SB_ALIGN_CENTRE) csrO = ev.y - scrollBar.top; /* FALLTHROUGH */ @@ -2034,7 +2060,7 @@ scr_page (DN, nrow / 4); # endif else - scrollBar.setMotion (); + scrollBar.state = STATE_MOTION; } else { @@ -2061,15 +2087,14 @@ if (!bypass_keystate) reportmode = !! (priv_modes & PrivMode_mouse_report); - if (scrollbar_isUpDn ()) + if (scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN) { - scrollBar.setIdle (); + scrollBar.state = STATE_IDLE; scrollbar_show (0); } #ifdef SELECTION_SCROLLING - if (sel_scroll_ev.active) - sel_scroll_ev.stop(); + sel_scroll_ev.stop(); #endif if (ev.window == vt) @@ -2151,16 +2176,15 @@ if (mouse_slip_wheel_speed < -nrow) mouse_slip_wheel_speed = -nrow; if (mouse_slip_wheel_speed > +nrow) mouse_slip_wheel_speed = +nrow; - slip_wheel_ev.start (SCROLLBAR_CONTINUOUS_DELAY, SCROLLBAR_CONTINUOUS_DELAY); + 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 @@ -2753,7 +2777,8 @@ priv = 0; ch = cmd_getc (); if (ch >= '<' && ch <= '?') - { /* '<' '=' '>' '?' */ + { + /* '<' '=' '>' '?' */ priv = ch; ch = cmd_getc (); } @@ -2812,6 +2837,7 @@ 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); @@ -3337,9 +3363,11 @@ process_color_seq (op, color, name, resp); } break; + case Rxvt_restoreFG: case XTerm_Color00: process_color_seq (op, Color_fg, str, resp); break; + case Rxvt_restoreBG: case XTerm_Color01: process_color_seq (op, Color_bg, str, resp); break; @@ -3375,10 +3403,12 @@ 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 (); } @@ -3411,6 +3441,7 @@ if (str == NULL) bgPixmap.set_defaultGeometry (); } + while (str) { str++; @@ -3418,19 +3449,13 @@ changed++; str = strchr (str, ';'); } + if (changed) - update_background (); + update_background (); } break; #endif - case Rxvt_restoreFG: - set_window_color (Color_fg, str); - break; - case Rxvt_restoreBG: - set_window_color (Color_bg, str); - break; - case XTerm_logfile: // TODO, when secure mode? break; @@ -3583,7 +3608,6 @@ { 67, PrivMode_BackSpace }, #endif { 1000, PrivMode_MouseX11 }, - // 1001 Use Hilite Mouse Tracking. NYI, TODO { 1002, PrivMode_MouseBtnEvent }, { 1003, PrivMode_MouseAnyEvent }, { 1010, PrivMode_TtyOutputInh }, // rxvt extension @@ -3595,6 +3619,7 @@ // 1048 save and restore cursor { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ // 1051, 1052, 1060, 1061 keyboard emulation NYI + { 2004, PrivMode_BracketPaste }, }; if (nargs == 0) @@ -3652,7 +3677,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); @@ -3694,10 +3722,6 @@ if (state) /* orthogonal */ priv_modes &= ~(PrivMode_MouseX10|PrivMode_MouseBtnEvent|PrivMode_MouseAnyEvent); break; -#if 0 - case 1001: - break; /* X11 mouse highlighting */ -#endif case 1002: case 1003: if (state) @@ -3896,7 +3920,8 @@ unicode_t ch, cmd = cmd_getc (); if (cmd == 'Q') - { /* query graphics */ + { + /* query graphics */ tt_printf ("\033G0\012"); /* no graphics */ return; }