--- rxvt-unicode/src/command.C 2004/12/11 17:18:29 1.175 +++ rxvt-unicode/src/command.C 2005/02/04 11:41:23 1.192 @@ -50,8 +50,12 @@ #include "version.h" #include "command.h" -#include -#include +#ifdef KEYSYM_RESOURCE +# include "keyboard.h" +#endif + +#include +#include /*----------------------------------------------------------------------*/ @@ -346,6 +350,11 @@ if (valid_keysym) { +#ifdef KEYSYM_RESOURCE + if (keyboard->dispatch (this, keysym, ev.state)) + return; +#endif + if (TermWin.saveLines) { #ifdef UNSHIFTED_SCROLLKEYS @@ -489,31 +498,6 @@ if (keysym >= 0xFF00 && keysym <= 0xFFFF) { -#ifdef KEYSYM_RESOURCE - if (! (shft | ctrl) && Keysym_map[keysym & 0xFF] != NULL) - { - unsigned int l; - const unsigned char *kbuf0; - - kbuf0 = (Keysym_map[keysym & 0xFF]); - l = (unsigned int)*kbuf0++; - - /* escape prefix */ - if (meta -# ifdef META8_OPTION - && meta_char == C0_ESC -# endif - ) - { - const unsigned char ch = C0_ESC; - tt_write (&ch, 1); - } - - tt_write (kbuf0, l); - return; - } - else -#endif { newlen = 1; switch (keysym) @@ -790,6 +774,7 @@ newlen = 0; break; } + if (newlen) len = strlen (kbuf); } @@ -808,6 +793,11 @@ len = 1; kbuf[0] = '\037'; /* Ctrl-Minus generates ^_ (31) */ } + else if (keysym == XK_ISO_Left_Tab) + { + strcpy (kbuf, "\033[Z"); + len = 3; + } else { #ifdef META8_OPTION @@ -875,7 +865,7 @@ } /*}}} */ -#if (MENUBAR_MAX) +#if MENUBAR_MAX || defined (KEYSYM_RESOURCE) /*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ /* attempt to `write' count to the input buffer */ unsigned int @@ -908,7 +898,7 @@ return 0; } -#endif /* MENUBAR_MAX */ +#endif void rxvt_term::flush () @@ -1019,6 +1009,10 @@ || 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) + mouse_slip_wheel_speed = 0; + refresh_type |= SMOOTH_REFRESH; want_refresh = 1; w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); @@ -1060,13 +1054,14 @@ SET_R (this); SET_LOCALE (locale); - if (revents & EVENT_WRITE) - tt_write (0, 0); - else if (revents & EVENT_READ) + if (revents & EVENT_READ) // loop, but don't allow a single term to monopolize us while (pty_fill ()) if (cmd_parse ()) break; + + if (revents & EVENT_WRITE) + pty_write (); } void @@ -1090,7 +1085,7 @@ if (! (options & Opt_pointerBlank)) return; - XDefineCursor (display->display, TermWin.vt, blank_cursor); + XDefineCursor (display->display, TermWin.vt, display->blank_cursor); XFlush (display->display); hidden_pointer = 1; @@ -1189,6 +1184,8 @@ void rxvt_term::x_cb (XEvent &ev) { + dDisp; + SET_R (this); SET_LOCALE (locale); @@ -1329,17 +1326,17 @@ unsigned char *data; unsigned long Size, RemainingBytes; - XGetWindowProperty (display->display, display->root, - xa[XA_DNDSELECTION], - 0L, 1000000L, - False, AnyPropertyType, - &ActualType, &ActualFormat, - &Size, &RemainingBytes, - &data); + XGetWindowProperty (disp, display->root, + xa[XA_DNDSELECTION], + 0L, 1000000L, + False, AnyPropertyType, + &ActualType, &ActualFormat, + &Size, &RemainingBytes, + &data); set_string_property (XA_CUT_BUFFER0, data); XFree (data); - selection_paste (display->root, XA_CUT_BUFFER0, True); - XSetInputFocus (display->display, display->root, RevertToNone, CurrentTime); + selection_paste (display->root, XA_CUT_BUFFER0, true); + XSetInputFocus (disp, display->root, RevertToNone, CurrentTime); } #endif /* OFFIX_DND */ break; @@ -1442,7 +1439,7 @@ height = ev.xconfigure.height; D_SIZE ((stderr, "Size: ConfigureNotify: %4d x %4d", width, height)); } - while (XCheckTypedWindowEvent (display->display, ev.xconfigure.window, ConfigureNotify, &ev)); + while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)); if (szHint.width != width || szHint.height != height) { @@ -1470,8 +1467,7 @@ case SelectionNotify: if (selection_wait == Sel_normal) - selection_paste (ev.xselection.requestor, - ev.xselection.property, True); + selection_paste (ev.xselection.requestor, ev.xselection.property, true); break; case SelectionRequest: @@ -1505,11 +1501,11 @@ do scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); - while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)); + while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)); ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; - while (XCheckTypedWindowEvent (display->display, TermWin.vt, ev.xany.type, &ev)) + while (XCheckTypedWindowEvent (disp, TermWin.vt, ev.xany.type, &ev)) scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); @@ -1519,9 +1515,9 @@ { XEvent unused_event; - while (XCheckTypedWindowEvent (display->display, ev.xany.window, Expose, &unused_event)) + while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) ; - while (XCheckTypedWindowEvent (display->display, ev.xany.window, GraphicsExpose, &unused_event)) + while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) ; if (isScrollbarWindow (ev.xany.window)) @@ -1536,7 +1532,7 @@ #ifdef TRANSPARENT if (am_transparent && ev.xany.window == TermWin.parent[0]) - XClearWindow (display->display, ev.xany.window); + XClearWindow (disp, ev.xany.window); #endif } break; @@ -1560,10 +1556,10 @@ { if (ev.xbutton.state & (Button1Mask | Button3Mask)) { - while (XCheckTypedWindowEvent (display->display, TermWin.vt, MotionNotify, &ev)) + while (XCheckTypedWindowEvent (disp, TermWin.vt, MotionNotify, &ev)) ; - XQueryPointer (display->display, TermWin.vt, + XQueryPointer (disp, TermWin.vt, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, @@ -1637,11 +1633,11 @@ } else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) { - while (XCheckTypedWindowEvent (display->display, scrollBar.win, + while (XCheckTypedWindowEvent (disp, scrollBar.win, MotionNotify, &ev)) ; - XQueryPointer (display->display, scrollBar.win, + XQueryPointer (disp, scrollBar.win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, @@ -1670,10 +1666,8 @@ * if user used some Esetroot compatible prog to set the root bg, * use the property to determine the pixmap. We use it later on. */ - if (xa[XA_XROOTPMAPID] == 0) - xa[XA_XROOTPMAPID] = XInternAtom (display->display, "_XROOTPMAP_ID", False); - - if (ev.xproperty.atom != xa[XA_XROOTPMAPID]) + if (ev.xproperty.atom != xa[XA_XROOTPMAP_ID] + && ev.xproperty.atom != xa[XA_ESETROOT_PMAP_ID]) return; /* FALLTHROUGH */ @@ -1755,7 +1749,7 @@ /* allow meta + click to select rectangular areas */ /* should be done in screen.C */ #if ENABLE_FRILLS - selection.rect = !! (ev.state & ModMetaMask); + selection.rect = !!(ev.state & ModMetaMask); #else selection.rect = false; #endif @@ -2091,7 +2085,7 @@ unsigned int upper_lim_r, upper_lim_g, upper_lim_b; int i; - Visual* visual = display->visual; + Visual *visual = display->visual; if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; @@ -2322,23 +2316,24 @@ Window root, oldp, *list; Pixmap rootpixmap = None; XWindowAttributes wattr, wrootattr; + dDisp; pchanged = 0; if (!(options & Opt_transparent)) return pchanged; /* Don't try any more */ - XGetWindowAttributes (display->display, display->root, &wrootattr); + XGetWindowAttributes (disp, display->root, &wrootattr); rootdepth = wrootattr.depth; - XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); + XGetWindowAttributes (disp, TermWin.parent[0], &wattr); if (rootdepth != wattr.depth) { if (am_transparent) { pchanged = 1; - XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); + XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]); am_transparent = am_pixmap_trans = 0; } @@ -2346,21 +2341,21 @@ } /* Get all X ops out of the queue so that our information is up-to-date. */ - XSync (display->display, False); + XSync (disp, False); /* * Make the frame window set by the window manager have * 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] - && XGetWindowProperty (display->display, display->root, xa[XA_XROOTPMAPID], + i = (xa[XA_XROOTPMAP_ID] + && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID], 0L, 1L, False, XA_PIXMAP, &atype, &aformat, &nitems, &bytes_after, &prop) == Success); if (!i || prop == NULL) - i = (xa[XA_XSETROOTID] - && XGetWindowProperty (display->display, display->root, xa[XA_XSETROOTID], + i = (xa[XA_ESETROOT_PMAP_ID] + && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID], 0L, 1L, False, XA_PIXMAP, &atype, &aformat, &nitems, &bytes_after, &prop) == Success); @@ -2389,7 +2384,7 @@ GC gc; XGCValues gcvalue; - XTranslateCoordinates (display->display, TermWin.parent[0], display->root, + XTranslateCoordinates (disp, TermWin.parent[0], display->root, 0, 0, &sx, &sy, &cr); nw = (unsigned int)szHint.width; nh = (unsigned int)szHint.height; @@ -2412,9 +2407,9 @@ MIN_IT (nw, (unsigned int) (wrootattr.width - sx)); MIN_IT (nh, (unsigned int) (wrootattr.height - sy)); - XSync (display->display, False); + XSync (disp, False); allowedxerror = -1; - image = XGetImage (display->display, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); + image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); /* XXX: handle BadMatch - usually because we're outside the pixmap */ /* XXX: may need a delay here? */ @@ -2427,7 +2422,7 @@ pchanged = 1; if (TermWin.pixmap != None) { - XFreePixmap (display->display, TermWin.pixmap); + XFreePixmap (disp, TermWin.pixmap); TermWin.pixmap = None; } } @@ -2437,7 +2432,7 @@ else { if (TermWin.pixmap != None) - XFreePixmap (display->display, TermWin.pixmap); + XFreePixmap (disp, TermWin.pixmap); #if TINTING if (ISSET_PIXCOLOR (Color_tint)) @@ -2451,15 +2446,15 @@ } #endif - TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, + TermWin.pixmap = XCreatePixmap (disp, TermWin.vt, szHint.width, szHint.height, image->depth); - gc = XCreateGC (display->display, TermWin.vt, 0UL, &gcvalue); - XPutImage (display->display, TermWin.pixmap, gc, image, 0, 0, + gc = XCreateGC (disp, TermWin.vt, 0UL, &gcvalue); + XPutImage (disp, TermWin.pixmap, gc, image, 0, 0, nx, ny, image->width, image->height); - XFreeGC (display->display, gc); + XFreeGC (disp, gc); XDestroyImage (image); - XSetWindowBackgroundPixmap (display->display, TermWin.parent[0], TermWin.pixmap); - XClearWindow (display->display, TermWin.parent[0]); + XSetWindowBackgroundPixmap (disp, TermWin.parent[0], TermWin.pixmap); + XClearWindow (disp, TermWin.parent[0]); if (!am_transparent || !am_pixmap_trans) pchanged = 1; @@ -2469,7 +2464,7 @@ } if (am_pixmap_trans) - XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); + XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative); else { unsigned int n; @@ -2479,7 +2474,7 @@ for (i = 1; i < (int) (sizeof (TermWin.parent) / sizeof (Window)); i++) { oldp = TermWin.parent[i]; - XQueryTree (display->display, TermWin.parent[i - 1], &root, + XQueryTree (disp, TermWin.parent[i - 1], &root, &TermWin.parent[i], &list, &n); XFree (list); @@ -2501,7 +2496,7 @@ { for (; n < (unsigned int)i; n++) { - XGetWindowAttributes (display->display, TermWin.parent[n], &wattr); + XGetWindowAttributes (disp, TermWin.parent[n], &wattr); if (wattr.depth != rootdepth || wattr.c_class == InputOnly) { n = (int) (sizeof (TermWin.parent) / sizeof (Window)) + 1; @@ -2512,8 +2507,8 @@ if (n > (int) (sizeof (TermWin.parent) / sizeof (TermWin.parent[0]))) { - XSetWindowBackground (display->display, TermWin.parent[0], pix_colors_focused[Color_fg]); - XSetWindowBackground (display->display, TermWin.vt, pix_colors_focused[Color_bg]); + XSetWindowBackground (disp, TermWin.parent[0], pix_colors_focused[Color_fg]); + XSetWindowBackground (disp, TermWin.vt, pix_colors_focused[Color_bg]); am_transparent = 0; /* XXX: also turn off Opt_transparent? */ } @@ -2526,11 +2521,11 @@ #endif for (n = 0; n < (unsigned int)i; n++) { - XSetWindowBackgroundPixmap (display->display, TermWin.parent[n], ParentRelative); - XClearWindow (display->display, TermWin.parent[n]); + XSetWindowBackgroundPixmap (disp, TermWin.parent[n], ParentRelative); + XClearWindow (disp, TermWin.parent[n]); } - XSetWindowBackgroundPixmap (display->display, TermWin.vt, ParentRelative); + XSetWindowBackgroundPixmap (disp, TermWin.vt, ParentRelative); am_transparent = 1; } @@ -2540,7 +2535,7 @@ if (scrollBar.win) { - XSetWindowBackgroundPixmap (display->display, scrollBar.win, ParentRelative); + XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative); scrollBar.setIdle (); scrollbar_show (0); } @@ -2711,7 +2706,7 @@ // assume wchar == unicode cmdbuf_ptr += len; - return wc; + return wc & UNICODE_MASK; } return NOCHAR; @@ -3423,6 +3418,7 @@ int x, y; XWindowAttributes wattr; Window wdummy; + dDisp; if (nargs == 0) return; @@ -3433,23 +3429,22 @@ * commands */ case 1: /* deiconify window */ - XMapWindow (display->display, TermWin.parent[0]); + XMapWindow (disp, TermWin.parent[0]); break; case 2: /* iconify window */ - XIconifyWindow (display->display, TermWin.parent[0], - DefaultScreen (display->display)); + XIconifyWindow (disp, TermWin.parent[0], display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (display->display, TermWin.parent[0], args[1], args[2]); + XMoveWindow (disp, TermWin.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 (display->display, TermWin.parent[0]); + XRaiseWindow (disp, TermWin.parent[0]); break; case 6: /* lower window */ - XLowerWindow (display->display, TermWin.parent[0]); + XLowerWindow (disp, TermWin.parent[0]); break; case 7: /* refresh window */ scr_touch (true); @@ -3471,18 +3466,18 @@ * reports - some output format copied from XTerm */ case 11: /* report window state */ - XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); + XGetWindowAttributes (disp, TermWin.parent[0], &wattr); tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); break; case 13: /* report window position */ - XGetWindowAttributes (display->display, TermWin.parent[0], &wattr); - XTranslateCoordinates (display->display, TermWin.parent[0], wattr.root, + XGetWindowAttributes (disp, TermWin.parent[0], &wattr); + XTranslateCoordinates (disp, TermWin.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 (display->display, TermWin.parent[0], &wattr); + XGetWindowAttributes (disp, TermWin.parent[0], &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; case 18: /* report text area size (chars) */ @@ -3494,7 +3489,7 @@ case 20: /* report icon label */ { char *s; - XGetIconName (display->display, TermWin.parent[0], &s); + XGetIconName (disp, TermWin.parent[0], &s); tt_printf ("\033]L%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } @@ -3502,7 +3497,7 @@ case 21: /* report window title */ { char *s; - XFetchName (display->display, TermWin.parent[0], &s); + XFetchName (disp, TermWin.parent[0], &s); tt_printf ("\033]l%-.250s\234", (options & Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } @@ -3654,6 +3649,7 @@ char *buf, *name; bool query = str[0] == '?' && !str[1]; int saveop = op; + dDisp; assert (str != NULL); switch (op) @@ -3679,7 +3675,7 @@ const char *str = ""; if (prop - && XGetWindowProperty (display->display, TermWin.parent[0], + && XGetWindowProperty (disp, TermWin.parent[0], prop, 0, 1<<16, 0, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &value) == Success @@ -3701,7 +3697,7 @@ set_utf8_property (display->atom (str), eq + 1); } else - XDeleteProperty (display->display, TermWin.parent[0], + XDeleteProperty (disp, TermWin.parent[0], display->atom (str)); } break; @@ -3786,8 +3782,8 @@ #if XPM_BACKGROUND changed += scale_pixmap (str); #endif - } + if (changed) { #ifdef XPM_BACKGROUND @@ -3838,6 +3834,7 @@ else { set_locale (str); + pty.set_utf8_mode (enc_utf8); # ifdef USE_XIM im_cb (); # endif @@ -4285,60 +4282,53 @@ /* Write data to the pty as typed by the user, pasted with the mouse, * or generated by us in response to a query ESC sequence. */ +const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT + void rxvt_term::tt_write (const unsigned char *data, unsigned int len) { - const unsigned int MAX_PTY_WRITE = 255; // minimum MAX_INPUT - - if (len) + if (v_buflen == 0) { - if (v_buflen == 0) - { - ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); + ssize_t written = write (pty.pty, data, min (len, MAX_PTY_WRITE)); - if ((unsigned int)written == len) - return; + if ((unsigned int)written == len) + return; - data += written; - len -= written; - } + data += written; + len -= written; + } + v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); - v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); + memcpy (v_buffer + v_buflen, data, len); + v_buflen += len; - memcpy (v_buffer + v_buflen, data, len); - v_buflen += len; - } + pty_ev.set (EVENT_READ | EVENT_WRITE); +} - for (;;) +void rxvt_term::pty_write () +{ + int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); + + if (written > 0) { - int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); + v_buflen -= written; - if (written > 0) + if (v_buflen == 0) { - v_buflen -= written; + free (v_buffer); + v_buffer = 0; + v_buflen = 0; - if (v_buflen == 0) - { - free (v_buffer); - v_buffer = 0; - v_buflen = 0; - - pty_ev.set (EVENT_READ); - return; - } - - memmove (v_buffer, v_buffer + written, v_buflen); - } - else if (written != -1 || (errno != EAGAIN && errno != EINTR)) - // original code just ignores this... - destroy (); - else - { - pty_ev.set (EVENT_READ | EVENT_WRITE); + pty_ev.set (EVENT_READ); return; } + + memmove (v_buffer, v_buffer + written, v_buflen); } + else if (written != -1 || (errno != EAGAIN && errno != EINTR)) + // original code just ignores this... + destroy (); } /*----------------------- end-of-file (C source) -----------------------*/