--- rxvt-unicode/src/command.C 2003/11/24 17:28:08 1.1 +++ rxvt-unicode/src/command.C 2003/12/18 13:33:02 1.22 @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: command.c *----------------------------------------------------------------------* - * $Id: command.C,v 1.1 2003/11/24 17:28:08 pcg Exp $ + * $Id: command.C,v 1.22 2003/12/18 13:33:02 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -50,6 +50,8 @@ #include "version.h" #include "command.h" +#include + /*----------------------------------------------------------------------*/ /*{{{ Convert the keypress event into a string */ @@ -63,10 +65,8 @@ #ifdef DEBUG_CMD static int debug_key = 1; /* accessible by a debugger only */ #endif -#ifdef USE_XIM int valid_keysym; -#endif - unsigned char *kbuf = R->h->kbuf; + unsigned char *kbuf = R->kbuf; /* * use Num_Lock to toggle Keypad on/off. If Num_Lock is off, allow an @@ -76,66 +76,83 @@ */ shft = (ev->state & ShiftMask); ctrl = (ev->state & ControlMask); - meta = (ev->state & R->h->ModMetaMask); - if (R->numlock_state || (ev->state & R->h->ModNumLockMask)) { - R->numlock_state = (ev->state & R->h->ModNumLockMask); + meta = (ev->state & R->ModMetaMask); + + if (R->numlock_state || (ev->state & R->ModNumLockMask)) + { + R->numlock_state = (ev->state & R->ModNumLockMask); PrivMode((!R->numlock_state), PrivMode_aplKP); - } + } + + kbuf[0] = 0; + #ifdef USE_XIM - if (R->h->Input_Context != NULL) { - Status status_return; + if (R->Input_Context) + { + Status status_return; - kbuf[0] = '\0'; #ifdef X_HAVE_UTF8_STRING - len = Xutf8LookupString(R->h->Input_Context, ev, (char *)kbuf, - KBUFSZ, &keysym, &status_return); -#else - len = XmbLookupString(R->h->Input_Context, ev, (char *)kbuf, - KBUFSZ, &keysym, &status_return); + if (R->enc_utf8) + len = Xutf8LookupString (R->Input_Context, ev, (char *)kbuf, + KBUFSZ, &keysym, &status_return); + else #endif - valid_keysym = ((status_return == XLookupKeySym) - || (status_return == XLookupBoth)); - } else { - len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym, - &R->h->compose); - valid_keysym = 1; - } -#else /* USE_XIM */ - len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym, - &R->h->compose); -/* - * map unmapped Latin[2-4]/Katakana/Arabic/Cyrillic/Greek entries -> Latin1 - * good for installations with correct fonts, but without XLOCALE - */ - if (!len) { - if ((keysym >= 0x0100) && (keysym < 0x0800)) { - kbuf[0] = (keysym & 0xFF); - kbuf[1] = '\0'; - len = 1; - } else - kbuf[0] = '\0'; - } -#endif /* USE_XIM */ + { + wchar_t wkbuf[KBUFSZ + 1]; -#ifdef USE_XIM - if (valid_keysym) + // the XOpenIM manpage lies about hardcoding the locale + // at the point of XOpenIM, so temporarily switch locales + if (R->rs[Rs_imLocale]) + SET_LOCALE (R->rs[Rs_imLocale]); + // assume wchar_t == unicode or better + len = XwcLookupString (R->Input_Context, ev, wkbuf, + KBUFSZ, &keysym, &status_return); + if (R->rs[Rs_imLocale]) + SET_LOCALE (R->locale); + + if (status_return == XLookupChars + || status_return == XLookupBoth) + { + wkbuf[len] = 0; + len = wcstombs ((char *)kbuf, wkbuf, KBUFSZ); + if (len < 0) + len = 0; + } + else + len = 0; + } + + valid_keysym = status_return == XLookupKeySym + || status_return == XLookupBoth; + } + else #endif - { + { + len = XLookupString (ev, (char *)kbuf, KBUFSZ, &keysym, &R->compose); + valid_keysym = !len; + } + + if (valid_keysym) + { /* for some backwards compatibility */ #if defined(HOTKEY_CTRL) || defined(HOTKEY_META) # ifdef HOTKEY_CTRL - if (ctrl) { + if (ctrl) # else - if (meta) { + if (meta) # endif - if (keysym == R->h->ks_bigfont) { + { + if (keysym == R->ks_bigfont) + { rxvt_change_font(aR_ 0, FONT_UP); return; - } else if (keysym == R->h->ks_smallfont) { + } + else if (keysym == R->ks_smallfont) + { rxvt_change_font(aR_ 0, FONT_DN); return; - } - } + } + } #endif if (R->TermWin.saveLines) { @@ -188,7 +205,7 @@ if (keysym >= XK_F1 && keysym <= XK_F10) { keysym += (XK_F11 - XK_F1); shft = 0; /* turn off Shift */ - } else if (!ctrl && !meta && (R->h->PrivateModes & PrivMode_ShiftKeys)) { + } else if (!ctrl && !meta && (R->PrivateModes & PrivMode_ShiftKeys)) { switch (keysym) { /* normal XTerm key bindings */ case XK_Insert: /* Shift+Insert = paste mouse selection */ @@ -211,9 +228,9 @@ } #endif #ifdef GREEK_SUPPORT - if (keysym == R->h->ks_greekmodeswith) { - R->h->greek_mode = !R->h->greek_mode; - if (R->h->greek_mode) { + if (keysym == R->ks_greekmodeswith) { + R->greek_mode = !R->greek_mode; + if (R->greek_mode) { rxvt_xterm_seq(aR_ XTerm_title, (greek_getmode() == GREEK_ELOT928 ? "[Greek: iso]" : "[Greek: ibm]"), CHAR_ST); @@ -226,21 +243,21 @@ if (keysym >= 0xFF00 && keysym <= 0xFFFF) { #ifdef KEYSYM_RESOURCE - if (!(shft | ctrl) && R->h->Keysym_map[keysym & 0xFF] != NULL) { + if (!(shft | ctrl) && R->Keysym_map[keysym & 0xFF] != NULL) { unsigned int l; const unsigned char *kbuf0; const unsigned char ch = C0_ESC; - kbuf0 = (R->h->Keysym_map[keysym & 0xFF]); + kbuf0 = (R->Keysym_map[keysym & 0xFF]); l = (unsigned int)*kbuf0++; /* escape prefix */ if (meta) # ifdef META8_OPTION - if (R->h->meta_char == C0_ESC) + if (R->meta_char == C0_ESC) # endif - rxvt_tt_write(aR_ &ch, 1); - rxvt_tt_write(aR_ kbuf0, l); + R->tt_write (&ch, 1); + R->tt_write (kbuf0, l); return; } else #endif @@ -249,12 +266,12 @@ switch (keysym) { #ifndef NO_BACKSPACE_KEY case XK_BackSpace: - if (R->h->PrivateModes & PrivMode_HaveBackSpace) { - kbuf[0] = (!!(R->h->PrivateModes & PrivMode_BackSpace) + if (R->PrivateModes & PrivMode_HaveBackSpace) { + kbuf[0] = (!!(R->PrivateModes & PrivMode_BackSpace) ^ !!ctrl) ? '\b' : '\177'; kbuf[1] = '\0'; } else - STRCPY(kbuf, R->h->key_backspace); + STRCPY(kbuf, R->key_backspace); # ifdef MULTICHAR_SET if ((R->Options & Opt_mc_hack) && R->screen.cur.col > 0) { int col, row; @@ -270,7 +287,7 @@ #endif #ifndef NO_DELETE_KEY case XK_Delete: - STRCPY(kbuf, R->h->key_delete); + STRCPY(kbuf, R->key_delete); # ifdef MULTICHAR_SET if (R->Options & Opt_mc_hack) { int col, row; @@ -306,7 +323,7 @@ case XK_KP_Down: /* \033Or or standard */ case XK_KP_Right: /* \033Ov or standard */ case XK_KP_Left: /* \033Ot or standard */ - if ((R->h->PrivateModes & PrivMode_aplKP) ? !shft : shft) { + if ((R->PrivateModes & PrivMode_aplKP) ? !shft : shft) { STRCPY(kbuf, "\033OZ"); kbuf[2] = ("txvr"[keysym - XK_KP_Left]); break; @@ -327,7 +344,7 @@ else if (ctrl) { kbuf[1] = 'O'; kbuf[2] = ("dacb"[keysym - XK_Left]); - } else if (R->h->PrivateModes & PrivMode_aplCUR) + } else if (R->PrivateModes & PrivMode_aplCUR) kbuf[1] = 'O'; #ifdef MULTICHAR_SET //TODO: ?? @@ -365,7 +382,7 @@ # ifdef XK_KP_Prior case XK_KP_Prior: /* allow shift to override */ - if ((R->h->PrivateModes & PrivMode_aplKP) ? !shft : shft) { + if ((R->PrivateModes & PrivMode_aplKP) ? !shft : shft) { STRCPY(kbuf, "\033Oy"); break; } @@ -377,7 +394,7 @@ # ifdef XK_KP_Next case XK_KP_Next: /* allow shift to override */ - if ((R->h->PrivateModes & PrivMode_aplKP) ? !shft : shft) { + if ((R->PrivateModes & PrivMode_aplKP) ? !shft : shft) { STRCPY(kbuf, "\033Os"); break; } @@ -389,7 +406,7 @@ #endif case XK_KP_Enter: /* allow shift to override */ - if ((R->h->PrivateModes & PrivMode_aplKP) ? !shft : shft) { + if ((R->PrivateModes & PrivMode_aplKP) ? !shft : shft) { STRCPY(kbuf, "\033OM"); } else { kbuf[0] = '\r'; @@ -435,7 +452,7 @@ case XK_KP_8: /* "\033Ox" : "8" */ case XK_KP_9: /* "\033Oy" : "9" */ /* allow shift to override */ - if ((R->h->PrivateModes & PrivMode_aplKP) ? !shft : shft) { + if ((R->PrivateModes & PrivMode_aplKP) ? !shft : shft) { STRCPY(kbuf, "\033Oj"); kbuf[2] += (keysym - XK_KP_Multiply); } else { @@ -463,7 +480,7 @@ #ifdef XK_KP_End case XK_KP_End: /* allow shift to override */ - if ((R->h->PrivateModes & PrivMode_aplKP) ? !shft : shft) { + if ((R->PrivateModes & PrivMode_aplKP) ? !shft : shft) { STRCPY(kbuf, "\033Oq"); break; } @@ -475,7 +492,7 @@ #ifdef XK_KP_Home case XK_KP_Home: /* allow shift to override */ - if ((R->h->PrivateModes & PrivMode_aplKP) ? !shft : shft) { + if ((R->PrivateModes & PrivMode_aplKP) ? !shft : shft) { STRCPY(kbuf, "\033Ow"); break; } @@ -551,7 +568,7 @@ * Pass meta for all function keys, if 'meta' option set */ #ifdef META8_OPTION - if (meta && (R->h->meta_char == 0x80) && len > 0) + if (meta && (R->meta_char == 0x80) && len > 0) kbuf[len - 1] |= 0x80; #endif } else if (ctrl && keysym == XK_minus) { @@ -560,7 +577,7 @@ } else { #ifdef META8_OPTION /* set 8-bit on */ - if (meta && (R->h->meta_char == 0x80)) { + if (meta && (R->meta_char == 0x80)) { unsigned char *ch; for (ch = kbuf; ch < kbuf + len; ch++) @@ -569,12 +586,12 @@ } #endif #ifdef GREEK_SUPPORT - if (R->h->greek_mode) + if (R->greek_mode) len = greek_xlat(kbuf, len); #endif /* nil */ ; } - } + } if (len <= 0) return; /* not mapped */ @@ -582,7 +599,7 @@ if (R->Options & Opt_scrollTtyKeypress) if (R->TermWin.view_start) { R->TermWin.view_start = 0; - R->h->want_refresh = 1; + R->want_refresh = 1; } /* @@ -602,12 +619,12 @@ /* escape prefix */ if (meta #ifdef META8_OPTION - && (R->h->meta_char == C0_ESC) + && (R->meta_char == C0_ESC) #endif ) { const unsigned char ch = C0_ESC; - rxvt_tt_write(aR_ &ch, 1); + R->tt_write(&ch, 1); } #ifdef DEBUG_CMD if (debug_key) { /* Display keyboard buffer contents */ @@ -620,7 +637,7 @@ fprintf(stderr, "'\n"); } #endif /* DEBUG_CMD */ - rxvt_tt_write(aR_ kbuf, (unsigned int)len); + R->tt_write(kbuf, (unsigned int)len); } /*}}} */ @@ -632,9 +649,9 @@ rxvt_cmd_write(pR_ const unsigned char *str, unsigned int count) { unsigned int n, s; - unsigned char *cmdbuf_base = R->h->cmdbuf_base, - *cmdbuf_endp = R->h->cmdbuf_endp, - *cmdbuf_ptr = R->h->cmdbuf_ptr; + unsigned char *cmdbuf_base = R->cmdbuf_base, + *cmdbuf_endp = R->cmdbuf_endp, + *cmdbuf_ptr = R->cmdbuf_ptr; n = cmdbuf_ptr - cmdbuf_base; s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp; @@ -651,64 +668,275 @@ } for (; count--;) *cmdbuf_endp++ = *str++; - R->h->cmdbuf_ptr = cmdbuf_ptr; - R->h->cmdbuf_endp = cmdbuf_endp; + R->cmdbuf_ptr = cmdbuf_ptr; + R->cmdbuf_endp = cmdbuf_endp; return 0; } #endif /* MENUBAR_MAX */ -// read the next character, currently handles UTF-8 -// will probably handle all sorts of other stuff in the future -static uint32_t -next_char (pR) +void +rxvt_term::flush () { - rxvt_hidden *h = R->h; - mbstate &s = h->mbstate; +#ifdef TRANSPARENT + if (want_full_refresh) + { + want_full_refresh = 0; + scr_clear (); + scr_touch (false); + want_refresh = 1; + } +#endif - while (h->cmdbuf_ptr < h->cmdbuf_endp) + if (want_refresh) { - uint8_t ch = *h->cmdbuf_ptr; + scr_refresh (refresh_type); + rxvt_scrollbar_show (this, 1); +#ifdef USE_XIM + rxvt_IMSendSpot (this); +#endif + } - if (s.cnt) - { - if ((ch & 0xc0) == 0x80) - { - h->cmdbuf_ptr++; + XFlush (Xdisplay); +#if 0 + if (XPending (Xdisplay)) process_x_events (); + if (XPending (Xdisplay)) process_x_events (); +#endif +} - /* continuation */ - s.reg = (s.reg << 6) | (ch & 0x7f); +void +rxvt_term::check_cb (check_watcher &w) +{ + SET_R (this); + SET_LOCALE (locale); - if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or hacking */ - return s.reg; + flush (); +} - continue; - } - else +void +rxvt_term::process_x_events () +{ + do + { + XEvent xev; + + XNextEvent (Xdisplay, &xev); + +#if defined(CURSOR_BLINK) + if ((Options & Opt_cursorBlink) + && xev.type == KeyPress) + { + if (hidden_cursor) { - s.cnt = 0; - return s.orig; /* the _occasional_ non-utf-8 character may slip through... */ + hidden_cursor = 0; + want_refresh = 1; } + + blink_ev.start (NOW + BLINK_INTERVAL); } - - if ((ch & 0xc0) == 0xc0) +#endif + +#if defined(POINTER_BLANK) + if ((Options & Opt_pointerBlank) + && (pointerBlankDelay > 0)) { - h->cmdbuf_ptr++; + if (xev.type == MotionNotify + || xev.type == ButtonPress + || xev.type == ButtonRelease) + if (hidden_pointer) + pointer_unblank (); - /* first byte */ - s.orig = ch; /* for broken encodings */ - s.reg = ch; - if ((ch & 0xe0) == 0xc0) { s.reg &= 0x1f; s.cnt = 1; } - if ((ch & 0xf0) == 0xe0) { s.reg &= 0x0f; s.cnt = 2; } - if ((ch & 0xf8) == 0xf0) { s.reg &= 0x07; s.cnt = 3; } - if ((ch & 0xfc) == 0xf8) { s.reg &= 0x03; s.cnt = 4; } - if ((ch & 0xfe) == 0xfc) { s.reg &= 0x01; s.cnt = 5; } + if (xev.type == KeyPress && hidden_pointer == 0) + pointer_blank (); } - else +#endif + +#ifdef USE_XIM + if (!XFilterEvent (&xev, xev.xany.window)) +#endif + rxvt_process_x_event (this, &xev); + } + while (XPending (Xdisplay)); +} + +void +rxvt_term::blink_cb (time_watcher &w) +{ + w.at += BLINK_INTERVAL; + hidden_cursor = !hidden_cursor; + want_refresh = 1; +} + +void +rxvt_term::x_cb (io_watcher &w, short revents) +{ + SET_R (this); + SET_LOCALE (locale); + + process_x_events (); +} + +bool +rxvt_term::pty_fill () +{ + ssize_t n = cmdbuf_endp - cmdbuf_ptr; + + memmove (cmdbuf_base, cmdbuf_ptr, n); + cmdbuf_ptr = cmdbuf_base; + cmdbuf_endp = cmdbuf_ptr + n; + + n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); + + if (n > 0) + { + cmdbuf_endp += n; + return true; + } + else if (n < 0 && errno != EAGAIN) + destroy (); + + return false; +} + +void +rxvt_term::pty_cb (io_watcher &w, short revents) +{ + SET_R (this); + SET_LOCALE (locale); + + 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 ()) { - h->cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */ - return ch; + if (!seen_input) + { + seen_input = 1; + /* once we know the shell is running, send the screen size. Again! */ + tt_winch (); + } + + uint32_t ch = NOCHAR; + + for (;;) + { + if (ch == NOCHAR) + ch = next_char (); + + if (ch == NOCHAR) // TODO: improve + break; + + if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') + { + /* Read a text string from the input buffer */ + uint32_t buf[BUFSIZ]; + bool refreshnow = false; + int nlines = 0; + uint32_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; + } + } + + if (str >= buf + BUFSIZ) + { + ch = NOCHAR; + break; + } + } + } + + rxvt_scr_add_lines (this, 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: + rxvt_process_nonprinting (this, ch); + break; + case C0_ESC: /* escape char */ + rxvt_process_escape_seq (this); + break; + /*case 0x9b: */ /* CSI */ + /* rxvt_process_csi_seq (this); */ + } + + ch = NOCHAR; + } + } } } +} + +// read the next character, currently handles UTF-8 +// will probably handle all sorts of other stuff in the future +uint32_t +rxvt_term::next_char () +{ + while (cmdbuf_ptr < cmdbuf_endp) + { + if (*cmdbuf_ptr < 0x80) // assume < 0x80 to be ascii ALWAYS (all shift-states etc.) uh-oh + return *cmdbuf_ptr++; + + wchar_t wc; + int len = mbrtowc (&wc, (char *)cmdbuf_ptr, cmdbuf_endp - cmdbuf_ptr, &mbstate.mbs); + + if (len == (size_t)-2) + return NOCHAR; + + 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; } @@ -722,6 +950,20 @@ uint32_t rxvt_cmd_getc(pR) { + for (;;) + { + uint32_t c = R->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 (R->cmd_fd, F_SETFL, 0); + R->pty_fill (); + fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK); + } + +#if 0 #define TIMEOUT_USEC 5000 fd_set readfds; int quick_timeout, select_res; @@ -730,276 +972,93 @@ #if defined(POINTER_BLANK) || defined(CURSOR_BLINK) struct timeval tp; #endif - struct rxvt_hidden *h = R->h; - - uint32_t c = next_char (aR); - if (c != NOCHAR) - return c; for (;;) { /* loop until we can return something */ - if (h->v_bufstr < h->v_bufptr) /* output any pending chars */ - rxvt_tt_write(aR_ NULL, 0); - -#if defined(POINTER_BLANK) || defined(CURSOR_BLINK) - tp.tv_sec = 0; /* presume == 0 implies time not yet retrieved */ -#endif -#if defined(CURSOR_BLINK) - want_keypress_time = 0; -#endif -#if defined(POINTER_BLANK) - want_motion_time = 0; -#endif - - while (XPending(R->Xdisplay)) { /* process pending X events */ - XEvent xev; - - XNextEvent(R->Xdisplay, &xev); -#if defined(CURSOR_BLINK) - if ((R->Options & Opt_cursorBlink) - && xev.type == KeyPress) { - if (h->hidden_cursor) { - h->hidden_cursor = 0; - h->want_refresh = 1; - } - want_keypress_time = 1; - } -#endif -#if defined(POINTER_BLANK) - if ((R->Options & Opt_pointerBlank) - && (h->pointerBlankDelay > 0)) { - if (xev.type == MotionNotify - || xev.type == ButtonPress - || xev.type == ButtonRelease) { - if (R->h->hidden_pointer) - rxvt_pointer_unblank(aR); - want_motion_time = 1; - } - if (xev.type == KeyPress && R->h->hidden_pointer == 0) - rxvt_pointer_blank(aR); - } -#endif -#ifdef USE_XIM - if (!XFilterEvent(&xev, xev.xany.window)) - rxvt_process_x_event(aR_ &xev); - h->event_type = xev.type; -#else - rxvt_process_x_event(aR_ &xev); -#endif - /* in case button actions pushed chars to cmdbuf */ - if (h->cmdbuf_ptr < h->cmdbuf_endp) - return *h->cmdbuf_ptr++; - } - -#if defined(CURSOR_BLINK) - if (want_keypress_time) { - (void)gettimeofday(&tp, NULL); - h->lastcursorchange.tv_sec = tp.tv_sec; - h->lastcursorchange.tv_usec = tp.tv_usec; - } -#endif -#if defined(POINTER_BLANK) - if (want_motion_time) { - if (!tp.tv_sec) - (void)gettimeofday(&tp, NULL); - h->lastmotion.tv_sec = tp.tv_sec; - h->lastmotion.tv_usec = tp.tv_usec; - } -#endif - -/* - * the command input buffer is empty and we have no pending X events - */ - quick_timeout = 0; + if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ + R->tt_write(NULL, 0); #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) - if (h->mouse_slip_wheel_speed) { + if (R->mouse_slip_wheel_speed) { quick_timeout = 1; - if (!h->mouse_slip_wheel_delay-- - && rxvt_scr_page(aR_ h->mouse_slip_wheel_speed > 0 ? UP : DN, - abs(h->mouse_slip_wheel_speed))) { - h->mouse_slip_wheel_delay = SCROLLBAR_CONTINUOUS_DELAY; - h->refresh_type |= SMOOTH_REFRESH; - h->want_refresh = 1; + if (!R->mouse_slip_wheel_delay-- + && rxvt_scr_page(aR_ R->mouse_slip_wheel_speed > 0 ? UP : DN, + abs(R->mouse_slip_wheel_speed))) { + R->mouse_slip_wheel_delay = SCROLLBAR_CONTINUOUS_DELAY; + R->refresh_type |= SMOOTH_REFRESH; + R->want_refresh = 1; } } #endif /* MOUSE_WHEEL && MOUSE_SLIP_WHEELING */ #ifdef SELECTION_SCROLLING - if (h->pending_scroll_selection) { + if (R->pending_scroll_selection) { quick_timeout = 1; - if (!h->scroll_selection_delay-- - && rxvt_scr_page(aR_ h->scroll_selection_dir, - h->scroll_selection_lines)) { - rxvt_selection_extend(aR_ h->selection_save_x, - h->selection_save_y, h->selection_save_state); - h->scroll_selection_delay = SCROLLBAR_CONTINUOUS_DELAY; - h->refresh_type |= SMOOTH_REFRESH; - h->want_refresh = 1; + if (!R->scroll_selection_delay-- + && rxvt_scr_page(aR_ R->scroll_selection_dir, + R->scroll_selection_lines)) { + R->selection_extend (R->selection_save_x, + R->selection_save_y, R->selection_save_state); + R->scroll_selection_delay = SCROLLBAR_CONTINUOUS_DELAY; + R->refresh_type |= SMOOTH_REFRESH; + R->want_refresh = 1; } } #endif #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING if (scrollbar_isUp() || scrollbar_isDn()) { quick_timeout = 1; - if (!h->scroll_arrow_delay-- + if (!R->scroll_arrow_delay-- && rxvt_scr_page(aR_ scrollbar_isUp() ? UP : DN, 1)) { - h->scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY; - h->refresh_type |= SMOOTH_REFRESH; - h->want_refresh = 1; + R->scroll_arrow_delay = SCROLLBAR_CONTINUOUS_DELAY; + R->refresh_type |= SMOOTH_REFRESH; + R->want_refresh = 1; } } #endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ - FD_ZERO(&readfds); - FD_SET(R->cmd_fd, &readfds); - FD_SET(R->Xfd, &readfds); - value.tv_usec = TIMEOUT_USEC; - value.tv_sec = 0; - - if (!R->TermWin.mapped) - quick_timeout = 0; - else { - quick_timeout |= h->want_refresh; #ifdef TRANSPARENT - quick_timeout |= h->want_full_refresh; + quick_timeout |= R->want_full_refresh; #endif - } - -#if defined(POINTER_BLANK) || defined(CURSOR_BLINK) - { - int set_quick_timeout = 0; - long csdiff, psdiff; - -#define BLINK_TIME 500000L - csdiff = psdiff = 60000000L; /* or, say, LONG_MAX */ -# if defined(CURSOR_BLINK) - if (R->Options & Opt_cursorBlink) { - if (!tp.tv_sec) /* didn't get it before so get it now */ - (void)gettimeofday(&tp, NULL); - - csdiff = (tp.tv_sec - h->lastcursorchange.tv_sec) * 1000000L - + tp.tv_usec - h->lastcursorchange.tv_usec; - if (csdiff > BLINK_TIME) { /* XXX: settable blink times */ - h->lastcursorchange.tv_sec = tp.tv_sec; - h->lastcursorchange.tv_usec = tp.tv_usec; - h->hidden_cursor = !h->hidden_cursor; - csdiff = 0; - } else - csdiff = BLINK_TIME - csdiff; - set_quick_timeout = 1; - } -# endif -# if defined(POINTER_BLANK) - /* - * If we haven't moved the pointer for a while - */ - if ((R->Options & Opt_pointerBlank) - && (h->pointerBlankDelay > 0) - && (h->hidden_pointer == 0)) { - long pdelay; - - if (!tp.tv_sec) /* didn't get it before so get it now */ - (void)gettimeofday(&tp, NULL); - psdiff = (tp.tv_sec - h->lastmotion.tv_sec) * 1000000L - + tp.tv_usec - h->lastmotion.tv_usec; - pdelay = h->pointerBlankDelay * 1000000L; - if (psdiff >= pdelay) - rxvt_pointer_blank(aR); - else { - set_quick_timeout = 1; - psdiff = pdelay - psdiff; - } - } -# endif - if (!quick_timeout && set_quick_timeout) { - MIN_IT(csdiff, psdiff); - value.tv_sec = csdiff / 1000000L; - value.tv_usec = csdiff % 1000000L; - quick_timeout = 1; - } - } #endif +} - if ((select_res = select(R->num_fds, &readfds, NULL, NULL, - (quick_timeout ? &value : NULL))) == 0) { - /* select statement timed out - we're not hard and fast scrolling */ - h->refresh_limit = 1; - } -#if defined(CURSOR_BLINK) - if (R->Options & Opt_cursorBlink) - h->want_refresh = 1; -#endif +void +rxvt_term::pointer_unblank () +{ + XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor); + recolour_cursor (); - /* See if we can read new data from the application */ - if (select_res > 0 && FD_ISSET(R->cmd_fd, &readfds)) { - int n; - unsigned int count; - - h->cmdbuf_ptr = h->cmdbuf_endp = h->cmdbuf_base; - for (count = BUFSIZ; count; count -= n, h->cmdbuf_endp += n) - if ((n = read(R->cmd_fd, h->cmdbuf_endp, count)) > 0) - continue; - else if (n == 0 || (n < 0 && errno == EAGAIN)) - break; - else { - rxvt_clean_exit(); - exit(EXIT_FAILURE); /* bad order of events? */ - } +#ifdef POINTER_BLANK + hidden_pointer = 0; - if (count != BUFSIZ) /* some characters read in */ - { - uint32_t c = next_char (aR); - if (c != NOCHAR) - return c; - } - } -#ifdef TRANSPARENT - if (h->want_full_refresh) { - h->want_full_refresh = 0; - rxvt_scr_clear(aR); - rxvt_scr_touch(aR_ False); - h->want_refresh = 1; - } + if (Options & Opt_pointerBlank) + pointer_ev.start (NOW + pointerBlankDelay); #endif - if (h->want_refresh) { - rxvt_scr_refresh(aR_ h->refresh_type); - rxvt_scrollbar_show(aR_ 1); -#ifdef USE_XIM - rxvt_IMSendSpot(aR); -#endif - } - } -/* NOTREACHED */ } -/*}}} */ -/* EXTPROTO */ +#ifdef POINTER_BLANK void -rxvt_pointer_unblank(pR) +rxvt_term::pointer_blank () { - XDefineCursor(R->Xdisplay, R->TermWin.vt, R->TermWin_cursor); - rxvt_recolour_cursor(aR); -#ifdef POINTER_BLANK - R->h->hidden_pointer = 0; - if (R->h->pointerBlankDelay > 0) { - struct timeval tp; - - (void)gettimeofday(&tp, NULL); - R->h->lastmotion.tv_sec = tp.tv_sec; - R->h->lastmotion.tv_usec = tp.tv_usec; - } -#endif + pointer_ev.stop (); + + if (!(Options & Opt_pointerBlank)) + return; + + XDefineCursor (Xdisplay, TermWin.vt, blank_cursor); + XFlush (Xdisplay); + + hidden_pointer = 1; } -#ifdef POINTER_BLANK -/* INTPROTO */ void -rxvt_pointer_blank(pR) +rxvt_term::pointer_cb (time_watcher &w) { - XDefineCursor(R->Xdisplay, R->TermWin.vt, R->h->pointer_blank); - XFlush(R->Xdisplay); - R->h->hidden_pointer = 1; + SET_R (this); + SET_LOCALE (locale); + + pointer_blank (); } #endif @@ -1012,18 +1071,18 @@ x = ev->x; y = ev->y; - rxvt_pixel_position(aR_ &x, &y); + R->pixel_position (&x, &y); - if (R->h->MEvent.button == AnyButton) { + if (R->MEvent.button == AnyButton) { button_number = 3; } else { - button_number = R->h->MEvent.button - Button1; + button_number = R->MEvent.button - Button1; /* add 0x3D for wheel events, like xterm does */ if (button_number >= 3) button_number += (64 - 3); } - if (R->h->PrivateModes & PrivMode_MouseX10) { + if (R->PrivateModes & PrivMode_MouseX10) { /* * do not report ButtonRelease * no state info allowed @@ -1039,11 +1098,11 @@ * plus will add in our own Double-Click reporting * 32 = Double Click */ - key_state = ((R->h->MEvent.state & ShiftMask) ? 4 : 0) - + ((R->h->MEvent.state & R->h->ModMetaMask) ? 8 : 0) - + ((R->h->MEvent.state & ControlMask) ? 16 : 0); + key_state = ((R->MEvent.state & ShiftMask) ? 4 : 0) + + ((R->MEvent.state & R->ModMetaMask) ? 8 : 0) + + ((R->MEvent.state & ControlMask) ? 16 : 0); #ifdef MOUSE_REPORT_DOUBLECLICK - key_state += ((R->h->MEvent.clicks > 1) ? 32 : 0); + key_state += ((R->MEvent.clicks > 1) ? 32 : 0); #endif } @@ -1062,7 +1121,7 @@ x + 1, y + 1); #else - rxvt_tt_printf(aR_ "\033[M%c%c%c", + R->tt_printf("\033[M%c%c%c", (32 + button_number + key_state), (32 + x + 1), (32 + y + 1)); @@ -1089,8 +1148,7 @@ Window unused_root, unused_child; int unused_root_x, unused_root_y; unsigned int unused_mask; - struct timeval tp; - struct rxvt_hidden *h = R->h; + #ifdef DEBUG_X const char *const eventnames[] = { /* mason - this matches my system */ @@ -1130,49 +1188,16 @@ "ClientMessage", "MappingNotify" }; - struct tm *ltt; -#endif - - /* - * check if we need to get the time for any timeouts - */ - - for (i = NUM_TIMEOUTS; i--; ) - if (h->timeout[i].tv_sec) { - want_timeout = 1; - break; - } - -#ifndef DEBUG_X - if (want_timeout) #endif - (void)gettimeofday(&tp, NULL); #ifdef DEBUG_X + struct timeval tp; + struct tm *ltt; + (void)gettimeofday(&tp, NULL); ltt = localtime(&(tp.tv_sec)); D_X((stderr, "Event: %-16s %-7s %08lx (%4d-%02d-%02d %02d:%02d:%02d.%.6ld) %s %lu", eventnames[ev->type], (ev->xany.window == R->TermWin.parent[0] ? "parent" : (ev->xany.window == R->TermWin.vt ? "vt" : (ev->xany.window == R->scrollBar.win ? "scroll" : (ev->xany.window == R->menuBar.win ? "menubar" : "UNKNOWN")))), (ev->xany.window == R->TermWin.parent[0] ? R->TermWin.parent[0] : (ev->xany.window == R->TermWin.vt ? R->TermWin.vt : (ev->xany.window == R->scrollBar.win ? R->scrollBar.win : (ev->xany.window == R->menuBar.win ? R->menuBar.win : 0)))), ltt->tm_year + 1900, ltt->tm_mon + 1, ltt->tm_mday, ltt->tm_hour, ltt->tm_min, ltt->tm_sec, tp.tv_usec, ev->xany.send_event ? "S" : " ", ev->xany.serial)); #endif - /* X event timeouts */ - if (want_timeout) - for (i = NUM_TIMEOUTS; i--; ) { - if (h->timeout[i].tv_sec == 0) - continue; - if ((tp.tv_sec < h->timeout[i].tv_sec) - || (tp.tv_sec == h->timeout[i].tv_sec - && tp.tv_usec < h->timeout[i].tv_usec)) - continue; - h->timeout[i].tv_sec = 0; - switch(i) { - case TIMEOUT_INCR: - rxvt_print_error("data loss: timeout on INCR selection paste"); - h->selection_wait = Sel_none; - break; - default: - break; - } - } - switch (ev->type) { case KeyPress: rxvt_lookup_key(aR_ (XKeyEvent *)ev); @@ -1182,13 +1207,13 @@ case KeyRelease: { if (!(ev->xkey.state & ControlMask)) - h->mouse_slip_wheel_speed = 0; + R->mouse_slip_wheel_speed = 0; else { KeySym ks; ks = XKeycodeToKeysym(R->Xdisplay, ev->xkey.keycode, 0); if (ks == XK_Control_L || ks == XK_Control_R) - h->mouse_slip_wheel_speed = 0; + R->mouse_slip_wheel_speed = 0; } break; } @@ -1204,11 +1229,11 @@ case ClientMessage: if (ev->xclient.format == 32 - && (Atom)ev->xclient.data.l[0] == h->xa[XA_WMDELETEWINDOW]) - exit(EXIT_SUCCESS); + && (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW]) + R->destroy (); #ifdef OFFIX_DND /* OffiX Dnd (drag 'n' drop) protocol */ - if (ev->xclient.message_type == h->xa[XA_DNDPROTOCOL] + else if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL] && (ev->xclient.data.l[0] == DndFile || ev->xclient.data.l[0] == DndDir || ev->xclient.data.l[0] == DndLink)) { @@ -1219,7 +1244,7 @@ unsigned long Size, RemainingBytes; XGetWindowProperty(R->Xdisplay, Xroot, - R->h->xa[XA_DNDSELECTION], + R->xa[XA_DNDSELECTION], 0L, 1000000L, False, AnyPropertyType, &ActualType, &ActualFormat, @@ -1250,26 +1275,31 @@ * which ought to make things real slow! */ case VisibilityNotify: - switch (ev->xvisibility.state) { - case VisibilityUnobscured: - h->refresh_type = FAST_REFRESH; - break; - case VisibilityPartiallyObscured: - h->refresh_type = SLOW_REFRESH; - break; - default: - h->refresh_type = NO_REFRESH; - break; - } + switch (ev->xvisibility.state) + { + case VisibilityUnobscured: + R->refresh_type = FAST_REFRESH; + break; + case VisibilityPartiallyObscured: + R->refresh_type = SLOW_REFRESH; + break; + default: + R->refresh_type = NO_REFRESH; + break; + } break; case FocusIn: if (!R->TermWin.focus) { R->TermWin.focus = 1; - h->want_refresh = 1; + R->want_refresh = 1; #ifdef USE_XIM - if (h->Input_Context != NULL) - XSetICFocus(h->Input_Context); + if (R->Input_Context != NULL) + XSetICFocus(R->Input_Context); +#endif +#ifdef CURSOR_BLINK + if (R->Options & Opt_cursorBlink) + R->blink_ev.start (NOW + BLINK_INTERVAL); #endif } break; @@ -1277,10 +1307,15 @@ case FocusOut: if (R->TermWin.focus) { R->TermWin.focus = 0; - h->want_refresh = 1; + R->want_refresh = 1; #ifdef USE_XIM - if (h->Input_Context != NULL) - XUnsetICFocus(h->Input_Context); + if (R->Input_Context != NULL) + XUnsetICFocus(R->Input_Context); +#endif +#ifdef CURSOR_BLINK + if (R->Options & Opt_cursorBlink) + R->blink_ev.stop (); + R->hidden_cursor = 0; #endif } break; @@ -1297,8 +1332,7 @@ ConfigureNotify, ev)); if (R->szHint.width != width || R->szHint.height != height) { D_SIZE((stderr, "Size: Resizing from: %4d x %4d", R->szHint.width, R->szHint.height)); - rxvt_resize_all_windows(aR_ (unsigned int)width, - (unsigned int)height, 1); + R->resize_all_windows (width, height, 1); } #ifdef DEBUG_SIZE else { @@ -1308,8 +1342,8 @@ #ifdef TRANSPARENT /* XXX: maybe not needed - leave in for now */ if (R->Options & Opt_transparent) { rxvt_check_our_parents(aR); - if (h->am_transparent) - h->want_full_refresh = 1; + if (R->am_transparent) + R->want_full_refresh = 1; } #endif } @@ -1320,7 +1354,7 @@ break; case SelectionNotify: - if (h->selection_wait == Sel_normal) + if (R->selection_wait == Sel_normal) rxvt_selection_paste(aR_ ev->xselection.requestor, ev->xselection.property, True); break; @@ -1338,7 +1372,7 @@ break; case PropertyNotify: - if (ev->xproperty.atom == h->xa[XA_VT_SELECTION]) { + if (ev->xproperty.atom == R->xa[XA_VT_SELECTION]) { if (ev->xproperty.state == PropertyNewValue) rxvt_selection_property(aR_ ev->xproperty.window, ev->xproperty.atom); @@ -1349,16 +1383,16 @@ * 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 (h->xa[XA_XROOTPMAPID] == 0) - h->xa[XA_XROOTPMAPID] = XInternAtom(R->Xdisplay, + if (R->xa[XA_XROOTPMAPID] == 0) + R->xa[XA_XROOTPMAPID] = XInternAtom(R->Xdisplay, "_XROOTPMAP_ID", False); - if (ev->xproperty.atom != h->xa[XA_XROOTPMAPID]) + if (ev->xproperty.atom != R->xa[XA_XROOTPMAPID]) break; /* FALLTHROUGH */ case ReparentNotify: if ((R->Options & Opt_transparent) && rxvt_check_our_parents(aR)) { - if (h->am_transparent) - h->want_full_refresh = 1; + if (R->am_transparent) + R->want_full_refresh = 1; } #endif /* TRANSPARENT */ break; @@ -1367,16 +1401,16 @@ case Expose: if (ev->xany.window == R->TermWin.vt) { #ifdef NO_SLOW_LINK_SUPPORT - rxvt_scr_expose(aR_ ev->xexpose.x, ev->xexpose.y, - ev->xexpose.width, ev->xexpose.height, False); + R->scr_expose (ev->xexpose.x, ev->xexpose.y, + ev->xexpose.width, ev->xexpose.height, False); #else // don't understand this, so commented it out - rxvt_scr_expose(aR_ ev->xexpose.x, ev->xexpose.y, - ev->xexpose.width, ev->xexpose.height, False); + R->scr_expose (ev->xexpose.x, ev->xexpose.y, + ev->xexpose.width, ev->xexpose.height, False); //rxvt_scr_expose(aR_ ev->xexpose.x, 0, // ev->xexpose.width, R->TermWin.height, False); #endif - h->want_refresh = 1; + R->want_refresh = 1; } else { XEvent unused_xevent; @@ -1387,7 +1421,7 @@ GraphicsExpose, &unused_xevent)) ; if (isScrollbarWindow(ev->xany.window)) { - scrollbar_setIdle(); + R->scrollBar.setIdle(); rxvt_scrollbar_show(aR_ 0); } #ifdef MENUBAR @@ -1402,8 +1436,8 @@ case MotionNotify: #ifdef POINTER_BLANK - if (R->h->hidden_pointer) - rxvt_pointer_unblank(aR); + if (R->hidden_pointer) + R->pointer_unblank (); #endif #if MENUBAR if (isMenuBarWindow(ev->xany.window)) { @@ -1411,7 +1445,7 @@ break; } #endif - if ((h->PrivateModes & PrivMode_mouse_report) && !(h->bypass_keystate)) + if ((R->PrivateModes & PrivMode_mouse_report) && !(R->bypass_keystate)) break; if (ev->xany.window == R->TermWin.vt) { @@ -1425,51 +1459,51 @@ &unused_mask); #ifdef MOUSE_THRESHOLD /* deal with a `jumpy' mouse */ - if ((ev->xmotion.time - h->MEvent.time) > MOUSE_THRESHOLD) { + if ((ev->xmotion.time - R->MEvent.time) > MOUSE_THRESHOLD) { #endif - rxvt_selection_extend(aR_ (ev->xbutton.x), (ev->xbutton.y), + R->selection_extend ((ev->xbutton.x), (ev->xbutton.y), (ev->xbutton.state & Button3Mask) ? 2 : 0); #ifdef SELECTION_SCROLLING if (ev->xbutton.yTermWin.int_bwidth || Pixel2Row(ev->xbutton.y)>(R->TermWin.nrow-1)) { int dist; - h->pending_scroll_selection=1; + R->pending_scroll_selection=1; /* don't clobber the current delay if we are * already in the middle of scrolling. */ - if (h->scroll_selection_delay<=0) - h->scroll_selection_delay=SCROLLBAR_CONTINUOUS_DELAY; + if (R->scroll_selection_delay<=0) + R->scroll_selection_delay=SCROLLBAR_CONTINUOUS_DELAY; /* save the event params so we can highlight * the selection in the pending-scroll loop */ - h->selection_save_x=ev->xbutton.x; - h->selection_save_y=ev->xbutton.y; - h->selection_save_state= + R->selection_save_x=ev->xbutton.x; + R->selection_save_y=ev->xbutton.y; + R->selection_save_state= (ev->xbutton.state & Button3Mask) ? 2 : 0; /* calc number of lines to scroll */ if (ev->xbutton.yTermWin.int_bwidth) { - h->scroll_selection_dir = UP; + R->scroll_selection_dir = UP; dist = R->TermWin.int_bwidth - ev->xbutton.y; } else { - h->scroll_selection_dir = DN; + R->scroll_selection_dir = DN; dist = ev->xbutton.y - (R->TermWin.int_bwidth + R->TermWin.height); } - h->scroll_selection_lines=(Pixel2Height(dist)/ + R->scroll_selection_lines=(Pixel2Height(dist)/ SELECTION_SCROLL_LINE_SPEEDUP)+1; - MIN_IT(h->scroll_selection_lines, + MIN_IT(R->scroll_selection_lines, SELECTION_SCROLL_MAX_LINES); } else { /* we are within the text window, so we * shouldn't be scrolling */ - h->pending_scroll_selection = 0; + R->pending_scroll_selection = 0; } #endif #ifdef MOUSE_THRESHOLD @@ -1484,10 +1518,10 @@ &unused_root_x, &unused_root_y, &(ev->xbutton.x), &(ev->xbutton.y), &unused_mask); - rxvt_scr_move_to(aR_ scrollbar_position(ev->xbutton.y) - h->csrO, + rxvt_scr_move_to(aR_ scrollbar_position(ev->xbutton.y) - R->csrO, scrollbar_size()); - rxvt_scr_refresh(aR_ h->refresh_type); - h->refresh_limit = 0; + R->scr_refresh (R->refresh_type); + R->refresh_limit = 0; rxvt_scrollbar_show(aR_ 1); } break; @@ -1499,11 +1533,10 @@ rxvt_button_press(pR_ XButtonEvent *ev) { int reportmode = 0, clickintime; - struct rxvt_hidden *h = R->h; - h->bypass_keystate = ev->state & (h->ModMetaMask | ShiftMask); - if (!h->bypass_keystate) - reportmode = !!(h->PrivateModes & PrivMode_mouse_report); + R->bypass_keystate = ev->state & (R->ModMetaMask | ShiftMask); + if (!R->bypass_keystate) + reportmode = !!(R->PrivateModes & PrivMode_mouse_report); /* * VT window processing of button press */ @@ -1511,69 +1544,82 @@ { #if RXVT_GRAPHICS if (ev->subwindow != None) - rxvt_Gr_ButtonPress(ev->x, ev->y); + rxvt_Gr_ButtonPress (ev->x, ev->y); else #endif { - clickintime = ev->time - h->MEvent.time < MULTICLICK_TIME; + clickintime = ev->time - R->MEvent.time < MULTICLICK_TIME; if (reportmode) { /* mouse report from vt window */ /* save the xbutton state (for ButtonRelease) */ - h->MEvent.state = ev->state; + R->MEvent.state = ev->state; #ifdef MOUSE_REPORT_DOUBLECLICK - if (ev->button == h->MEvent.button && clickintime) + if (ev->button == R->MEvent.button && clickintime) { /* same button, within alloted time */ - h->MEvent.clicks++; - if (h->MEvent.clicks > 1) + R->MEvent.clicks++; + if (R->MEvent.clicks > 1) { /* only report double clicks */ - h->MEvent.clicks = 2; + R->MEvent.clicks = 2; rxvt_mouse_report(aR_ ev); /* don't report the release */ - h->MEvent.clicks = 0; - h->MEvent.button = AnyButton; + R->MEvent.clicks = 0; + R->MEvent.button = AnyButton; } } else { /* different button, or time expired */ - h->MEvent.clicks = 1; - h->MEvent.button = ev->button; + R->MEvent.clicks = 1; + R->MEvent.button = ev->button; rxvt_mouse_report(aR_ ev); } #else - h->MEvent.button = ev->button; + R->MEvent.button = ev->button; rxvt_mouse_report(aR_ ev); #endif /* MOUSE_REPORT_DOUBLECLICK */ } else { - if (ev->button != h->MEvent.button) - h->MEvent.clicks = 0; + if (ev->button != R->MEvent.button) + R->MEvent.clicks = 0; switch (ev->button) { case Button1: - if (h->MEvent.button == Button1 && clickintime) - h->MEvent.clicks++; + /* allow shift+left click to extend selection */ + if (ev->state & ShiftMask) + { + if (R->MEvent.button == Button1 && clickintime) + R->selection_rotate (ev->x, ev->y); + else + R->selection_extend (ev->x, ev->y, 1); + } else - h->MEvent.clicks = 1; - rxvt_selection_click(aR_ h->MEvent.clicks, ev->x, ev->y); - h->MEvent.button = Button1; + { + if (R->MEvent.button == Button1 && clickintime) + R->MEvent.clicks++; + else + R->MEvent.clicks = 1; + + R->selection_click (R->MEvent.clicks, ev->x, ev->y); + } + + R->MEvent.button = Button1; break; case Button3: - if (h->MEvent.button == Button3 && clickintime) - rxvt_selection_rotate(aR_ ev->x, ev->y); + if (R->MEvent.button == Button3 && clickintime) + R->selection_rotate (ev->x, ev->y); else - rxvt_selection_extend(aR_ ev->x, ev->y, 1); - h->MEvent.button = Button3; + R->selection_extend (ev->x, ev->y, 1); + R->MEvent.button = Button3; break; } } - h->MEvent.time = ev->time; + R->MEvent.time = ev->time; return; } } @@ -1583,7 +1629,7 @@ */ if (isScrollbarWindow(ev->window)) { - scrollbar_setIdle(); + R->scrollBar.setIdle (); /* * Rxvt-style scrollbar: * move up if mouse is above slider @@ -1605,22 +1651,22 @@ && scrollbarnext_upButton(ev->y)) || (R->scrollBar.style == R_SB_RXVT && scrollbarrxvt_upButton(ev->y))) - rxvt_tt_printf(aR_ "\033[A"); + R->tt_printf("\033[A"); else if ((R->scrollBar.style == R_SB_NEXT && scrollbarnext_dnButton(ev->y)) || (R->scrollBar.style == R_SB_RXVT && scrollbarrxvt_dnButton(ev->y))) - rxvt_tt_printf(aR_ "\033[B"); + R->tt_printf("\033[B"); else switch (ev->button) { case Button2: - rxvt_tt_printf(aR_ "\014"); + R->tt_printf("\014"); break; case Button1: - rxvt_tt_printf(aR_ "\033[6~"); + R->tt_printf("\033[6~"); break; case Button3: - rxvt_tt_printf(aR_ "\033[5~"); + R->tt_printf("\033[5~"); break; } } @@ -1642,40 +1688,40 @@ } if (upordown) { #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - h->scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY; + R->scroll_arrow_delay = SCROLLBAR_INITIAL_DELAY; #endif if (rxvt_scr_page(aR_ upordown < 0 ? UP : DN, 1)) { if (upordown < 0) - scrollbar_setUp(); + R->scrollBar.setUp (); else - scrollbar_setDn(); + R->scrollBar.setDn (); } } else switch (ev->button) { case Button2: - switch (h->scrollbar_align) { + switch (R->scrollbar_align) { case R_SB_ALIGN_TOP: - h->csrO = 0; + R->csrO = 0; break; case R_SB_ALIGN_CENTRE: - h->csrO = (R->scrollBar.bot - R->scrollBar.top) / 2; + R->csrO = (R->scrollBar.bot - R->scrollBar.top) / 2; break; case R_SB_ALIGN_BOTTOM: - h->csrO = R->scrollBar.bot - R->scrollBar.top; + R->csrO = R->scrollBar.bot - R->scrollBar.top; break; } if (R->scrollBar.style == R_SB_XTERM || scrollbar_above_slider(ev->y) || scrollbar_below_slider(ev->y)) rxvt_scr_move_to(aR_ - scrollbar_position(ev->y) - h->csrO, + scrollbar_position(ev->y) - R->csrO, scrollbar_size()); - scrollbar_setMotion(); + R->scrollBar.setMotion (); break; case Button1: - if (h->scrollbar_align == R_SB_ALIGN_CENTRE) - h->csrO = ev->y - R->scrollBar.top; + if (R->scrollbar_align == R_SB_ALIGN_CENTRE) + R->csrO = ev->y - R->scrollBar.top; /* FALLTHROUGH */ case Button3: @@ -1693,7 +1739,7 @@ rxvt_scr_page(aR_ DN, R->TermWin.nrow / 4); # endif else - scrollbar_setMotion(); + R->scrollBar.setMotion (); } else { rxvt_scr_page(aR_ (ev->button == Button1 ? DN : UP), (R->TermWin.nrow @@ -1720,19 +1766,19 @@ { int reportmode = 0; - R->h->csrO = 0; /* reset csr Offset */ - if (!R->h->bypass_keystate) - reportmode = !!(R->h->PrivateModes & PrivMode_mouse_report); + R->csrO = 0; /* reset csr Offset */ + if (!R->bypass_keystate) + reportmode = !!(R->PrivateModes & PrivMode_mouse_report); if (scrollbar_isUpDn()) { - scrollbar_setIdle(); + R->scrollBar.setIdle (); rxvt_scrollbar_show(aR_ 0); #ifndef NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING - R->h->refresh_type &= ~SMOOTH_REFRESH; + R->refresh_type &= ~SMOOTH_REFRESH; #endif } #ifdef SELECTION_SCROLLING - R->h->pending_scroll_selection=0; + R->pending_scroll_selection=0; #endif if (ev->window == R->TermWin.vt) { @@ -1750,17 +1796,17 @@ return; #ifdef MOUSE_REPORT_DOUBLECLICK /* only report the release of 'slow' single clicks */ - if (R->h->MEvent.button != AnyButton - && (ev->button != R->h->MEvent.button - || (ev->time - R->h->MEvent.time + if (R->MEvent.button != AnyButton + && (ev->button != R->MEvent.button + || (ev->time - R->MEvent.time > MULTICLICK_TIME / 2))) { - R->h->MEvent.clicks = 0; - R->h->MEvent.button = AnyButton; + R->MEvent.clicks = 0; + R->MEvent.button = AnyButton; rxvt_mouse_report(aR_ ev); } #else /* MOUSE_REPORT_DOUBLECLICK */ - R->h->MEvent.button = AnyButton; + R->MEvent.button = AnyButton; rxvt_mouse_report(aR_ ev); #endif /* MOUSE_REPORT_DOUBLECLICK */ return; @@ -1769,10 +1815,10 @@ * dumb hack to compensate for the failure of click-and-drag * when overriding mouse reporting */ - if (R->h->PrivateModes & PrivMode_mouse_report - && R->h->bypass_keystate - && ev->button == Button1 && R->h->MEvent.clicks <= 1) - rxvt_selection_extend(aR_ ev->x, ev->y, 0); + if (R->PrivateModes & PrivMode_mouse_report + && R->bypass_keystate + && ev->button == Button1 && R->MEvent.clicks <= 1) + R->selection_extend (ev->x, ev->y, 0); switch (ev->button) { case Button1: @@ -1786,7 +1832,8 @@ case Button4: case Button5: { - int i, v; + int i; + page_dirn v; v = (ev->button == Button4) ? UP : DN; if (ev->state & ShiftMask) @@ -1798,19 +1845,19 @@ # ifdef MOUSE_SLIP_WHEELING if (ev->state & ControlMask) { - R->h->mouse_slip_wheel_speed += (v ? -1 : 1); - R->h->mouse_slip_wheel_delay = SCROLLBAR_CONTINUOUS_DELAY; + R->mouse_slip_wheel_speed += (v ? -1 : 1); + R->mouse_slip_wheel_delay = SCROLLBAR_CONTINUOUS_DELAY; } # endif # ifdef JUMP_MOUSE_WHEEL rxvt_scr_page(aR_ v, i); - rxvt_scr_refresh(aR_ SMOOTH_REFRESH); + R->scr_refresh (SMOOTH_REFRESH); rxvt_scrollbar_show(aR_ 1); # else - for (; i--;) + while (i--) { rxvt_scr_page(aR_ v, 1); - rxvt_scr_refresh(aR_ SMOOTH_REFRESH); + R->scr_refresh (SMOOTH_REFRESH); rxvt_scrollbar_show(aR_ 1); } # endif @@ -1854,11 +1901,11 @@ XGetWindowAttributes(R->Xdisplay, R->TermWin.parent[0], &wattr); if (rootdepth != wattr.depth) { - if (R->h->am_transparent) { + if (R->am_transparent) { pchanged = 1; XSetWindowBackground(R->Xdisplay, R->TermWin.vt, R->PixColors[Color_bg]); - R->h->am_transparent = R->h->am_pixmap_trans = 0; + R->am_transparent = R->am_pixmap_trans = 0; } return pchanged; /* Don't try any more */ } @@ -1871,8 +1918,8 @@ * the root background. Some window managers put multiple nested frame * windows for each client, so we have to take care about that. */ - i = (R->h->xa[XA_XROOTPMAPID] != 0 - && (XGetWindowProperty(R->Xdisplay, Xroot, R->h->xa[XA_XROOTPMAPID], + i = (R->xa[XA_XROOTPMAPID] != 0 + && (XGetWindowProperty(R->Xdisplay, Xroot, R->xa[XA_XROOTPMAPID], 0L, 1L, False, XA_PIXMAP, &atype, &aformat, &nitems, &bytes_after, &prop) == Success)); if (!i || prop == NULL) @@ -1910,21 +1957,21 @@ } MIN_IT(nw, (unsigned int)(wrootattr.width - sx)); MIN_IT(nh, (unsigned int)(wrootattr.height - sy)); - R->h->allowedxerror = -1; + R->allowedxerror = -1; image = XGetImage(R->Xdisplay, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap); /* XXX: handle BadMatch - usually because we're outside the pixmap */ /* XXX: may need a delay here? */ - R->h->allowedxerror = 0; + R->allowedxerror = 0; if (image == NULL) { - if (R->h->am_transparent && R->h->am_pixmap_trans) { + if (R->am_transparent && R->am_pixmap_trans) { pchanged = 1; if (R->TermWin.pixmap != None) { XFreePixmap(R->Xdisplay, R->TermWin.pixmap); R->TermWin.pixmap = None; } } - R->h->am_pixmap_trans = 0; + R->am_pixmap_trans = 0; } else { if (R->TermWin.pixmap != None) XFreePixmap(R->Xdisplay, R->TermWin.pixmap); @@ -1940,12 +1987,12 @@ XDestroyImage(image); XSetWindowBackgroundPixmap(R->Xdisplay, R->TermWin.vt, R->TermWin.pixmap); - if (!R->h->am_transparent || !R->h->am_pixmap_trans) + if (!R->am_transparent || !R->am_pixmap_trans) pchanged = 1; - R->h->am_transparent = R->h->am_pixmap_trans = 1; + R->am_transparent = R->am_pixmap_trans = 1; } } - if (!R->h->am_pixmap_trans) { + if (!R->am_pixmap_trans) { unsigned int n; /* * InheritPixmap transparency @@ -1971,7 +2018,7 @@ for (; n < (unsigned int)i; n++) { XGetWindowAttributes(R->Xdisplay, R->TermWin.parent[n], &wattr); D_X((stderr, "InheritPixmap Checking Parent[%d]: %s", n, (wattr.depth == rootdepth && wattr.class != InputOnly) ? "OK" : "FAIL")); - if (wattr.depth != rootdepth || wattr.class == InputOnly) { + if (wattr.depth != rootdepth || wattr.c_class == InputOnly) { n = (int)(sizeof(R->TermWin.parent) / sizeof(Window)) + 1; break; } @@ -1984,7 +2031,7 @@ R->PixColors[Color_fg]); XSetWindowBackground(R->Xdisplay, R->TermWin.vt, R->PixColors[Color_bg]); - R->h->am_transparent = 0; + R->am_transparent = 0; /* XXX: also turn off Opt_transparent? */ } else { /* wait (an arbitrary period) for the WM to do its thing @@ -2004,7 +2051,7 @@ ParentRelative); XSetWindowBackgroundPixmap(R->Xdisplay, R->TermWin.vt, ParentRelative); - R->h->am_transparent = 1; + R->am_transparent = 1; } for (; i < (int)(sizeof(R->TermWin.parent) / sizeof(Window)); i++) R->TermWin.parent[i] = None; @@ -2022,7 +2069,7 @@ FILE * rxvt_popen_printer(pR) { - FILE *stream = popen(R->h->rs[Rs_print_pipe], "w"); + FILE *stream = popen(R->rs[Rs_print_pipe], "w"); if (stream == NULL) rxvt_print_error("can't open printer pipe"); @@ -2031,15 +2078,15 @@ /* EXTPROTO */ int -rxvt_pclose_printer(FILE *stream) +rxvt_pclose_printer (FILE *stream) { - fflush(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); */ + return pclose (stream); /* return fclose (stream); */ # else - return pclose(stream); + return pclose (stream); # endif } @@ -2111,12 +2158,12 @@ { switch (ch) { case C0_ENQ: /* terminal Status */ - if (R->h->rs[Rs_answerbackstring]) - rxvt_tt_write(aR_ - (const unsigned char *)R->h->rs[Rs_answerbackstring], - (unsigned int)STRLEN(R->h->rs[Rs_answerbackstring])); + if (R->rs[Rs_answerbackstring]) + R->tt_write( + (const unsigned char *)R->rs[Rs_answerbackstring], + (unsigned int)STRLEN(R->rs[Rs_answerbackstring])); else - rxvt_tt_write(aR_ (unsigned char *)VT100_ANS, + R->tt_write((unsigned char *)VT100_ANS, (unsigned int)STRLEN(VT100_ANS)); break; case C0_BEL: /* bell */ @@ -2174,7 +2221,7 @@ rxvt_scr_index(aR_ DN); break; case 'J': /* erase to end of screen */ - rxvt_scr_erase_screen(aR_ 0); + R->scr_erase_screen (0); break; case 'K': /* erase to end of line */ rxvt_scr_erase_line(aR_ 0); @@ -2189,7 +2236,7 @@ rxvt_scr_gotorc(aR_ row, col, 0); break; case 'Z': /* identify the terminal type */ - rxvt_tt_printf(aR_ "\033/Z"); /* I am a VT100 emulating a VT52 */ + R->tt_printf("\033/Z"); /* I am a VT100 emulating a VT52 */ break; case '<': /* turn off VT52 mode */ PrivMode(0, PrivMode_vt52); @@ -2214,7 +2261,7 @@ { unsigned char ch = rxvt_cmd_getc(aR); - if (R->h->PrivateModes & PrivMode_vt52) { + if (R->PrivateModes & PrivMode_vt52) { rxvt_process_escape_vt52(aR_ ch); return; } @@ -2306,7 +2353,7 @@ /* 8.3.110: SINGLE CHARACTER INTRODUCER */ case C1_SCI: /* ESC Z */ - rxvt_tt_write(aR_ (const unsigned char *)ESCZ_ANSWER, + R->tt_write((const unsigned char *)ESCZ_ANSWER, (unsigned int)(sizeof(ESCZ_ANSWER) - 1)); break; /* steal obsolete ESC [ c */ @@ -2437,7 +2484,7 @@ switch (priv) { case '>': if (ch == CSI_DA) /* secondary device attributes */ - rxvt_tt_printf(aR_ "\033[>%d;%-.8s;0c", 'R', VSTRING); + R->tt_printf("\033[>%d;%-.8s;0c", 'R', VSTRING); break; case '?': if (ch == 'h' || ch == 'l' || ch == 'r' || ch == 's' || ch == 't') @@ -2519,7 +2566,7 @@ break; case CSI_ED: /* 8.3.40: (0) ERASE IN PAGE */ - rxvt_scr_erase_screen(aR_ arg[0]); + R->scr_erase_screen (arg[0]); break; case CSI_EL: /* 8.3.42: (0) ERASE IN LINE */ @@ -2550,11 +2597,11 @@ arg[0] = -arg[0]; /* FALLTHROUGH */ case CSI_SU: /* 8.3.148: (1) SCROLL UP */ - rxvt_scroll_text(aR_ R->screen.tscroll, R->screen.bscroll, arg[0], 0); + R->scr_scroll_text (R->screen.tscroll, R->screen.bscroll, arg[0], 0); break; case CSI_DA: /* 8.3.24: (0) DEVICE ATTRIBUTES */ - rxvt_tt_write(aR_ (const unsigned char *)VT100_ANS, + R->tt_write((const unsigned char *)VT100_ANS, (unsigned int)(sizeof(VT100_ANS) - 1)); break; @@ -2565,14 +2612,14 @@ case CSI_DSR: /* 8.3.36: (0) DEVICE STATUS REPORT */ switch (arg[0]) { case 5: /* DSR requested */ - rxvt_tt_printf(aR_ "\033[0n"); + R->tt_printf("\033[0n"); break; case 6: /* CPR requested */ rxvt_scr_report_position(aR); break; #if defined (ENABLE_DISPLAY_ANSWER) case 7: /* unofficial extension */ - rxvt_tt_printf(aR_ "%-.250s\n", R->h->rs[Rs_display_name]); + R->tt_printf("%-.250s\n", R->rs[Rs_display_name]); break; #endif case 8: /* unofficial extension */ @@ -2651,7 +2698,7 @@ case CSI_78: /* DECREQTPARM */ if (arg[0] == 0 || arg[0] == 1) - rxvt_tt_printf(aR_ "\033[%d;1;1;112;112;1;0x", arg[0] + 2); + R->tt_printf("\033[%d;1;1;112;112;1;0x", arg[0] + 2); /* FALLTHROUGH */ default: @@ -2699,7 +2746,7 @@ XLowerWindow(R->Xdisplay, R->TermWin.parent[0]); break; case 7: /* refresh window */ - rxvt_scr_touch(aR_ True); + R->scr_touch (true); break; case 8: /* set size (chars) */ rxvt_set_widthheight(aR_ (unsigned int)(args[2] * R->TermWin.fwidth), @@ -2715,30 +2762,30 @@ */ case 11: /* report window state */ XGetWindowAttributes(R->Xdisplay, R->TermWin.parent[0], &wattr); - rxvt_tt_printf(aR_ "\033[%dt", wattr.map_state == IsViewable ? 1 : 2); + R->tt_printf("\033[%dt", wattr.map_state == IsViewable ? 1 : 2); break; case 13: /* report window position */ XGetWindowAttributes(R->Xdisplay, R->TermWin.parent[0], &wattr); XTranslateCoordinates(R->Xdisplay, R->TermWin.parent[0], wattr.root, -wattr.border_width, -wattr.border_width, &x, &y, &wdummy); - rxvt_tt_printf(aR_ "\033[3;%d;%dt", x, y); + R->tt_printf("\033[3;%d;%dt", x, y); break; case 14: /* report window size (pixels) */ XGetWindowAttributes(R->Xdisplay, R->TermWin.parent[0], &wattr); - rxvt_tt_printf(aR_ "\033[4;%d;%dt", wattr.height, wattr.width); + R->tt_printf("\033[4;%d;%dt", wattr.height, wattr.width); break; case 18: /* report window size (chars) */ - rxvt_tt_printf(aR_ "\033[8;%d;%dt", R->TermWin.nrow, R->TermWin.ncol); + R->tt_printf("\033[8;%d;%dt", R->TermWin.nrow, R->TermWin.ncol); break; #if 0 /* XXX: currently disabled due to security concerns */ case 20: /* report icon label */ XGetIconName(R->Xdisplay, R->TermWin.parent[0], &s); - rxvt_tt_printf(aR_ "\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ + R->tt_printf("\033]L%-.200s\234", s ? s : ""); /* 8bit ST */ break; case 21: /* report window title */ XFetchName(R->Xdisplay, R->TermWin.parent[0], &s); - rxvt_tt_printf(aR_ "\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ + R->tt_printf("\033]l%-.200s\234", s ? s : ""); /* 8bit ST */ break; #endif } @@ -2920,7 +2967,7 @@ rxvt_scale_pixmap(aR_ ""); /* reset to default scaling */ rxvt_set_bgPixmap(aR_ str); /* change pixmap */ #endif - rxvt_scr_touch(aR_ True); + R->scr_touch (true); } while ((str = STRCHR(str, ';')) != NULL) { str++; @@ -2932,7 +2979,7 @@ #ifdef XPM_BACKGROUND rxvt_resize_pixmap(aR); #endif - rxvt_scr_touch(aR_ True); + R->scr_touch (true); } break; @@ -2979,13 +3026,13 @@ int state; if (mode == 's') { - R->h->SavedModes |= (R->h->PrivateModes & bit); + R->SavedModes |= (R->PrivateModes & bit); return -1; } else { if (mode == 'r') - state = (R->h->SavedModes & bit) ? 1 : 0; /* no overlapping */ + state = (R->SavedModes & bit) ? 1 : 0; /* no overlapping */ else - state = (mode == 't') ? !(R->h->PrivateModes & bit) : mode; + state = (mode == 't') ? !(R->PrivateModes & bit) : mode; PrivMode(state, bit); } return state; @@ -3073,7 +3120,7 @@ PrivMode(1, PrivMode_vt52); break; case 3: /* 80/132 */ - if (R->h->PrivateModes & PrivMode_132OK) + if (R->PrivateModes & PrivMode_132OK) rxvt_set_widthheight(aR_ (unsigned int)((state ? 132 : 80) * R->TermWin.fwidth), (unsigned int)R->TermWin.height); @@ -3096,7 +3143,7 @@ /* case 8: - auto repeat, can't do on a per window basis */ case 9: /* X10 mouse reporting */ if (state) /* orthogonal */ - R->h->PrivateModes &= ~(PrivMode_MouseX11); + R->PrivateModes &= ~(PrivMode_MouseX11); break; #ifdef menuBar_esc case menuBar_esc: @@ -3108,8 +3155,8 @@ #ifdef scrollBar_esc case scrollBar_esc: if (rxvt_scrollbar_mapping(aR_ state)) { - rxvt_resize_all_windows(aR_ 0, 0, 0); - rxvt_scr_touch(aR_ True); + R->resize_all_windows (0, 0, 0); + R->scr_touch (true); } break; #endif @@ -3125,7 +3172,7 @@ /* case 67: - backspace key */ case 1000: /* X11 mouse reporting */ if (state) /* orthogonal */ - R->h->PrivateModes &= ~(PrivMode_MouseX10); + R->PrivateModes &= ~(PrivMode_MouseX10); break; #if 0 case 1001: @@ -3144,8 +3191,8 @@ R->Options &= ~Opt_scrollTtyKeypress; break; case 1047: /* secondary screen w/ clearing */ - if (R->h->current_screen != PRIMARY) - rxvt_scr_erase_screen(aR_ 2); + if (R->current_screen != PRIMARY) + R->scr_erase_screen (2); rxvt_scr_change_screen(aR_ state); /* FALLTHROUGH */ default: @@ -3291,7 +3338,7 @@ #ifndef RXVT_GRAPHICS if (cmd == 'Q') { /* query graphics */ - rxvt_tt_printf(aR_ "\033G0\n"); /* no graphics */ + R->tt_printf("\033G0\n"); /* no graphics */ return; } /* swallow other graphics sequences until terminating ':' */ @@ -3304,7 +3351,7 @@ unsigned char *text = NULL; if (cmd == 'Q') { /* query graphics */ - rxvt_tt_printf(aR_ "\033G1\n"); /* yes, graphics (color) */ + R->tt_printf("\033G1\n"); /* yes, graphics (color) */ return; } for (nargs = 0; nargs < (sizeof(args) / sizeof(args[0])) - 1;) { @@ -3329,7 +3376,7 @@ if ((cmd == 'T') && (nargs >= 5)) { int i, len = args[4]; - text = rxvt_malloc((len + 1) * sizeof(char)); + text = (unsigned char *)rxvt_malloc((len + 1) * sizeof(char)); if (text != NULL) { for (i = 0; i < len; i++) @@ -3344,240 +3391,80 @@ /* ------------------------------------------------------------------------- */ -/*{{{ Read and process output from the application */ -/* LIBPROTO */ -void -rxvt_main_loop(pR) -{ - uint32_t ch, *str, buf[BUFSIZ]; - int nlines, refreshnow; - struct rxvt_hidden *h = R->h; - - h->cmdbuf_ptr = h->cmdbuf_endp = h->cmdbuf_base; - - /* once we know the shell is running, send the screen size. Again! */ - ch = rxvt_cmd_getc(aR); /* wait for something */ - rxvt_tt_winsize(R->cmd_fd, R->TermWin.ncol, R->TermWin.nrow, R->h->cmd_pid); - - refreshnow = 0; - for (;;) { - if (ch == NOCHAR) - ch = rxvt_cmd_getc(aR); - - if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r') - { - /* Read a text string from the input buffer */ - nlines = 0; - str = buf; - *str++ = ch; - for (;;) - { - ch = next_char (aR); - - if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r')) - break; - else - { - *str++ = ch; - - if (ch == '\n') - { - nlines++; - h->refresh_count++; - if (!(R->Options & Opt_jumpScroll) - || (h->refresh_count >= (h->refresh_limit - * (R->TermWin.nrow - 1)))) - { - refreshnow = 1; - ch = NOCHAR; - break; - } - } - - if (str >= buf + BUFSIZ) - { - ch = NOCHAR; - break; - } - } - } - - rxvt_scr_add_lines(aR_ 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 h->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 - */ - - //TODO: REFRESH_PERIOD is one, fix it - if (refreshnow) - { - refreshnow = 0; - - if ((R->Options & Opt_jumpScroll) && h->refresh_limit < REFRESH_PERIOD) - h->refresh_limit++; - - rxvt_scr_refresh(aR_ h->refresh_type); - } - - } - else - { - switch (ch) - { - default: - rxvt_process_nonprinting(aR_ ch); - break; - case C0_ESC: /* escape char */ - rxvt_process_escape_seq(aR); - break; - /* case 0x9b: */ /* CSI */ - /* rxvt_process_csi_seq(aR); */ - } - - ch = NOCHAR; - } - } -/* NOTREACHED */ -} - /* * Send printf() formatted output to the command. * Only use for small amounts of data. */ -/* EXTPROTO */ void -rxvt_tt_printf(pR_ const char *fmt,...) +rxvt_term::tt_printf (const char *fmt,...) { - va_list arg_ptr; - unsigned char buf[256]; + va_list arg_ptr; + unsigned char buf[256]; - va_start(arg_ptr, fmt); - vsprintf((char *)buf, fmt, arg_ptr); - va_end(arg_ptr); - rxvt_tt_write(aR_ buf, (unsigned int)STRLEN(buf)); + va_start (arg_ptr, fmt); + vsnprintf ((char *)buf, 256, fmt, arg_ptr); + va_end (arg_ptr); + tt_write (buf, STRLEN (buf)); } /* ---------------------------------------------------------------------- */ -/* Addresses pasting large amounts of data and rxvt hang - * code pinched from xterm (v_write()) and applied originally to - * rxvt-2.18 - Hops - * Write data to the pty as typed by the user, pasted with the mouse, +/* 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. */ -/* EXTPROTO */ void -rxvt_tt_write(pR_ const unsigned char *d, unsigned int len) +rxvt_term::tt_write (const unsigned char *data, unsigned int len) { -#define MAX_PTY_WRITE 256 /* POSIX minimum MAX_INPUT */ - int riten; - unsigned int p; - unsigned char *v_buffer, /* start of physical buffer */ - *v_bufstr, /* start of current buffer pending */ - *v_bufptr, /* end of current buffer pending */ - *v_bufend; /* end of physical buffer */ - - if (R->h->v_bufstr == NULL && len > 0) { - p = (len / MAX_PTY_WRITE + 1) * MAX_PTY_WRITE; - v_buffer = v_bufstr = v_bufptr = (unsigned char *)rxvt_malloc(p); - v_bufend = v_buffer + p; - } else { - v_buffer = R->h->v_buffer; - v_bufstr = R->h->v_bufstr; - v_bufptr = R->h->v_bufptr; - v_bufend = R->h->v_bufend; - } + enum { MAX_PTY_WRITE = 255 }; // minimum MAX_INPUT - /* - * Append to the block we already have. Always doing this simplifies the - * code, and isn't too bad, either. If this is a short block, it isn't - * too expensive, and if this is a long block, we won't be able to write - * it all anyway. - */ - if (len > 0) { - if (v_bufend < v_bufptr + len) { /* run out of room */ - if (v_bufstr != v_buffer) { - /* there is unused space, move everything down */ - MEMMOVE(v_buffer, v_bufstr, - (unsigned int)(v_bufptr - v_bufstr)); - v_bufptr -= v_bufstr - v_buffer; - v_bufstr = v_buffer; - } - if (v_bufend < v_bufptr + len) { - /* still won't fit: get more space */ - /* use most basic realloc because an error is not fatal. */ - unsigned int size = v_bufptr - v_buffer; - unsigned int reallocto; - - reallocto = ((size + len) / MAX_PTY_WRITE + 1) * MAX_PTY_WRITE; - v_buffer = (unsigned char *)realloc(v_buffer, reallocto); - /* save across realloc */ - if (v_buffer) { - v_bufstr = v_buffer; - v_bufptr = v_buffer + size; - v_bufend = v_buffer + reallocto; - } else { /* no memory: ignore entire write request */ - rxvt_print_error("data loss: cannot allocate buffer space"); - v_buffer = v_bufstr; /* restore clobbered pointer */ - } - } - } - if (v_bufend >= v_bufptr + len) { /* new stuff will fit */ - MEMCPY(v_bufptr, d, len); - v_bufptr += len; - } - } + if (len) + { + if (v_buflen == 0) + { + int written = write (cmd_fd, data, min (MAX_PTY_WRITE, len)); + if (written == len) + return; - /* - * Write out as much of the buffer as we can. - * Be careful not to overflow the pty's input silo. - * We are conservative here and only write a small amount at a time. - * - * If we can't push all the data into the pty yet, we expect write - * to return a non-negative number less than the length requested - * (if some data written) or -1 and set errno to EAGAIN, - * EWOULDBLOCK, or EINTR (if no data written). - * - * (Not all systems do this, sigh, so the code is actually - * a little more forgiving.) - */ - if ((p = v_bufptr - v_bufstr) > 0) { - riten = write(R->cmd_fd, v_bufstr, min(p, MAX_PTY_WRITE)); - if (riten < 0) - riten = 0; - v_bufstr += riten; - if (v_bufstr >= v_bufptr) /* we wrote it all */ - v_bufstr = v_bufptr = v_buffer; + data += written; + len -= written; + } + + + v_buffer = (unsigned char *)realloc (v_buffer, v_buflen + len); + + memcpy (v_buffer + v_buflen, data, len); + v_buflen += len; } - /* - * If we have lots of unused memory allocated, return it - */ - if (v_bufend - v_bufptr > MAX_PTY_WRITE * 8) { /* arbitrary hysteresis */ - /* save pointers across realloc */ - unsigned int start = v_bufstr - v_buffer; - unsigned int size = v_bufptr - v_buffer; - unsigned int reallocto; - - reallocto = (size / MAX_PTY_WRITE + 1) * MAX_PTY_WRITE; - v_buffer = (unsigned char *)realloc(v_buffer, reallocto); - if (v_buffer) { - v_bufstr = v_buffer + start; - v_bufptr = v_buffer + size; - v_bufend = v_buffer + reallocto; - } else { - /* should we print a warning if couldn't return memory? */ - v_buffer = v_bufstr - start; /* restore clobbered pointer */ - } + + for (;;) + { + int written = write (cmd_fd, v_buffer, min (MAX_PTY_WRITE, v_buflen)); + + if (written > 0) + { + v_buflen -= written; + + 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); + return; + } } - R->h->v_buffer = v_buffer; - R->h->v_bufstr = v_bufstr; - R->h->v_bufptr = v_bufptr; - R->h->v_bufend = v_bufend; } + /*----------------------- end-of-file (C source) -----------------------*/