--- rxvt-unicode/src/command.C 2006/01/07 20:23:52 1.247 +++ rxvt-unicode/src/command.C 2006/01/28 20:41:38 1.290 @@ -66,9 +66,6 @@ #define IS_CONTROL(ch) !((ch) & 0xffffff60UL) -// exception thrown when the command parser runs out of input data -class out_of_input { } out_of_input; - #if ENABLE_FRILLS || ISO_14755 #define ISO_14755_STARTED 0x80000000UL @@ -149,7 +146,7 @@ for (;;) { - const line_t &l = ROW(y - view_start); + const line_t &l = ROW(y + view_start); text_t t = l.t[x]; @@ -304,9 +301,6 @@ int ctrl, meta, shft, len; unsigned int newlen; KeySym keysym; -#ifdef DEBUG_CMD - static int debug_key = 1; /* accessible by a debugger only */ -#endif int valid_keysym; char kbuf[KBUFSZ]; @@ -445,7 +439,7 @@ } else if (keysym == XK_End) { - scr_move_to (1, 0); + scr_move_to (1, 1); return; } } @@ -466,7 +460,7 @@ { /* normal XTerm key bindings */ case XK_Insert: /* Shift+Insert = paste mouse selection */ - selection_request (ev.time, 0, 0); + selection_request (ev.time); return; #if TODO /* rxvt extras */ @@ -869,7 +863,7 @@ } } - if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_STR_LEN, kbuf, len, DT_END))) + if (HOOK_INVOKE ((this, HOOK_KEY_PRESS, DT_XEVENT, &ev, DT_INT, keysym, DT_STR_LEN, kbuf, len, DT_END))) return; if (len <= 0) @@ -907,23 +901,11 @@ tt_write (&ch, 1); } -#if defined(DEBUG_CMD) - /* Display keyboard buffer contents */ - unsigned char *p; - int i; - - fprintf (stderr, "key 0x%04X [%d]: `", (unsigned int)keysym, len); - for (i = 0, p = kbuf; i < len; i++, p++) - fprintf (stderr, (*p >= ' ' && *p < '\177' ? "%c" : "\\%03o"), *p); - fprintf (stderr, "'\n"); -#endif /* DEBUG_CMD */ tt_write (kbuf, (unsigned int)len); } /*}}} */ -#if MENUBAR_MAX || defined (KEYSYM_RESOURCE) -/*{{{ rxvt_cmd_write (), rxvt_cmd_getc () */ -/* attempt to `write' count to the input buffer */ +#if defined (KEYSYM_RESOURCE) unsigned int rxvt_term::cmd_write (const char *str, unsigned int count) { @@ -974,19 +956,20 @@ { if (SHOULD_INVOKE (HOOK_LINE_UPDATE)) { - int row = -view_start; + int row = view_start; + int end_row = row + nrow; - while (row > -nsaved && ROW (row - 1).is_longer ()) + while (row > top_row && ROW (row - 1).is_longer ()) --row; - while (row < -view_start + nrow) + do { int start_row = row; line_t *l; do { - l = &ROW (row); + l = &ROW (row++); if (!(l->f & LINE_FILTERED)) { @@ -994,7 +977,7 @@ l->f |= LINE_FILTERED; while (l->is_longer ()) { - l = &ROW (++row); + l = &ROW (row++); l->f |= LINE_FILTERED; } @@ -1004,14 +987,12 @@ break; } } - while (l->is_longer ()); - - row++; + while (l->is_longer () && row < end_row); } - + while (row < end_row); } - scr_refresh (refresh_type); + scr_refresh (); scrollbar_show (1); #ifdef USE_XIM IMSendSpot (); @@ -1024,8 +1005,7 @@ void rxvt_term::check_cb (check_watcher &w) { - SET_R (this); - SET_LOCALE (locale); + make_current (); display->flush (); @@ -1036,8 +1016,7 @@ void rxvt_term::flush_cb (time_watcher &w) { - SET_R (this); - SET_LOCALE (locale); + make_current (); refresh_limit = 1; refresh_count = 0; @@ -1051,7 +1030,7 @@ hidden_cursor = !hidden_cursor; want_refresh = 1; - w.start (w.at + BLINK_INTERVAL); + w.start (w.at + CURSOR_BLINK_INTERVAL); } #endif @@ -1075,7 +1054,6 @@ if ((scrollbar_isUp() || scrollbar_isDn()) && scr_page (scrollbar_isUp() ? UP : DN, 1)) { - refresh_type |= SMOOTH_REFRESH; want_refresh = 1; w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); } @@ -1089,7 +1067,6 @@ if (scr_page (scroll_selection_dir, scroll_selection_lines)) { selection_extend (selection_save_x, selection_save_y, selection_save_state); - refresh_type |= SMOOTH_REFRESH; want_refresh = 1; w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); } @@ -1104,11 +1081,9 @@ || mouse_slip_wheel_speed < 0 ? scr_page (DN, -mouse_slip_wheel_speed) : scr_page (UP, mouse_slip_wheel_speed)) { - if (view_start == nsaved || - view_start == 0) + if (view_start == top_row || view_start == 0) mouse_slip_wheel_speed = 0; - refresh_type |= SMOOTH_REFRESH; want_refresh = 1; w.start (w.at + SCROLLBAR_CONTINUOUS_DELAY); } @@ -1148,7 +1123,7 @@ 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, CBUFSIZ - n); if (r > 0) { @@ -1176,8 +1151,7 @@ void rxvt_term::pty_cb (io_watcher &w, short revents) { - SET_R (this); - SET_LOCALE (locale); + make_current (); if (revents & EVENT_READ) // loop, but don't allow a single term to monopolize us @@ -1192,7 +1166,7 @@ void rxvt_term::pointer_unblank () { - XDefineCursor (display->display, vt, TermWin_cursor); + XDefineCursor (xdisp, vt, TermWin_cursor); recolour_cursor (); #ifdef POINTER_BLANK @@ -1210,8 +1184,8 @@ if (!OPTION (Opt_pointerBlank)) return; - XDefineCursor (display->display, vt, display->blank_cursor); - XFlush (display->display); + XDefineCursor (xdisp, vt, display->blank_cursor); + XFlush (xdisp); hidden_pointer = 1; } @@ -1219,8 +1193,7 @@ void rxvt_term::pointer_cb (time_watcher &w) { - SET_R (this); - SET_LOCALE (locale); + make_current (); pointer_blank (); } @@ -1295,52 +1268,20 @@ (32 + y + 1)); } -#ifdef USING_W11LIB -void -rxvt_W11_process_x_event (XEvent *ev) -{ - rxvt_t *r = rxvt_get_r (); - - x_cb (*ev); -} -#endif - /*{{{ process an X event */ void rxvt_term::x_cb (XEvent &ev) { - dDisp; - - SET_R (this); - SET_LOCALE (locale); + make_current (); -#if defined(CURSOR_BLINK) - if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) - { - if (hidden_cursor) - { - hidden_cursor = 0; - want_refresh = 1; - } - - cursor_blink_ev.start (NOW + BLINK_INTERVAL); - } -#endif + dLocal (Display *, xdisp); -#if defined(POINTER_BLANK) - if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) - { - if (ev.type == MotionNotify - || ev.type == ButtonPress - || ev.type == ButtonRelease) - if (hidden_pointer) - pointer_unblank (); - - if (ev.type == KeyPress && hidden_pointer == 0) - pointer_blank (); - } -#endif + if (ev.xany.window == vt + && SHOULD_INVOKE (HOOK_X_EVENT) + && HOOK_INVOKE ((this, HOOK_X_EVENT, DT_XEVENT, &ev, DT_END))) + return; + // for XQueryPointer Window unused_root, unused_child; int unused_root_x, unused_root_y; unsigned int unused_mask; @@ -1357,10 +1298,10 @@ case KeyRelease: { -#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 - KeySym ks; +#if (MOUSE_WHEEL && MOUSE_SLIP_WHEELING) || ISO_14755 || ENABLE_PERL + KeySym keysym; - ks = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ + keysym = XLookupKeysym (&ev.xkey, ev.xkey.state & ShiftMask ? 1 : 0); // sorry, only shift supported :/ #endif #if ENABLE_FRILLS || ISO_14755 @@ -1375,20 +1316,20 @@ // iso14755 part 5.2 handling: release time // first: controls if ((ev.xkey.state & ControlMask) - && ((ks >= 0x40 && ks <= 0x5f) - || (ks >= 0x61 && ks <= 0x7f))) + && ((keysym >= 0x40 && keysym <= 0x5f) + || (keysym >= 0x61 && keysym <= 0x7f))) { - iso14755buf = ISO_14755_51 | 0x2400 | (ks & 0x1f); + iso14755buf = ISO_14755_51 | 0x2400 | (keysym & 0x1f); commit_iso14755 (); - return; // case-break; + goto skip_switch; } for (unsigned short *i = iso14755_symtab; i[0]; i+= 2) - if (i[0] == ks) + if (i[0] == keysym) { iso14755buf = ISO_14755_51 | i[1]; commit_iso14755 (); - return; // case-break; + goto skip_switch; } scr_bell (); @@ -1418,13 +1359,13 @@ #endif if (ev.xany.window == vt - && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_END))) + && HOOK_INVOKE ((this, HOOK_KEY_RELEASE, DT_XEVENT, &ev, DT_INT, keysym, DT_END))) break; #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) if (!(ev.xkey.state & ControlMask)) slip_wheel_ev.stop (); - else if (ks == XK_Control_L || ks == XK_Control_R) + else if (keysym == XK_Control_L || keysym == XK_Control_R) mouse_slip_wheel_speed = 0; #endif break; @@ -1440,52 +1381,35 @@ case ClientMessage: if (ev.xclient.format == 32 - && ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) + && !HOOK_INVOKE ((this, HOOK_CLIENT_MESSAGE, DT_XEVENT, &ev, DT_END))) { - if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) - destroy (); + if (ev.xclient.message_type == xa[XA_WM_PROTOCOLS]) + { + if (!HOOK_INVOKE ((this, HOOK_WM_PROTOCOLS, DT_XEVENT, &ev, DT_END))) + { + if (ev.xclient.data.l[0] == xa[XA_WM_DELETE_WINDOW]) + { + if (!HOOK_INVOKE ((this, HOOK_WM_DELETE_WINDOW, DT_XEVENT, &ev, DT_END))) + 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); + else if (ev.xclient.data.l[0] == xa[XA_NET_WM_PING]) + XSendEvent (xdisp, 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 (); - } + 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)) - { - /* Get Dnd data */ - Atom ActualType; - int ActualFormat; - unsigned char *data; - unsigned long Size, RemainingBytes; - - 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 (disp, display->root, RevertToNone, CurrentTime); } -#endif /* OFFIX_DND */ break; case MappingNotify: @@ -1528,7 +1452,7 @@ case ConfigureNotify: if (ev.xconfigure.window == parent[0]) { - while (XCheckTypedWindowEvent (disp, ev.xconfigure.window, ConfigureNotify, &ev)) + while (XCheckTypedWindowEvent (xdisp, ev.xconfigure.window, ConfigureNotify, &ev)) ; if (szHint.width != ev.xconfigure.width || szHint.height != ev.xconfigure.height) @@ -1537,6 +1461,8 @@ resize_all_windows (ev.xconfigure.width, ev.xconfigure.height, 1); } + HOOK_INVOKE ((this, HOOK_CONFIGURE_NOTIFY, DT_XEVENT, &ev, DT_END)); + #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ if (OPTION (Opt_transparent)) check_our_parents (); @@ -1545,9 +1471,10 @@ break; case PropertyNotify: - if (ev.xproperty.atom == xa[XA_VT_SELECTION] - && ev.xproperty.state == PropertyNewValue) - selection_property (ev.xproperty.window, ev.xproperty.atom); + 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); break; @@ -1593,23 +1520,23 @@ do scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); - while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)); + while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)); ev.xany.type = ev.xany.type == Expose ? GraphicsExpose : Expose; - while (XCheckTypedWindowEvent (disp, vt, ev.xany.type, &ev)) + while (XCheckTypedWindowEvent (xdisp, vt, ev.xany.type, &ev)) scr_expose (ev.xexpose.x, ev.xexpose.y, ev.xexpose.width, ev.xexpose.height, False); - scr_refresh (refresh_type); + want_refresh = 1; } else { XEvent unused_event; - while (XCheckTypedWindowEvent (disp, ev.xany.window, Expose, &unused_event)) + while (XCheckTypedWindowEvent (xdisp, ev.xany.window, Expose, &unused_event)) ; - while (XCheckTypedWindowEvent (disp, ev.xany.window, GraphicsExpose, &unused_event)) + while (XCheckTypedWindowEvent (xdisp, ev.xany.window, GraphicsExpose, &unused_event)) ; if (isScrollbarWindow (ev.xany.window)) @@ -1617,14 +1544,10 @@ scrollBar.setIdle (); scrollbar_show (0); } -#ifdef MENUBAR - if (menubar_visible () && isMenuBarWindow (ev.xany.window)) - menubar_expose (); -#endif #ifdef TRANSPARENT if (am_transparent && ev.xany.window == parent[0]) - XClearWindow (disp, ev.xany.window); + XClearWindow (xdisp, ev.xany.window); #endif } break; @@ -1634,26 +1557,20 @@ if (hidden_pointer) pointer_unblank (); #endif -#if MENUBAR - if (isMenuBarWindow (ev.xany.window)) - { - menubar_control (ev.xbutton); - break; - } -#endif if ((priv_modes & PrivMode_mouse_report) && !bypass_keystate) break; if (ev.xany.window == vt) { - if (HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END))) + if (SHOULD_INVOKE (HOOK_MOTION_NOTIFY) + && HOOK_INVOKE ((this, HOOK_MOTION_NOTIFY, DT_XEVENT, &ev, DT_END))) ; // nop else if (ev.xbutton.state & (Button1Mask | Button3Mask)) { - while (XCheckTypedWindowEvent (disp, vt, MotionNotify, &ev)) + while (XCheckTypedWindowEvent (xdisp, vt, MotionNotify, &ev)) ; - XQueryPointer (disp, vt, + XQueryPointer (xdisp, vt, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, @@ -1727,23 +1644,52 @@ } else if (isScrollbarWindow (ev.xany.window) && scrollbar_isMotion ()) { - while (XCheckTypedWindowEvent (disp, scrollBar.win, + while (XCheckTypedWindowEvent (xdisp, scrollBar.win, MotionNotify, &ev)) ; - XQueryPointer (disp, scrollBar.win, + XQueryPointer (xdisp, scrollBar.win, &unused_root, &unused_child, &unused_root_x, &unused_root_y, &ev.xbutton.x, &ev.xbutton.y, &unused_mask); scr_move_to (scrollbar_position (ev.xbutton.y) - csrO, scrollbar_size ()); - scr_refresh (refresh_type); + want_refresh = 1; refresh_limit = 0; scrollbar_show (1); } break; } + +skip_switch: ; + +#if defined(CURSOR_BLINK) + if (OPTION (Opt_cursorBlink) && ev.type == KeyPress) + { + if (hidden_cursor) + { + hidden_cursor = 0; + want_refresh = 1; + } + + cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); + } +#endif + +#if defined(POINTER_BLANK) + if (OPTION (Opt_pointerBlank) && pointerBlankDelay > 0) + { + if (ev.type == MotionNotify + || ev.type == ButtonPress + || ev.type == ButtonRelease) + if (hidden_pointer) + pointer_unblank (); + + if (ev.type == KeyPress && hidden_pointer == 0) + pointer_blank (); + } +#endif } void @@ -1765,7 +1711,7 @@ #endif #if CURSOR_BLINK if (OPTION (Opt_cursorBlink)) - cursor_blink_ev.start (NOW + BLINK_INTERVAL); + cursor_blink_ev.start (NOW + CURSOR_BLINK_INTERVAL); #endif #if OFF_FOCUS_FADING if (rs[Rs_fade]) @@ -1819,8 +1765,7 @@ void rxvt_term::rootwin_cb (XEvent &ev) { - SET_R (this); - SET_LOCALE (locale); + make_current (); switch (ev.type) { @@ -1857,6 +1802,9 @@ */ if (ev.window == vt) { + if (HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END))) + return; + #if ISO_14755 // 5.4 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) @@ -1908,49 +1856,48 @@ if (ev.button != MEvent.button) MEvent.clicks = 0; - if (!HOOK_INVOKE ((this, HOOK_BUTTON_PRESS, DT_XEVENT, &ev, DT_END))) - switch (ev.button) - { - case Button1: - /* allow meta + click to select rectangular areas */ - /* should be done in screen.C */ + switch (ev.button) + { + case Button1: + /* 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; + selection.rect = false; #endif - /* allow shift+left click to extend selection */ - if (ev.state & ShiftMask && ! (priv_modes & PrivMode_mouse_report)) - { - if (MEvent.button == Button1 && clickintime) - selection_rotate (ev.x, ev.y); - else - selection_extend (ev.x, ev.y, 1); - } - else - { - if (MEvent.button == Button1 && clickintime) - MEvent.clicks++; - else - MEvent.clicks = 1; + /* allow shift+left click to extend selection */ + if (ev.state & ShiftMask && !(priv_modes & PrivMode_mouse_report)) + { + if (MEvent.button == Button1 && clickintime) + selection_rotate (ev.x, ev.y); + else + selection_extend (ev.x, ev.y, 1); + } + else + { + if (MEvent.button == Button1 && clickintime) + MEvent.clicks++; + else + MEvent.clicks = 1; - selection_click (MEvent.clicks, ev.x, ev.y); - } + selection_click (MEvent.clicks, ev.x, ev.y); + } - MEvent.button = Button1; - break; + MEvent.button = Button1; + break; - case Button3: - if (MEvent.button == Button3 && clickintime) - selection_rotate (ev.x, ev.y); - else - selection_extend (ev.x, ev.y, 1); + case Button3: + if (MEvent.button == Button3 && clickintime) + selection_rotate (ev.x, ev.y); + else + selection_extend (ev.x, ev.y, 1); - MEvent.button = Button3; - break; - } - } + MEvent.button = Button3; + break; + } + } MEvent.time = ev.time; return; @@ -2099,14 +2046,6 @@ return; } - -#if MENUBAR - /* - * Menubar window processing of button press - */ - if (isMenuBarWindow (ev.window)) - menubar_control (ev); -#endif } void @@ -2122,9 +2061,6 @@ { scrollBar.setIdle (); scrollbar_show (0); -#ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - refresh_type &= ~SMOOTH_REFRESH; -#endif } #ifdef SELECTION_SCROLLING @@ -2134,11 +2070,15 @@ if (ev.window == vt) { + if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END))) + return; + #if ISO_14755 // 5.4 if (iso14755buf & (ISO_14755_STARTED | ISO_14755_54)) return; #endif + if (reportmode) { /* mouse report from vt window */ @@ -2172,18 +2112,18 @@ && ev.button == Button1 && MEvent.clicks <= 1) selection_extend (ev.x, ev.y, 0); - if (HOOK_INVOKE ((this, HOOK_BUTTON_RELEASE, DT_XEVENT, &ev, DT_END))) - return; - switch (ev.button) { case Button1: case Button3: selection_make (ev.time); break; + case Button2: - selection_request (ev.time, ev.x, ev.y); + if (IN_RANGE_EXC (ev.x, 0, width) && IN_RANGE_EXC (ev.y, 0, height)) // inside window? + selection_request (ev.time, ev.state & ModMetaMask ? Sel_Primary : Sel_Primary); break; + #ifdef MOUSE_WHEEL case Button4: case Button5: @@ -2215,30 +2155,16 @@ else { # endif -# ifdef JUMP_MOUSE_WHEEL scr_page (v, i); - scr_refresh (SMOOTH_REFRESH); scrollbar_show (1); -# else - while (i--) - { - scr_page (v, 1); - scr_refresh (SMOOTH_REFRESH); - scrollbar_show (1); - } -# endif # ifdef MOUSE_SLIP_WHEELING } -#endif +# endif } break; #endif } } -#ifdef MENUBAR - else if (isMenuBarWindow (ev.window)) - menubar_control (ev); -#endif } #ifdef TRANSPARENT @@ -2247,7 +2173,7 @@ typedef uint32_t RUINT32T; -void ShadeXImage(rxvt_display *display, XImage* srcImage, int shade, int rm, int gm, int bm) +void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) { int sh_r, sh_g, sh_b; RUINT32T mask_r, mask_g, mask_b; @@ -2256,7 +2182,7 @@ unsigned int upper_lim_r, upper_lim_g, upper_lim_b; int i; - Visual *visual = display->visual; + Visual *visual = term->visual; if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; @@ -2487,24 +2413,23 @@ Window root, oldp, *list; Pixmap rootpixmap = None; XWindowAttributes wattr, wrootattr; - dDisp; pchanged = 0; if (!OPTION (Opt_transparent)) return pchanged; /* Don't try any more */ - XGetWindowAttributes (disp, display->root, &wrootattr); + XGetWindowAttributes (xdisp, display->root, &wrootattr); rootdepth = wrootattr.depth; - XGetWindowAttributes (disp, parent[0], &wattr); + XGetWindowAttributes (xdisp, parent[0], &wattr); if (rootdepth != wattr.depth) { if (am_transparent) { pchanged = 1; - XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]); + XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]); am_transparent = am_pixmap_trans = 0; } @@ -2512,7 +2437,7 @@ } /* Get all X ops out of the queue so that our information is up-to-date. */ - XSync (disp, False); + XSync (xdisp, False); /* * Make the frame window set by the window manager have @@ -2520,13 +2445,13 @@ * windows for each client, so we have to take care about that. */ i = (xa[XA_XROOTPMAP_ID] - && XGetWindowProperty (disp, display->root, xa[XA_XROOTPMAP_ID], + && XGetWindowProperty (xdisp, 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_ESETROOT_PMAP_ID] - && XGetWindowProperty (disp, display->root, xa[XA_ESETROOT_PMAP_ID], + && XGetWindowProperty (xdisp, display->root, xa[XA_ESETROOT_PMAP_ID], 0L, 1L, False, XA_PIXMAP, &atype, &aformat, &nitems, &bytes_after, &prop) == Success); @@ -2555,7 +2480,7 @@ GC gc; XGCValues gcvalue; - XTranslateCoordinates (disp, parent[0], display->root, + XTranslateCoordinates (xdisp, parent[0], display->root, 0, 0, &sx, &sy, &cr); nw = (unsigned int)szHint.width; nh = (unsigned int)szHint.height; @@ -2578,9 +2503,9 @@ min_it (nw, (unsigned int) (wrootattr.width - sx)); min_it (nh, (unsigned int) (wrootattr.height - sy)); - XSync (disp, False); + XSync (xdisp, False); allowedxerror = -1; - image = XGetImage (disp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); + image = XGetImage (xdisp, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); /* XXX: handle BadMatch - usually because we're outside the pixmap */ /* XXX: may need a delay here? */ @@ -2593,7 +2518,7 @@ pchanged = 1; if (pixmap != None) { - XFreePixmap (disp, pixmap); + XFreePixmap (xdisp, pixmap); pixmap = None; } } @@ -2603,7 +2528,7 @@ else { if (pixmap != None) - XFreePixmap (disp, pixmap); + XFreePixmap (xdisp, pixmap); #if TINTING if (ISSET_PIXCOLOR (Color_tint)) @@ -2611,21 +2536,20 @@ unsigned short rm, gm, bm; int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100; - pix_colors_focused[Color_tint].get (display, rm, gm, bm); + pix_colors_focused[Color_tint].get (this, rm, gm, bm); - ShadeXImage (display, image, shade, rm, gm, bm); + ShadeXImage (this, image, shade, rm, gm, bm); } #endif - pixmap = XCreatePixmap (disp, vt, - szHint.width, szHint.height, image->depth); - gc = XCreateGC (disp, vt, 0UL, &gcvalue); - XPutImage (disp, pixmap, gc, image, 0, 0, + pixmap = XCreatePixmap (xdisp, vt, szHint.width, szHint.height, image->depth); + gc = XCreateGC (xdisp, vt, 0UL, &gcvalue); + XPutImage (xdisp, pixmap, gc, image, 0, 0, nx, ny, image->width, image->height); - XFreeGC (disp, gc); + XFreeGC (xdisp, gc); XDestroyImage (image); - XSetWindowBackgroundPixmap (disp, parent[0], pixmap); - XClearWindow (disp, parent[0]); + XSetWindowBackgroundPixmap (xdisp, parent[0], pixmap); + XClearWindow (xdisp, parent[0]); if (!am_transparent || !am_pixmap_trans) pchanged = 1; @@ -2635,7 +2559,7 @@ } if (am_pixmap_trans) - XSetWindowBackgroundPixmap (disp, vt, ParentRelative); + XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative); else { unsigned int n; @@ -2645,7 +2569,7 @@ for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) { oldp = parent[i]; - XQueryTree (disp, parent[i - 1], &root, + XQueryTree (xdisp, parent[i - 1], &root, &parent[i], &list, &n); XFree (list); @@ -2667,7 +2591,7 @@ { for (; n < (unsigned int)i; n++) { - XGetWindowAttributes (disp, parent[n], &wattr); + XGetWindowAttributes (xdisp, parent[n], &wattr); if (wattr.depth != rootdepth || wattr.c_class == InputOnly) { n = (int) (sizeof (parent) / sizeof (Window)) + 1; @@ -2678,25 +2602,20 @@ if (n > (int) (sizeof (parent) / sizeof (parent[0]))) { - XSetWindowBackground (disp, parent[0], pix_colors_focused[Color_border]); - XSetWindowBackground (disp, vt, pix_colors_focused[Color_bg]); + XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]); + XSetWindowBackground (xdisp, vt, pix_colors_focused[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?) */ - sleep (1); -#endif for (n = 0; n < (unsigned int)i; n++) { - XSetWindowBackgroundPixmap (disp, parent[n], ParentRelative); - XClearWindow (disp, parent[n]); + XSetWindowBackgroundPixmap (xdisp, parent[n], ParentRelative); + XClearWindow (xdisp, parent[n]); } - XSetWindowBackgroundPixmap (disp, vt, ParentRelative); + XSetWindowBackgroundPixmap (xdisp, vt, ParentRelative); am_transparent = 1; } @@ -2706,7 +2625,7 @@ if (scrollBar.win) { - XSetWindowBackgroundPixmap (disp, scrollBar.win, ParentRelative); + XSetWindowBackgroundPixmap (xdisp, scrollBar.win, ParentRelative); scrollBar.setIdle (); scrollbar_show (0); } @@ -2791,7 +2710,8 @@ // scr_add_lines only works for nlines <= nrow - 1. if (nlines >= nrow - 1) { - if (!HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))) + if (!(SHOULD_INVOKE (HOOK_ADD_LINES) + && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) scr_add_lines (buf, str - buf, nlines); nlines = 0; @@ -2816,7 +2736,8 @@ ch = next_char (); } - if (!HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END))) + if (!(SHOULD_INVOKE (HOOK_ADD_LINES) + && HOOK_INVOKE ((this, HOOK_ADD_LINES, DT_WCS_LEN, buf, str - buf, DT_END)))) scr_add_lines (buf, str - buf, nlines); /* @@ -2832,8 +2753,8 @@ else { flag = true; - scr_refresh (refresh_type); - flush_ev.stop (); + scr_refresh (); + want_refresh = 1; } } @@ -2860,7 +2781,7 @@ // read the next character wchar_t -rxvt_term::next_char () +rxvt_term::next_char () NOTHROW { while (cmdbuf_ptr < cmdbuf_endp) { @@ -2891,20 +2812,22 @@ // read the next octet uint32_t -rxvt_term::next_octet () +rxvt_term::next_octet () NOTHROW { return cmdbuf_ptr < cmdbuf_endp ? (unsigned char)*cmdbuf_ptr++ : NOCHAR; } +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 () +rxvt_term::cmd_getc () THROW ((class out_of_input)) { wchar_t c = next_char (); @@ -2915,7 +2838,7 @@ } uint32_t -rxvt_term::cmd_get8 () +rxvt_term::cmd_get8 () THROW ((class out_of_input)) { uint32_t c = next_octet (); @@ -3346,13 +3269,6 @@ if (arg[p] == -1) arg[p] = ndef; -#ifdef DEBUG_CMD - fprintf (stderr, "CSI "); - for (p = 0; p < nargs; p++) - fprintf (stderr, "%d%s", arg[p], p < nargs - 1 ? ";" : ""); - fprintf (stderr, "%c\n", ch); -#endif - /* * private mode handling */ @@ -3362,7 +3278,16 @@ { case '>': if (ch == CSI_DA) /* secondary device attributes */ - tt_printf ("\033[>%d;%c%c;0c", 'U', VERSION[0], VERSION[2]); + { + // first parameter is normally 0 for vt100, 1 for some newer vtxxx, 'R' for rxvt, + // 'U' for rxvt-unicode != 7.[34] (where it was broken). + // + // second parameter is xterm patch level for xterm, MMmmpp (e.g. 20703) for rxvt + // and Mm (e.g. 72 for 7.2) for urxvt <= 7.2, and 94 for later versions, to signify + // that we do not support xterm mouse reporting (should be 95 when we do). + // + tt_printf ("\033[>%d;94;0c", 'U'); + } break; case '?': if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') @@ -3600,7 +3525,8 @@ int x, y; XWindowAttributes wattr; Window wdummy; - dDisp; + + dLocal (Display *, xdisp); if (nargs == 0) return; @@ -3611,22 +3537,22 @@ * commands */ case 1: /* deiconify window */ - XMapWindow (disp, parent[0]); + XMapWindow (xdisp, parent[0]); break; case 2: /* iconify window */ - XIconifyWindow (disp, parent[0], display->screen); + XIconifyWindow (xdisp, parent[0], display->screen); break; case 3: /* set position (pixels) */ - XMoveWindow (disp, parent[0], args[1], args[2]); + XMoveWindow (xdisp, 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, parent[0]); + XRaiseWindow (xdisp, parent[0]); break; case 6: /* lower window */ - XLowerWindow (disp, parent[0]); + XLowerWindow (xdisp, parent[0]); break; case 7: /* refresh window */ scr_touch (true); @@ -3648,18 +3574,18 @@ * reports - some output format copied from XTerm */ case 11: /* report window state */ - XGetWindowAttributes (disp, parent[0], &wattr); + XGetWindowAttributes (xdisp, parent[0], &wattr); tt_printf ("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); break; case 13: /* report window position */ - XGetWindowAttributes (disp, parent[0], &wattr); - XTranslateCoordinates (disp, parent[0], wattr.root, + XGetWindowAttributes (xdisp, parent[0], &wattr); + XTranslateCoordinates (xdisp, 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, parent[0], &wattr); + XGetWindowAttributes (xdisp, parent[0], &wattr); tt_printf ("\033[4;%d;%dt", wattr.height, wattr.width); break; case 18: /* report text area size (chars) */ @@ -3671,7 +3597,7 @@ case 20: /* report icon label */ { char *s; - XGetIconName (disp, parent[0], &s); + XGetIconName (xdisp, parent[0], &s); tt_printf ("\033]L%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } @@ -3679,7 +3605,7 @@ case 21: /* report window title */ { char *s; - XFetchName (disp, parent[0], &s); + XFetchName (xdisp, parent[0], &s); tt_printf ("\033]l%-.250s\234", OPTION (Opt_insecure) && s ? s : ""); /* 8bit ST */ XFree (s); } @@ -3791,7 +3717,7 @@ if (str[0] == '?' && !str[1]) { unsigned short r, g, b; - pix_colors_focused[color].get (display, r, g, b); + pix_colors_focused[color].get (this, r, g, b); tt_printf ("\033]%d;rgb:%04x/%04x/%04x%c", report, r, g, b, resp); } else @@ -3804,12 +3730,12 @@ void rxvt_term::process_xterm_seq (int op, const char *str, char resp) { - int changed = 0; int color; char *buf, *name; bool query = str[0] == '?' && !str[1]; int saveop = op; - dDisp; + + dLocal (Display *, xdisp); assert (str != NULL); switch (op) @@ -3835,7 +3761,7 @@ const char *str = ""; if (prop - && XGetWindowProperty (disp, parent[0], + && XGetWindowProperty (xdisp, parent[0], prop, 0, 1<<16, 0, AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes_after, &value) == Success @@ -3843,7 +3769,7 @@ && actual_format == 8) str = (const char *)(value); - tt_printf ("\033]%d;%s%c", XTerm_property, str, resp); + tt_printf ("\033]%d;%s%c", op, str, resp); XFree (value); } @@ -3857,7 +3783,7 @@ set_utf8_property (display->atom (str), eq + 1); } else - XDeleteProperty (disp, parent[0], + XDeleteProperty (xdisp, parent[0], display->atom (str)); } break; @@ -3869,9 +3795,9 @@ break; *name++ = '\0'; - color = atoi (buf); + color = atoi (buf) + minCOLOR; - if (color < 0 || color >= TOTAL_COLORS) + if (!IN_RANGE_INC (color, minCOLOR, maxTermCOLOR)) break; if ((buf = strchr (name, ';')) != NULL) @@ -3880,83 +3806,90 @@ if (name[0] == '?' && !name[1]) { unsigned short r, g, b; - pix_colors_focused[color + minCOLOR].get (display, r, g, b); - tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", XTerm_Color, color, r, g, b, resp); + pix_colors_focused[color].get (this, r, g, b); + tt_printf ("\033]%d;%d;rgb:%04x/%04x/%04x%c", op, color, r, g, b, resp); } else - set_window_color (color + minCOLOR, name); + set_window_color (color, name); } break; case XTerm_Color00: - process_color_seq (XTerm_Color00, Color_fg, str, resp); + process_color_seq (op, Color_fg, str, resp); break; case XTerm_Color01: - process_color_seq (XTerm_Color00, Color_bg, str, resp); + process_color_seq (op, Color_bg, str, resp); break; #ifndef NO_CURSORCOLOR case XTerm_Color_cursor: - process_color_seq (XTerm_Color_cursor, Color_cursor, str, resp); + process_color_seq (op, Color_cursor, str, resp); break; #endif case XTerm_Color_pointer_fg: - process_color_seq (XTerm_Color_pointer_fg, Color_pointer_fg, str, resp); + process_color_seq (op, Color_pointer_fg, str, resp); break; case XTerm_Color_pointer_bg: - process_color_seq (XTerm_Color_pointer_bg, Color_pointer_bg, str, resp); + process_color_seq (op, Color_pointer_bg, str, resp); break; #ifndef NO_BOLD_UNDERLINE_REVERSE - case XTerm_Color_BD: - process_color_seq (XTerm_Color_BD, Color_BD, 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); + process_color_seq (op, Color_RV, str, resp); + break; + case Rxvt_Color_BD: + case URxvt_Color_BD: + process_color_seq (op, Color_BD, str, resp); + break; + case Rxvt_Color_UL: + case URxvt_Color_UL: + process_color_seq (op, Color_UL, str, resp); break; case URxvt_Color_IT: - process_color_seq (URxvt_Color_IT, Color_IT, str, resp); + process_color_seq (op, Color_IT, str, resp); break; #endif #if TRANSPARENT && TINTING case URxvt_Color_tint: - process_color_seq (URxvt_Color_tint, Color_tint, str, resp); + process_color_seq (op, Color_tint, str, resp); check_our_parents (); if (am_transparent) want_full_refresh = want_refresh = 1; break; #endif - case XTerm_Pixmap: - if (*str != ';') - { + case Rxvt_Pixmap: + { + if (*str != ';') + { #if XPM_BACKGROUND - scale_pixmap (""); /* reset to default scaling */ - set_bgPixmap (str); /* change pixmap */ + scale_pixmap (""); /* reset to default scaling */ + set_bgPixmap (str); /* change pixmap */ + scr_touch (true); #endif - scr_touch (true); - } - while ((str = strchr (str, ';')) != NULL) - { - str++; + } + + int changed = 0; + + while ((str = strchr (str, ';')) != NULL) + { + str++; #if XPM_BACKGROUND - changed += scale_pixmap (str); + changed += scale_pixmap (str); #endif - } + } - if (changed) - { + if (changed) + { #ifdef XPM_BACKGROUND - resize_pixmap (); + resize_pixmap (); + scr_touch (true); #endif - scr_touch (true); - } + } + } break; - case XTerm_restoreFG: + case Rxvt_restoreFG: set_window_color (Color_fg, str); break; - case XTerm_restoreBG: + case Rxvt_restoreBG: set_window_color (Color_bg, str); break; @@ -3964,14 +3897,8 @@ // 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 */ + case Rxvt_dumpscreen: /* no error notices */ { int fd; if ((fd = open (str, O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) @@ -4005,14 +3932,22 @@ } break; + case URxvt_version: + if (query) + tt_printf ("\33]%d;rxvt-unicode;%-.20s;%c;%c%c", + op, + rs[Rs_name], VERSION[0], VERSION[2], + resp); + break; + #if ENABLE_FRILLS case URxvt_locale: if (query) - tt_printf ("\33]%d;%-.250s%c", URxvt_locale, OPTION (Opt_insecure) ? locale : "", resp); + tt_printf ("\33]%d;%-.250s%c", op, OPTION (Opt_insecure) ? locale : "", resp); else { set_locale (str); - pty.set_utf8_mode (enc_utf8); + pty->set_utf8_mode (enc_utf8); init_xlocale (); } break; @@ -4075,7 +4010,7 @@ /* we're not using priv _yet_ */ void -rxvt_term::process_terminal_mode (int mode, int priv __attribute__ ((unused)), unsigned int nargs, const int *arg) +rxvt_term::process_terminal_mode (int mode, int priv UNUSED, unsigned int nargs, const int *arg) { unsigned int i, j; int state; @@ -4096,9 +4031,6 @@ { 7, PrivMode_Autowrap }, // 8, bi-directional support mode { 9, PrivMode_MouseX10 }, -#ifdef menuBar_esc - { menuBar_esc, PrivMode_menuBar }, -#endif // 18, 19 printing-related { 25, PrivMode_VisibleCursor }, #ifdef scrollBar_esc @@ -4155,10 +4087,7 @@ { #if ENABLE_STYLES case 1021: - if (mode) - SET_OPTION (Opt_intensityStyles); - else - CLR_OPTION (Opt_intensityStyles); + set_option (Opt_intensityStyles, mode); scr_touch (true); break; @@ -4190,10 +4119,7 @@ set_widthheight (((state ? 132 : 80) * fwidth), height); break; case 4: /* smooth scrolling */ - if (!state) - SET_OPTION (Opt_jumpScroll); - else - CLR_OPTION (Opt_jumpScroll); + set_option (Opt_jumpScroll, !state); break; case 5: /* reverse video */ scr_rvideo_mode (state); @@ -4209,13 +4135,6 @@ if (state) /* orthogonal */ priv_modes &= ~PrivMode_MouseX11; break; -#ifdef menuBar_esc - case menuBar_esc: -#ifdef MENUBAR - map_menuBar (state); -#endif - break; -#endif #ifdef scrollBar_esc case scrollBar_esc: if (scrollbar_mapping (state)) @@ -4244,16 +4163,10 @@ break; /* X11 mouse highlighting */ #endif case 1010: /* scroll to bottom on TTY output inhibit */ - if (!state) - SET_OPTION (Opt_scrollTtyOutput); - else - CLR_OPTION (Opt_scrollTtyOutput); + set_option (Opt_scrollTtyOutput, !state); break; case 1011: /* scroll to bottom on key press */ - if (state) - SET_OPTION (Opt_scrollTtyKeypress); - else - CLR_OPTION (Opt_scrollTtyKeypress); + set_option (Opt_scrollTtyKeypress, state); break; case 1047: /* secondary screen w/ clearing last */ if (OPTION (Opt_secondaryScreen)) @@ -4473,12 +4386,15 @@ void rxvt_term::tt_write (const char *data, unsigned int len) { - if (pty.pty < 0) + if (HOOK_INVOKE ((this, HOOK_TT_WRITE, DT_STR_LEN, data, len, DT_END))) + return; + + if (pty->pty < 0) return; 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; @@ -4497,7 +4413,7 @@ void rxvt_term::pty_write () { - int written = write (pty.pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); + int written = write (pty->pty, v_buffer, min (v_buflen, MAX_PTY_WRITE)); if (written > 0) {