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.4 by pcg, Tue Nov 25 15:25:16 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.4 2003/11/25 15:25:16 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>
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
698 } 702 }
699 while (XPending (Xdisplay)); 703 while (XPending (Xdisplay));
700} 704}
701 705
702void 706void
707rxvt_term::blink_cb (time_watcher &w)
708{
709 SET_R (this);
710
711 w.at += BLINK_INTERVAL;
712 hidden_cursor = !hidden_cursor;
713 want_refresh = 1;
714 flush ();
715}
716
717void
703rxvt_term::x_cb (io_watcher &w, short revents) 718rxvt_term::x_cb (io_watcher &w, short revents)
704{ 719{
720 SET_R (this);
721
705 process_x_events (); 722 process_x_events ();
706 723
707 flush (); 724 flush ();
708} 725}
709 726
761 778
762 return NOCHAR; 779 return NOCHAR;
763} 780}
764 781
765bool 782bool
766rxvt_term::pty_fill (size_t count) 783rxvt_term::pty_fill ()
767{ 784{
768 ssize_t n = cmdbuf_endp - cmdbuf_ptr; 785 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
769 786
770 memmove (cmdbuf_base, cmdbuf_ptr, n); 787 memmove (cmdbuf_base, cmdbuf_ptr, n);
771 cmdbuf_ptr = cmdbuf_base; 788 cmdbuf_ptr = cmdbuf_base;
772 cmdbuf_endp = cmdbuf_ptr + n; 789 cmdbuf_endp = cmdbuf_ptr + n;
773 790
774 n = read (cmd_fd, cmdbuf_endp, count); 791 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n);
775 792
776 if (n > 0) 793 if (n > 0)
777 { 794 {
778 cmdbuf_endp += n; 795 cmdbuf_endp += n;
779 return true; 796 return true;
780 } 797 }
781 else if (n < 0 && errno == EAGAIN) 798 else if (n < 0 && errno == EAGAIN)
782 return false; 799 return false;
783 800
784 rxvt_clean_exit(); 801 destroy ();
785 exit(EXIT_FAILURE); /* bad order of events? */
786} 802}
787 803
788void 804void
789rxvt_term::pty_cb (io_watcher &w, short revents) 805rxvt_term::pty_cb (io_watcher &w, short revents)
790{ 806{
791 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 (); )
792 { 812 {
813 //TODO:
793 /* 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! */
794 //ch = rxvt_cmd_getc(aR); /* wait for something */ 815 //ch = rxvt_cmd_getc(aR); /* wait for something */
795 //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid); 816 //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid);
796 817
797 uint32_t ch = NOCHAR; 818 uint32_t ch = NOCHAR;
908#ifdef USE_XIM 929#ifdef USE_XIM
909 rxvt_IMSendSpot (this); 930 rxvt_IMSendSpot (this);
910#endif 931#endif
911 } 932 }
912 933
934 if (XPending (Xdisplay)) process_x_events ();
913 XFlush (Xdisplay); 935 XFlush (Xdisplay);
936 if (XPending (Xdisplay)) process_x_events ();
914} 937}
915 938
916/* rxvt_cmd_getc() - Return next input character */ 939/* rxvt_cmd_getc() - Return next input character */
917/* 940/*
918 * Return the next input character after first passing any keyboard input 941 * Return the next input character after first passing any keyboard input
929 return c; 952 return c;
930 953
931 // incomplete sequences should occur rarely, still, a better solution 954 // incomplete sequences should occur rarely, still, a better solution
932 // would be preferred. either setjmp/longjmp or better design. 955 // would be preferred. either setjmp/longjmp or better design.
933 fcntl (R->cmd_fd, F_SETFL, 0); 956 fcntl (R->cmd_fd, F_SETFL, 0);
934 R->pty_fill (1); 957 R->pty_fill ();
935 fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK); 958 fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK);
936 } 959 }
937 960
961#if 0
938#define TIMEOUT_USEC 5000 962#define TIMEOUT_USEC 5000
939 fd_set readfds; 963 fd_set readfds;
940 int quick_timeout, select_res; 964 int quick_timeout, select_res;
941 int want_motion_time, want_keypress_time; 965 int want_motion_time, want_keypress_time;
942 struct timeval value; 966 struct timeval value;
947 for (;;) { 971 for (;;) {
948 /* loop until we can return something */ 972 /* loop until we can return something */
949 973
950 if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ 974 if (R->v_bufstr < R->v_bufptr) /* output any pending chars */
951 rxvt_tt_write(aR_ NULL, 0); 975 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 976
993#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 977#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
994 if (R->mouse_slip_wheel_speed) { 978 if (R->mouse_slip_wheel_speed) {
995 quick_timeout = 1; 979 quick_timeout = 1;
996 if (!R->mouse_slip_wheel_delay-- 980 if (!R->mouse_slip_wheel_delay--
1026 R->want_refresh = 1; 1010 R->want_refresh = 1;
1027 } 1011 }
1028 } 1012 }
1029#endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ 1013#endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */
1030 1014
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 1015#ifdef TRANSPARENT
1042 quick_timeout |= R->want_full_refresh; 1016 quick_timeout |= R->want_full_refresh;
1043#endif 1017#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 1018#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} 1019}
1112 1020
1113/* EXTPROTO */
1114void 1021void
1115rxvt_pointer_unblank(pR) 1022rxvt_term::pointer_unblank ()
1116{ 1023{
1117 XDefineCursor(R->Xdisplay, R->TermWin.vt, R->TermWin_cursor); 1024 XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor);
1118 rxvt_recolour_cursor(aR); 1025 rxvt_recolour_cursor (this);
1026
1119#ifdef POINTER_BLANK 1027#ifdef POINTER_BLANK
1120 R->hidden_pointer = 0; 1028 hidden_pointer = 0;
1121 if (R->pointerBlankDelay > 0) {
1122 struct timeval tp;
1123 1029
1124 (void)gettimeofday(&tp, NULL); 1030 if (Options & Opt_pointerBlank)
1125 R->lastmotion.tv_sec = tp.tv_sec; 1031 pointer_ev.start (NOW + pointerBlankDelay);
1126 R->lastmotion.tv_usec = tp.tv_usec;
1127 }
1128#endif 1032#endif
1129} 1033}
1130 1034
1131#ifdef POINTER_BLANK 1035#ifdef POINTER_BLANK
1132/* INTPROTO */
1133void 1036void
1134rxvt_pointer_blank(pR) 1037rxvt_term::pointer_blank ()
1135{ 1038{
1039 pointer_ev.stop ();
1040
1041 if (!(Options & Opt_pointerBlank))
1042 return;
1043
1136 XDefineCursor(R->Xdisplay, R->TermWin.vt, R->pointer_blank); 1044 XDefineCursor (Xdisplay, TermWin.vt, blank_cursor);
1137 XFlush(R->Xdisplay); 1045 XFlush (Xdisplay);
1046
1138 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 ();
1139} 1056}
1140#endif 1057#endif
1141 1058
1142/* INTPROTO */ 1059/* INTPROTO */
1143void 1060void
1339 break; 1256 break;
1340 1257
1341 case ClientMessage: 1258 case ClientMessage:
1342 if (ev->xclient.format == 32 1259 if (ev->xclient.format == 32
1343 && (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW]) 1260 && (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW])
1344 exit(EXIT_SUCCESS); 1261 R->destroy ();
1345#ifdef OFFIX_DND 1262#ifdef OFFIX_DND
1346 /* OffiX Dnd (drag 'n' drop) protocol */ 1263 /* OffiX Dnd (drag 'n' drop) protocol */
1347 if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL] 1264 else if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL]
1348 && (ev->xclient.data.l[0] == DndFile 1265 && (ev->xclient.data.l[0] == DndFile
1349 || ev->xclient.data.l[0] == DndDir 1266 || ev->xclient.data.l[0] == DndDir
1350 || ev->xclient.data.l[0] == DndLink)) { 1267 || ev->xclient.data.l[0] == DndLink)) {
1351 /* Get Dnd data */ 1268 /* Get Dnd data */
1352 Atom ActualType; 1269 Atom ActualType;
1384 * in the GraphicsExpose parts, which means that after each refresh, 1301 * in the GraphicsExpose parts, which means that after each refresh,
1385 * we need to wait for the graphics expose or Noexpose events, 1302 * we need to wait for the graphics expose or Noexpose events,
1386 * which ought to make things real slow! 1303 * which ought to make things real slow!
1387 */ 1304 */
1388 case VisibilityNotify: 1305 case VisibilityNotify:
1389 switch (ev->xvisibility.state) { 1306 switch (ev->xvisibility.state)
1307 {
1390 case VisibilityUnobscured: 1308 case VisibilityUnobscured:
1391 R->refresh_type = FAST_REFRESH; 1309 R->refresh_type = FAST_REFRESH;
1392 break; 1310 break;
1393 case VisibilityPartiallyObscured: 1311 case VisibilityPartiallyObscured:
1394 R->refresh_type = SLOW_REFRESH; 1312 R->refresh_type = SLOW_REFRESH;
1395 break; 1313 break;
1396 default: 1314 default:
1397 R->refresh_type = NO_REFRESH; 1315 R->refresh_type = NO_REFRESH;
1398 break; 1316 break;
1399 } 1317 }
1400 break; 1318 break;
1401 1319
1402 case FocusIn: 1320 case FocusIn:
1403 if (!R->TermWin.focus) { 1321 if (!R->TermWin.focus) {
1404 R->TermWin.focus = 1; 1322 R->TermWin.focus = 1;
1405 R->want_refresh = 1; 1323 R->want_refresh = 1;
1406#ifdef USE_XIM 1324#ifdef USE_XIM
1407 if (R->Input_Context != NULL) 1325 if (R->Input_Context != NULL)
1408 XSetICFocus(R->Input_Context); 1326 XSetICFocus(R->Input_Context);
1409#endif 1327#endif
1328#ifdef CURSOR_BLINK
1329 if (R->Options & Opt_cursorBlink)
1330 R->blink_ev.start (NOW + BLINK_INTERVAL);
1331#endif
1410 } 1332 }
1411 break; 1333 break;
1412 1334
1413 case FocusOut: 1335 case FocusOut:
1414 if (R->TermWin.focus) { 1336 if (R->TermWin.focus) {
1415 R->TermWin.focus = 0; 1337 R->TermWin.focus = 0;
1416 R->want_refresh = 1; 1338 R->want_refresh = 1;
1417#ifdef USE_XIM 1339#ifdef USE_XIM
1418 if (R->Input_Context != NULL) 1340 if (R->Input_Context != NULL)
1419 XUnsetICFocus(R->Input_Context); 1341 XUnsetICFocus(R->Input_Context);
1342#endif
1343#ifdef CURSOR_BLINK
1344 if (R->Options & Opt_cursorBlink)
1345 R->blink_ev.stop ();
1346 R->hidden_cursor = 0;
1420#endif 1347#endif
1421 } 1348 }
1422 break; 1349 break;
1423 1350
1424 case ConfigureNotify: 1351 case ConfigureNotify:
1537 break; 1464 break;
1538 1465
1539 case MotionNotify: 1466 case MotionNotify:
1540#ifdef POINTER_BLANK 1467#ifdef POINTER_BLANK
1541 if (R->hidden_pointer) 1468 if (R->hidden_pointer)
1542 rxvt_pointer_unblank(aR); 1469 R->pointer_unblank ();
1543#endif 1470#endif
1544#if MENUBAR 1471#if MENUBAR
1545 if (isMenuBarWindow(ev->xany.window)) { 1472 if (isMenuBarWindow(ev->xany.window)) {
1546 rxvt_menubar_control(aR_ &(ev->xbutton)); 1473 rxvt_menubar_control(aR_ &(ev->xbutton));
1547 break; 1474 break;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines