--- rxvt-unicode/src/command.C 2005/02/14 10:44:50 1.194 +++ rxvt-unicode/src/command.C 2005/12/31 18:19:06 1.220 @@ -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-2004 Marc Lehmann + * Copyright (c) 2003-2005 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 @@ -119,7 +119,15 @@ XK_Print, 0x2399, XK_space, 0x2423, + +#ifdef XK_KP_Begin + XK_KP_Prior, 0x21de, + XK_KP_Next, 0x21df, + XK_KP_Begin, 0x2320, + XK_KP_Insert, 0x2380, + XK_KP_Delete, 0x2326, XK_KP_Space, 0x2422, +#endif 0, }; @@ -129,38 +137,38 @@ x = Pixel2Col (x); y = Pixel2Row (y); - if (x < 0 || x >= TermWin.ncol - || y < 0 || y >= TermWin.nrow) + if (!IN_RANGE_EXC (x, 0, ncol) + || !IN_RANGE_EXC (y, 0, nrow)) return; for (;;) { - text_t t = screen.text[y + TermWin.saveLines - TermWin.view_start][x]; + const line_t &l = ROW(y - view_start); + + text_t t = l.t[x]; if (t != NOCHAR || !x) { - iso14755_51 (screen.text[y + TermWin.saveLines - TermWin.view_start][x], - screen.rend[y + TermWin.saveLines - TermWin.view_start][x]); + iso14755_51 (l.t[x], l.r[x], x, y); iso14755buf = ISO_14755_54; break; } x--; } - } -#endif -#if ENABLE_OVERLAY void -rxvt_term::iso14755_51 (unicode_t ch, rend_t r) +rxvt_term::iso14755_51 (unicode_t ch, rend_t r, int x, int y) { rxvt_fontset *fs = FONTSET (r); rxvt_font *f = (*fs)[fs->find_font (ch)]; - wchar_t *chr, *alloc, ch2; + wchar_t *chr, *alloc, ch2, *fname; int len; -#if ENABLE_COMBINING + fname = rxvt_utf8towcs (f->name); + +# if ENABLE_COMBINING if (IS_COMPOSE (ch)) { len = rxvt_composite.expand (ch, 0); @@ -168,7 +176,7 @@ rxvt_composite.expand (ch, chr); } else -#endif +# endif { ch2 = ch; @@ -177,9 +185,30 @@ len = 1; } - int width = strlen (f->name); + char attr[80]; // plenty + + sprintf (attr, "%08x = fg %d bg %d%s%s%s%s%s%s", + (int)r, + fgcolor_of (r), bgcolor_of (r), + r & RS_Bold ? " bold" : "", + r & RS_Italic ? " italic" : "", + r & RS_Blink ? " blink" : "", + r & RS_RVid ? " rvid" : "", + r & RS_Uline ? " uline" : "", + r & RS_Careful ? " careful" : ""); - scr_overlay_new (0, -1, width < 8+5 ? 8+5 : width, len + 1); + int width = wcswidth (fname, wcslen (fname)); + + max_it (width, 8+5); // for char + hey + max_it (width, strlen (attr)); + + if (y >= 0) + { + y = (y >= nrow - len - 4 && x < width + 2) ? 0 : -1; + x = 0; + } + + scr_overlay_new (x, y, width, len + 2); r = SET_STYLE (OVERLAY_RSTYLE, GET_STYLE (r)); @@ -192,20 +221,23 @@ sprintf (buf, "%8x", ch); scr_overlay_set (0, y, buf); scr_overlay_set (9, y, '='); -#if !UNICODE3 +# if !UNICODE3 if (ch >= 0x10000) ch = 0xfffd; -#endif +# endif scr_overlay_set (11, y, ch, r); scr_overlay_set (12, y, NOCHAR, r); } - scr_overlay_set (0, len, f->name); + scr_overlay_set (0, len , attr); + scr_overlay_set (0, len + 1, fname); + + free (fname); -#if ENABLE_COMBINING +# if ENABLE_COMBINING if (alloc) delete [] alloc; -#endif +# endif } #endif @@ -278,9 +310,9 @@ * * Always permit `shift' to override the current setting */ - shft = (ev.state & ShiftMask); - ctrl = (ev.state & ControlMask); - meta = (ev.state & ModMetaMask); + shft = ev.state & ShiftMask; + ctrl = ev.state & ControlMask; + meta = ev.state & ModMetaMask; if (numlock_state || (ev.state & ModNumLockMask)) { @@ -310,9 +342,11 @@ // at the point of XOpenIM, so temporarily switch locales if (rs[Rs_imLocale]) SET_LOCALE (rs[Rs_imLocale]); + // assume wchar_t == unicode or better len = XwcLookupString (Input_Context, &ev, wkbuf, KBUFSZ, &keysym, &status_return); + if (rs[Rs_imLocale]) SET_LOCALE (locale); @@ -354,7 +388,7 @@ return; #endif - if (TermWin.saveLines) + if (saveLines) { #ifdef UNSHIFTED_SCROLLKEYS if (!ctrl && !meta) @@ -365,9 +399,9 @@ int lnsppg; #ifdef PAGING_CONTEXT_LINES - lnsppg = TermWin.nrow - PAGING_CONTEXT_LINES; + lnsppg = nrow - PAGING_CONTEXT_LINES; #else - lnsppg = TermWin.nrow * 4 / 5; + lnsppg = nrow * 4 / 5; #endif if (keysym == XK_Prior) { @@ -514,6 +548,16 @@ break; #endif #ifndef NO_DELETE_KEY +# ifdef XK_KP_Prior + 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, key_delete); break; @@ -626,13 +670,6 @@ strcpy (kbuf, "\033Ou"); break; - case XK_KP_Insert: - strcpy (kbuf, "\033Op"); - break; - - case XK_KP_Delete: - strcpy (kbuf, "\033On"); - break; #endif case XK_KP_F1: /* "\033OP" */ case XK_KP_F2: /* "\033OQ" */ @@ -674,6 +711,17 @@ case XK_Find: strcpy (kbuf, "\033[1~"); break; + +#ifdef XK_KP_End + 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; @@ -818,10 +866,10 @@ if (len <= 0) return; /* not mapped */ - if (options & Opt_scrollTtyKeypress) - if (TermWin.view_start) + if (OPTION (Opt_scrollTtyKeypress)) + if (view_start) { - TermWin.view_start = 0; + view_start = 0; want_refresh = 1; } @@ -1008,8 +1056,8 @@ || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) : scr_page (UP, mouse_slip_wheel_speed)) { - if (TermWin.view_start == TermWin.nscrolled || - TermWin.view_start == 0) + if (view_start == nsaved || + view_start == 0) mouse_slip_wheel_speed = 0; refresh_type |= SMOOTH_REFRESH; @@ -1041,8 +1089,13 @@ cmdbuf_endp += n; return true; } - else if (n < 0 && errno != EAGAIN) - destroy (); + else if ((n < 0 && errno != EAGAIN && errno != EINTR) || n == 0) + { + pty_ev.stop (); + + if (!OPTION (Opt_hold)) + destroy (); + } return false; } @@ -1066,13 +1119,13 @@ void rxvt_term::pointer_unblank () { - XDefineCursor (display->display, TermWin.vt, TermWin_cursor); + XDefineCursor (display->display, vt, TermWin_cursor); recolour_cursor (); #ifdef POINTER_BLANK hidden_pointer = 0; - if (options & Opt_pointerBlank) + if (OPTION (Opt_pointerBlank)) pointer_ev.start (NOW + pointerBlankDelay); #endif } @@ -1081,10 +1134,10 @@ void rxvt_term::pointer_blank () { - if (! (options & Opt_pointerBlank)) + if (! OPTION (Opt_pointerBlank)) return; - XDefineCursor (display->display, TermWin.vt, display->blank_cursor); + XDefineCursor (display->display, vt, display->blank_cursor); XFlush (display->display); hidden_pointer = 1; @@ -1189,7 +1242,7 @@ SET_LOCALE (locale); #if defined(CURSOR_BLINK) - if ((options & Opt_cursorBlink) && ev.type == KeyPress) + if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) { if (hidden_cursor) { @@ -1202,7 +1255,7 @@ #endif #if defined(POINTER_BLANK) - if ((options & Opt_pointerBlank) && pointerBlankDelay > 0) + if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) { if (ev.type == MotionNotify || ev.type == ButtonPress @@ -1310,14 +1363,32 @@ case ClientMessage: if (ev.xclient.format == 32 - && (Atom)ev.xclient.data.l[0] == xa[XA_WMDELETEWINDOW]) - destroy (); + && ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) + { + if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) + destroy (); +#if ENABLE_EWMH + else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) + XSendEvent (disp, ev.xclient.window = display->root, + False, SubstructureRedirectMask | SubstructureNotifyMask, + &ev); +#endif + } +#if ENABLE_XEMBED + else if (ev.xclient.format == 32 && ev.xclient.message_type == xa[XA_XEMBED]) + { + if (ev.xclient.data.l[1] == XEMBED_FOCUS_IN) + focus_in (); + else if (ev.xclient.data.l[1] == XEMBED_FOCUS_OUT) + focus_out (); + } +#endif #ifdef OFFIX_DND /* OffiX Dnd (drag 'n' drop) protocol */ - else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL] - && (ev.xclient.data.l[0] == DndFile - || ev.xclient.data.l[0] == DndDir - || ev.xclient.data.l[0] == DndLink)) + else if (ev.xclient.message_type == xa[XA_DNDPROTOCOL] + && (ev.xclient.data.l[0] == DndFile + || ev.xclient.data.l[0] == DndDir + || ev.xclient.data.l[0] == DndLink)) { /* Get Dnd data */ Atom ActualType; @@ -1370,84 +1441,27 @@ break; case FocusIn: - if (!TermWin.focus) - { - TermWin.focus = 1; - want_refresh = 1; -#ifdef USE_XIM - if (Input_Context != NULL) - { - IMSetStatusPosition (); - XSetICFocus (Input_Context); - } -#endif -#ifdef CURSOR_BLINK - if (options & Opt_cursorBlink) - cursor_blink_ev.start (NOW + BLINK_INTERVAL); -#endif -#ifdef OFF_FOCUS_FADING - if (rs[Rs_fade]) - { - pix_colors = pix_colors_focused; - scr_recolour (); - } -#endif - - } + focus_in (); break; case FocusOut: - if (TermWin.focus) - { - TermWin.focus = 0; - want_refresh = 1; - -#if ENABLE_FRILLS || ISO_14755 - iso14755buf = 0; -#endif -#if ENABLE_OVERLAY - scr_overlay_off (); -#endif -#ifdef USE_XIM - if (Input_Context != NULL) - XUnsetICFocus (Input_Context); -#endif -#ifdef CURSOR_BLINK - if (options & Opt_cursorBlink) - cursor_blink_ev.stop (); - hidden_cursor = 0; -#endif -#ifdef OFF_FOCUS_FADING - if (rs[Rs_fade]) - { - pix_colors = pix_colors_unfocused; - scr_recolour (); - } -#endif - } + focus_out (); break; case ConfigureNotify: - if (ev.xconfigure.window == TermWin.parent[0]) + if (ev.xconfigure.window == parent[0]) { - int height, width; - - do - { /* Wrap lots of configures into one */ - width = ev.xconfigure.width; - height = ev.xconfigure.height; - D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height)); - } - while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)); + while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)) + ; - if (szHint.width != width || szHint.height != height) + if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) { seen_resize = 1; - resize_all_windows (width, height, 1); + resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); } #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ - if (options & Opt_transparent) + if (OPTION (Opt_transparent)) check_our_parents (); #endif } @@ -1474,14 +1488,14 @@ break; case UnmapNotify: - TermWin.mapped = 0; + mapped = 0; #ifdef TEXT_BLINK text_blink_ev.stop (); #endif break; case MapNotify: - TermWin.mapped = 1; + mapped = 1; #ifdef TEXT_BLINK text_blink_ev.start (NOW + TEXT_BLINK_INTERVAL); #endif @@ -1495,16 +1509,16 @@ case GraphicsExpose: case Expose: - if (ev.xany.window == TermWin.vt) + if (ev.xany.window == vt) { do scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); - while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)); + while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)); ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; - while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)) + while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)) scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); @@ -1530,7 +1544,7 @@ #endif #ifdef TRANSPARENT - if (am_transparent && ev.xany.window == TermWin.parent[0]) + if (am_transparent && ev.xany.window == parent[0]) XClearWindow (disp, ev.xany.window); #endif } @@ -1551,14 +1565,14 @@ if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) break; - if (ev.xany.window == TermWin.vt) + if (ev.xany.window == vt) { if (ev.xbutton.state & (Button1Mask | Button3Mask)) { - while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev)) + while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev)) ; - XQueryPointer (disp, TermWin.vt, + XQueryPointer (disp, vt, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, @@ -1580,8 +1594,8 @@ ev.xbutton.state & Button3Mask ? 2 : 0); #ifdef SELECTION_SCROLLING - if (ev.xbutton.y < TermWin.int_bwidth - || Pixel2Row (ev.xbutton.y) > (TermWin.nrow-1)) + if (ev.xbutton.y < int_bwidth + || Pixel2Row (ev.xbutton.y) > (nrow-1)) { int dist; @@ -1599,21 +1613,21 @@ selection_save_state = (ev.xbutton.state & Button3Mask) ? 2 : 0; /* calc number of lines to scroll */ - if (ev.xbutton.y < TermWin.int_bwidth) + if (ev.xbutton.y < int_bwidth) { scroll_selection_dir = UP; - dist = TermWin.int_bwidth - ev.xbutton.y; + dist = int_bwidth - ev.xbutton.y; } else { scroll_selection_dir = DN; - dist = ev.xbutton.y - (TermWin.int_bwidth + TermWin.height); + dist = ev.xbutton.y - (int_bwidth + height); } scroll_selection_lines = Pixel2Height (dist) / SELECTION_SCROLL_LINE_SPEEDUP + 1; - MIN_IT (scroll_selection_lines, + min_it (scroll_selection_lines, SELECTION_SCROLL_MAX_LINES); } else @@ -1651,6 +1665,67 @@ } } +void +rxvt_term::focus_in () +{ + if (!focus) + { + focus = 1; + want_refresh = 1; +#if USE_XIM + if (Input_Context != NULL) + { + IMSetStatusPosition (); + XSetICFocus (Input_Context); + } +#endif +#if CURSOR_BLINK + if (OPTION (Opt_cursorBlink)) + cursor_blink_ev.start (NOW + BLINK_INTERVAL); +#endif +#if OFF_FOCUS_FADING + if (rs[Rs_fade]) + { + pix_colors = pix_colors_focused; + scr_recolour (); + } +#endif + } +} + +void +rxvt_term::focus_out () +{ + if (focus) + { + focus = 0; + want_refresh = 1; + +#if ENABLE_FRILLS || ISO_14755 + iso14755buf = 0; +#endif +#if ENABLE_OVERLAY + scr_overlay_off (); +#endif +#if USE_XIM + if (Input_Context != NULL) + XUnsetICFocus (Input_Context); +#endif +#if CURSOR_BLINK + if (OPTION (Opt_cursorBlink)) + cursor_blink_ev.stop (); + hidden_cursor = 0; +#endif +#if OFF_FOCUS_FADING + if (rs[Rs_fade]) + { + pix_colors = pix_colors_unfocused; + scr_recolour (); + } +#endif + } +} + #if TRANSPARENT void rxvt_term::rootwin_cb (XEvent &ev) @@ -1671,7 +1746,7 @@ /* FALLTHROUGH */ case ReparentNotify: - if ((options & Opt_transparent) && check_our_parents () && am_transparent) + if (OPTION (Opt_transparent) && check_our_parents () && am_transparent) want_refresh = want_full_refresh = 1; break; } @@ -1690,7 +1765,7 @@ /* * VT window processing of button press */ - if (ev.window == TermWin.vt) + if (ev.window == vt) { #if ISO_14755 // 5.4 @@ -1905,15 +1980,15 @@ { if (scrollbar_above_slider (ev.y)) # ifdef RXVT_SCROLL_FULL - scr_page (UP, TermWin.nrow - 1); + scr_page (UP, nrow - 1); # else - scr_page (UP, TermWin.nrow / 4); + scr_page (UP, nrow / 4); # endif else if (scrollbar_below_slider (ev.y)) # ifdef RXVT_SCROLL_FULL - scr_page (DN, TermWin.nrow - 1); + scr_page (DN, nrow - 1); # else - scr_page (DN, TermWin.nrow / 4); + scr_page (DN, nrow / 4); # endif else scrollBar.setMotion (); @@ -1921,7 +1996,7 @@ else { scr_page ((ev.button == Button1 ? DN : UP), - (TermWin.nrow + (nrow * scrollbar_position (ev.y) / scrollbar_size ())); } @@ -1963,7 +2038,7 @@ sel_scroll_ev.stop(); #endif - if (ev.window == TermWin.vt) + if (ev.window == vt) { #if ISO_14755 // 5.4 @@ -2023,8 +2098,8 @@ if (ev.state & ShiftMask) i = 1; - else if (options & Opt_mouseWheelScrollPage) - i = TermWin.nrow - 1; + else if (OPTION (Opt_mouseWheelScrollPage)) + i = nrow - 1; else i = 5; @@ -2032,8 +2107,8 @@ if (ev.state & ControlMask) { mouse_slip_wheel_speed += v ? -1 : 1; - if (mouse_slip_wheel_speed < -TermWin.nrow) mouse_slip_wheel_speed = -TermWin.nrow; - if (mouse_slip_wheel_speed > +TermWin.nrow) mouse_slip_wheel_speed = +TermWin.nrow; + 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; @@ -2319,20 +2394,20 @@ pchanged = 0; - if (!(options & Opt_transparent)) + if (!OPTION (Opt_transparent)) return pchanged; /* Don't try any more */ XGetWindowAttributes (disp, display->root, &wrootattr); rootdepth = wrootattr.depth; - XGetWindowAttributes (disp, TermWin.parent[0], &wattr); + XGetWindowAttributes (disp, parent[0], &wattr); if (rootdepth != wattr.depth) { if (am_transparent) { pchanged = 1; - XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]); + XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]); am_transparent = am_pixmap_trans = 0; } @@ -2383,7 +2458,7 @@ GC gc; XGCValues gcvalue; - XTranslateCoordinates (disp, TermWin.parent[0], display->root, + XTranslateCoordinates (disp, parent[0], display->root, 0, 0, &sx, &sy, &cr); nw = (unsigned int)szHint.width; nh = (unsigned int)szHint.height; @@ -2403,8 +2478,8 @@ sy = 0; } - MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); - MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); + min_it (nw, (unsigned int) (wrootattr.width - sx)); + min_it (nh, (unsigned int) (wrootattr.height - sy)); XSync (disp, False); allowedxerror = -1; @@ -2419,10 +2494,10 @@ if (am_transparent && am_pixmap_trans) { pchanged = 1; - if (TermWin.pixmap != None) + if (pixmap != None) { - XFreePixmap (disp, TermWin.pixmap); - TermWin.pixmap = None; + XFreePixmap (disp, pixmap); + pixmap = None; } } @@ -2430,8 +2505,8 @@ } else { - if (TermWin.pixmap != None) - XFreePixmap (disp, TermWin.pixmap); + if (pixmap != None) + XFreePixmap (disp, pixmap); #if TINTING if (ISSET_PIXCOLOR (Color_tint)) @@ -2445,15 +2520,15 @@ } #endif - TermWin.pixmap = XCreatePixmap (disp, TermWin.vt, + pixmap = XCreatePixmap (disp, vt, szHint.width, szHint.height, image->depth); - gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue); - XPutImage (disp, TermWin.pixmap, gc, image, 0, 0, + gc = XCreateGC (disp, vt, 0UL, &gcvalue); + XPutImage (disp, pixmap, gc, image, 0, 0, nx, ny, image->width, image->height); XFreeGC (disp, gc); XDestroyImage (image); - XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap); - XClearWindow (disp, TermWin.parent[0]); + XSetWindowBackgroundPixmap (disp, parent[0], pixmap); + XClearWindow (disp, parent[0]); if (!am_transparent || !am_pixmap_trans) pchanged = 1; @@ -2463,21 +2538,21 @@ } if (am_pixmap_trans) - XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative); + XSetWindowBackgroundPixmap (disp, vt, ParentRelative); else { unsigned int n; /* * InheritPixmap transparency */ - for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) + for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) { - oldp = TermWin.parent[i]; - XQueryTree (disp, TermWin.parent[i - 1], &root, - &TermWin.parent[i], &list, &n); + oldp = parent[i]; + XQueryTree (disp, parent[i - 1], &root, + &parent[i], &list, &n); XFree (list); - if (TermWin.parent[i] == display->root) + if (parent[i] == display->root) { if (oldp != None) pchanged = 1; @@ -2485,7 +2560,7 @@ break; } - if (oldp != TermWin.parent[i]) + if (oldp != parent[i]) pchanged = 1; } @@ -2495,19 +2570,19 @@ { for (; n < (unsigned int)i; n++) { - XGetWindowAttributes (disp, TermWin.parent[n], &wattr); + XGetWindowAttributes (disp, parent[n], &wattr); if (wattr.depth != rootdepth || wattr.c_class == InputOnly) { - n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; + n = (int) (sizeof (parent) / sizeof (Window)) + 1; break; } } } - if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) + if (n > (int) (sizeof (parent) / sizeof (parent[0]))) { - XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]); - XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]); + XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]); + XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]); am_transparent = 0; /* XXX: also turn off Opt_transparent? */ } @@ -2520,16 +2595,16 @@ #endif for (n = 0; n < (unsigned int)i; n++) { - XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative); - XClearWindow (disp, TermWin.parent[n]); + XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative); + XClearWindow (disp, parent[n]); } - XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative); + XSetWindowBackgroundPixmap (disp, vt, ParentRelative); am_transparent = 1; } - for (; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) - TermWin.parent[i] = None; + for (; i < (int) (sizeof (parent) / sizeof (Window)); i++) + parent[i] = None; } if (scrollBar.win) @@ -2582,7 +2657,7 @@ // unfortunately other programs are even more buggy and dislike // being sent SIGWINCH, so only do it when we were in fact being // resized. - if (seen_resize) + if (seen_resize && cmd_pid) kill (-cmd_pid, SIGWINCH); } @@ -2591,6 +2666,7 @@ bool refreshnow = false; int nlines = 0; unicode_t *str = buf; + unicode_t *eol = str + min (ncol, UBUFSIZ); for (;;) { @@ -2599,32 +2675,41 @@ *str++ = ch; - if (ch == C0_LF) + if (ch == C0_LF || str >= eol) { - nlines++; + if (ch == C0_LF) + nlines++; + refresh_count++; - if (!(options & Opt_jumpScroll) - || (refresh_count >= refresh_limit * (TermWin.nrow - 1))) + if (!OPTION (Opt_jumpScroll) + || (refresh_count >= refresh_limit * (nrow - 1))) { refreshnow = true; ch = NOCHAR; break; } - // scr_add_lines only works for nlines <= TermWin.nrow - 1. - if (nlines >= TermWin.nrow - 1) + // scr_add_lines only works for nlines <= nrow - 1. + if (nlines >= nrow - 1) { scr_add_lines (buf, nlines, str - buf); nlines = 0; str = buf; + eol = str + min (ncol, UBUFSIZ); + } + + if (str >= eol) + { + if (eol >= buf + UBUFSIZ) + { + ch = NOCHAR; + break; + } + else + eol = min (eol + ncol, buf + UBUFSIZ); } - } - if (str >= buf + UBUFSIZ) - { - ch = NOCHAR; - break; } seq_begin = cmdbuf_ptr; @@ -2641,7 +2726,7 @@ */ if (refreshnow) { - if ((options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) + if (OPTION (Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD) refresh_limit++; else { @@ -3293,7 +3378,7 @@ arg[0] = -arg[0]; /* FALLTHROUGH */ case CSI_SU: /* 8.3.148: (1) SCROLL UP */ - scr_scroll_text (screen.tscroll, screen.bscroll, arg[0], 0); + scr_scroll_text (screen.tscroll, screen.bscroll, arg[0]); break; case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ @@ -3315,7 +3400,7 @@ scr_report_position (); break; case 7: /* unofficial extension */ - if (options & Opt_insecure) + if (OPTION (Opt_insecure)) tt_printf ("%-.250s\012", rs[Rs_display_name]); break; case 8: /* unofficial extension */ @@ -3428,36 +3513,36 @@ * commands */ case 1: /* deiconify window */ - XMapWindow (disp, TermWin.parent[0]); + XMapWindow (disp, parent[0]); break; case 2: /* iconify window */ - XIconifyWindow (disp, TermWin.parent[0], display->screen); + XIconifyWindow (disp, parent[0], display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (disp, TermWin.parent[0], args[1], args[2]); + XMoveWindow (disp, parent[0], 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 (disp, TermWin.parent[0]); + XRaiseWindow (disp, parent[0]); break; case 6: /* lower window */ - XLowerWindow (disp, TermWin.parent[0]); + XLowerWindow (disp, parent[0]); break; case 7: /* refresh window */ scr_touch (true); break; case 8: /* set size (chars) */ - set_widthheight ((unsigned int) (args[2] * TermWin.fwidth), - (unsigned int) (args[1] * TermWin.fheight)); + set_widthheight ((unsigned int) (args[2] * fwidth), + (unsigned int) (args[1] * 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)); + set_widthheight ((unsigned int)width, + (unsigned int) (args[1] * fheight)); break; @@ -3465,39 +3550,39 @@ * reports - some output format copied from XTerm */ case 11: /* report window state */ - XGetWindowAttributes (disp, TermWin.parent[0], &wattr); + XGetWindowAttributes (disp, parent[0], &wattr); tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); break; case 13: /* report window position */ - XGetWindowAttributes (disp, TermWin.parent[0], &wattr); - XTranslateCoordinates (disp, TermWin.parent[0], wattr.root, + XGetWindowAttributes (disp, parent[0], &wattr); + XTranslateCoordinates (disp, parent[0], 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 (disp, TermWin.parent[0], &wattr); + XGetWindowAttributes (disp, parent[0], &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; case 18: /* report text area size (chars) */ - tt_printf ("\033[8;%d;%dt", TermWin.nrow, TermWin.ncol); + tt_printf ("\033[8;%d;%dt", nrow, ncol); break; case 19: /* report window size (chars) */ - tt_printf ("\033[9;%d;%dt", TermWin.nrow, TermWin.ncol); + tt_printf ("\033[9;%d;%dt", nrow, ncol); break; case 20: /* report icon label */ { char *s; - XGetIconName (disp, TermWin.parent[0], &s); - tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ + XGetIconName (disp, parent[0], &s); + tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } break; case 21: /* report window title */ { char *s; - XFetchName (disp, TermWin.parent[0], &s); - tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ + XFetchName (disp, parent[0], &s); + tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } break; @@ -3539,7 +3624,7 @@ seen_esc = false; - if (n >= sizeof (string) - 1) + if (n >= STRING_MAX - 1) // stop at some sane length return NULL; @@ -3617,28 +3702,6 @@ /* * 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 - * 18 = change bold character color - * 19 = change underlined character color - * 46 = change logfile (not implemented) - * 50 = change font - * - * rxvt extensions: - * 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::process_xterm_seq (int op, const char *str, unsigned char resp) @@ -3674,7 +3737,7 @@ const char *str = ""; if (prop - && XGetWindowProperty (disp, TermWin.parent[0], + && XGetWindowProperty (disp, parent[0], prop, 0, 1<<16, 0, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &value) == Success @@ -3696,7 +3759,7 @@ set_utf8_property (display->atom (str), eq + 1); } else - XDeleteProperty (disp, TermWin.parent[0], + XDeleteProperty (disp, parent[0], display->atom (str)); } break; @@ -3747,19 +3810,19 @@ case XTerm_Color_BD: process_color_seq (XTerm_Color_BD, Color_BD, str, resp); break; - case XTerm_Color_IT: - process_color_seq (XTerm_Color_IT, Color_IT, str, resp); - break; case XTerm_Color_UL: process_color_seq (XTerm_Color_UL, Color_UL, str, resp); break; case XTerm_Color_RV: process_color_seq (XTerm_Color_RV, Color_RV, str, resp); break; + case URxvt_Color_IT: + process_color_seq (URxvt_Color_IT, Color_IT, str, resp); + break; #endif #if TRANSPARENT && TINTING - case XTerm_Color_tint: - process_color_seq (XTerm_Color_tint, Color_tint, str, resp); + case URxvt_Color_tint: + process_color_seq (URxvt_Color_tint, Color_tint, str, resp); check_our_parents (); if (am_transparent) want_full_refresh = want_refresh = 1; @@ -3803,6 +3866,24 @@ // TODO, when secure mode? break; +#ifdef MENUBAR + case URxvt_Menu: + if (OPTION (Opt_insecure)) + menubar_dispatch (const_cast(str)); // casting away constness is checked + break; +#endif +#if 0 + case XTerm_dumpscreen: /* no error notices */ + { + int fd; + if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) + { + scr_dump (fd); + close (fd); + } + } + break; +#endif case XTerm_font: op = URxvt_font; case URxvt_font: @@ -3813,8 +3894,8 @@ #endif if (query) tt_printf ("\33]%d;%-.250s%c", saveop, - (options & Opt_insecure) && TermWin.fontset[op - URxvt_font]->fontdesc - ? TermWin.fontset[op - URxvt_font]->fontdesc : "", + OPTION (Opt_insecure) && fontset[op - URxvt_font]->fontdesc + ? fontset[op - URxvt_font]->fontdesc : "", resp); else { @@ -3827,36 +3908,28 @@ break; #if ENABLE_FRILLS - case XTerm_locale: + case URxvt_locale: if (query) - tt_printf ("\33]%d;%-.250s%c", XTerm_locale, (options & Opt_insecure) ? locale : "", resp); + tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp); else { set_locale (str); pty.set_utf8_mode (enc_utf8); -# ifdef USE_XIM - im_cb (); -# endif + init_xlocale (); } 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; - if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) - { - scr_dump (fd); - close (fd); - } - } + case URxvt_view_up: + case URxvt_view_down: + int lines = atoi (str); + + if (lines) + scr_page (op == URxvt_view_up ? UP : DN, lines); + else + { + scr_erase_savelines (); + } + break; #endif } @@ -3975,9 +4048,16 @@ /* extra handling for values with state unkept */ switch (arg[i]) { +#if ENABLE_STYLES + case 1021: + if (mode) + SET_OPTION (Opt_intensityStyles); + else + CLR_OPTION (Opt_intensityStyles); +#endif case 1048: /* alternative cursor save */ case 1049: - if (options & Opt_secondaryScreen) + if (OPTION (Opt_secondaryScreen)) if (mode == 0) scr_cursor (RESTORE); else if (mode == 1) @@ -3999,13 +4079,13 @@ break; case 3: /* 80/132 */ if (priv_modes & PrivMode_132OK) - set_widthheight (((state ? 132 : 80) * TermWin.fwidth), TermWin.height); + set_widthheight (((state ? 132 : 80) * fwidth), height); break; case 4: /* smooth scrolling */ - if (state) - options &= ~Opt_jumpScroll; + if (!state) + SET_OPTION (Opt_jumpScroll); else - options |= Opt_jumpScroll; + CLR_OPTION (Opt_jumpScroll); break; case 5: /* reverse video */ scr_rvideo_mode (state); @@ -4056,26 +4136,26 @@ break; /* X11 mouse highlighting */ #endif case 1010: /* scroll to bottom on TTY output inhibit */ - if (state) - options &= ~Opt_scrollTtyOutput; + if (!state) + SET_OPTION (Opt_scrollTtyOutput); else - options |= Opt_scrollTtyOutput; + CLR_OPTION (Opt_scrollTtyOutput); break; case 1011: /* scroll to bottom on key press */ if (state) - options |= Opt_scrollTtyKeypress; + SET_OPTION (Opt_scrollTtyKeypress); else - options &= ~Opt_scrollTtyKeypress; + CLR_OPTION (Opt_scrollTtyKeypress); break; case 1047: /* secondary screen w/ clearing last */ - if (options & Opt_secondaryScreen) + if (OPTION (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); - if (options & Opt_secondaryScreen) + if (OPTION (Opt_secondaryScreen)) if (current_screen != PRIMARY) scr_erase_screen (2); break; @@ -4326,8 +4406,7 @@ memmove (v_buffer, v_buffer + written, v_buflen); } else if (written != -1 || (errno != EAGAIN && errno != EINTR)) - // original code just ignores this... - destroy (); + pty_ev.set (EVENT_READ); } /*----------------------- end-of-file (C source) -----------------------*/