--- rxvt-unicode/src/command.C 2004/03/15 00:08:11 1.73 +++ rxvt-unicode/src/command.C 2004/05/09 18:19:49 1.95 @@ -1,5 +1,5 @@ /*--------------------------------*-C-*---------------------------------* - * File: command.c + * File: command.C *----------------------------------------------------------------------* * * All portions of code are copyright by their respective author/s. @@ -54,6 +54,11 @@ /*----------------------------------------------------------------------*/ +#define IS_CONTROL(ch) !((ch) & 0xffffff60UL) + +// exception thrown when the command parser runs out of input data +class out_of_input { } out_of_input; + /*{{{ Convert the keypress event into a string */ void rxvt_term::lookup_key (XKeyEvent &ev) @@ -90,12 +95,14 @@ { Status status_return; +#if 0 #ifdef X_HAVE_UTF8_STRING if (enc_utf8 && 0) // currently disabled, doesn't seem to work, nor is useful len = Xutf8LookupString (Input_Context, &ev, (char *)kbuf, KBUFSZ, &keysym, &status_return); else #endif +#endif { wchar_t wkbuf[KBUFSZ + 1]; @@ -618,10 +625,10 @@ unsigned int rxvt_term::cmd_write (const unsigned char *str, unsigned int count) { - unsigned int n, s; + unsigned int n, s; n = cmdbuf_ptr - cmdbuf_base; - s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp; + s = cmdbuf_base + CBUFSIZ - 1 - cmdbuf_endp; if (n > 0 && s < count) { @@ -634,7 +641,7 @@ if (count > s) { - rxvt_print_error ("data loss: cmd_write too large"); + rxvt_warn ("data loss: cmd_write too large, continuing.\n"); count = s; } @@ -667,7 +674,6 @@ #ifdef USE_XIM IMSendSpot (); #endif - } display->flush (); @@ -711,11 +717,17 @@ { ssize_t n = cmdbuf_endp - cmdbuf_ptr; + if (CBUFSIZ == n) + { + rxvt_warn ("pty_fill on full buffer, draining input, continuing.\n"); + n = 0; + } + memmove (cmdbuf_base, cmdbuf_ptr, n); cmdbuf_ptr = cmdbuf_base; cmdbuf_endp = cmdbuf_ptr + n; - n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); + n = read (cmd_fd, cmdbuf_endp, CBUFSIZ - n); if (n > 0) { @@ -737,185 +749,10 @@ if (revents & EVENT_WRITE) tt_write (0, 0); else if (revents & EVENT_READ) - { - bool flag = true; - - // loop, but don't allow a single term to monopolize us - // the number of loops is fully arbitrary, and thus wrong - while (flag && pty_fill ()) - { - if (!seen_input) - { - seen_input = 1; - /* once we know the shell is running, send the screen size. Again! */ - tt_winch (); - } - - if (cmd_parse ()) - break; - } - } -} - -bool -rxvt_term::cmd_parse () -{ - bool flag = false; - unicode_t ch = NOCHAR; - - for (;;) - { - if (ch == NOCHAR) - ch = next_char (); - - if (ch == NOCHAR) // TODO: improve + // loop, but don't allow a single term to monopolize us + while (pty_fill ()) + if (cmd_parse ()) break; - - if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') - { - /* Read a text string from the input buffer */ - unicode_t buf[BUFSIZ]; - bool refreshnow = false; - int nlines = 0; - unicode_t *str = buf; - - *str++ = ch; - - for (;;) - { - ch = next_char (); - - if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')) - break; - else - { - *str++ = ch; - - if (ch == '\n') - { - nlines++; - refresh_count++; - - if (! (Options & Opt_jumpScroll) - || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) - { - refreshnow = true; - flag = false; - ch = NOCHAR; - break; - } - - // scr_add_lines only works for nlines < TermWin.nrow - 1. - if (nlines >= TermWin.nrow - 1) - { - scr_add_lines (buf, nlines, str - buf); - nlines = 0; - str = buf; - } - } - - if (str >= buf + BUFSIZ) - { - ch = NOCHAR; - break; - } - } - } - - scr_add_lines (buf, nlines, str - buf); - - /* - * 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. - * - * refreshing should be correct for small scrolls, because of the - * time-out - */ - if (refreshnow) - { - if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) - refresh_limit++; - - scr_refresh (refresh_type); - } - - } - else - { - switch (ch) - { - default: - process_nonprinting (ch); - break; - case C0_ESC: /* escape char */ - process_escape_seq (); - break; - /*case 0x9b: */ /* CSI */ - /* process_csi_seq (); */ - } - - ch = NOCHAR; - } - } - - return flag; -} - -// read the next character, currently handles UTF-8 -// will probably handle all sorts of other stuff in the future -unicode_t -rxvt_term::next_char () -{ - while (cmdbuf_ptr < cmdbuf_endp) - { - // assume 0x20 .. 0x7f to be ascii ALWAYS (all shift-states etc.) uh-oh - if ((*cmdbuf_ptr <= 0x7f && 0x20 <= *cmdbuf_ptr) - || !*cmdbuf_ptr) - return *cmdbuf_ptr++; - - wchar_t wc; - size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); - - if (len == (size_t)-2) - { - // the mbstate stores incomplete sequences. didn't know this :/ - cmdbuf_ptr = cmdbuf_endp; - break; - } - - if (len == (size_t)-1) - return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through - - // assume wchar == unicode - cmdbuf_ptr += len; - return wc; - } - - return NOCHAR; -} - -/* rxvt_cmd_getc () - Return next input character */ -/* - * Return the next input character after first passing any keyboard input - * to the command. - */ -unicode_t -rxvt_term::cmd_getc () -{ - for (;;) - { - unicode_t c = next_char (); - if (c != NOCHAR) - return c; - - // incomplete sequences should occur rarely, still, a better solution - // would be preferred. either setjmp/longjmp or better design. - fcntl (cmd_fd, F_SETFL, 0); - pty_fill (); - fcntl (cmd_fd, F_SETFL, O_NONBLOCK); - } } #ifdef POINTER_BLANK @@ -1170,10 +1007,10 @@ || ev.xclient.data.l[0] == DndLink)) { /* Get Dnd data */ - Atom ActualType; - int ActualFormat; - unsigned char *data; - unsigned long Size, RemainingBytes; + Atom ActualType; + int ActualFormat; + unsigned char *data; + unsigned long Size, RemainingBytes; XGetWindowProperty (display->display, display->root, xa[XA_DNDSELECTION], @@ -1186,6 +1023,7 @@ XA_CUT_BUFFER0, XA_STRING, 8, PropModeReplace, data, STRLEN (data)); + XFree (data); selection_paste (display->root, XA_CUT_BUFFER0, True); XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); } @@ -1288,12 +1126,11 @@ want_full_refresh = 1; } #endif - } break; case SelectionClear: - display->set_selection_owner (0); + selection_clear (); break; case SelectionNotify: @@ -1334,7 +1171,7 @@ scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); #else - // don't understand this, so commented it out + // I don't understand this, so I changed it :) scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); //scr_expose (ev.xexpose.x, 0, @@ -1346,12 +1183,11 @@ { XEvent unused_event; - while (XCheckTypedWindowEvent (display->display, ev.xany.window, - Expose, - &unused_event)) ; - while (XCheckTypedWindowEvent (display->display, ev.xany.window, - GraphicsExpose, - &unused_event)) ; + while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event)) + ; + while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) + ; + if (isScrollbarWindow (ev.xany.window)) { scrollBar.setIdle (); @@ -1502,9 +1338,8 @@ /* FALLTHROUGH */ case ReparentNotify: - if ((Options & Opt_transparent) && check_our_parents ()) - if (am_transparent) - want_full_refresh = 1; + if ((Options & Opt_transparent) && check_our_parents () && am_transparent) + want_full_refresh = 1; break; #endif } @@ -1858,8 +1693,242 @@ #endif } - #ifdef TRANSPARENT +#if TINTING +/* shading taken from eterm-0.9.2 */ +/* RGB 15 */ + +static void +shade_ximage_15(void *data, int bpl, int w, int h, int rm, int gm, int bm) +{ + unsigned char *ptr; + int x, y; + + ptr = (unsigned char *)data + (w * sizeof(uint16_t)); + if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { + /* No saturation */ + for (y = h; --y >= 0;) { + for (x = -w; x < 0; x++) { + int r, g, b; + + b = ((uint16_t *) ptr)[x]; + r = (b & 0x7c00) * rm; + g = (b & 0x3e0) * gm; + b = (b & 0x1f) * bm; + ((uint16_t *) ptr)[x] = ((r >> 8) & 0x7c00) + | ((g >> 8) & 0x3e0) + | ((b >> 8) & 0x1f); + } + ptr += bpl; + } + } else { + for (y = h; --y >= 0;) { + for (x = -w; x < 0; x++) { + int r, g, b; + + b = ((uint16_t *) ptr)[x]; + r = (b & 0x7c00) * rm; + g = (b & 0x3e0) * gm; + b = (b & 0x1f) * bm; + r |= (!(r >> 15) - 1); + g |= (!(g >> 10) - 1); + b |= (!(b >> 5) - 1); + ((uint16_t *) ptr)[x] = ((r >> 8) & 0x7c00) + | ((g >> 8) & 0x3e0) + | ((b >> 8) & 0x1f); + } + ptr += bpl; + } + } +} + +/* RGB 16 */ +static void +shade_ximage_16(void *data, int bpl, int w, int h, int rm, int gm, int bm) +{ + unsigned char *ptr; + int x, y; + + ptr = (unsigned char *)data + (w * sizeof(uint16_t)); + if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { + /* No saturation */ + for (y = h; --y >= 0;) { + for (x = -w; x < 0; x++) { + int r, g, b; + + b = ((uint16_t *) ptr)[x]; + r = (b & 0xf800) * rm; + g = (b & 0x7e0) * gm; + b = (b & 0x1f) * bm; + ((uint16_t *) ptr)[x] = ((r >> 8) & 0xf800) + | ((g >> 8) & 0x7e0) + | ((b >> 8) & 0x1f); + } + ptr += bpl; + } + } else { + for (y = h; --y >= 0;) { + for (x = -w; x < 0; x++) { + int r, g, b; + + b = ((uint16_t *) ptr)[x]; + r = (b & 0xf800) * rm; + g = (b & 0x7e0) * gm; + b = (b & 0x1f) * bm; + r |= (!(r >> 16) - 1); + g |= (!(g >> 11) - 1); + b |= (!(b >> 5) - 1); + ((uint16_t *) ptr)[x] = ((r >> 8) & 0xf800) + | ((g >> 8) & 0x7e0) + | ((b >> 8) & 0x1f); + } + ptr += bpl; + } + } +} + +/* RGB 24 */ +static void +shade_ximage_24(void *data, int bpl, int w, int h, int rm, int gm, int bm) +{ + unsigned char *ptr; + int x, y; + + ptr = (unsigned char *)data + (w * 3); + if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { + /* No saturation */ + for (y = h; --y >= 0;) { + for (x = -(w * 3); x < 0; x += 3) { + int r, g, b; + + if (byteorder.big_endian()) { + r = (ptr[x + 0] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 2] * bm) >> 8; + ptr[x + 0] = r; + ptr[x + 1] = g; + ptr[x + 2] = b; + } else { + r = (ptr[x + 2] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 0] * bm) >> 8; + ptr[x + 2] = r; + ptr[x + 1] = g; + ptr[x + 0] = b; + } + } + ptr += bpl; + } + } else { + for (y = h; --y >= 0;) { + for (x = -(w * 3); x < 0; x += 3) { + int r, g, b; + + if (byteorder.big_endian()) { + r = (ptr[x + 0] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 2] * bm) >> 8; + + r |= (!(r >> 8) - 1); + g |= (!(g >> 8) - 1); + b |= (!(b >> 8) - 1); + + ptr[x + 0] = r; + ptr[x + 1] = g; + ptr[x + 2] = b; + } else { + r = (ptr[x + 2] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 0] * bm) >> 8; + + r |= (!(r >> 8) - 1); + g |= (!(g >> 8) - 1); + b |= (!(b >> 8) - 1); + + ptr[x + 2] = r; + ptr[x + 1] = g; + ptr[x + 0] = b; + } + } + ptr += bpl; + } + } +} + +/* RGB 32 */ +static void +shade_ximage_32(void *data, int bpl, int w, int h, int rm, int gm, int bm) +{ + unsigned char *ptr; + int x, y; + + ptr = (unsigned char *)data + (w * 4); + if ((rm <= 256) && (gm <= 256) && (bm <= 256)) { + /* No saturation */ + for (y = h; --y >= 0;) { + if (byteorder.big_endian()) { + for (x = -(w * 4); x < 0; x += 4) { + int r, g, b; + + r = (ptr[x + 1] * rm) >> 8; + g = (ptr[x + 2] * gm) >> 8; + b = (ptr[x + 3] * bm) >> 8; + ptr[x + 1] = r; + ptr[x + 2] = g; + ptr[x + 3] = b; + } + } else { + for (x = -(w * 4); x < 0; x += 4) { + int r, g, b; + + r = (ptr[x + 2] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 0] * bm) >> 8; + ptr[x + 2] = r; + ptr[x + 1] = g; + ptr[x + 0] = b; + } + } + ptr += bpl; + } + } else { + for (y = h; --y >= 0;) { + for (x = -(w * 4); x < 0; x += 4) { + int r, g, b; + + if (byteorder.big_endian()) { + r = (ptr[x + 1] * rm) >> 8; + g = (ptr[x + 2] * gm) >> 8; + b = (ptr[x + 3] * bm) >> 8; + + r |= (!(r >> 8) - 1); + g |= (!(g >> 8) - 1); + b |= (!(b >> 8) - 1); + + ptr[x + 1] = r; + ptr[x + 2] = g; + ptr[x + 3] = b; + } else { + r = (ptr[x + 2] * rm) >> 8; + g = (ptr[x + 1] * gm) >> 8; + b = (ptr[x + 0] * bm) >> 8; + + r |= (!(r >> 8) - 1); + g |= (!(g >> 8) - 1); + b |= (!(b >> 8) - 1); + + ptr[x + 2] = r; + ptr[x + 1] = g; + ptr[x + 0] = b; + } + } + ptr += bpl; + } + } +} + +#endif + /* * Check our parents are still who we think they are. * Do transparency updates if required @@ -1867,32 +1936,33 @@ 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; + 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 (! (Options & Opt_transparent)) + if (!(Options & Opt_transparent)) return pchanged; /* Don't try any more */ XGetWindowAttributes (display->display, display->root, &wrootattr); rootdepth = wrootattr.depth; XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); + if (rootdepth != wattr.depth) { if (am_transparent) { pchanged = 1; - XSetWindowBackground (display->display, TermWin.vt, - PixColors[Color_bg]); + XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); am_transparent = am_pixmap_trans = 0; } + return pchanged; /* Don't try any more */ } @@ -1904,18 +1974,26 @@ * 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_XROOTPMAPID] != 0 - && (XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], + i = (xa[XA_XROOTPMAPID] + && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], 0L, 1L, False, XA_PIXMAP, &atype, &aformat, - &nitems, &bytes_after, &prop) == Success)); + &nitems, &bytes_after, &prop) == Success); + + if (!i || prop == NULL) + i = (xa[XA_XSETROOTID] + && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], + 0L, 1L, False, XA_PIXMAP, &atype, &aformat, + &nitems, &bytes_after, &prop) == Success); + if (!i || prop == NULL) have_pixmap = 0; else { have_pixmap = 1; - rootpixmap = * ((Pixmap *)prop); + rootpixmap = *(Pixmap *)prop; XFree (prop); } + if (have_pixmap) { /* @@ -1929,7 +2007,7 @@ XGCValues gcvalue; XTranslateCoordinates (display->display, TermWin.parent[0], display->root, - 0, 0, &sx, &sy, &cr); + 0, 0, &sx, &sy, &cr); nw = (unsigned int)szHint.width; nh = (unsigned int)szHint.height; nx = ny = 0; @@ -1951,11 +2029,12 @@ MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); allowedxerror = -1; - image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, - ZPixmap); + image = XGetImage (display->display, 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) @@ -1967,51 +2046,74 @@ TermWin.pixmap = None; } } + am_pixmap_trans = 0; } else { if (TermWin.pixmap != None) XFreePixmap (display->display, TermWin.pixmap); + +#if TINTING + if (ISSET_PIXCOLOR (Color_tint)) + { + unsigned short shade, rm, gm, bm; + + PixColors[Color_tint].get (display, rm, gm, bm); + + rm >>= 8; gm >>= 8; bm >>= 8; // not 100% correct, but... + + /* Determine bitshift and bitmask values */ + switch (image->bits_per_pixel) + { + case 15: shade_ximage_15 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break; + case 16: shade_ximage_16 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break; + case 24: shade_ximage_24 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break; + case 32: shade_ximage_32 (image->data, image->bytes_per_line, image->width, image->height, rm, gm, bm); break; + } + } +#endif + TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, - (unsigned int)szHint.width, - (unsigned int)szHint.height, - (unsigned int)image->depth); + szHint.width, szHint.height, image->depth); gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, - nx, ny, (unsigned int)image->width, - (unsigned int)image->height); + nx, ny, image->width, image->height); XFreeGC (display->display, gc); XDestroyImage (image); XSetWindowBackgroundPixmap (display->display, TermWin.vt, TermWin.pixmap); + if (!am_transparent || !am_pixmap_trans) pchanged = 1; + am_transparent = am_pixmap_trans = 1; } } if (!am_pixmap_trans) { - unsigned int n; + unsigned int n; /* * InheritPixmap transparency */ D_X ((stderr, "InheritPixmap Seeking to %08lx", display->root)); - for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); - i++) + for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) { oldp = TermWin.parent[i]; XQueryTree (display->display, TermWin.parent[i - 1], &root, - &TermWin.parent[i], &list, &n); + &TermWin.parent[i], &list, &n); XFree (list); D_X ((stderr, "InheritPixmap Parent[%d] = %08lx", i, TermWin.parent[i])); + if (TermWin.parent[i] == display->root) { if (oldp != None) pchanged = 1; + break; } + if (oldp != TermWin.parent[i]) pchanged = 1; } @@ -2032,48 +2134,194 @@ } } - if (n > (int) (sizeof (TermWin.parent) - / sizeof (TermWin.parent[0]))) + if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) { D_X ((stderr, "InheritPixmap Turning off")); - XSetWindowBackground (display->display, TermWin.parent[0], - PixColors[Color_fg]); - XSetWindowBackground (display->display, TermWin.vt, - PixColors[Color_bg]); + XSetWindowBackground (display->display, TermWin.parent[0], PixColors[Color_fg]); + XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); am_transparent = 0; /* XXX: also turn off Opt_transparent? */ } else { +#if WAIT_FOR_WM /* wait (an arbitrary period) for the WM to do its thing * needed for fvwm2.2.2 (and before?) */ -# ifdef HAVE_NANOSLEEP - struct timespec rqt; - - rqt.tv_sec = 1; - rqt.tv_nsec = 0; - nanosleep (&rqt, NULL); -# else sleep (1); -# endif +#endif D_X ((stderr, "InheritPixmap Turning on (%d parents)", i - 1)); for (n = 0; n < (unsigned int)i; n++) - XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], - ParentRelative); - XSetWindowBackgroundPixmap (display->display, TermWin.vt, - ParentRelative); + XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative); + + XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); am_transparent = 1; } for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) TermWin.parent[i] = None; } + return pchanged; } #endif /*}}} */ +bool +rxvt_term::cmd_parse () +{ + bool flag = false; + unicode_t ch = NOCHAR; + unsigned char *seq_begin; // remember start of esc-sequence here + + for (;;) + { + if (ch == NOCHAR) + { + seq_begin = cmdbuf_ptr; + ch = next_char (); + } + + if (ch == NOCHAR) // TODO: improve + break; + + if (!IS_CONTROL (ch) || ch == C0_LF || ch == C0_CR || ch == C0_HT) + { + /* Read a text string from the input buffer */ + unicode_t buf[UBUFSIZ]; + bool refreshnow = false; + int nlines = 0; + unicode_t *str = buf; + + *str++ = ch; + + for (;;) + { + seq_begin = cmdbuf_ptr; + ch = next_char (); + + if (ch == NOCHAR || (IS_CONTROL (ch) && ch != C0_LF && ch != C0_CR && ch != C0_HT)) + break; + + *str++ = ch; + + if (ch == C0_LF) + { + nlines++; + refresh_count++; + + if (! (Options & Opt_jumpScroll) + || (refresh_count >= (refresh_limit * (TermWin.nrow - 1)))) + { + refreshnow = true; + flag = true; + ch = NOCHAR; + break; + } + + // scr_add_lines only works for nlines < TermWin.nrow - 1. + if (nlines >= TermWin.nrow - 1) + { + scr_add_lines (buf, nlines, str - buf); + nlines = 0; + str = buf; + } + } + + if (str >= buf + UBUFSIZ) + { + ch = NOCHAR; + break; + } + } + + scr_add_lines (buf, nlines, str - buf); + + /* + * 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. + * + * refreshing should be correct for small scrolls, because of the + * time-out + */ + if (refreshnow) + { + if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) + refresh_limit++; + else + scr_refresh (refresh_type); + } + + } + else + { + try + { + process_nonprinting (ch); + } + catch (const class out_of_input &o) + { + // we ran out of input, retry later + cmdbuf_ptr = seq_begin; + break; + } + + ch = NOCHAR; + } + } + + return flag; +} + +// read the next character +unicode_t +rxvt_term::next_char () +{ + while (cmdbuf_ptr < cmdbuf_endp) + { + // assume 7-bit to be ascii ALWAYS + if (*cmdbuf_ptr <= 0x7f && *cmdbuf_ptr != 0x1b) + return *cmdbuf_ptr++; + + wchar_t wc; + size_t len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, mbstate); + + if (len == (size_t)-2) + { + // the mbstate stores incomplete sequences. didn't know this :/ + cmdbuf_ptr = cmdbuf_endp; + break; + } + + if (len == (size_t)-1) + return *cmdbuf_ptr++; // the _occasional_ latin1 character is allowed to slip through + + // assume wchar == unicode + cmdbuf_ptr += len; + return wc; + } + + return NOCHAR; +} + +/* rxvt_cmd_getc () - Return next input character */ +/* + * Return the next input character after first passing any keyboard input + * to the command. + */ +unicode_t +rxvt_term::cmd_getc () +{ + unicode_t c = next_char (); + + if (c == NOCHAR) + throw out_of_input; + + return c; +} + /*{{{ print pipe */ /*----------------------------------------------------------------------*/ #ifdef PRINTPIPE @@ -2083,7 +2331,8 @@ FILE *stream = popen (rs[Rs_print_pipe], "w"); if (stream == NULL) - rxvt_print_error ("can't open printer pipe"); + rxvt_warn ("can't open printer pipe, not printing.\n"); + return stream; } @@ -2091,13 +2340,7 @@ rxvt_term::pclose_printer (FILE *stream) { fflush (stream); - /* pclose () reported not to work on SunOS 4.1.3 */ -# if defined (__sun__) /* TODO: RESOLVE THIS */ - /* pclose works provided SIGCHLD handler uses waitpid */ - return pclose (stream); /* return fclose (stream); */ -# else return pclose (stream); -# endif } /* @@ -2106,8 +2349,8 @@ void rxvt_term::process_print_pipe () { - int done; - FILE *fd; + int done; + FILE *fd; if ((fd = popen_printer ()) == NULL) return; @@ -2118,9 +2361,9 @@ */ for (done = 0; !done;) { - unsigned char buf[8]; - unsigned char ch; - unsigned int i, len; + unsigned char buf[8]; + unicode_t ch; + unsigned int i, len; if ((ch = cmd_getc ()) != C0_ESC) { @@ -2145,6 +2388,7 @@ break; /* done = 1 */ } } + for (i = 0; i < len; i++) if (putc (buf[i], fd) == EOF) { @@ -2153,6 +2397,7 @@ } } } + pclose_printer (fd); } #endif /* PRINTPIPE */ @@ -2161,27 +2406,29 @@ /* *INDENT-OFF* */ enum { C1_40 = 0x40, - C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, + C1_41 , C1_BPH, C1_NBH, C1_44 , C1_NEL, C1_SSA, C1_ESA, C1_HTS, C1_HTJ, C1_VTS, C1_PLD, C1_PLU, C1_RI , C1_SS2, C1_SS3, 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 + C1_SOS, C1_59 , C1_SCI, C1_CSI, CS_ST , C1_OSC, C1_PM , C1_APC, }; /* *INDENT-ON* */ /*{{{ process non-printing single characters */ void -rxvt_term::process_nonprinting (unsigned char ch) +rxvt_term::process_nonprinting (unicode_t ch) { switch (ch) { + case C0_ESC: + process_escape_seq (); + break; case C0_ENQ: /* terminal Status */ if (rs[Rs_answerbackstring]) - tt_write ( - (const unsigned char *)rs[Rs_answerbackstring], - (unsigned int)STRLEN (rs[Rs_answerbackstring])); + tt_write ((const unsigned char *)rs[Rs_answerbackstring], + (unsigned int)STRLEN (rs[Rs_answerbackstring])); else tt_write ((unsigned char *)VT100_ANS, - (unsigned int)STRLEN (VT100_ANS)); + (unsigned int)STRLEN (VT100_ANS)); break; case C0_BEL: /* bell */ scr_bell (); @@ -2206,6 +2453,17 @@ case C0_SI: /* shift in - acs */ scr_charset_choose (0); break; + + // 8-bit controls + case 0x90: /* DCS */ + process_dcs_seq (); + break; + case 0x9b: /* CSI */ + process_csi_seq (); + break; + case 0x9d: /* CSI */ + process_osc_seq (); + break; } } /*}}} */ @@ -2213,7 +2471,7 @@ /*{{{ process VT52 escape sequences */ void -rxvt_term::process_escape_vt52 (unsigned char ch) +rxvt_term::process_escape_vt52 (unicode_t ch) { int row, col; @@ -2275,7 +2533,7 @@ void rxvt_term::process_escape_seq () { - unsigned char ch = cmd_getc (); + unicode_t ch = cmd_getc (); if (PrivateModes & PrivMode_vt52) { @@ -2333,7 +2591,7 @@ /* 8.3.87: NEXT LINE */ case C1_NEL: /* ESC E */ { - unicode_t nlcr[] = { L'\n', L'\r' }; + unicode_t nlcr[] = { C0_LF, C0_CR }; scr_add_lines (nlcr, 1, 2); } break; @@ -2354,10 +2612,10 @@ break; /* 8.3.142: SINGLE-SHIFT TWO */ - /*case C1_SS2: scr_single_shift (2); break; */ + /*case C1_SS2: scr_single_shift (2); break; */ /* 8.3.143: SINGLE-SHIFT THREE */ - /*case C1_SS3: scr_single_shift (3); break; */ + /*case C1_SS3: scr_single_shift (3); break; */ /* 8.3.27: DEVICE CONTROL STRING */ case C1_DCS: /* ESC P */ @@ -2382,6 +2640,7 @@ /* 8.3.106: RESET TO INITIAL STATE */ case 'c': + mbstate.reset (); scr_poweron (); scrollbar_show (1); break; @@ -2403,7 +2662,7 @@ /* *INDENT-OFF* */ enum { CSI_ICH = 0x40, - CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, + CSI_CUU, CSI_CUD, CSI_CUF, CSI_CUB, CSI_CNL, CSI_CPL, CSI_CHA, CSI_CUP, CSI_CHT, CSI_ED , CSI_EL , CSI_IL , CSI_DL , CSI_EF , CSI_EA , CSI_DCH, CSI_SEE, CSI_CPR, CSI_SU , CSI_SD , CSI_NP , CSI_PP , CSI_CTC, CSI_ECH, CSI_CVT, CSI_CBT, CSI_SRS, CSI_PTX, CSI_SDS, CSI_SIMD, CSI_5F, @@ -2428,17 +2687,17 @@ make_byte (1,1,1,0,1,1,1,0), /* `, a, b, c, d, e, f, g, */ make_byte (0,0,1,1,0,0,0,0), /* h, i, j, k, l, m, n, o, */ 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, {, |, }, ~, */ + make_byte (0,0,0,0,0,0,0,0), /* x, y, z, {, |, }, ~, */ }; /* *INDENT-ON* */ void rxvt_term::process_csi_seq () { - unsigned char ch, priv, i; - unsigned int nargs, p; - int n, ndef; - int arg[ESC_ARGS]; + unicode_t ch, priv, i; + unsigned int nargs, p; + int n, ndef; + int arg[ESC_ARGS]; for (nargs = ESC_ARGS; nargs > 0;) arg[--nargs] = 0; @@ -2450,6 +2709,7 @@ priv = ch; ch = cmd_getc (); } + /* read any numerical arguments */ for (n = -1; ch < CSI_ICH; ) { @@ -2466,19 +2726,9 @@ arg[nargs++] = n; n = -1; } - else if (ch == '\b') - { - scr_backspace (); - } - else if (ch == C0_ESC) - { - process_escape_seq (); - return; - } - else if (ch < ' ') - { - process_nonprinting (ch); - } + else if (IS_CONTROL (ch)) + process_nonprinting (ch); + ch = cmd_getc (); } @@ -2646,13 +2896,12 @@ case 6: /* CPR requested */ scr_report_position (); break; -#if defined (ENABLE_DISPLAY_ANSWER) case 7: /* unofficial extension */ - tt_printf ("%-.250s\n", rs[Rs_display_name]); + if (Options & Opt_insecure) + tt_printf ("%-.250s\n", rs[Rs_display_name]); break; -#endif case 8: /* unofficial extension */ - xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); + process_xterm_seq (XTerm_title, RESNAME "-" VERSION, CHAR_ST); break; } break; @@ -2730,7 +2979,7 @@ case CSI_78: /* DECREQTPARM */ if (arg[0] == 0 || arg[0] == 1) tt_printf ("\033[%d;1;1;128;128;1;0x", arg[0] + 2); - /* FALLTHROUGH */ + break; default: break; @@ -2743,20 +2992,18 @@ void rxvt_term::process_window_ops (const int *args, unsigned int nargs) { - int x, y; -#if 0 - char *s; -#endif + int x, y; XWindowAttributes wattr; - Window wdummy; + Window wdummy; if (nargs == 0) return; + switch (args[0]) { - /* - * commands - */ + /* + * commands + */ case 1: /* deiconify window */ XMapWindow (display->display, TermWin.parent[0]); break; @@ -2783,14 +3030,18 @@ set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), (unsigned int) (args[1] * TermWin.fheight)); break; + + //case 9: NYI, TODO, restore maximized window or maximize window default: if (args[0] >= 24) /* set height (chars) */ set_widthheight ((unsigned int)TermWin.width, (unsigned int) (args[1] * TermWin.fheight)); break; - /* - * reports - some output format copied from XTerm - */ + + + /* + * reports - some output format copied from XTerm + */ case 11: /* report window state */ XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); @@ -2798,28 +3049,36 @@ case 13: /* report window position */ XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, - -wattr.border_width, -wattr.border_width, - &x, &y, &wdummy); + -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 (display->display, TermWin.parent[0], &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; - case 18: /* report window size (chars) */ + case 18: /* report text area size (chars) */ tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); break; -#if 0 /* XXX: currently disabled due to security concerns */ + case 19: /* report window size (chars) */ + tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); + break; case 20: /* report icon label */ - XGetIconName (display->display, TermWin.parent[0], &s); - tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ + if (Options & Opt_insecure) + { + char *s; + XGetIconName (display->display, TermWin.parent[0], &s); + tt_printf ("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ + } break; case 21: /* report window title */ - XFetchName (display->display, TermWin.parent[0], &s); - tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ + if (Options & Opt_insecure) + { + char *s; + XFetchName (display->display, TermWin.parent[0], &s); + tt_printf ("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ + } break; -#endif - } } #endif @@ -2827,39 +3086,52 @@ /*----------------------------------------------------------------------*/ /* * get input up until STRING TERMINATOR (or BEL) - * ends_how is terminator used. returned input must be free ()d + * ends_how is terminator used. returned input must be free()'d */ -unsigned char * -rxvt_term::get_to_st (unsigned char *ends_how) +unsigned char * +rxvt_term::get_to_st (unicode_t &ends_how) { - int seen_esc = 0; /* seen escape? */ - unsigned int n = 0; - unsigned char *s; - unsigned char ch, string[STRING_MAX]; - - for (; (ch = cmd_getc ());) - { - if (ch == C0_BEL - || ch == CHAR_ST - || (ch == 0x5c && seen_esc)) /* 7bit ST */ + int seen_esc = 0; /* seen escape? */ + unsigned int n = 0; + unsigned char *s; + unicode_t ch; + unsigned char string[STRING_MAX]; + + while ((ch = cmd_getc ())) + { + if (ch == C0_BEL || ch == CHAR_ST) break; + + if (seen_esc) + if (ch == 0x5c) /* 7bit ST */ + break; + else + return NULL; + if (ch == C0_ESC) { seen_esc = 1; continue; } - else if (ch == '\t') + else if (ch == C0_HT) ch = ' '; /* translate '\t' to space */ - else if (ch < 0x08 || (ch > 0x0d && ch < 0x20)) + else if (ch < 0x20 && (ch != C0_LF && ch != C0_CR)) return NULL; /* other control character - exit */ - if (n < sizeof (string) - 1) - string[n++] = ch; + + if (n >= sizeof (string) - 1) + // stop at some sane length + return NULL; + + string[n++] = ch; seen_esc = 0; } + string[n++] = '\0'; + if ((s = (unsigned char *)rxvt_malloc (n)) == NULL) return NULL; - *ends_how = (ch == 0x5c ? C0_ESC : ch); + + ends_how = (ch == 0x5c ? C0_ESC : ch); STRNCPY (s, string, n); return s; } @@ -2871,13 +3143,16 @@ void rxvt_term::process_dcs_seq () { - unsigned char eh, *s; + unsigned char *s; + unicode_t eh; + /* * Not handled yet */ - s = get_to_st (&eh); + s = get_to_st (eh); if (s) free (s); + return; } @@ -2888,8 +3163,8 @@ void rxvt_term::process_osc_seq () { - unsigned char ch, eh, *s; - int arg; + unicode_t ch, eh; + int arg; ch = cmd_getc (); for (arg = 0; isdigit (ch); ch = cmd_getc ()) @@ -2897,31 +3172,40 @@ if (ch == ';') { - s = get_to_st (&eh); + unsigned char *s = get_to_st (eh); + if (s) { - /* - * rxvt_menubar_dispatch () violates the constness of the string, - * so do it here - */ - if (arg == XTerm_Menu) -#if 0 /* XXX: currently disabled due to security concerns */ - menubar_dispatch ((char *)s); -#else - (void)0; -#endif - else - xterm_seq (arg, (char *)s, eh); + process_xterm_seq (arg, (char *)s, eh); free (s); } } } + +void +rxvt_term::process_color_seq (int report, int color, const char *str, unsigned char resp) +{ + if (str[0] == '?' && !str[1]) + { + if (Options & Opt_insecure) + { + unsigned short r, g, b; + PixColors[color].get (display, r, g, b); + tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); + } + } + else + set_window_color (color, str); +} + /* * XTerm escape sequences: ESC ] Ps;Pt (ST|BEL) * 0 = change iconName/title * 1 = change iconName * 2 = change title * 4 = change color + * 10 = change fg color + * 11 = change bg color * 12 = change text color * 13 = change mouse foreground color * 17 = change highlight character colour @@ -2931,20 +3215,21 @@ * 50 = change font * * rxvt extensions: - * 10 = menu (may change in future) * 20 = bg pixmap * 39 = change default fg color * 49 = change default bg color * 55 = dump scrollback buffer and all of screen * 701 = change locale * 702 = find font + * 703 = menu */ void -rxvt_term::xterm_seq (int op, const char *str, unsigned char resp __attribute__ ((unused))) +rxvt_term::process_xterm_seq (int op, const char *str, unsigned char resp) { - int changed = 0; - int color; - char *buf, *name; + int changed = 0; + int color; + char *buf, *name; + bool query = str[0] == '?' && !str[1]; assert (str != NULL); switch (op) @@ -2953,51 +3238,110 @@ set_title (str); /* FALLTHROUGH */ case XTerm_iconName: - set_iconName (str); + set_icon_name (str); break; case XTerm_title: set_title (str); break; + case XTerm_property: + if (str[0] == '?') + { + Atom prop = XInternAtom (display->display, str + 1, True); + Atom actual_type; + int actual_format; + unsigned long nitems; + unsigned long bytes_after; + unsigned char *value = 0; + const char *str = ""; + + if (prop + && XGetWindowProperty (display->display, TermWin.parent[0], + prop, 0, 1<<16, 0, AnyPropertyType, + &actual_type, &actual_format, + &nitems, &bytes_after, &value) == Success + && actual_type != None + && actual_format == 8) + str = (const char *)(value); + + tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); + + XFree (value); + } + else + { + char *eq = strchr (str, '='); // constness lost, but verified to be ok + + if (eq) + { + *eq = 0; + XChangeProperty (display->display, TermWin.parent[0], + display->atom (str), XA_STRING, 8, + PropModeReplace, (unsigned char *)eq + 1, + strlen (eq + 1)); + } + else + XDeleteProperty (display->display, TermWin.parent[0], + display->atom (str)); + } + break; + case XTerm_Color: for (buf = (char *)str; buf && *buf;) { if ((name = STRCHR (buf, ';')) == NULL) break; + *name++ = '\0'; color = atoi (buf); + if (color < 0 || color >= TOTAL_COLORS) break; + if ((buf = STRCHR (name, ';')) != NULL) *buf++ = '\0'; - set_window_color (color + minCOLOR, name); + + if (name[0] == '?' && !name[1]) + { + if (Options & Opt_insecure) + { + unsigned short r, g, b; + PixColors[color + minCOLOR].get (display, 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 + minCOLOR, name); } break; + case XTerm_Color00: + process_color_seq (XTerm_Color00, Color_fg, str, resp); + break; + case XTerm_Color01: + process_color_seq (XTerm_Color00, Color_bg, str, resp); + break; #ifndef NO_CURSORCOLOR case XTerm_Color_cursor: - set_window_color (Color_cursor, str); + process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); break; #endif - case XTerm_Color_pointer: - set_window_color (Color_pointer, str); + case XTerm_Color_pointer_fg: + process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); + break; + case XTerm_Color_pointer_bg: + process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); break; #ifndef NO_BOLD_UNDERLINE_REVERSE case XTerm_Color_BD: - set_window_color (Color_BD, str); + process_color_seq (XTerm_Color_BD, Color_BD, str, resp); break; case XTerm_Color_UL: - set_window_color (Color_UL, str); + process_color_seq (XTerm_Color_UL, Color_UL, str, resp); break; case XTerm_Color_RV: - set_window_color (Color_RV, str); + process_color_seq (XTerm_Color_RV, Color_RV, str, resp); break; #endif - case XTerm_Menu: - /* - * rxvt_menubar_dispatch () violates the constness of the string, - * so DON'T do it here - */ - break; case XTerm_Pixmap: if (*str != ';') { @@ -3030,15 +3374,32 @@ case XTerm_restoreBG: set_window_color (Color_bg, str); break; + case XTerm_logfile: + // TODO, when secure mode? break; + case XTerm_font: - change_font (str); + if (query) + { + if (Options & Opt_insecure) + tt_printf ("\33]%d;%-.250s%c", XTerm_font, + TermWin.fontset->fontdesc + ? TermWin.fontset->fontdesc + : "", + resp); + } + else + change_font (str); break; + #ifndef NO_FRILLS case XTerm_locale: - if (str[0] == '?' && !str[1]) - tt_printf ("%-.250s\n", locale); + if (query) + { + if (Options & Opt_insecure) + tt_printf ("\33]%d;%-.250s%c", XTerm_locale, locale, resp); + } else { set_locale (str); @@ -3047,17 +3408,27 @@ # endif } break; + case XTerm_findfont: - { - int fid = TermWin.fontset->find_font (atoi (str)); - tt_printf ("%d %-.250s\n", fid, (*TermWin.fontset)[fid]->name); - } + if (Options & Opt_insecure) + { + int fid = TermWin.fontset->find_font (atoi (str)); + tt_printf ("\33]%d;%d;%-.250s%c", XTerm_findfont, + fid, (*TermWin.fontset)[fid]->name, resp); + } break; #endif + +#ifdef MENUBAR + case XTerm_Menu: + if (Options & Opt_insecure) + menubar_dispatch (const_cast(str)); // casting away constness is checked + break; +#endif #if 0 case XTerm_dumpscreen: /* no error notices */ { - int fd; + int fd; if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) { scr_dump (fd); @@ -3066,7 +3437,6 @@ } break; #endif - } } /*----------------------------------------------------------------------*/ @@ -3084,7 +3454,7 @@ int rxvt_term::privcases (int mode, unsigned long bit) { - int state; + int state; if (mode == 's') { @@ -3099,6 +3469,7 @@ state = (mode == 't') ? ! (PrivateModes & bit) : mode; PrivMode (state, bit); } + return state; } @@ -3106,13 +3477,15 @@ void rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) { - unsigned int i, j; - int state; + unsigned int i, j; + int state; + static const struct { const int argval; const unsigned long bit; } + argtopriv[] = { { 1, PrivMode_aplCUR }, { 2, PrivMode_vt52 }, @@ -3152,7 +3525,7 @@ // 1037 send DEL for keypad delete NYI { 1047, PrivMode_Screen }, // 1048 save and restore cursor - { 1049, PrivMode_Screen }, /* xterm extension, not fully implemented */ + { 1049, PrivMode_Screen }, /* xterm extension, clear screen on ti rather than te */ // 1051, 1052, 1060, 1061 keyboard emulation NYI }; @@ -3181,12 +3554,12 @@ switch (arg[i]) { case 1048: /* alternative cursor save */ - case 1049: - if (mode == 0) - scr_cursor (RESTORE); - else if (mode == 1) - scr_cursor (SAVE); - /* FALLTHROUGH */ + if (Options & Opt_secondaryScreen) + if (mode == 0) + scr_cursor (RESTORE); + else if (mode == 1) + scr_cursor (SAVE); + break; } if (state >= 0) @@ -3220,10 +3593,10 @@ case 7: /* autowrap */ scr_autowrap (state); break; - /* case 8: - auto repeat, can't do on a per window basis */ + /* case 8: - auto repeat, can't do on a per window basis */ case 9: /* X10 mouse reporting */ if (state) /* orthogonal */ - PrivateModes &= ~ (PrivMode_MouseX11); + PrivateModes &= ~PrivMode_MouseX11; break; #ifdef menuBar_esc case menuBar_esc: @@ -3244,16 +3617,16 @@ case 25: /* visible/invisible cursor */ scr_cursor_visible (state); break; - /* case 35: - shift keys */ - /* case 40: - 80 <--> 132 mode */ + /* case 35: - shift keys */ + /* case 40: - 80 <--> 132 mode */ case 47: /* secondary screen */ scr_change_screen (state); break; - /* case 66: - application key pad */ - /* case 67: - backspace key */ + /* case 66: - application key pad */ + /* case 67: - backspace key */ case 1000: /* X11 mouse reporting */ if (state) /* orthogonal */ - PrivateModes &= ~ (PrivMode_MouseX10); + PrivateModes &= ~PrivMode_MouseX10; break; #if 0 case 1001: @@ -3271,12 +3644,18 @@ else Options &= ~Opt_scrollTtyKeypress; break; - case 1047: /* secondary screen w/ clearing */ - case 1049: /* better secondary screen w/ clearing, but not fully implemented */ - if (current_screen != PRIMARY) - scr_erase_screen (2); + case 1047: /* secondary screen w/ clearing last */ + if (Options & 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); - /* FALLTHROUGH */ + if (Options & Opt_secondaryScreen) + if (current_screen != PRIMARY) + scr_erase_screen (2); + break; default: break; } @@ -3288,15 +3667,16 @@ void rxvt_term::process_sgr_mode (unsigned int nargs, const int *arg) { - unsigned int i; - short rendset; - int rendstyle; + unsigned int i; + short rendset; + int rendstyle; if (nargs == 0) { scr_rendition (0, ~RS_None); return; } + for (i = 0; i < nargs; i++) { rendset = -1; @@ -3314,12 +3694,19 @@ case 5: rendset = 1, rendstyle = RS_Blink; break; + //case 6: // scoansi light background case 7: rendset = 1, rendstyle = RS_RVid; break; case 8: // invisible. NYI break; + //case 10: // scoansi acs off + //case 11: // scoansi acs on + //case 12: // scoansi acs on, |0x80 + case 21: // disable bold, blink and invis (some terminals use this) + rendset = 0, rendstyle = RS_Bold | RS_Blink; + break; case 22: rendset = 0, rendstyle = RS_Bold; break; @@ -3421,11 +3808,11 @@ } /*}}} */ -/*{{{ process Rob Nation's own graphics mode sequences */ +/*{{{ (do not) process Rob Nation's own graphics mode sequences */ void rxvt_term::process_graphics () { - unsigned char ch, cmd = cmd_getc (); + unicode_t ch, cmd = cmd_getc (); if (cmd == 'Q') { /* query graphics */