--- rxvt-unicode/src/command.C 2011/04/29 10:10:20 1.484 +++ rxvt-unicode/src/command.C 2012/05/25 18:45:40 1.511 @@ -56,10 +56,10 @@ # include "keyboard.h" #endif -#include +#include #if LINUX_YIELD_HACK -# include +# include #endif /*----------------------------------------------------------------------*/ @@ -259,22 +259,19 @@ void rxvt_term::commit_iso14755 () { - wchar_t ch[2]; - - ch[0] = iso14755buf & ISO_14755_MASK; - ch[1] = 0; + wchar_t ch = iso14755buf & ISO_14755_MASK; if (iso14755buf & ISO_14755_51) { - char mb[16]; + char mb[MB_LEN_MAX]; int len; // allow verbatim 0-bytes and control-bytes to be entered - if (ch[0] >= 0x20) - len = wcstombs (mb, ch, 16); + if (ch >= 0x20) + len = wctomb (mb, ch); else { - mb[0] = ch[0]; + mb[0] = ch; len = 1; } @@ -781,13 +778,28 @@ if (newlen) len = strlen (kbuf); - /* - * Pass meta for all function keys, if 'meta' option set - */ + if (len > 0) + { + /* + * pass Shift/Control indicators for function keys ending with `~' + * + * eg, + * Prior = "ESC[5~" + * Shift+Prior = "ESC[5$" + * Ctrl+Prior = "ESC[5^" + * Ctrl+Shift+Prior = "ESC[5@" + */ + if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~') + kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); + + /* + * Pass meta for all function keys, if 'meta' option set + */ #ifdef META8_OPTION - if (meta && (meta_char == 0x80) && len > 0) - kbuf[len - 1] |= 0x80; + if (meta && (meta_char == 0x80)) + kbuf[len - 1] |= 0x80; #endif + } } else if (ctrl && keysym == XK_minus) @@ -831,20 +843,6 @@ want_refresh = 1; } - /* - * these modifications only affect the static keybuffer - * pass Shift/Control indicators for function keys ending with `~' - * - * eg, - * Prior = "ESC[5~" - * Shift+Prior = "ESC[5$" - * Ctrl+Prior = "ESC[5^" - * Ctrl+Shift+Prior = "ESC[5@" - * Meta adds an Escape prefix (with META8_OPTION, if meta == ). - */ - if (kbuf[0] == C0_ESC && kbuf[1] == '[' && kbuf[len - 1] == '~') - kbuf[len - 1] = (shft ? (ctrl ? '@' : '$') : (ctrl ? '^' : '~')); - /* escape prefix */ if (meta #ifdef META8_OPTION @@ -992,7 +990,7 @@ scr_refresh (); scrollBar.show (1); #ifdef USE_XIM - IMSendSpot (); + im_send_spot (); #endif } @@ -1020,6 +1018,21 @@ #ifdef CURSOR_BLINK void +rxvt_term::cursor_blink_reset () +{ + if (hidden_cursor) + { + hidden_cursor = 0; + want_refresh = 1; + } + + if (option (Opt_cursorBlink)) + cursor_blink_ev.again (); + else + cursor_blink_ev.stop (); +} + +void rxvt_term::cursor_blink_cb (ev::timer &w, int revents) { hidden_cursor = !hidden_cursor; @@ -1047,8 +1060,8 @@ void rxvt_term::cont_scroll_cb (ev::timer &w, int revents) { - if ((scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN) - && scr_page (scrollBar.state == STATE_UP ? UP : DN, 1)) + if ((scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN) + && scr_page (scrollBar.state == SB_STATE_UP ? UP : DN, 1)) { want_refresh = 1; refresh_check (); @@ -1478,12 +1491,7 @@ { #ifdef HAVE_BG_PIXMAP if (moved) - { - if (mapped) - update_background (); - else - bg_invalidate (); - } + update_background (); #endif } @@ -1567,7 +1575,7 @@ if (scrollBar.state && ev.xany.window == scrollBar.win) { - scrollBar.state = STATE_IDLE; + scrollBar.state = SB_STATE_IDLE; scrollBar.show (0); } } @@ -1643,7 +1651,7 @@ else { scroll_selection_dir = DN; - dist = ev.xbutton.y - (int_bwidth + height); + dist = ev.xbutton.y - (int_bwidth + vt_height); } scroll_selection_lines = Pixel2Height (dist) @@ -1665,7 +1673,7 @@ #endif } } - else if (scrollBar.state == STATE_MOTION && ev.xany.window == scrollBar.win) + else if (scrollBar.state == SB_STATE_MOTION && ev.xany.window == scrollBar.win) { while (XCheckTypedWindowEvent (dpy, scrollBar.win, MotionNotify, &ev)) @@ -1676,7 +1684,7 @@ &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, &unused_mask); - scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, + scr_move_to (scrollBar.position (ev.xbutton.y) - csrO, scrollBar.size ()); want_refresh = 1; scrollBar.show (1); @@ -1685,16 +1693,8 @@ } #if defined(CURSOR_BLINK) - if (option (Opt_cursorBlink) && ev.type == KeyPress) - { - if (hidden_cursor) - { - hidden_cursor = 0; - want_refresh = 1; - } - - cursor_blink_ev.again (); - } + if (ev.type == KeyPress) + cursor_blink_reset (); #endif #if defined(POINTER_BLANK) @@ -1726,6 +1726,7 @@ h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0); XSetWMHints (dpy, parent, h); urgency_hint = enable; + XFree (h); } } #endif @@ -1741,7 +1742,7 @@ #if USE_XIM if (Input_Context != NULL) { - IMSetPosition (); + im_set_position (); XSetICFocus (Input_Context); } #endif @@ -1982,7 +1983,7 @@ else if (scrollBar.dnButton (ev.y)) direction = DN; /* down */ - scrollBar.state = STATE_IDLE; + scrollBar.state = SB_STATE_IDLE; /* * Rxvt-style scrollbar: * move up if mouse is above slider @@ -2031,9 +2032,9 @@ if (scr_page (direction, 1)) { if (direction == UP) - scrollBar.state = STATE_UP; + scrollBar.state = SB_STATE_UP; else - scrollBar.state = STATE_DOWN; + scrollBar.state = SB_STATE_DOWN; } } else @@ -2042,53 +2043,53 @@ case Button2: switch (scrollBar.align) { - case R_SB_ALIGN_TOP: + case SB_ALIGN_TOP: csrO = 0; break; - case R_SB_ALIGN_CENTRE: + case SB_ALIGN_CENTRE: csrO = (scrollBar.bot - scrollBar.top) / 2; break; - case R_SB_ALIGN_BOTTOM: + case SB_ALIGN_BOTTOM: csrO = scrollBar.bot - scrollBar.top; break; } - if (scrollBar.style == R_SB_XTERM - || scrollbar_above_slider (ev.y) - || scrollbar_below_slider (ev.y)) - scr_move_to (scrollbar_position (ev.y) - csrO, scrollBar.size ()); + if (scrollBar.style == SB_STYLE_XTERM + || scrollBar.above_slider (ev.y) + || scrollBar.below_slider (ev.y)) + scr_move_to (scrollBar.position (ev.y) - csrO, scrollBar.size ()); - scrollBar.state = STATE_MOTION; + scrollBar.state = SB_STATE_MOTION; break; case Button1: - if (scrollBar.align == R_SB_ALIGN_CENTRE) + if (scrollBar.align == SB_ALIGN_CENTRE) csrO = ev.y - scrollBar.top; /* FALLTHROUGH */ case Button3: - if (scrollBar.style != R_SB_XTERM) + if (scrollBar.style != SB_STYLE_XTERM) { - if (scrollbar_above_slider (ev.y)) + if (scrollBar.above_slider (ev.y)) # ifdef RXVT_SCROLL_FULL scr_page (UP, nrow - 1); # else scr_page (UP, nrow / 4); # endif - else if (scrollbar_below_slider (ev.y)) + else if (scrollBar.below_slider (ev.y)) # ifdef RXVT_SCROLL_FULL scr_page (DN, nrow - 1); # else scr_page (DN, nrow / 4); # endif else - scrollBar.state = STATE_MOTION; + scrollBar.state = SB_STATE_MOTION; } else { scr_page ((ev.button == Button1 ? DN : UP), (nrow - * scrollbar_position (ev.y) + * scrollBar.position (ev.y) / scrollBar.size ())); } @@ -2109,9 +2110,9 @@ if (!bypass_keystate) reportmode = !! (priv_modes & PrivMode_mouse_report); - if (scrollBar.state == STATE_UP || scrollBar.state == STATE_DOWN) + if (scrollBar.state == SB_STATE_UP || scrollBar.state == SB_STATE_DOWN) { - scrollBar.state = STATE_IDLE; + scrollBar.state = SB_STATE_IDLE; scrollBar.show (0); } @@ -2171,7 +2172,7 @@ break; case Button2: - if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? + if (IN_RANGE_EXC (ev.x, 0, vt_width) && IN_RANGE_EXC (ev.y, 0, vt_height)) // inside window? selection_request (ev.time, ev.state & ModMetaMask ? Sel_Clipboard : Sel_Primary); break; @@ -2224,7 +2225,7 @@ for (;;) { - if (expect_false (ch == NOCHAR)) + if (ecb_unlikely (ch == NOCHAR)) { seq_begin = cmdbuf_ptr; ch = next_char (); @@ -2233,9 +2234,9 @@ break; } - if (expect_true (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)) + if (ecb_likely (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT)) { - if (expect_false (!seen_input)) + if (ecb_unlikely (!seen_input)) { seen_input = 1; // many badly-written programs (e.g. jed) contain a race condition: @@ -2258,12 +2259,12 @@ for (;;) { - if (expect_false (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))) + if (ecb_unlikely (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT))) break; *str++ = ch; - if (expect_false (ch == C0_LF || str >= eol)) + if (ecb_unlikely (ch == C0_LF || str >= eol)) { if (ch == C0_LF) nlines++; @@ -2351,7 +2352,7 @@ while (cmdbuf_ptr < cmdbuf_endp) { // assume 7-bit to be ascii ALWAYS - if (expect_true ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)) + if (ecb_likely ((unsigned char)*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b)) return *cmdbuf_ptr++; wchar_t wc; @@ -2491,7 +2492,6 @@ #endif /* PRINTPIPE */ /*}}} */ -/* *INDENT-OFF* */ enum { C1_40 = 0x40, C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, @@ -2499,7 +2499,6 @@ C1_DCS, C1_PU1, C1_PU2, C1_STS, C1_CCH, C1_MW , C1_SPA, C1_EPA, C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC, }; -/* *INDENT-ON* */ /*{{{ process non-printing single characters */ void @@ -2602,7 +2601,7 @@ tt_printf ("\033/Z"); /* I am a VT100 emulating a VT52 */ break; case '<': /* turn off VT52 mode */ - set_privmode (PrivMode_vt52, 0); + priv_modes &= ~PrivMode_vt52; break; case 'F': /* use special graphics character set */ case 'G': /* use regular character set */ @@ -2631,7 +2630,6 @@ switch (ch) { - /* case 1: do_tek_mode (); break; */ case '#': if (cmd_getc () == '8') scr_E (); @@ -2664,9 +2662,12 @@ scr_forwardindex (); break; #endif + // DECPAM/DECPNM case '=': + priv_modes |= PrivMode_aplKP; + break; case '>': - set_privmode (PrivMode_aplKP, ch == '='); + priv_modes &= ~PrivMode_aplKP; break; case C1_40: @@ -2680,7 +2681,7 @@ case C1_NEL: /* ESC E */ { wchar_t nlcr[] = { C0_LF, C0_CR }; - scr_add_lines (nlcr, ARRAY_LENGTH(nlcr), 1); + scr_add_lines (nlcr, ecb_array_length (nlcr), 1); } break; @@ -2702,10 +2703,10 @@ break; /* 8.3.142: SINGLE-SHIFT TWO */ - /*case C1_SS2: scr_single_shift (2); break; */ + /* case C1_SS2: break; */ /* 8.3.143: SINGLE-SHIFT THREE */ - /*case C1_SS3: scr_single_shift (3); break; */ + /* case C1_SS3: break; */ /* 8.3.27: DEVICE CONTROL STRING */ case C1_DCS: /* ESC P */ @@ -2748,7 +2749,6 @@ /*}}} */ /*{{{ process CONTROL SEQUENCE INTRODUCER (CSI) sequences `ESC[' */ -/* *INDENT-OFF* */ enum { CSI_ICH = 0x40, CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, @@ -2778,7 +2778,6 @@ make_byte (0,0,0,0,0,0,0,0), /* p, q, r, s, t, u, v, w, */ make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */ }; -/* *INDENT-ON* */ void rxvt_term::process_csi_seq () @@ -2868,8 +2867,8 @@ static const int pm_h[] = { 7, 25 }; static const int pm_l[] = { 1, 3, 4, 5, 6, 9, 66, 1000, 1001, 1005, 1015, 1049 }; - process_terminal_mode ('h', 0, ARRAY_LENGTH(pm_h), pm_h); - process_terminal_mode ('l', 0, ARRAY_LENGTH(pm_l), pm_l); + process_terminal_mode ('h', 0, ecb_array_length (pm_h), pm_h); + process_terminal_mode ('l', 0, ecb_array_length (pm_l), pm_l); } break; } @@ -2897,11 +2896,11 @@ #endif case CSI_CUU: /* 8.3.22: (1) CURSOR UP */ - case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */ + case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */ arg[0] = -arg[0]; /* FALLTHROUGH */ case CSI_CUD: /* 8.3.19: (1) CURSOR DOWN */ - case CSI_VPB: /* 8.3.160: (1) LINE POSITION BACKWARD */ + case CSI_VPR: /* 8.3.161: (1) LINE POSITION FORWARD */ scr_gotorc (arg[0], 0, RELATIVE); break; @@ -3098,7 +3097,6 @@ /*}}} */ #if !ENABLE_MINIMAL -/* ARGSUSED */ void rxvt_term::process_window_ops (const int *args, unsigned int nargs) { @@ -3145,7 +3143,7 @@ //case 9: NYI, TODO, restore maximized window or maximize window default: if (args[0] >= 24) /* set height (chars) */ - set_widthheight ((unsigned int)width, + set_widthheight ((unsigned int)vt_width, (unsigned int) (args[1] * fheight)); break; @@ -3455,33 +3453,43 @@ if (!strcmp (str, "?")) { char str[256]; + int h_scale = 0, v_scale = 0; + int h_align = 0, v_align = 0; + if (image_vec.size () > 0) + { + h_scale = image_vec[0].h_scale; + v_scale = image_vec[0].v_scale; + h_align = image_vec[0].h_align; + v_align = image_vec[0].v_align; + } sprintf (str, "[%dx%d+%d+%d]", - min (h_scale, 32767), min (v_scale, 32767), - min (h_align, 32767), min (v_align, 32767)); + h_scale, v_scale, + h_align, v_align); process_xterm_seq (XTerm_title, str, CHAR_ST); } else { - int changed = 0; + bool changed = false; if (*str != ';') { - if (bg_set_file (str)) /* change pixmap */ + if (image_vec.size () > 0) + changed = image_vec[0].set_file_geometry (str); + else { - changed++; - str = strchr (str, ';'); - if (str == NULL) - bg_set_default_geometry (); + rxvt_image *image = new_image (); + if (!image->set_file_geometry (str)) + image_vec.pop_back (); else - bg_set_geometry (str+1); + changed = true; } } else { str++; - if (bg_set_geometry (str, true)) - changed++; + if (image_vec.size () > 0) + changed = image_vec[0].set_geometry (str, true); } if (changed) @@ -3597,7 +3605,10 @@ if (mode == 's') { - SavedModes |= (priv_modes & bit); + if (priv_modes & bit) + SavedModes |= bit; + else + SavedModes &= ~bit; return -1; } else @@ -3607,7 +3618,10 @@ else state = (mode == 't') ? ! (priv_modes & bit) : mode; - set_privmode (bit, state); + if (state) + priv_modes |= bit; + else + priv_modes &= ~bit; } return state; @@ -3615,7 +3629,7 @@ /* we're not using priv _yet_ */ void -rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg) +rxvt_term::process_terminal_mode (int mode, int priv ecb_unused, unsigned int nargs, const int *arg) { unsigned int i, j; int state; @@ -3626,7 +3640,7 @@ const unsigned long bit; } argtopriv[] = { { 1, PrivMode_aplCUR }, // DECCKM - { 2, PrivMode_vt52 }, + { 2, PrivMode_vt52 }, // DECANM { 3, PrivMode_132 }, // DECCOLM { 4, PrivMode_smoothScroll }, // DECSCLM { 5, PrivMode_rVideo }, // DECSCNM @@ -3636,7 +3650,7 @@ { 9, PrivMode_MouseX10 }, // 18 end FF to printer after print screen // 19 Print screen prints full screen/scroll region - { 25, PrivMode_VisibleCursor }, // cnorm/cvvis/civis + { 25, PrivMode_VisibleCursor }, // DECTCEM cnorm/cvvis/civis #ifdef scrollBar_esc { scrollBar_esc, PrivMode_scrollBar }, #endif @@ -3647,7 +3661,7 @@ // 45 margin bell NYI // 46 start logging { 47, PrivMode_Screen }, - { 66, PrivMode_aplKP }, // DECPAM/DECPNM + { 66, PrivMode_aplKP }, // DECNKM #ifndef NO_BACKSPACE_KEY { 67, PrivMode_BackSpace }, // DECBKM #endif @@ -3686,7 +3700,7 @@ state = -1; /* basic handling */ - for (j = 0; j < ARRAY_LENGTH(argtopriv); j++) + for (j = 0; j < ecb_array_length (argtopriv); j++) if (argtopriv[j].argval == arg[i]) { state = privcases (mode, argtopriv[j].bit); @@ -3722,7 +3736,7 @@ * parameter. Return from VT52 mode with an ESC < from * within VT52 mode */ - set_privmode (PrivMode_vt52, 1); + priv_modes |= PrivMode_vt52; break; case 3: /* 80/132 */ if (priv_modes & PrivMode_132OK) @@ -3747,11 +3761,9 @@ break; #ifdef scrollBar_esc case scrollBar_esc: - if (scrollBar.map (state)) - { - resize_all_windows (0, 0, 0); - scr_touch (true); - } + scrollBar.map (state); + resize_all_windows (0, 0, 0); + scr_touch (true); break; #endif case 25: /* visible/invisible cursor */