--- rxvt-unicode/src/command.C 2003/11/24 17:31:27 1.2 +++ rxvt-unicode/src/command.C 2003/12/02 21:49:46 1.11 @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: command.c *----------------------------------------------------------------------* - * $Id: command.C,v 1.2 2003/11/24 17:31:27 pcg Exp $ + * $Id: command.C,v 1.11 2003/12/02 21:49:46 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -66,7 +66,7 @@ #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,33 +76,33 @@ */ 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); } #ifdef USE_XIM - if (R->h->Input_Context != NULL) { + if (R->Input_Context != NULL) { Status status_return; kbuf[0] = '\0'; #ifdef X_HAVE_UTF8_STRING - len = Xutf8LookupString(R->h->Input_Context, ev, (char *)kbuf, + len = Xutf8LookupString(R->Input_Context, ev, (char *)kbuf, KBUFSZ, &keysym, &status_return); #else - len = XmbLookupString(R->h->Input_Context, ev, (char *)kbuf, + len = XmbLookupString(R->Input_Context, ev, (char *)kbuf, KBUFSZ, &keysym, &status_return); #endif valid_keysym = ((status_return == XLookupKeySym) || (status_return == XLookupBoth)); } else { len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym, - &R->h->compose); + &R->compose); valid_keysym = 1; } #else /* USE_XIM */ len = XLookupString(ev, (char *)kbuf, KBUFSZ, &keysym, - &R->h->compose); + &R->compose); /* * map unmapped Latin[2-4]/Katakana/Arabic/Cyrillic/Greek entries -> Latin1 * good for installations with correct fonts, but without XLOCALE @@ -128,10 +128,10 @@ # else 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; } @@ -188,7 +188,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 +211,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 +226,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 +249,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 +270,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 +306,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 +327,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 +365,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 +377,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 +389,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 +435,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 +463,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 +475,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 +551,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 +560,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,7 +569,7 @@ } #endif #ifdef GREEK_SUPPORT - if (R->h->greek_mode) + if (R->greek_mode) len = greek_xlat(kbuf, len); #endif /* nil */ ; @@ -582,7 +582,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 +602,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 +620,7 @@ fprintf(stderr, "'\n"); } #endif /* DEBUG_CMD */ - rxvt_tt_write(aR_ kbuf, (unsigned int)len); + R->tt_write(kbuf, (unsigned int)len); } /*}}} */ @@ -632,9 +632,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,34 +651,267 @@ } 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 */ +void +rxvt_term::flush () +{ +#ifdef TRANSPARENT + if (want_full_refresh) + { + want_full_refresh = 0; + rxvt_scr_clear (this); + rxvt_scr_touch (this, False); + want_refresh = 1; + } +#endif + + if (want_refresh) + { + rxvt_scr_refresh (this, refresh_type); + rxvt_scrollbar_show (this, 1); +#ifdef USE_XIM + rxvt_IMSendSpot (this); +#endif + } + + XFlush (Xdisplay); +#if 0 + if (XPending (Xdisplay)) process_x_events (); + if (XPending (Xdisplay)) process_x_events (); +#endif +} + +void +rxvt_term::check_cb (check_watcher &w) +{ + SET_R (this); + + flush (); +} + +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) + { + hidden_cursor = 0; + want_refresh = 1; + } + + blink_ev.start (NOW + BLINK_INTERVAL); + } +#endif + +#if defined(POINTER_BLANK) + if ((Options & Opt_pointerBlank) + && (pointerBlankDelay > 0)) + { + if (xev.type == MotionNotify + || xev.type == ButtonPress + || xev.type == ButtonRelease) + if (hidden_pointer) + pointer_unblank (); + + if (xev.type == KeyPress && hidden_pointer == 0) + pointer_blank (); + } +#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) +{ + SET_R (this); + + w.at += BLINK_INTERVAL; + hidden_cursor = !hidden_cursor; + want_refresh = 1; +} + +void +rxvt_term::x_cb (io_watcher &w, short revents) +{ + SET_R (this); + + 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) + return false; + + destroy (); +} + +void +rxvt_term::pty_cb (io_watcher &w, short revents) +{ + SET_R (this); + + if (revents & EVENT_WRITE) + tt_write (0, 0); + else if (revents & EVENT_READ) + // loop, but don't allow a single term to monopolize us + // the number of loops is fully arbitrary, and thus wrong + for (int i = 1; i-- && pty_fill (); ) + { + 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; + 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++; + + rxvt_scr_refresh (this, 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 -static uint32_t -next_char (pR) +uint32_t +rxvt_term::next_char () { - rxvt_hidden *h = R->h; - mbstate &s = h->mbstate; + struct mbstate &s = mbstate; - while (h->cmdbuf_ptr < h->cmdbuf_endp) + while (cmdbuf_ptr < cmdbuf_endp) { - uint8_t ch = *h->cmdbuf_ptr; + uint8_t ch = *cmdbuf_ptr; if (s.cnt) { if ((ch & 0xc0) == 0x80) { - h->cmdbuf_ptr++; + cmdbuf_ptr++; /* continuation */ s.reg = (s.reg << 6) | (ch & 0x7f); - if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or hacking */ + if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or Racking */ return s.reg; continue; @@ -692,7 +925,7 @@ if ((ch & 0xc0) == 0xc0) { - h->cmdbuf_ptr++; + cmdbuf_ptr++; /* first byte */ s.orig = ch; /* for broken encodings */ @@ -705,7 +938,7 @@ } else { - h->cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */ + cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */ return ch; } } @@ -722,6 +955,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 +977,92 @@ #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)) { + rxvt_selection_extend(aR_ 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); + rxvt_recolour_cursor (this); - /* 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; + pointer_ev.stop (); - (void)gettimeofday(&tp, NULL); - R->h->lastmotion.tv_sec = tp.tv_sec; - R->h->lastmotion.tv_usec = tp.tv_usec; - } -#endif + 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); + + pointer_blank (); } #endif @@ -1014,16 +1077,16 @@ y = ev->y; rxvt_pixel_position(aR_ &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 +1102,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 +1125,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)); @@ -1090,7 +1153,7 @@ 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 */ @@ -1138,7 +1201,7 @@ */ for (i = NUM_TIMEOUTS; i--; ) - if (h->timeout[i].tv_sec) { + if (R->timeout[i].tv_sec) { want_timeout = 1; break; } @@ -1156,17 +1219,17 @@ /* X event timeouts */ if (want_timeout) for (i = NUM_TIMEOUTS; i--; ) { - if (h->timeout[i].tv_sec == 0) + if (R->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)) + if ((tp.tv_sec < R->timeout[i].tv_sec) + || (tp.tv_sec == R->timeout[i].tv_sec + && tp.tv_usec < R->timeout[i].tv_usec)) continue; - h->timeout[i].tv_sec = 0; + R->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; + R->selection_wait = Sel_none; break; default: break; @@ -1182,13 +1245,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 +1267,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 +1282,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 +1313,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 +1345,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; @@ -1308,8 +1381,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 +1393,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 +1411,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 +1422,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; @@ -1376,7 +1449,7 @@ //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; @@ -1402,8 +1475,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 +1484,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,7 +1498,7 @@ &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), (ev->xbutton.state & Button3Mask) ? 2 : 0); @@ -1434,42 +1507,42 @@ 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 +1557,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; + rxvt_scr_refresh(aR_ R->refresh_type); + R->refresh_limit = 0; rxvt_scrollbar_show(aR_ 1); } break; @@ -1499,11 +1572,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 */ @@ -1515,65 +1587,65 @@ 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++; + if (R->MEvent.button == Button1 && clickintime) + R->MEvent.clicks++; else - h->MEvent.clicks = 1; - rxvt_selection_click(aR_ h->MEvent.clicks, ev->x, ev->y); - h->MEvent.button = Button1; + R->MEvent.clicks = 1; + rxvt_selection_click(aR_ R->MEvent.clicks, ev->x, ev->y); + R->MEvent.button = Button1; break; case Button3: - if (h->MEvent.button == Button3 && clickintime) + if (R->MEvent.button == Button3 && clickintime) rxvt_selection_rotate(aR_ ev->x, ev->y); else rxvt_selection_extend(aR_ ev->x, ev->y, 1); - h->MEvent.button = Button3; + R->MEvent.button = Button3; break; } } - h->MEvent.time = ev->time; + R->MEvent.time = ev->time; return; } } @@ -1605,22 +1677,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,7 +1714,7 @@ } 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) @@ -1653,29 +1725,29 @@ } 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(); 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: @@ -1720,19 +1792,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(); 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 +1822,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,9 +1841,9 @@ * 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) + if (R->PrivateModes & PrivMode_mouse_report + && R->bypass_keystate + && ev->button == Button1 && R->MEvent.clicks <= 1) rxvt_selection_extend(aR_ ev->x, ev->y, 0); switch (ev->button) { @@ -1798,8 +1870,8 @@ # 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 @@ -1854,11 +1926,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 +1943,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 +1982,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 +2012,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 @@ -1984,7 +2056,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 +2076,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 +2094,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 +2103,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 +2183,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 */ @@ -2189,7 +2261,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 +2286,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 +2378,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 +2509,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') @@ -2554,7 +2626,7 @@ 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 +2637,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 +2723,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: @@ -2715,30 +2787,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 } @@ -2979,13 +3051,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 +3145,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 +3168,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: @@ -3125,7 +3197,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,7 +3216,7 @@ R->Options &= ~Opt_scrollTtyKeypress; break; case 1047: /* secondary screen w/ clearing */ - if (R->h->current_screen != PRIMARY) + if (R->current_screen != PRIMARY) rxvt_scr_erase_screen(aR_ 2); rxvt_scr_change_screen(aR_ state); /* FALLTHROUGH */ @@ -3291,7 +3363,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 +3376,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;) { @@ -3344,240 +3416,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) -----------------------*/