--- rxvt-unicode/src/command.C 2011/01/08 10:15:36 1.469 +++ rxvt-unicode/src/command.C 2011/08/31 22:39:49 1.496 @@ -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-2007 Marc Lehmann + * Copyright (c) 2003-2011 Marc Lehmann * Copyright (c) 2007 Emanuele Giaquinta * * This program is free software; you can redistribute it and/or modify @@ -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; } @@ -571,10 +568,8 @@ #if TODO /* rxvt extras */ case XK_KP_Add: /* Shift+KP_Add = bigger font */ - change_font (FONT_UP); return; case XK_KP_Subtract: /* Shift+KP_Subtract = smaller font */ - change_font (FONT_DN); return; #endif } @@ -938,49 +933,15 @@ #endif } -#if defined (KEYSYM_RESOURCE) -unsigned int -rxvt_term::cmd_write (const char *str, unsigned int count) -{ - unsigned int n, s; - - n = cmdbuf_ptr - cmdbuf_base; - s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; - - if (n > 0 && s < count) - { - memmove (cmdbuf_base, cmdbuf_ptr, - (unsigned int) (cmdbuf_endp - cmdbuf_ptr)); - cmdbuf_ptr = cmdbuf_base; - cmdbuf_endp -= n; - s += n; - } - - if (count > s) - { - rxvt_warn ("data loss: cmd_write too large, continuing.\n"); - count = s; - } - - for (; count--;) - *cmdbuf_endp++ = *str++; - - cmd_parse (); - - return 0; -} -#endif - void rxvt_term::flush () { flush_ev.stop (); #ifdef HAVE_BG_PIXMAP - if (bgPixmap.flags & bgPixmap_t::hasChanged) + if (bg_flags & BG_NEEDS_REFRESH) { - bgPixmap.flags &= ~bgPixmap_t::hasChanged; -// scr_clear (true); This needs to be researched further! + bg_flags &= ~BG_NEEDS_REFRESH; scr_touch (false); } #endif @@ -1028,7 +989,7 @@ scr_refresh (); scrollBar.show (1); #ifdef USE_XIM - IMSendSpot (); + im_send_spot (); #endif } @@ -1155,22 +1116,55 @@ } event_handler; #endif +/* make sure all the cmd data is at beginning of cmdbuf */ +void +rxvt_term::cmdbuf_reify () +{ + if (cmdbuf_ptr == cmdbuf_base) + return; + + ssize_t used = cmdbuf_endp - cmdbuf_ptr; + + memmove (cmdbuf_base, cmdbuf_ptr, used); + cmdbuf_ptr = cmdbuf_base; + cmdbuf_endp = cmdbuf_ptr + used; + +} + +#if defined (KEYSYM_RESOURCE) +void +rxvt_term::cmdbuf_append (const char *str, size_t count) +{ + cmdbuf_reify (); + + size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp; + + if (count > avail) + return; + + memcpy (cmdbuf_endp, str, count); + cmdbuf_endp += count; + + cmd_parse (); +} +#endif + bool rxvt_term::pty_fill () { - ssize_t n = cmdbuf_endp - cmdbuf_ptr; + cmdbuf_reify (); - if (CBUFSIZ == n) + size_t avail = cmdbuf_base + CBUFSIZ - cmdbuf_endp; + + if (!avail) { - rxvt_warn ("PLEASE REPORT: pty_fill on full buffer, draining input, continuing.\n"); - n = 0; + // normally this indicates a "too long" command sequence - just drop the data we have + cmdbuf_ptr = cmdbuf_base; + cmdbuf_endp = cmdbuf_ptr; + avail = CBUFSIZ; } - memmove (cmdbuf_base, cmdbuf_ptr, n); - cmdbuf_ptr = cmdbuf_base; - cmdbuf_endp = cmdbuf_ptr + n; - - ssize_t r = read (pty->pty, cmdbuf_endp, CBUFSIZ - n); + ssize_t r = read (pty->pty, cmdbuf_endp, avail); if (r > 0) { @@ -1448,14 +1442,14 @@ break; case ConfigureNotify: - if (ev.xconfigure.window == parent[0]) + if (ev.xconfigure.window == parent) { while (XCheckTypedWindowEvent (dpy, ev.xconfigure.window, ConfigureNotify, &ev)) ; #ifdef HAVE_BG_PIXMAP bool moved = false; - if (bgPixmap.window_position_sensitive ()) + if (bg_window_position_sensitive ()) { int x, y; if (ev.xconfigure.send_event) @@ -1466,8 +1460,8 @@ else get_window_origin (x, y); - if (bgPixmap.set_position (x, y) - || (bgPixmap.flags & bgPixmap_t::isInvalid)) + if (bg_set_position (x, y) + || !(bg_flags & BG_IS_VALID)) moved = true; } #endif @@ -1481,12 +1475,7 @@ { #ifdef HAVE_BG_PIXMAP if (moved) - { - if (mapped) - update_background (); - else - bgPixmap.invalidate (); - } + update_background (); #endif } @@ -1495,22 +1484,13 @@ break; case PropertyNotify: - if (!HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END))) - if (ev.xproperty.atom == xa[XA_VT_SELECTION] - && ev.xproperty.state == PropertyNewValue) - selection_property (ev.xproperty.window, ev.xproperty.atom); - + HOOK_INVOKE ((this, HOOK_PROPERTY_NOTIFY, DT_XEVENT, &ev, DT_END)); break; case SelectionClear: selection_clear (ev.xselectionclear.selection == xa[XA_CLIPBOARD]); break; - case SelectionNotify: - if (selection_wait == Sel_normal) - selection_paste (ev.xselection.requestor, ev.xselection.property, true); - break; - case SelectionRequest: selection_send (ev.xselectionrequest); break; @@ -1529,7 +1509,7 @@ * We should render background PRIOR to drawing any text, but AFTER all * of ConfigureNotifys for the best results. */ - if (bgPixmap.flags & bgPixmap_t::isInvalid) + if (!(bg_flags & BG_IS_VALID)) update_background_ev.start (0.025); #endif mapped = 1; @@ -1554,7 +1534,7 @@ do { scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); + ev.xexpose.width, ev.xexpose.height, false); } while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)); @@ -1563,7 +1543,7 @@ while (XCheckTypedWindowEvent (dpy, vt, ev.xany.type, &ev)) { scr_expose (ev.xexpose.x, ev.xexpose.y, - ev.xexpose.width, ev.xexpose.height, False); + ev.xexpose.width, ev.xexpose.height, false); } want_refresh = 1; @@ -1688,7 +1668,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); @@ -1733,10 +1713,10 @@ if (enable == urgency_hint) return; - if (XWMHints *h = XGetWMHints (dpy, parent[0])) + if (XWMHints *h = XGetWMHints (dpy, parent)) { h->flags = h->flags & ~XUrgencyHint | (enable ? XUrgencyHint : 0); - XSetWMHints (dpy, parent[0], h); + XSetWMHints (dpy, parent, h); urgency_hint = enable; } } @@ -1753,7 +1733,7 @@ #if USE_XIM if (Input_Context != NULL) { - IMSetPosition (); + im_set_position (); XSetICFocus (Input_Context); } #endif @@ -1854,7 +1834,7 @@ if (ev.xproperty.atom == xa[XA_XROOTPMAP_ID] || ev.xproperty.atom == xa[XA_ESETROOT_PMAP_ID]) { - bgPixmap.set_root_pixmap (); + bg_set_root_pixmap (); update_background (); } @@ -2066,9 +2046,9 @@ } 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 ()); + || scrollBar.above_slider (ev.y) + || scrollBar.below_slider (ev.y)) + scr_move_to (scrollBar.position (ev.y) - csrO, scrollBar.size ()); scrollBar.state = STATE_MOTION; break; @@ -2081,13 +2061,13 @@ case Button3: if (scrollBar.style != R_SB_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 @@ -2100,7 +2080,7 @@ { scr_page ((ev.button == Button1 ? DN : UP), (nrow - * scrollbar_position (ev.y) + * scrollBar.position (ev.y) / scrollBar.size ())); } @@ -2236,7 +2216,7 @@ for (;;) { - if (expect_false (ch == NOCHAR)) + if (ecb_unlikely (ch == NOCHAR)) { seq_begin = cmdbuf_ptr; ch = next_char (); @@ -2245,9 +2225,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: @@ -2270,12 +2250,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++; @@ -2363,7 +2343,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; @@ -2401,11 +2381,6 @@ static class out_of_input out_of_input; -/* rxvt_cmd_getc () - Return next input character */ -/* - * Return the next input character after first passing any keyboard input - * to the command. - */ wchar_t rxvt_term::cmd_getc () THROW ((class out_of_input)) { @@ -2508,7 +2483,6 @@ #endif /* PRINTPIPE */ /*}}} */ -/* *INDENT-OFF* */ enum { C1_40 = 0x40, C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, @@ -2516,7 +2490,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 @@ -2619,7 +2592,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 */ @@ -2648,7 +2621,6 @@ switch (ch) { - /* case 1: do_tek_mode (); break; */ case '#': if (cmd_getc () == '8') scr_E (); @@ -2681,9 +2653,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: @@ -2697,13 +2672,15 @@ 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; /* kidnapped escape sequence: Should be 8.3.48 */ case C1_ESA: /* ESC G */ - process_graphics (); + // used by original rxvt for rob nations own graphics mode + if (cmd_getc () == 'Q') + tt_printf ("\033G0\012"); /* query graphics - no graphics */ break; /* 8.3.63: CHARACTER TABULATION SET */ @@ -2717,10 +2694,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 */ @@ -2763,7 +2740,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, @@ -2793,7 +2769,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 () @@ -2883,8 +2858,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; } @@ -3113,7 +3088,6 @@ /*}}} */ #if !ENABLE_MINIMAL -/* ARGSUSED */ void rxvt_term::process_window_ops (const int *args, unsigned int nargs) { @@ -3132,22 +3106,22 @@ * commands */ case 1: /* deiconify window */ - XMapWindow (dpy, parent[0]); + XMapWindow (dpy, parent); break; case 2: /* iconify window */ - XIconifyWindow (dpy, parent[0], display->screen); + XIconifyWindow (dpy, parent, display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (dpy, parent[0], args[1], args[2]); + XMoveWindow (dpy, parent, 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 (dpy, parent[0]); + XRaiseWindow (dpy, parent); break; case 6: /* lower window */ - XLowerWindow (dpy, parent[0]); + XLowerWindow (dpy, parent); break; case 7: /* refresh window */ scr_touch (true); @@ -3168,18 +3142,18 @@ * reports - some output format copied from XTerm */ case 11: /* report window state */ - XGetWindowAttributes (dpy, parent[0], &wattr); + XGetWindowAttributes (dpy, parent, &wattr); tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); break; case 13: /* report window position */ - XGetWindowAttributes (dpy, parent[0], &wattr); - XTranslateCoordinates (dpy, parent[0], wattr.root, + XGetWindowAttributes (dpy, parent, &wattr); + XTranslateCoordinates (dpy, parent, 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 (dpy, parent[0], &wattr); + XGetWindowAttributes (dpy, parent, &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; case 18: /* report text area size (chars) */ @@ -3191,7 +3165,7 @@ case 20: /* report icon label */ { char *s; - XGetIconName (dpy, parent[0], &s); + XGetIconName (dpy, parent, &s); tt_printf ("\033]L%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } @@ -3199,7 +3173,7 @@ case 21: /* report window title */ { char *s; - XFetchName (dpy, parent[0], &s); + XFetchName (dpy, parent, &s); tt_printf ("\033]l%-.250s\234", option (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } @@ -3363,7 +3337,7 @@ const char *str = ""; if (prop - && XGetWindowProperty (dpy, parent[0], + && XGetWindowProperty (dpy, parent, prop, 0, 1<<16, 0, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &value) == Success @@ -3385,7 +3359,7 @@ set_utf8_property (display->atom (str), eq + 1); } else - XDeleteProperty (dpy, parent[0], + XDeleteProperty (dpy, parent, display->atom (str)); } break; @@ -3456,9 +3430,7 @@ bool changed = false; if (ISSET_PIXCOLOR (Color_tint)) - changed = bgPixmap.set_tint (pix_colors_focused [Color_tint]); - else - changed = bgPixmap.unset_tint (); + changed = bg_set_tint (pix_colors_focused [Color_tint]); if (changed) update_background (); @@ -3474,40 +3446,33 @@ char str[256]; sprintf (str, "[%dx%d+%d+%d]", - min (bgPixmap.h_scale, 32767), min (bgPixmap.v_scale, 32767), - min (bgPixmap.h_align, 32767), min (bgPixmap.v_align, 32767)); + min (h_scale, 32767), min (v_scale, 32767), + min (h_align, 32767), min (v_align, 32767)); process_xterm_seq (XTerm_title, str, CHAR_ST); } else { - int changed = 0; + bool changed = false; if (*str != ';') { - if (bgPixmap.set_file (str)) /* change pixmap */ - { - changed++; - str = strchr (str, ';'); - if (str == NULL) - bgPixmap.set_defaultGeometry (); - else - bgPixmap.set_geometry (str+1); - } + if (bg_set_file (str)) /* change pixmap */ + changed = true; } else { str++; - if (bgPixmap.set_geometry (str, true)) - changed++; + if (bg_set_geometry (str, true)) + changed = true; } if (changed) { - if (bgPixmap.window_position_sensitive ()) + if (bg_window_position_sensitive ()) { int x, y; get_window_origin (x, y); - bgPixmap.set_position (x, y); + bg_set_position (x, y); } update_background (); } @@ -3624,7 +3589,10 @@ else state = (mode == 't') ? ! (priv_modes & bit) : mode; - set_privmode (bit, state); + if (state) + priv_modes |= bit; + else + priv_modes &= ~bit; } return state; @@ -3632,7 +3600,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; @@ -3643,7 +3611,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 @@ -3653,7 +3621,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 @@ -3664,7 +3632,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 @@ -3703,7 +3671,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); @@ -3739,7 +3707,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) @@ -3764,11 +3732,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 */ @@ -3986,25 +3952,6 @@ } /*}}} */ -/*{{{ (do not) process Rob Nation's own graphics mode sequences */ -void -rxvt_term::process_graphics () -{ - unicode_t ch, cmd = cmd_getc (); - - if (cmd == 'Q') - { - /* query graphics */ - tt_printf ("\033G0\012"); /* no graphics */ - return; - } - /* swallow other graphics sequences until terminating ':' */ - do - ch = cmd_getc (); - while (ch != ':'); -} -/*}}} */ - /* ------------------------------------------------------------------------- */ /* @@ -4042,7 +3989,9 @@ { ssize_t written = write (pty->pty, data, min (len, MAX_PTY_WRITE)); - if ((unsigned int)written == len) + max_it (written, 0); + + if (written == len) return; data += written;