1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: command.c |
2 | * File: command.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: command.C,v 1.5 2003/11/25 15:44:38 pcg Exp $ |
4 | * $Id: command.C,v 1.8 2003/11/26 10:42:34 pcg Exp $ |
5 | * |
5 | * |
6 | * All portions of code are copyright by their respective author/s. |
6 | * All portions of code are copyright by their respective author/s. |
7 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
7 | * Copyright (c) 1992 John Bovey, University of Kent at Canterbury <jdb@ukc.ac.uk> |
8 | * - original version |
8 | * - original version |
9 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
9 | * Copyright (c) 1994 Robert Nation <nation@rocket.sanders.lockheed.com> |
… | |
… | |
666 | |
666 | |
667 | XNextEvent (Xdisplay, &xev); |
667 | XNextEvent (Xdisplay, &xev); |
668 | |
668 | |
669 | #if defined(CURSOR_BLINK) |
669 | #if defined(CURSOR_BLINK) |
670 | if ((Options & Opt_cursorBlink) |
670 | if ((Options & Opt_cursorBlink) |
671 | && xev.type == KeyPress) { |
671 | && xev.type == KeyPress) |
|
|
672 | { |
672 | if (hidden_cursor) { |
673 | if (hidden_cursor) |
|
|
674 | { |
673 | hidden_cursor = 0; |
675 | hidden_cursor = 0; |
674 | want_refresh = 1; |
676 | want_refresh = 1; |
675 | } |
677 | } |
|
|
678 | |
676 | blink_ev.start (NOW + BLINK_INTERVAL); |
679 | blink_ev.start (NOW + BLINK_INTERVAL); |
677 | } |
680 | } |
678 | #endif |
681 | #endif |
679 | |
682 | |
680 | #if defined(POINTER_BLANK) |
683 | #if defined(POINTER_BLANK) |
681 | if ((Options & Opt_pointerBlank) |
684 | if ((Options & Opt_pointerBlank) |
682 | && (pointerBlankDelay > 0)) { |
685 | && (pointerBlankDelay > 0)) |
|
|
686 | { |
683 | if (xev.type == MotionNotify |
687 | if (xev.type == MotionNotify |
684 | || xev.type == ButtonPress |
688 | || xev.type == ButtonPress |
685 | || xev.type == ButtonRelease) { |
689 | || xev.type == ButtonRelease) |
686 | if (hidden_pointer) |
690 | if (hidden_pointer) |
687 | rxvt_pointer_unblank(aR); |
691 | pointer_unblank (); |
688 | want_motion_time = 1; |
692 | |
689 | } |
|
|
690 | if (xev.type == KeyPress && hidden_pointer == 0) |
693 | if (xev.type == KeyPress && hidden_pointer == 0) |
691 | rxvt_pointer_blank (this); |
694 | pointer_blank (); |
692 | } |
695 | } |
693 | #endif |
696 | #endif |
694 | |
697 | |
695 | #ifdef USE_XIM |
698 | #ifdef USE_XIM |
696 | if (!XFilterEvent (&xev, xev.xany.window)) |
699 | if (!XFilterEvent (&xev, xev.xany.window)) |
697 | #endif |
700 | #endif |
… | |
… | |
704 | rxvt_term::blink_cb (time_watcher &w) |
707 | rxvt_term::blink_cb (time_watcher &w) |
705 | { |
708 | { |
706 | w.at += BLINK_INTERVAL; |
709 | w.at += BLINK_INTERVAL; |
707 | hidden_cursor = !hidden_cursor; |
710 | hidden_cursor = !hidden_cursor; |
708 | want_refresh = 1; |
711 | want_refresh = 1; |
709 | flush(); |
712 | flush (); |
710 | } |
713 | } |
711 | |
714 | |
712 | void |
715 | void |
713 | rxvt_term::x_cb (io_watcher &w, short revents) |
716 | rxvt_term::x_cb (io_watcher &w, short revents) |
714 | { |
717 | { |
… | |
… | |
771 | |
774 | |
772 | return NOCHAR; |
775 | return NOCHAR; |
773 | } |
776 | } |
774 | |
777 | |
775 | bool |
778 | bool |
776 | rxvt_term::pty_fill (size_t count) |
779 | rxvt_term::pty_fill () |
777 | { |
780 | { |
778 | ssize_t n = cmdbuf_endp - cmdbuf_ptr; |
781 | ssize_t n = cmdbuf_endp - cmdbuf_ptr; |
779 | |
782 | |
780 | memmove (cmdbuf_base, cmdbuf_ptr, n); |
783 | memmove (cmdbuf_base, cmdbuf_ptr, n); |
781 | cmdbuf_ptr = cmdbuf_base; |
784 | cmdbuf_ptr = cmdbuf_base; |
782 | cmdbuf_endp = cmdbuf_ptr + n; |
785 | cmdbuf_endp = cmdbuf_ptr + n; |
783 | |
786 | |
784 | n = read (cmd_fd, cmdbuf_endp, count); |
787 | n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); |
785 | |
788 | |
786 | if (n > 0) |
789 | if (n > 0) |
787 | { |
790 | { |
788 | cmdbuf_endp += n; |
791 | cmdbuf_endp += n; |
789 | return true; |
792 | return true; |
790 | } |
793 | } |
791 | else if (n < 0 && errno == EAGAIN) |
794 | else if (n < 0 && errno == EAGAIN) |
792 | return false; |
795 | return false; |
793 | |
796 | |
794 | rxvt_clean_exit(); |
797 | rxvt_clean_exit (); |
795 | exit(EXIT_FAILURE); /* bad order of events? */ |
798 | exit (EXIT_FAILURE); /* bad order of events? */ |
796 | } |
799 | } |
797 | |
800 | |
798 | void |
801 | void |
799 | rxvt_term::pty_cb (io_watcher &w, short revents) |
802 | rxvt_term::pty_cb (io_watcher &w, short revents) |
800 | { |
803 | { |
801 | while (pty_fill (BUFSIZ - (cmdbuf_endp - cmdbuf_ptr))) |
804 | // loop, but don't allow a single term to monopolize us |
|
|
805 | // the number of loops is fully arbitrary, and thus wrong |
|
|
806 | for (int i = 7; i-- && pty_fill (); ) |
802 | { |
807 | { |
|
|
808 | //TODO: |
803 | /* once we know the shell is running, send the screen size. Again! */ |
809 | /* once we know the shell is running, send the screen size. Again! */ |
804 | //ch = rxvt_cmd_getc(aR); /* wait for something */ |
810 | //ch = rxvt_cmd_getc(aR); /* wait for something */ |
805 | //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid); |
811 | //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid); |
806 | |
812 | |
807 | uint32_t ch = NOCHAR; |
813 | uint32_t ch = NOCHAR; |
… | |
… | |
918 | #ifdef USE_XIM |
924 | #ifdef USE_XIM |
919 | rxvt_IMSendSpot (this); |
925 | rxvt_IMSendSpot (this); |
920 | #endif |
926 | #endif |
921 | } |
927 | } |
922 | |
928 | |
|
|
929 | if (XPending (Xdisplay)) process_x_events (); |
923 | XFlush (Xdisplay); |
930 | XFlush (Xdisplay); |
|
|
931 | if (XPending (Xdisplay)) process_x_events (); |
924 | } |
932 | } |
925 | |
933 | |
926 | /* rxvt_cmd_getc() - Return next input character */ |
934 | /* rxvt_cmd_getc() - Return next input character */ |
927 | /* |
935 | /* |
928 | * Return the next input character after first passing any keyboard input |
936 | * Return the next input character after first passing any keyboard input |
… | |
… | |
939 | return c; |
947 | return c; |
940 | |
948 | |
941 | // incomplete sequences should occur rarely, still, a better solution |
949 | // incomplete sequences should occur rarely, still, a better solution |
942 | // would be preferred. either setjmp/longjmp or better design. |
950 | // would be preferred. either setjmp/longjmp or better design. |
943 | fcntl (R->cmd_fd, F_SETFL, 0); |
951 | fcntl (R->cmd_fd, F_SETFL, 0); |
944 | R->pty_fill (1); |
952 | R->pty_fill (); |
945 | fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK); |
953 | fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK); |
946 | } |
954 | } |
947 | |
955 | |
|
|
956 | #if 0 |
948 | #define TIMEOUT_USEC 5000 |
957 | #define TIMEOUT_USEC 5000 |
949 | fd_set readfds; |
958 | fd_set readfds; |
950 | int quick_timeout, select_res; |
959 | int quick_timeout, select_res; |
951 | int want_motion_time, want_keypress_time; |
960 | int want_motion_time, want_keypress_time; |
952 | struct timeval value; |
961 | struct timeval value; |
… | |
… | |
957 | for (;;) { |
966 | for (;;) { |
958 | /* loop until we can return something */ |
967 | /* loop until we can return something */ |
959 | |
968 | |
960 | if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ |
969 | if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ |
961 | rxvt_tt_write(aR_ NULL, 0); |
970 | rxvt_tt_write(aR_ NULL, 0); |
962 | |
|
|
963 | #if defined(POINTER_BLANK) || defined(CURSOR_BLINK) |
|
|
964 | tp.tv_sec = 0; /* presume == 0 implies time not yet retrieved */ |
|
|
965 | #endif |
|
|
966 | #if defined(CURSOR_BLINK) |
|
|
967 | want_keypress_time = 0; |
|
|
968 | #endif |
|
|
969 | #if defined(POINTER_BLANK) |
|
|
970 | want_motion_time = 0; |
|
|
971 | #endif |
|
|
972 | |
|
|
973 | if (XPending (R->Xdisplay)) |
|
|
974 | { |
|
|
975 | R->process_x_events (); |
|
|
976 | |
|
|
977 | /* in case button actions pushed chars to cmdbuf */ |
|
|
978 | if (R->cmdbuf_ptr < R->cmdbuf_endp) |
|
|
979 | return *R->cmdbuf_ptr++; |
|
|
980 | } |
|
|
981 | |
|
|
982 | #if defined(CURSOR_BLINK) |
|
|
983 | if (want_keypress_time) { |
|
|
984 | (void)gettimeofday(&tp, NULL); |
|
|
985 | R->lastcursorchange.tv_sec = tp.tv_sec; |
|
|
986 | R->lastcursorchange.tv_usec = tp.tv_usec; |
|
|
987 | } |
|
|
988 | #endif |
|
|
989 | #if defined(POINTER_BLANK) |
|
|
990 | if (want_motion_time) { |
|
|
991 | if (!tp.tv_sec) |
|
|
992 | (void)gettimeofday(&tp, NULL); |
|
|
993 | R->lastmotion.tv_sec = tp.tv_sec; |
|
|
994 | R->lastmotion.tv_usec = tp.tv_usec; |
|
|
995 | } |
|
|
996 | #endif |
|
|
997 | |
|
|
998 | /* |
|
|
999 | * the command input buffer is empty and we have no pending X events |
|
|
1000 | */ |
|
|
1001 | quick_timeout = 0; |
|
|
1002 | |
971 | |
1003 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
972 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
1004 | if (R->mouse_slip_wheel_speed) { |
973 | if (R->mouse_slip_wheel_speed) { |
1005 | quick_timeout = 1; |
974 | quick_timeout = 1; |
1006 | if (!R->mouse_slip_wheel_delay-- |
975 | if (!R->mouse_slip_wheel_delay-- |
… | |
… | |
1036 | R->want_refresh = 1; |
1005 | R->want_refresh = 1; |
1037 | } |
1006 | } |
1038 | } |
1007 | } |
1039 | #endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ |
1008 | #endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ |
1040 | |
1009 | |
1041 | FD_ZERO(&readfds); |
|
|
1042 | FD_SET(R->cmd_fd, &readfds); |
|
|
1043 | FD_SET(R->Xfd, &readfds); |
|
|
1044 | value.tv_usec = TIMEOUT_USEC; |
|
|
1045 | value.tv_sec = 0; |
|
|
1046 | |
|
|
1047 | if (!R->TermWin.mapped) |
|
|
1048 | quick_timeout = 0; |
|
|
1049 | else { |
|
|
1050 | quick_timeout |= R->want_refresh; |
|
|
1051 | #ifdef TRANSPARENT |
1010 | #ifdef TRANSPARENT |
1052 | quick_timeout |= R->want_full_refresh; |
1011 | quick_timeout |= R->want_full_refresh; |
1053 | #endif |
1012 | #endif |
1054 | } |
|
|
1055 | |
|
|
1056 | #if defined(POINTER_BLANK) || defined(CURSOR_BLINK) |
|
|
1057 | { |
|
|
1058 | int set_quick_timeout = 0; |
|
|
1059 | long csdiff, psdiff; |
|
|
1060 | |
|
|
1061 | #define BLINK_TIME 500000L |
|
|
1062 | csdiff = psdiff = 60000000L; /* or, say, LONG_MAX */ |
|
|
1063 | # if defined(CURSOR_BLINK) |
|
|
1064 | if (R->Options & Opt_cursorBlink) { |
|
|
1065 | if (!tp.tv_sec) /* didn't get it before so get it now */ |
|
|
1066 | (void)gettimeofday(&tp, NULL); |
|
|
1067 | |
|
|
1068 | csdiff = (tp.tv_sec - R->lastcursorchange.tv_sec) * 1000000L |
|
|
1069 | + tp.tv_usec - R->lastcursorchange.tv_usec; |
|
|
1070 | if (csdiff > BLINK_TIME) { /* XXX: settable blink times */ |
|
|
1071 | R->lastcursorchange.tv_sec = tp.tv_sec; |
|
|
1072 | R->lastcursorchange.tv_usec = tp.tv_usec; |
|
|
1073 | R->hidden_cursor = !R->hidden_cursor; |
|
|
1074 | csdiff = 0; |
|
|
1075 | } else |
|
|
1076 | csdiff = BLINK_TIME - csdiff; |
|
|
1077 | set_quick_timeout = 1; |
|
|
1078 | } |
|
|
1079 | # endif |
1013 | #endif |
1080 | # if defined(POINTER_BLANK) |
|
|
1081 | /* |
|
|
1082 | * If we haven't moved the pointer for a while |
|
|
1083 | */ |
|
|
1084 | if ((R->Options & Opt_pointerBlank) |
|
|
1085 | && (R->pointerBlankDelay > 0) |
|
|
1086 | && (R->hidden_pointer == 0)) { |
|
|
1087 | long pdelay; |
|
|
1088 | |
|
|
1089 | if (!tp.tv_sec) /* didn't get it before so get it now */ |
|
|
1090 | (void)gettimeofday(&tp, NULL); |
|
|
1091 | psdiff = (tp.tv_sec - R->lastmotion.tv_sec) * 1000000L |
|
|
1092 | + tp.tv_usec - R->lastmotion.tv_usec; |
|
|
1093 | pdelay = R->pointerBlankDelay * 1000000L; |
|
|
1094 | if (psdiff >= pdelay) |
|
|
1095 | rxvt_pointer_blank(aR); |
|
|
1096 | else { |
|
|
1097 | set_quick_timeout = 1; |
|
|
1098 | psdiff = pdelay - psdiff; |
|
|
1099 | } |
|
|
1100 | } |
|
|
1101 | # endif |
|
|
1102 | if (!quick_timeout && set_quick_timeout) { |
|
|
1103 | MIN_IT(csdiff, psdiff); |
|
|
1104 | value.tv_sec = csdiff / 1000000L; |
|
|
1105 | value.tv_usec = csdiff % 1000000L; |
|
|
1106 | quick_timeout = 1; |
|
|
1107 | } |
|
|
1108 | } |
|
|
1109 | #endif |
|
|
1110 | |
|
|
1111 | if ((select_res = select(R->num_fds, &readfds, NULL, NULL, |
|
|
1112 | (quick_timeout ? &value : NULL))) == 0) { |
|
|
1113 | /* select statement timed out - we're not hard and fast scrolling */ |
|
|
1114 | R->refresh_limit = 1; |
|
|
1115 | } |
|
|
1116 | #if defined(CURSOR_BLINK) |
|
|
1117 | if (R->Options & Opt_cursorBlink) |
|
|
1118 | R->want_refresh = 1; |
|
|
1119 | #endif |
|
|
1120 | } |
|
|
1121 | } |
1014 | } |
1122 | |
1015 | |
1123 | /* EXTPROTO */ |
|
|
1124 | void |
1016 | void |
1125 | rxvt_pointer_unblank(pR) |
1017 | rxvt_term::pointer_unblank () |
1126 | { |
1018 | { |
1127 | XDefineCursor(R->Xdisplay, R->TermWin.vt, R->TermWin_cursor); |
1019 | XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor); |
1128 | rxvt_recolour_cursor(aR); |
1020 | rxvt_recolour_cursor (this); |
|
|
1021 | |
1129 | #ifdef POINTER_BLANK |
1022 | #ifdef POINTER_BLANK |
1130 | R->hidden_pointer = 0; |
1023 | hidden_pointer = 0; |
1131 | if (R->pointerBlankDelay > 0) { |
|
|
1132 | struct timeval tp; |
|
|
1133 | |
1024 | |
1134 | (void)gettimeofday(&tp, NULL); |
1025 | if (Options & Opt_pointerBlank) |
1135 | R->lastmotion.tv_sec = tp.tv_sec; |
1026 | pointer_ev.start (NOW + pointerBlankDelay); |
1136 | R->lastmotion.tv_usec = tp.tv_usec; |
|
|
1137 | } |
|
|
1138 | #endif |
1027 | #endif |
1139 | } |
1028 | } |
1140 | |
1029 | |
1141 | #ifdef POINTER_BLANK |
1030 | #ifdef POINTER_BLANK |
1142 | /* INTPROTO */ |
|
|
1143 | void |
1031 | void |
1144 | rxvt_pointer_blank(pR) |
1032 | rxvt_term::pointer_blank () |
1145 | { |
1033 | { |
|
|
1034 | pointer_ev.stop (); |
|
|
1035 | |
|
|
1036 | if (!(Options & Opt_pointerBlank)) |
|
|
1037 | return; |
|
|
1038 | |
1146 | XDefineCursor(R->Xdisplay, R->TermWin.vt, R->pointer_blank); |
1039 | XDefineCursor (Xdisplay, TermWin.vt, blank_cursor); |
1147 | XFlush(R->Xdisplay); |
1040 | XFlush (Xdisplay); |
|
|
1041 | |
1148 | R->hidden_pointer = 1; |
1042 | hidden_pointer = 1; |
|
|
1043 | } |
|
|
1044 | |
|
|
1045 | void |
|
|
1046 | rxvt_term::pointer_cb (time_watcher &w) |
|
|
1047 | { |
|
|
1048 | pointer_blank (); |
1149 | } |
1049 | } |
1150 | #endif |
1050 | #endif |
1151 | |
1051 | |
1152 | /* INTPROTO */ |
1052 | /* INTPROTO */ |
1153 | void |
1053 | void |
… | |
… | |
1394 | * in the GraphicsExpose parts, which means that after each refresh, |
1294 | * in the GraphicsExpose parts, which means that after each refresh, |
1395 | * we need to wait for the graphics expose or Noexpose events, |
1295 | * we need to wait for the graphics expose or Noexpose events, |
1396 | * which ought to make things real slow! |
1296 | * which ought to make things real slow! |
1397 | */ |
1297 | */ |
1398 | case VisibilityNotify: |
1298 | case VisibilityNotify: |
1399 | switch (ev->xvisibility.state) { |
1299 | switch (ev->xvisibility.state) |
|
|
1300 | { |
1400 | case VisibilityUnobscured: |
1301 | case VisibilityUnobscured: |
1401 | R->refresh_type = FAST_REFRESH; |
1302 | R->refresh_type = FAST_REFRESH; |
1402 | break; |
1303 | break; |
1403 | case VisibilityPartiallyObscured: |
1304 | case VisibilityPartiallyObscured: |
1404 | R->refresh_type = SLOW_REFRESH; |
1305 | R->refresh_type = SLOW_REFRESH; |
1405 | break; |
1306 | break; |
1406 | default: |
1307 | default: |
1407 | R->refresh_type = NO_REFRESH; |
1308 | R->refresh_type = NO_REFRESH; |
1408 | break; |
1309 | break; |
1409 | } |
1310 | } |
1410 | break; |
1311 | break; |
1411 | |
1312 | |
1412 | case FocusIn: |
1313 | case FocusIn: |
1413 | if (!R->TermWin.focus) { |
1314 | if (!R->TermWin.focus) { |
1414 | R->TermWin.focus = 1; |
1315 | R->TermWin.focus = 1; |
… | |
… | |
1556 | break; |
1457 | break; |
1557 | |
1458 | |
1558 | case MotionNotify: |
1459 | case MotionNotify: |
1559 | #ifdef POINTER_BLANK |
1460 | #ifdef POINTER_BLANK |
1560 | if (R->hidden_pointer) |
1461 | if (R->hidden_pointer) |
1561 | rxvt_pointer_unblank(aR); |
1462 | R->pointer_unblank (); |
1562 | #endif |
1463 | #endif |
1563 | #if MENUBAR |
1464 | #if MENUBAR |
1564 | if (isMenuBarWindow(ev->xany.window)) { |
1465 | if (isMenuBarWindow(ev->xany.window)) { |
1565 | rxvt_menubar_control(aR_ &(ev->xbutton)); |
1466 | rxvt_menubar_control(aR_ &(ev->xbutton)); |
1566 | break; |
1467 | break; |