1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: command.c |
2 | * File: command.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: command.C,v 1.4 2003/11/25 15:25:16 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> |
… | |
… | |
663 | do |
663 | do |
664 | { |
664 | { |
665 | XEvent xev; |
665 | XEvent xev; |
666 | |
666 | |
667 | XNextEvent (Xdisplay, &xev); |
667 | XNextEvent (Xdisplay, &xev); |
|
|
668 | |
668 | #if defined(CURSOR_BLINK) |
669 | #if defined(CURSOR_BLINK) |
669 | if ((Options & Opt_cursorBlink) |
670 | if ((Options & Opt_cursorBlink) |
670 | && xev.type == KeyPress) { |
671 | && xev.type == KeyPress) |
|
|
672 | { |
671 | if (hidden_cursor) { |
673 | if (hidden_cursor) |
|
|
674 | { |
672 | hidden_cursor = 0; |
675 | hidden_cursor = 0; |
673 | want_refresh = 1; |
676 | want_refresh = 1; |
674 | } |
677 | } |
675 | want_keypress_time = 1; |
678 | |
|
|
679 | blink_ev.start (NOW + BLINK_INTERVAL); |
676 | } |
680 | } |
677 | #endif |
681 | #endif |
678 | |
682 | |
679 | #if defined(POINTER_BLANK) |
683 | #if defined(POINTER_BLANK) |
680 | if ((Options & Opt_pointerBlank) |
684 | if ((Options & Opt_pointerBlank) |
681 | && (pointerBlankDelay > 0)) { |
685 | && (pointerBlankDelay > 0)) |
|
|
686 | { |
682 | if (xev.type == MotionNotify |
687 | if (xev.type == MotionNotify |
683 | || xev.type == ButtonPress |
688 | || xev.type == ButtonPress |
684 | || xev.type == ButtonRelease) { |
689 | || xev.type == ButtonRelease) |
685 | if (hidden_pointer) |
690 | if (hidden_pointer) |
686 | rxvt_pointer_unblank(aR); |
691 | pointer_unblank (); |
687 | want_motion_time = 1; |
692 | |
688 | } |
|
|
689 | if (xev.type == KeyPress && hidden_pointer == 0) |
693 | if (xev.type == KeyPress && hidden_pointer == 0) |
690 | rxvt_pointer_blank (this); |
694 | pointer_blank (); |
691 | } |
695 | } |
692 | #endif |
696 | #endif |
693 | |
697 | |
694 | #ifdef USE_XIM |
698 | #ifdef USE_XIM |
695 | if (!XFilterEvent (&xev, xev.xany.window)) |
699 | if (!XFilterEvent (&xev, xev.xany.window)) |
696 | #endif |
700 | #endif |
697 | rxvt_process_x_event (this, &xev); |
701 | rxvt_process_x_event (this, &xev); |
698 | } |
702 | } |
699 | while (XPending (Xdisplay)); |
703 | while (XPending (Xdisplay)); |
|
|
704 | } |
|
|
705 | |
|
|
706 | void |
|
|
707 | rxvt_term::blink_cb (time_watcher &w) |
|
|
708 | { |
|
|
709 | w.at += BLINK_INTERVAL; |
|
|
710 | hidden_cursor = !hidden_cursor; |
|
|
711 | want_refresh = 1; |
|
|
712 | flush (); |
700 | } |
713 | } |
701 | |
714 | |
702 | void |
715 | void |
703 | rxvt_term::x_cb (io_watcher &w, short revents) |
716 | rxvt_term::x_cb (io_watcher &w, short revents) |
704 | { |
717 | { |
… | |
… | |
761 | |
774 | |
762 | return NOCHAR; |
775 | return NOCHAR; |
763 | } |
776 | } |
764 | |
777 | |
765 | bool |
778 | bool |
766 | rxvt_term::pty_fill (size_t count) |
779 | rxvt_term::pty_fill () |
767 | { |
780 | { |
768 | ssize_t n = cmdbuf_endp - cmdbuf_ptr; |
781 | ssize_t n = cmdbuf_endp - cmdbuf_ptr; |
769 | |
782 | |
770 | memmove (cmdbuf_base, cmdbuf_ptr, n); |
783 | memmove (cmdbuf_base, cmdbuf_ptr, n); |
771 | cmdbuf_ptr = cmdbuf_base; |
784 | cmdbuf_ptr = cmdbuf_base; |
772 | cmdbuf_endp = cmdbuf_ptr + n; |
785 | cmdbuf_endp = cmdbuf_ptr + n; |
773 | |
786 | |
774 | n = read (cmd_fd, cmdbuf_endp, count); |
787 | n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n); |
775 | |
788 | |
776 | if (n > 0) |
789 | if (n > 0) |
777 | { |
790 | { |
778 | cmdbuf_endp += n; |
791 | cmdbuf_endp += n; |
779 | return true; |
792 | return true; |
780 | } |
793 | } |
781 | else if (n < 0 && errno == EAGAIN) |
794 | else if (n < 0 && errno == EAGAIN) |
782 | return false; |
795 | return false; |
783 | |
796 | |
784 | rxvt_clean_exit(); |
797 | rxvt_clean_exit (); |
785 | exit(EXIT_FAILURE); /* bad order of events? */ |
798 | exit (EXIT_FAILURE); /* bad order of events? */ |
786 | } |
799 | } |
787 | |
800 | |
788 | void |
801 | void |
789 | rxvt_term::pty_cb (io_watcher &w, short revents) |
802 | rxvt_term::pty_cb (io_watcher &w, short revents) |
790 | { |
803 | { |
791 | 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 (); ) |
792 | { |
807 | { |
|
|
808 | //TODO: |
793 | /* 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! */ |
794 | //ch = rxvt_cmd_getc(aR); /* wait for something */ |
810 | //ch = rxvt_cmd_getc(aR); /* wait for something */ |
795 | //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid); |
811 | //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid); |
796 | |
812 | |
797 | uint32_t ch = NOCHAR; |
813 | uint32_t ch = NOCHAR; |
… | |
… | |
908 | #ifdef USE_XIM |
924 | #ifdef USE_XIM |
909 | rxvt_IMSendSpot (this); |
925 | rxvt_IMSendSpot (this); |
910 | #endif |
926 | #endif |
911 | } |
927 | } |
912 | |
928 | |
|
|
929 | if (XPending (Xdisplay)) process_x_events (); |
913 | XFlush (Xdisplay); |
930 | XFlush (Xdisplay); |
|
|
931 | if (XPending (Xdisplay)) process_x_events (); |
914 | } |
932 | } |
915 | |
933 | |
916 | /* rxvt_cmd_getc() - Return next input character */ |
934 | /* rxvt_cmd_getc() - Return next input character */ |
917 | /* |
935 | /* |
918 | * Return the next input character after first passing any keyboard input |
936 | * Return the next input character after first passing any keyboard input |
… | |
… | |
929 | return c; |
947 | return c; |
930 | |
948 | |
931 | // incomplete sequences should occur rarely, still, a better solution |
949 | // incomplete sequences should occur rarely, still, a better solution |
932 | // would be preferred. either setjmp/longjmp or better design. |
950 | // would be preferred. either setjmp/longjmp or better design. |
933 | fcntl (R->cmd_fd, F_SETFL, 0); |
951 | fcntl (R->cmd_fd, F_SETFL, 0); |
934 | R->pty_fill (1); |
952 | R->pty_fill (); |
935 | fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK); |
953 | fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK); |
936 | } |
954 | } |
937 | |
955 | |
|
|
956 | #if 0 |
938 | #define TIMEOUT_USEC 5000 |
957 | #define TIMEOUT_USEC 5000 |
939 | fd_set readfds; |
958 | fd_set readfds; |
940 | int quick_timeout, select_res; |
959 | int quick_timeout, select_res; |
941 | int want_motion_time, want_keypress_time; |
960 | int want_motion_time, want_keypress_time; |
942 | struct timeval value; |
961 | struct timeval value; |
… | |
… | |
947 | for (;;) { |
966 | for (;;) { |
948 | /* loop until we can return something */ |
967 | /* loop until we can return something */ |
949 | |
968 | |
950 | if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ |
969 | if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ |
951 | rxvt_tt_write(aR_ NULL, 0); |
970 | rxvt_tt_write(aR_ NULL, 0); |
952 | |
|
|
953 | #if defined(POINTER_BLANK) || defined(CURSOR_BLINK) |
|
|
954 | tp.tv_sec = 0; /* presume == 0 implies time not yet retrieved */ |
|
|
955 | #endif |
|
|
956 | #if defined(CURSOR_BLINK) |
|
|
957 | want_keypress_time = 0; |
|
|
958 | #endif |
|
|
959 | #if defined(POINTER_BLANK) |
|
|
960 | want_motion_time = 0; |
|
|
961 | #endif |
|
|
962 | |
|
|
963 | if (XPending (R->Xdisplay)) |
|
|
964 | { |
|
|
965 | R->process_x_events (); |
|
|
966 | |
|
|
967 | /* in case button actions pushed chars to cmdbuf */ |
|
|
968 | if (R->cmdbuf_ptr < R->cmdbuf_endp) |
|
|
969 | return *R->cmdbuf_ptr++; |
|
|
970 | } |
|
|
971 | |
|
|
972 | #if defined(CURSOR_BLINK) |
|
|
973 | if (want_keypress_time) { |
|
|
974 | (void)gettimeofday(&tp, NULL); |
|
|
975 | R->lastcursorchange.tv_sec = tp.tv_sec; |
|
|
976 | R->lastcursorchange.tv_usec = tp.tv_usec; |
|
|
977 | } |
|
|
978 | #endif |
|
|
979 | #if defined(POINTER_BLANK) |
|
|
980 | if (want_motion_time) { |
|
|
981 | if (!tp.tv_sec) |
|
|
982 | (void)gettimeofday(&tp, NULL); |
|
|
983 | R->lastmotion.tv_sec = tp.tv_sec; |
|
|
984 | R->lastmotion.tv_usec = tp.tv_usec; |
|
|
985 | } |
|
|
986 | #endif |
|
|
987 | |
|
|
988 | /* |
|
|
989 | * the command input buffer is empty and we have no pending X events |
|
|
990 | */ |
|
|
991 | quick_timeout = 0; |
|
|
992 | |
971 | |
993 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
972 | #if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) |
994 | if (R->mouse_slip_wheel_speed) { |
973 | if (R->mouse_slip_wheel_speed) { |
995 | quick_timeout = 1; |
974 | quick_timeout = 1; |
996 | if (!R->mouse_slip_wheel_delay-- |
975 | if (!R->mouse_slip_wheel_delay-- |
… | |
… | |
1026 | R->want_refresh = 1; |
1005 | R->want_refresh = 1; |
1027 | } |
1006 | } |
1028 | } |
1007 | } |
1029 | #endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ |
1008 | #endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ |
1030 | |
1009 | |
1031 | FD_ZERO(&readfds); |
|
|
1032 | FD_SET(R->cmd_fd, &readfds); |
|
|
1033 | FD_SET(R->Xfd, &readfds); |
|
|
1034 | value.tv_usec = TIMEOUT_USEC; |
|
|
1035 | value.tv_sec = 0; |
|
|
1036 | |
|
|
1037 | if (!R->TermWin.mapped) |
|
|
1038 | quick_timeout = 0; |
|
|
1039 | else { |
|
|
1040 | quick_timeout |= R->want_refresh; |
|
|
1041 | #ifdef TRANSPARENT |
1010 | #ifdef TRANSPARENT |
1042 | quick_timeout |= R->want_full_refresh; |
1011 | quick_timeout |= R->want_full_refresh; |
1043 | #endif |
1012 | #endif |
1044 | } |
|
|
1045 | |
|
|
1046 | #if defined(POINTER_BLANK) || defined(CURSOR_BLINK) |
|
|
1047 | { |
|
|
1048 | int set_quick_timeout = 0; |
|
|
1049 | long csdiff, psdiff; |
|
|
1050 | |
|
|
1051 | #define BLINK_TIME 500000L |
|
|
1052 | csdiff = psdiff = 60000000L; /* or, say, LONG_MAX */ |
|
|
1053 | # if defined(CURSOR_BLINK) |
|
|
1054 | if (R->Options & Opt_cursorBlink) { |
|
|
1055 | if (!tp.tv_sec) /* didn't get it before so get it now */ |
|
|
1056 | (void)gettimeofday(&tp, NULL); |
|
|
1057 | |
|
|
1058 | csdiff = (tp.tv_sec - R->lastcursorchange.tv_sec) * 1000000L |
|
|
1059 | + tp.tv_usec - R->lastcursorchange.tv_usec; |
|
|
1060 | if (csdiff > BLINK_TIME) { /* XXX: settable blink times */ |
|
|
1061 | R->lastcursorchange.tv_sec = tp.tv_sec; |
|
|
1062 | R->lastcursorchange.tv_usec = tp.tv_usec; |
|
|
1063 | R->hidden_cursor = !R->hidden_cursor; |
|
|
1064 | csdiff = 0; |
|
|
1065 | } else |
|
|
1066 | csdiff = BLINK_TIME - csdiff; |
|
|
1067 | set_quick_timeout = 1; |
|
|
1068 | } |
|
|
1069 | # endif |
1013 | #endif |
1070 | # if defined(POINTER_BLANK) |
|
|
1071 | /* |
|
|
1072 | * If we haven't moved the pointer for a while |
|
|
1073 | */ |
|
|
1074 | if ((R->Options & Opt_pointerBlank) |
|
|
1075 | && (R->pointerBlankDelay > 0) |
|
|
1076 | && (R->hidden_pointer == 0)) { |
|
|
1077 | long pdelay; |
|
|
1078 | |
|
|
1079 | if (!tp.tv_sec) /* didn't get it before so get it now */ |
|
|
1080 | (void)gettimeofday(&tp, NULL); |
|
|
1081 | psdiff = (tp.tv_sec - R->lastmotion.tv_sec) * 1000000L |
|
|
1082 | + tp.tv_usec - R->lastmotion.tv_usec; |
|
|
1083 | pdelay = R->pointerBlankDelay * 1000000L; |
|
|
1084 | if (psdiff >= pdelay) |
|
|
1085 | rxvt_pointer_blank(aR); |
|
|
1086 | else { |
|
|
1087 | set_quick_timeout = 1; |
|
|
1088 | psdiff = pdelay - psdiff; |
|
|
1089 | } |
|
|
1090 | } |
|
|
1091 | # endif |
|
|
1092 | if (!quick_timeout && set_quick_timeout) { |
|
|
1093 | MIN_IT(csdiff, psdiff); |
|
|
1094 | value.tv_sec = csdiff / 1000000L; |
|
|
1095 | value.tv_usec = csdiff % 1000000L; |
|
|
1096 | quick_timeout = 1; |
|
|
1097 | } |
|
|
1098 | } |
|
|
1099 | #endif |
|
|
1100 | |
|
|
1101 | if ((select_res = select(R->num_fds, &readfds, NULL, NULL, |
|
|
1102 | (quick_timeout ? &value : NULL))) == 0) { |
|
|
1103 | /* select statement timed out - we're not hard and fast scrolling */ |
|
|
1104 | R->refresh_limit = 1; |
|
|
1105 | } |
|
|
1106 | #if defined(CURSOR_BLINK) |
|
|
1107 | if (R->Options & Opt_cursorBlink) |
|
|
1108 | R->want_refresh = 1; |
|
|
1109 | #endif |
|
|
1110 | } |
|
|
1111 | } |
1014 | } |
1112 | |
1015 | |
1113 | /* EXTPROTO */ |
|
|
1114 | void |
1016 | void |
1115 | rxvt_pointer_unblank(pR) |
1017 | rxvt_term::pointer_unblank () |
1116 | { |
1018 | { |
1117 | XDefineCursor(R->Xdisplay, R->TermWin.vt, R->TermWin_cursor); |
1019 | XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor); |
1118 | rxvt_recolour_cursor(aR); |
1020 | rxvt_recolour_cursor (this); |
|
|
1021 | |
1119 | #ifdef POINTER_BLANK |
1022 | #ifdef POINTER_BLANK |
1120 | R->hidden_pointer = 0; |
1023 | hidden_pointer = 0; |
1121 | if (R->pointerBlankDelay > 0) { |
|
|
1122 | struct timeval tp; |
|
|
1123 | |
1024 | |
1124 | (void)gettimeofday(&tp, NULL); |
1025 | if (Options & Opt_pointerBlank) |
1125 | R->lastmotion.tv_sec = tp.tv_sec; |
1026 | pointer_ev.start (NOW + pointerBlankDelay); |
1126 | R->lastmotion.tv_usec = tp.tv_usec; |
|
|
1127 | } |
|
|
1128 | #endif |
1027 | #endif |
1129 | } |
1028 | } |
1130 | |
1029 | |
1131 | #ifdef POINTER_BLANK |
1030 | #ifdef POINTER_BLANK |
1132 | /* INTPROTO */ |
|
|
1133 | void |
1031 | void |
1134 | rxvt_pointer_blank(pR) |
1032 | rxvt_term::pointer_blank () |
1135 | { |
1033 | { |
|
|
1034 | pointer_ev.stop (); |
|
|
1035 | |
|
|
1036 | if (!(Options & Opt_pointerBlank)) |
|
|
1037 | return; |
|
|
1038 | |
1136 | XDefineCursor(R->Xdisplay, R->TermWin.vt, R->pointer_blank); |
1039 | XDefineCursor (Xdisplay, TermWin.vt, blank_cursor); |
1137 | XFlush(R->Xdisplay); |
1040 | XFlush (Xdisplay); |
|
|
1041 | |
1138 | R->hidden_pointer = 1; |
1042 | hidden_pointer = 1; |
|
|
1043 | } |
|
|
1044 | |
|
|
1045 | void |
|
|
1046 | rxvt_term::pointer_cb (time_watcher &w) |
|
|
1047 | { |
|
|
1048 | pointer_blank (); |
1139 | } |
1049 | } |
1140 | #endif |
1050 | #endif |
1141 | |
1051 | |
1142 | /* INTPROTO */ |
1052 | /* INTPROTO */ |
1143 | void |
1053 | void |
… | |
… | |
1384 | * in the GraphicsExpose parts, which means that after each refresh, |
1294 | * in the GraphicsExpose parts, which means that after each refresh, |
1385 | * we need to wait for the graphics expose or Noexpose events, |
1295 | * we need to wait for the graphics expose or Noexpose events, |
1386 | * which ought to make things real slow! |
1296 | * which ought to make things real slow! |
1387 | */ |
1297 | */ |
1388 | case VisibilityNotify: |
1298 | case VisibilityNotify: |
1389 | switch (ev->xvisibility.state) { |
1299 | switch (ev->xvisibility.state) |
|
|
1300 | { |
1390 | case VisibilityUnobscured: |
1301 | case VisibilityUnobscured: |
1391 | R->refresh_type = FAST_REFRESH; |
1302 | R->refresh_type = FAST_REFRESH; |
1392 | break; |
1303 | break; |
1393 | case VisibilityPartiallyObscured: |
1304 | case VisibilityPartiallyObscured: |
1394 | R->refresh_type = SLOW_REFRESH; |
1305 | R->refresh_type = SLOW_REFRESH; |
1395 | break; |
1306 | break; |
1396 | default: |
1307 | default: |
1397 | R->refresh_type = NO_REFRESH; |
1308 | R->refresh_type = NO_REFRESH; |
1398 | break; |
1309 | break; |
1399 | } |
1310 | } |
1400 | break; |
1311 | break; |
1401 | |
1312 | |
1402 | case FocusIn: |
1313 | case FocusIn: |
1403 | if (!R->TermWin.focus) { |
1314 | if (!R->TermWin.focus) { |
1404 | R->TermWin.focus = 1; |
1315 | R->TermWin.focus = 1; |
1405 | R->want_refresh = 1; |
1316 | R->want_refresh = 1; |
1406 | #ifdef USE_XIM |
1317 | #ifdef USE_XIM |
1407 | if (R->Input_Context != NULL) |
1318 | if (R->Input_Context != NULL) |
1408 | XSetICFocus(R->Input_Context); |
1319 | XSetICFocus(R->Input_Context); |
1409 | #endif |
1320 | #endif |
|
|
1321 | #ifdef CURSOR_BLINK |
|
|
1322 | if (R->Options & Opt_cursorBlink) |
|
|
1323 | R->blink_ev.start (NOW + BLINK_INTERVAL); |
|
|
1324 | #endif |
1410 | } |
1325 | } |
1411 | break; |
1326 | break; |
1412 | |
1327 | |
1413 | case FocusOut: |
1328 | case FocusOut: |
1414 | if (R->TermWin.focus) { |
1329 | if (R->TermWin.focus) { |
1415 | R->TermWin.focus = 0; |
1330 | R->TermWin.focus = 0; |
1416 | R->want_refresh = 1; |
1331 | R->want_refresh = 1; |
1417 | #ifdef USE_XIM |
1332 | #ifdef USE_XIM |
1418 | if (R->Input_Context != NULL) |
1333 | if (R->Input_Context != NULL) |
1419 | XUnsetICFocus(R->Input_Context); |
1334 | XUnsetICFocus(R->Input_Context); |
|
|
1335 | #endif |
|
|
1336 | #ifdef CURSOR_BLINK |
|
|
1337 | if (R->Options & Opt_cursorBlink) |
|
|
1338 | R->blink_ev.stop (); |
|
|
1339 | R->hidden_cursor = 0; |
1420 | #endif |
1340 | #endif |
1421 | } |
1341 | } |
1422 | break; |
1342 | break; |
1423 | |
1343 | |
1424 | case ConfigureNotify: |
1344 | case ConfigureNotify: |
… | |
… | |
1537 | break; |
1457 | break; |
1538 | |
1458 | |
1539 | case MotionNotify: |
1459 | case MotionNotify: |
1540 | #ifdef POINTER_BLANK |
1460 | #ifdef POINTER_BLANK |
1541 | if (R->hidden_pointer) |
1461 | if (R->hidden_pointer) |
1542 | rxvt_pointer_unblank(aR); |
1462 | R->pointer_unblank (); |
1543 | #endif |
1463 | #endif |
1544 | #if MENUBAR |
1464 | #if MENUBAR |
1545 | if (isMenuBarWindow(ev->xany.window)) { |
1465 | if (isMenuBarWindow(ev->xany.window)) { |
1546 | rxvt_menubar_control(aR_ &(ev->xbutton)); |
1466 | rxvt_menubar_control(aR_ &(ev->xbutton)); |
1547 | break; |
1467 | break; |