ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/command.C
(Generate patch)

Comparing rxvt-unicode/src/command.C (file contents):
Revision 1.5 by pcg, Tue Nov 25 15:44:38 2003 UTC vs.
Revision 1.9 by pcg, Thu Nov 27 10:12:10 2003 UTC

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.9 2003/11/27 10:12:10 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
701} 704}
702 705
703void 706void
704rxvt_term::blink_cb (time_watcher &w) 707rxvt_term::blink_cb (time_watcher &w)
705{ 708{
709 SET_R (this);
710
706 w.at += BLINK_INTERVAL; 711 w.at += BLINK_INTERVAL;
707 hidden_cursor = !hidden_cursor; 712 hidden_cursor = !hidden_cursor;
708 want_refresh = 1; 713 want_refresh = 1;
709 flush(); 714 flush ();
710} 715}
711 716
712void 717void
713rxvt_term::x_cb (io_watcher &w, short revents) 718rxvt_term::x_cb (io_watcher &w, short revents)
714{ 719{
720 SET_R (this);
721
715 process_x_events (); 722 process_x_events ();
716 723
717 flush (); 724 flush ();
718} 725}
719 726
771 778
772 return NOCHAR; 779 return NOCHAR;
773} 780}
774 781
775bool 782bool
776rxvt_term::pty_fill (size_t count) 783rxvt_term::pty_fill ()
777{ 784{
778 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 785 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
779 786
780 memmove (cmdbuf_base, cmdbuf_ptr, n); 787 memmove (cmdbuf_base, cmdbuf_ptr, n);
781 cmdbuf_ptr = cmdbuf_base; 788 cmdbuf_ptr = cmdbuf_base;
782 cmdbuf_endp = cmdbuf_ptr + n; 789 cmdbuf_endp = cmdbuf_ptr + n;
783 790
784 n = read (cmd_fd, cmdbuf_endp, count); 791 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n);
785 792
786 if (n > 0) 793 if (n > 0)
787 { 794 {
788 cmdbuf_endp += n; 795 cmdbuf_endp += n;
789 return true; 796 return true;
790 } 797 }
791 else if (n < 0 && errno == EAGAIN) 798 else if (n < 0 && errno == EAGAIN)
792 return false; 799 return false;
793 800
794 rxvt_clean_exit(); 801 destroy ();
795 exit(EXIT_FAILURE); /* bad order of events? */
796} 802}
797 803
798void 804void
799rxvt_term::pty_cb (io_watcher &w, short revents) 805rxvt_term::pty_cb (io_watcher &w, short revents)
800{ 806{
801 while (pty_fill (BUFSIZ - (cmdbuf_endp - cmdbuf_ptr))) 807 SET_R (this);
808
809 // loop, but don't allow a single term to monopolize us
810 // the number of loops is fully arbitrary, and thus wrong
811 for (int i = 7; i-- && pty_fill (); )
802 { 812 {
813 //TODO:
803 /* once we know the shell is running, send the screen size. Again! */ 814 /* once we know the shell is running, send the screen size. Again! */
804 //ch = rxvt_cmd_getc(aR); /* wait for something */ 815 //ch = rxvt_cmd_getc(aR); /* wait for something */
805 //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid); 816 //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid);
806 817
807 uint32_t ch = NOCHAR; 818 uint32_t ch = NOCHAR;
918#ifdef USE_XIM 929#ifdef USE_XIM
919 rxvt_IMSendSpot (this); 930 rxvt_IMSendSpot (this);
920#endif 931#endif
921 } 932 }
922 933
934 if (XPending (Xdisplay)) process_x_events ();
923 XFlush (Xdisplay); 935 XFlush (Xdisplay);
936 if (XPending (Xdisplay)) process_x_events ();
924} 937}
925 938
926/* rxvt_cmd_getc() - Return next input character */ 939/* rxvt_cmd_getc() - Return next input character */
927/* 940/*
928 * Return the next input character after first passing any keyboard input 941 * Return the next input character after first passing any keyboard input
939 return c; 952 return c;
940 953
941 // incomplete sequences should occur rarely, still, a better solution 954 // incomplete sequences should occur rarely, still, a better solution
942 // would be preferred. either setjmp/longjmp or better design. 955 // would be preferred. either setjmp/longjmp or better design.
943 fcntl (R->cmd_fd, F_SETFL, 0); 956 fcntl (R->cmd_fd, F_SETFL, 0);
944 R->pty_fill (1); 957 R->pty_fill ();
945 fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK); 958 fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK);
946 } 959 }
947 960
961#if 0
948#define TIMEOUT_USEC 5000 962#define TIMEOUT_USEC 5000
949 fd_set readfds; 963 fd_set readfds;
950 int quick_timeout, select_res; 964 int quick_timeout, select_res;
951 int want_motion_time, want_keypress_time; 965 int want_motion_time, want_keypress_time;
952 struct timeval value; 966 struct timeval value;
957 for (;;) { 971 for (;;) {
958 /* loop until we can return something */ 972 /* loop until we can return something */
959 973
960 if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ 974 if (R->v_bufstr < R->v_bufptr) /* output any pending chars */
961 rxvt_tt_write(aR_ NULL, 0); 975 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 976
1003#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 977#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
1004 if (R->mouse_slip_wheel_speed) { 978 if (R->mouse_slip_wheel_speed) {
1005 quick_timeout = 1; 979 quick_timeout = 1;
1006 if (!R->mouse_slip_wheel_delay-- 980 if (!R->mouse_slip_wheel_delay--
1036 R->want_refresh = 1; 1010 R->want_refresh = 1;
1037 } 1011 }
1038 } 1012 }
1039#endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ 1013#endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */
1040 1014
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 1015#ifdef TRANSPARENT
1052 quick_timeout |= R->want_full_refresh; 1016 quick_timeout |= R->want_full_refresh;
1053#endif 1017#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 1018#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} 1019}
1122 1020
1123/* EXTPROTO */
1124void 1021void
1125rxvt_pointer_unblank(pR) 1022rxvt_term::pointer_unblank ()
1126{ 1023{
1127 XDefineCursor(R->Xdisplay, R->TermWin.vt, R->TermWin_cursor); 1024 XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor);
1128 rxvt_recolour_cursor(aR); 1025 rxvt_recolour_cursor (this);
1026
1129#ifdef POINTER_BLANK 1027#ifdef POINTER_BLANK
1130 R->hidden_pointer = 0; 1028 hidden_pointer = 0;
1131 if (R->pointerBlankDelay > 0) {
1132 struct timeval tp;
1133 1029
1134 (void)gettimeofday(&tp, NULL); 1030 if (Options & Opt_pointerBlank)
1135 R->lastmotion.tv_sec = tp.tv_sec; 1031 pointer_ev.start (NOW + pointerBlankDelay);
1136 R->lastmotion.tv_usec = tp.tv_usec;
1137 }
1138#endif 1032#endif
1139} 1033}
1140 1034
1141#ifdef POINTER_BLANK 1035#ifdef POINTER_BLANK
1142/* INTPROTO */
1143void 1036void
1144rxvt_pointer_blank(pR) 1037rxvt_term::pointer_blank ()
1145{ 1038{
1039 pointer_ev.stop ();
1040
1041 if (!(Options & Opt_pointerBlank))
1042 return;
1043
1146 XDefineCursor(R->Xdisplay, R->TermWin.vt, R->pointer_blank); 1044 XDefineCursor (Xdisplay, TermWin.vt, blank_cursor);
1147 XFlush(R->Xdisplay); 1045 XFlush (Xdisplay);
1046
1148 R->hidden_pointer = 1; 1047 hidden_pointer = 1;
1048}
1049
1050void
1051rxvt_term::pointer_cb (time_watcher &w)
1052{
1053 SET_R (this);
1054
1055 pointer_blank ();
1149} 1056}
1150#endif 1057#endif
1151 1058
1152/* INTPROTO */ 1059/* INTPROTO */
1153void 1060void
1349 break; 1256 break;
1350 1257
1351 case ClientMessage: 1258 case ClientMessage:
1352 if (ev->xclient.format == 32 1259 if (ev->xclient.format == 32
1353 && (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW]) 1260 && (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW])
1354 exit(EXIT_SUCCESS); 1261 R->destroy ();
1355#ifdef OFFIX_DND 1262#ifdef OFFIX_DND
1356 /* OffiX Dnd (drag 'n' drop) protocol */ 1263 /* OffiX Dnd (drag 'n' drop) protocol */
1357 if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL] 1264 else if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL]
1358 && (ev->xclient.data.l[0] == DndFile 1265 && (ev->xclient.data.l[0] == DndFile
1359 || ev->xclient.data.l[0] == DndDir 1266 || ev->xclient.data.l[0] == DndDir
1360 || ev->xclient.data.l[0] == DndLink)) { 1267 || ev->xclient.data.l[0] == DndLink)) {
1361 /* Get Dnd data */ 1268 /* Get Dnd data */
1362 Atom ActualType; 1269 Atom ActualType;
1394 * in the GraphicsExpose parts, which means that after each refresh, 1301 * in the GraphicsExpose parts, which means that after each refresh,
1395 * we need to wait for the graphics expose or Noexpose events, 1302 * we need to wait for the graphics expose or Noexpose events,
1396 * which ought to make things real slow! 1303 * which ought to make things real slow!
1397 */ 1304 */
1398 case VisibilityNotify: 1305 case VisibilityNotify:
1399 switch (ev->xvisibility.state) { 1306 switch (ev->xvisibility.state)
1307 {
1400 case VisibilityUnobscured: 1308 case VisibilityUnobscured:
1401 R->refresh_type = FAST_REFRESH; 1309 R->refresh_type = FAST_REFRESH;
1402 break; 1310 break;
1403 case VisibilityPartiallyObscured: 1311 case VisibilityPartiallyObscured:
1404 R->refresh_type = SLOW_REFRESH; 1312 R->refresh_type = SLOW_REFRESH;
1405 break; 1313 break;
1406 default: 1314 default:
1407 R->refresh_type = NO_REFRESH; 1315 R->refresh_type = NO_REFRESH;
1408 break; 1316 break;
1409 } 1317 }
1410 break; 1318 break;
1411 1319
1412 case FocusIn: 1320 case FocusIn:
1413 if (!R->TermWin.focus) { 1321 if (!R->TermWin.focus) {
1414 R->TermWin.focus = 1; 1322 R->TermWin.focus = 1;
1556 break; 1464 break;
1557 1465
1558 case MotionNotify: 1466 case MotionNotify:
1559#ifdef POINTER_BLANK 1467#ifdef POINTER_BLANK
1560 if (R->hidden_pointer) 1468 if (R->hidden_pointer)
1561 rxvt_pointer_unblank(aR); 1469 R->pointer_unblank ();
1562#endif 1470#endif
1563#if MENUBAR 1471#if MENUBAR
1564 if (isMenuBarWindow(ev->xany.window)) { 1472 if (isMenuBarWindow(ev->xany.window)) {
1565 rxvt_menubar_control(aR_ &(ev->xbutton)); 1473 rxvt_menubar_control(aR_ &(ev->xbutton));
1566 break; 1474 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines