--- rxvt-unicode/src/command.C 2003/11/25 15:25:16 1.4 +++ rxvt-unicode/src/command.C 2003/11/27 10:12:10 1.9 @@ -1,7 +1,7 @@ /*--------------------------------*-C-*---------------------------------* * File: command.c *----------------------------------------------------------------------* - * $Id: command.C,v 1.4 2003/11/25 15:25:16 pcg Exp $ + * $Id: command.C,v 1.9 2003/11/27 10:12:10 pcg Exp $ * * All portions of code are copyright by their respective author/s. * Copyright (c) 1992 John Bovey, University of Kent at Canterbury @@ -665,30 +665,34 @@ XEvent xev; XNextEvent (Xdisplay, &xev); + #if defined(CURSOR_BLINK) if ((Options & Opt_cursorBlink) - && xev.type == KeyPress) { - if (hidden_cursor) { + && xev.type == KeyPress) + { + if (hidden_cursor) + { hidden_cursor = 0; want_refresh = 1; - } - want_keypress_time = 1; - } + } + + blink_ev.start (NOW + BLINK_INTERVAL); + } #endif #if defined(POINTER_BLANK) if ((Options & Opt_pointerBlank) - && (pointerBlankDelay > 0)) { + && (pointerBlankDelay > 0)) + { if (xev.type == MotionNotify || xev.type == ButtonPress - || xev.type == ButtonRelease) { - if (hidden_pointer) - rxvt_pointer_unblank(aR); - want_motion_time = 1; - } + || xev.type == ButtonRelease) + if (hidden_pointer) + pointer_unblank (); + if (xev.type == KeyPress && hidden_pointer == 0) - rxvt_pointer_blank (this); - } + pointer_blank (); + } #endif #ifdef USE_XIM @@ -700,8 +704,21 @@ } void +rxvt_term::blink_cb (time_watcher &w) +{ + SET_R (this); + + w.at += BLINK_INTERVAL; + hidden_cursor = !hidden_cursor; + want_refresh = 1; + flush (); +} + +void rxvt_term::x_cb (io_watcher &w, short revents) { + SET_R (this); + process_x_events (); flush (); @@ -763,7 +780,7 @@ } bool -rxvt_term::pty_fill (size_t count) +rxvt_term::pty_fill () { ssize_t n = cmdbuf_endp - cmdbuf_ptr; @@ -771,7 +788,7 @@ cmdbuf_ptr = cmdbuf_base; cmdbuf_endp = cmdbuf_ptr + n; - n = read (cmd_fd, cmdbuf_endp, count); + n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); if (n > 0) { @@ -781,15 +798,19 @@ else if (n < 0 && errno == EAGAIN) return false; - rxvt_clean_exit(); - exit(EXIT_FAILURE); /* bad order of events? */ + destroy (); } void rxvt_term::pty_cb (io_watcher &w, short revents) { - while (pty_fill (BUFSIZ - (cmdbuf_endp - cmdbuf_ptr))) + SET_R (this); + + // loop, but don't allow a single term to monopolize us + // the number of loops is fully arbitrary, and thus wrong + for (int i = 7; i-- && pty_fill (); ) { + //TODO: /* once we know the shell is running, send the screen size. Again! */ //ch = rxvt_cmd_getc(aR); /* wait for something */ //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid); @@ -910,7 +931,9 @@ #endif } + if (XPending (Xdisplay)) process_x_events (); XFlush (Xdisplay); + if (XPending (Xdisplay)) process_x_events (); } /* rxvt_cmd_getc() - Return next input character */ @@ -931,10 +954,11 @@ // 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 (1); + 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; @@ -950,46 +974,6 @@ if (R->v_bufstr < R->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 - - if (XPending (R->Xdisplay)) - { - R->process_x_events (); - - /* in case button actions pushed chars to cmdbuf */ - if (R->cmdbuf_ptr < R->cmdbuf_endp) - return *R->cmdbuf_ptr++; - } - -#if defined(CURSOR_BLINK) - if (want_keypress_time) { - (void)gettimeofday(&tp, NULL); - R->lastcursorchange.tv_sec = tp.tv_sec; - R->lastcursorchange.tv_usec = tp.tv_usec; - } -#endif -#if defined(POINTER_BLANK) - if (want_motion_time) { - if (!tp.tv_sec) - (void)gettimeofday(&tp, NULL); - R->lastmotion.tv_sec = tp.tv_sec; - R->lastmotion.tv_usec = tp.tv_usec; - } -#endif - -/* - * the command input buffer is empty and we have no pending X events - */ - quick_timeout = 0; - #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) if (R->mouse_slip_wheel_speed) { quick_timeout = 1; @@ -1028,114 +1012,47 @@ } #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 |= R->want_refresh; #ifdef TRANSPARENT 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 - R->lastcursorchange.tv_sec) * 1000000L - + tp.tv_usec - R->lastcursorchange.tv_usec; - if (csdiff > BLINK_TIME) { /* XXX: settable blink times */ - R->lastcursorchange.tv_sec = tp.tv_sec; - R->lastcursorchange.tv_usec = tp.tv_usec; - R->hidden_cursor = !R->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) - && (R->pointerBlankDelay > 0) - && (R->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 - R->lastmotion.tv_sec) * 1000000L - + tp.tv_usec - R->lastmotion.tv_usec; - pdelay = R->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 */ - R->refresh_limit = 1; - } -#if defined(CURSOR_BLINK) - if (R->Options & Opt_cursorBlink) - R->want_refresh = 1; #endif - } } -/* EXTPROTO */ void -rxvt_pointer_unblank(pR) +rxvt_term::pointer_unblank () { - XDefineCursor(R->Xdisplay, R->TermWin.vt, R->TermWin_cursor); - rxvt_recolour_cursor(aR); + XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor); + rxvt_recolour_cursor (this); + #ifdef POINTER_BLANK - R->hidden_pointer = 0; - if (R->pointerBlankDelay > 0) { - struct timeval tp; + hidden_pointer = 0; - (void)gettimeofday(&tp, NULL); - R->lastmotion.tv_sec = tp.tv_sec; - R->lastmotion.tv_usec = tp.tv_usec; - } + if (Options & Opt_pointerBlank) + pointer_ev.start (NOW + pointerBlankDelay); #endif } #ifdef POINTER_BLANK -/* INTPROTO */ void -rxvt_pointer_blank(pR) +rxvt_term::pointer_blank () +{ + pointer_ev.stop (); + + if (!(Options & Opt_pointerBlank)) + return; + + XDefineCursor (Xdisplay, TermWin.vt, blank_cursor); + XFlush (Xdisplay); + + hidden_pointer = 1; +} + +void +rxvt_term::pointer_cb (time_watcher &w) { - XDefineCursor(R->Xdisplay, R->TermWin.vt, R->pointer_blank); - XFlush(R->Xdisplay); - R->hidden_pointer = 1; + SET_R (this); + + pointer_blank (); } #endif @@ -1341,10 +1258,10 @@ case ClientMessage: if (ev->xclient.format == 32 && (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW]) - exit(EXIT_SUCCESS); + R->destroy (); #ifdef OFFIX_DND /* OffiX Dnd (drag 'n' drop) protocol */ - if (ev->xclient.message_type == R->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)) { @@ -1386,17 +1303,18 @@ * which ought to make things real slow! */ case VisibilityNotify: - 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; - } + 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: @@ -1407,6 +1325,10 @@ 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; @@ -1418,6 +1340,11 @@ 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; @@ -1539,7 +1466,7 @@ case MotionNotify: #ifdef POINTER_BLANK if (R->hidden_pointer) - rxvt_pointer_unblank(aR); + R->pointer_unblank (); #endif #if MENUBAR if (isMenuBarWindow(ev->xany.window)) {