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.3 by pcg, Tue Nov 25 11:52:42 2003 UTC vs.
Revision 1.8 by pcg, Wed Nov 26 10:42:34 2003 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: command.c 2 * File: command.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: command.C,v 1.3 2003/11/25 11:52:42 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>
632rxvt_cmd_write(pR_ const unsigned char *str, unsigned int count) 632rxvt_cmd_write(pR_ const unsigned char *str, unsigned int count)
633{ 633{
634 unsigned int n, s; 634 unsigned int n, s;
635 unsigned char *cmdbuf_base = R->cmdbuf_base, 635 unsigned char *cmdbuf_base = R->cmdbuf_base,
636 *cmdbuf_endp = R->cmdbuf_endp, 636 *cmdbuf_endp = R->cmdbuf_endp,
637 *cmdbuf_ptr = R->cmdbuf_ptr; 637 *cmdbuf_ptr = R->cmdbuf_ptr;
638 638
639 n = cmdbuf_ptr - cmdbuf_base; 639 n = cmdbuf_ptr - cmdbuf_base;
640 s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp; 640 s = cmdbuf_base + BUFSIZ - 1 - cmdbuf_endp;
641 if (n > 0 && s < count) { 641 if (n > 0 && s < count) {
642 MEMMOVE(cmdbuf_base, cmdbuf_ptr, 642 MEMMOVE(cmdbuf_base, cmdbuf_ptr,
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 w.at += BLINK_INTERVAL;
710 hidden_cursor = !hidden_cursor;
711 want_refresh = 1;
712 flush ();
713}
714
715void
703rxvt_term::x_cb (io_watcher &w, short revents) 716rxvt_term::x_cb (io_watcher &w, short revents)
704{ 717{
705 process_x_events (); 718 process_x_events ();
719
720 flush ();
706} 721}
707 722
708// read the next character, currently handles UTF-8 723// read the next character, currently handles UTF-8
709// will probably handle all sorts of other stuff in the future 724// will probably handle all sorts of other stuff in the future
710static uint32_t 725uint32_t
711next_char (pR) 726rxvt_term::next_char ()
712{ 727{
713 mbstate &s = R->mbstate; 728 struct mbstate &s = mbstate;
714 729
715 while (R->cmdbuf_ptr < R->cmdbuf_endp) 730 while (cmdbuf_ptr < cmdbuf_endp)
716 { 731 {
717 uint8_t ch = *R->cmdbuf_ptr; 732 uint8_t ch = *cmdbuf_ptr;
718 733
719 if (s.cnt) 734 if (s.cnt)
720 { 735 {
721 if ((ch & 0xc0) == 0x80) 736 if ((ch & 0xc0) == 0x80)
722 { 737 {
723 R->cmdbuf_ptr++; 738 cmdbuf_ptr++;
724 739
725 /* continuation */ 740 /* continuation */
726 s.reg = (s.reg << 6) | (ch & 0x7f); 741 s.reg = (s.reg << 6) | (ch & 0x7f);
727 742
728 if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or Racking */ 743 if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or Racking */
737 } 752 }
738 } 753 }
739 754
740 if ((ch & 0xc0) == 0xc0) 755 if ((ch & 0xc0) == 0xc0)
741 { 756 {
742 R->cmdbuf_ptr++; 757 cmdbuf_ptr++;
743 758
744 /* first byte */ 759 /* first byte */
745 s.orig = ch; /* for broken encodings */ 760 s.orig = ch; /* for broken encodings */
746 s.reg = ch; 761 s.reg = ch;
747 if ((ch & 0xe0) == 0xc0) { s.reg &= 0x1f; s.cnt = 1; } 762 if ((ch & 0xe0) == 0xc0) { s.reg &= 0x1f; s.cnt = 1; }
750 if ((ch & 0xfc) == 0xf8) { s.reg &= 0x03; s.cnt = 4; } 765 if ((ch & 0xfc) == 0xf8) { s.reg &= 0x03; s.cnt = 4; }
751 if ((ch & 0xfe) == 0xfc) { s.reg &= 0x01; s.cnt = 5; } 766 if ((ch & 0xfe) == 0xfc) { s.reg &= 0x01; s.cnt = 5; }
752 } 767 }
753 else 768 else
754 { 769 {
755 R->cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */ 770 cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */
756 return ch; 771 return ch;
757 } 772 }
758 } 773 }
759 774
760 return NOCHAR; 775 return NOCHAR;
761} 776}
762 777
778bool
779rxvt_term::pty_fill ()
780{
781 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
782
783 memmove (cmdbuf_base, cmdbuf_ptr, n);
784 cmdbuf_ptr = cmdbuf_base;
785 cmdbuf_endp = cmdbuf_ptr + n;
786
787 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n);
788
789 if (n > 0)
790 {
791 cmdbuf_endp += n;
792 return true;
793 }
794 else if (n < 0 && errno == EAGAIN)
795 return false;
796
797 rxvt_clean_exit ();
798 exit (EXIT_FAILURE); /* bad order of events? */
799}
800
763void 801void
764rxvt_term::pty_cb (io_watcher &w, short revents) 802rxvt_term::pty_cb (io_watcher &w, short revents)
765{ 803{
766 int n; 804 // loop, but don't allow a single term to monopolize us
767 unsigned int count; 805 // the number of loops is fully arbitrary, and thus wrong
768 806 for (int i = 7; i-- && pty_fill (); )
769 if (count = (cmdbuf_endp - cmdbuf_ptr))
770 { 807 {
771 memmove (cmdbuf_base, cmdbuf_ptr, count); 808 //TODO:
772 cmdbuf_ptr = cmdbuf_base; 809 /* once we know the shell is running, send the screen size. Again! */
773 cmdbuf_endp = cmdbuf_ptr + count; 810 //ch = rxvt_cmd_getc(aR); /* wait for something */
774 } 811 //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid);
775
776 812
777 for (count = BUFSIZ - count; count; count -= n, cmdbuf_endp += n) 813 uint32_t ch = NOCHAR;
778 if ((n = read(cmd_fd, cmdbuf_endp, count)) > 0) 814
779 continue; 815 for (;;)
780 else if (n == 0 || (n < 0 && errno == EAGAIN))
781 break;
782 else
783 { 816 {
784 rxvt_clean_exit(); 817 if (ch == NOCHAR)
785 exit(EXIT_FAILURE); /* bad order of events? */ 818 ch = next_char ();
819
820 if (ch == NOCHAR) // TODO: improve
821 break;
822
823 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
824 {
825 /* Read a text string from the input buffer */
826 uint32_t buf[BUFSIZ];
827 bool refreshnow = false;
828 int nlines = 0;
829 uint32_t *str = buf;
830
831 *str++ = ch;
832
833 for (;;)
834 {
835 ch = next_char ();
836
837 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
838 break;
839 else
840 {
841 *str++ = ch;
842
843 if (ch == '\n')
844 {
845 nlines++;
846 refresh_count++;
847
848 if (!(Options & Opt_jumpScroll)
849 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
850 {
851 refreshnow = true;
852 ch = NOCHAR;
853 break;
854 }
855 }
856
857 if (str >= buf + BUFSIZ)
858 {
859 ch = NOCHAR;
860 break;
861 }
862 }
863 }
864
865 rxvt_scr_add_lines (this, buf, nlines, str - buf);
866
867 /*
868 * If there have been a lot of new lines, then update the screen
869 * What the heck I'll cheat and only refresh less than every page-full.
870 * the number of pages between refreshes is refresh_limit, which
871 * is incremented here because we must be doing flat-out scrolling.
872 *
873 * refreshing should be correct for small scrolls, because of the
874 * time-out
875 */
876 if (refreshnow)
877 {
878 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
879 refresh_limit++;
880
881 rxvt_scr_refresh (this, refresh_type);
882 }
883
884 }
885 else
886 {
887 switch (ch)
888 {
889 default:
890 rxvt_process_nonprinting (this, ch);
891 break;
892 case C0_ESC: /* escape char */
893 rxvt_process_escape_seq (this);
894 break;
895 /*case 0x9b: */ /* CSI */
896 /* rxvt_process_csi_seq (this); */
897 }
898
899 ch = NOCHAR;
900 }
786 } 901 }
902 }
787 903
788 if (count != BUFSIZ) /* some characters read in */ 904 flush ();
905}
906
907void
908rxvt_term::flush ()
909{
910#ifdef TRANSPARENT
911 if (want_full_refresh)
789 { 912 {
790 uint32_t c = next_char (this); 913 want_full_refresh = 0;
791 914 rxvt_scr_clear (this);
792#if 0 915 rxvt_scr_touch (this, False);
793 if (c != NOCHAR) 916 want_refresh = 1;
794 return c; 917 }
795#endif 918#endif
919
920 if (want_refresh)
796 } 921 {
922 rxvt_scr_refresh (this, refresh_type);
923 rxvt_scrollbar_show (this, 1);
924#ifdef USE_XIM
925 rxvt_IMSendSpot (this);
926#endif
927 }
928
929 if (XPending (Xdisplay)) process_x_events ();
930 XFlush (Xdisplay);
931 if (XPending (Xdisplay)) process_x_events ();
797} 932}
798 933
799/* rxvt_cmd_getc() - Return next input character */ 934/* rxvt_cmd_getc() - Return next input character */
800/* 935/*
801 * Return the next input character after first passing any keyboard input 936 * Return the next input character after first passing any keyboard input
803 */ 938 */
804/* INTPROTO */ 939/* INTPROTO */
805uint32_t 940uint32_t
806rxvt_cmd_getc(pR) 941rxvt_cmd_getc(pR)
807{ 942{
943 for (;;)
944 {
945 uint32_t c = R->next_char ();
946 if (c != NOCHAR)
947 return c;
948
949 // incomplete sequences should occur rarely, still, a better solution
950 // would be preferred. either setjmp/longjmp or better design.
951 fcntl (R->cmd_fd, F_SETFL, 0);
952 R->pty_fill ();
953 fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK);
954 }
955
956#if 0
808#define TIMEOUT_USEC 5000 957#define TIMEOUT_USEC 5000
809 fd_set readfds; 958 fd_set readfds;
810 int quick_timeout, select_res; 959 int quick_timeout, select_res;
811 int want_motion_time, want_keypress_time; 960 int want_motion_time, want_keypress_time;
812 struct timeval value; 961 struct timeval value;
813#if defined(POINTER_BLANK) || defined(CURSOR_BLINK) 962#if defined(POINTER_BLANK) || defined(CURSOR_BLINK)
814 struct timeval tp; 963 struct timeval tp;
815#endif 964#endif
816 965
817 uint32_t c = next_char (aR);
818 if (c != NOCHAR)
819 return c;
820
821 for (;;) { 966 for (;;) {
822 /* loop until we can return something */ 967 /* loop until we can return something */
823 968
824 if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ 969 if (R->v_bufstr < R->v_bufptr) /* output any pending chars */
825 rxvt_tt_write(aR_ NULL, 0); 970 rxvt_tt_write(aR_ NULL, 0);
826
827#if defined(POINTER_BLANK) || defined(CURSOR_BLINK)
828 tp.tv_sec = 0; /* presume == 0 implies time not yet retrieved */
829#endif
830#if defined(CURSOR_BLINK)
831 want_keypress_time = 0;
832#endif
833#if defined(POINTER_BLANK)
834 want_motion_time = 0;
835#endif
836
837 if (XPending (R->Xdisplay))
838 {
839 R->process_x_events ();
840
841 /* in case button actions pushed chars to cmdbuf */
842 if (R->cmdbuf_ptr < R->cmdbuf_endp)
843 return *R->cmdbuf_ptr++;
844 }
845
846#if defined(CURSOR_BLINK)
847 if (want_keypress_time) {
848 (void)gettimeofday(&tp, NULL);
849 R->lastcursorchange.tv_sec = tp.tv_sec;
850 R->lastcursorchange.tv_usec = tp.tv_usec;
851 }
852#endif
853#if defined(POINTER_BLANK)
854 if (want_motion_time) {
855 if (!tp.tv_sec)
856 (void)gettimeofday(&tp, NULL);
857 R->lastmotion.tv_sec = tp.tv_sec;
858 R->lastmotion.tv_usec = tp.tv_usec;
859 }
860#endif
861
862/*
863 * the command input buffer is empty and we have no pending X events
864 */
865 quick_timeout = 0;
866 971
867#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 972#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
868 if (R->mouse_slip_wheel_speed) { 973 if (R->mouse_slip_wheel_speed) {
869 quick_timeout = 1; 974 quick_timeout = 1;
870 if (!R->mouse_slip_wheel_delay-- 975 if (!R->mouse_slip_wheel_delay--
900 R->want_refresh = 1; 1005 R->want_refresh = 1;
901 } 1006 }
902 } 1007 }
903#endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ 1008#endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */
904 1009
905 FD_ZERO(&readfds);
906 FD_SET(R->cmd_fd, &readfds);
907 FD_SET(R->Xfd, &readfds);
908 value.tv_usec = TIMEOUT_USEC;
909 value.tv_sec = 0;
910
911 if (!R->TermWin.mapped)
912 quick_timeout = 0;
913 else {
914 quick_timeout |= R->want_refresh;
915#ifdef TRANSPARENT 1010#ifdef TRANSPARENT
916 quick_timeout |= R->want_full_refresh; 1011 quick_timeout |= R->want_full_refresh;
917#endif 1012#endif
918 }
919
920#if defined(POINTER_BLANK) || defined(CURSOR_BLINK)
921 {
922 int set_quick_timeout = 0;
923 long csdiff, psdiff;
924
925#define BLINK_TIME 500000L
926 csdiff = psdiff = 60000000L; /* or, say, LONG_MAX */
927# if defined(CURSOR_BLINK)
928 if (R->Options & Opt_cursorBlink) {
929 if (!tp.tv_sec) /* didn't get it before so get it now */
930 (void)gettimeofday(&tp, NULL);
931
932 csdiff = (tp.tv_sec - R->lastcursorchange.tv_sec) * 1000000L
933 + tp.tv_usec - R->lastcursorchange.tv_usec;
934 if (csdiff > BLINK_TIME) { /* XXX: settable blink times */
935 R->lastcursorchange.tv_sec = tp.tv_sec;
936 R->lastcursorchange.tv_usec = tp.tv_usec;
937 R->hidden_cursor = !R->hidden_cursor;
938 csdiff = 0;
939 } else
940 csdiff = BLINK_TIME - csdiff;
941 set_quick_timeout = 1;
942 }
943# endif 1013#endif
944# if defined(POINTER_BLANK)
945 /*
946 * If we haven't moved the pointer for a while
947 */
948 if ((R->Options & Opt_pointerBlank)
949 && (R->pointerBlankDelay > 0)
950 && (R->hidden_pointer == 0)) {
951 long pdelay;
952
953 if (!tp.tv_sec) /* didn't get it before so get it now */
954 (void)gettimeofday(&tp, NULL);
955 psdiff = (tp.tv_sec - R->lastmotion.tv_sec) * 1000000L
956 + tp.tv_usec - R->lastmotion.tv_usec;
957 pdelay = R->pointerBlankDelay * 1000000L;
958 if (psdiff >= pdelay)
959 rxvt_pointer_blank(aR);
960 else {
961 set_quick_timeout = 1;
962 psdiff = pdelay - psdiff;
963 }
964 }
965# endif
966 if (!quick_timeout && set_quick_timeout) {
967 MIN_IT(csdiff, psdiff);
968 value.tv_sec = csdiff / 1000000L;
969 value.tv_usec = csdiff % 1000000L;
970 quick_timeout = 1;
971 }
972 }
973#endif
974
975 if ((select_res = select(R->num_fds, &readfds, NULL, NULL,
976 (quick_timeout ? &value : NULL))) == 0) {
977 /* select statement timed out - we're not hard and fast scrolling */
978 R->refresh_limit = 1;
979 }
980#if defined(CURSOR_BLINK)
981 if (R->Options & Opt_cursorBlink)
982 R->want_refresh = 1;
983#endif
984
985 /* See if we can read new data from the application */
986 if (select_res > 0 && FD_ISSET(R->cmd_fd, &readfds)) {
987 int n;
988 unsigned int count;
989
990 R->cmdbuf_ptr = R->cmdbuf_endp = R->cmdbuf_base;
991 for (count = BUFSIZ; count; count -= n, R->cmdbuf_endp += n)
992 if ((n = read(R->cmd_fd, R->cmdbuf_endp, count)) > 0)
993 continue;
994 else if (n == 0 || (n < 0 && errno == EAGAIN))
995 break;
996 else {
997 rxvt_clean_exit();
998 exit(EXIT_FAILURE); /* bad order of events? */
999 }
1000
1001 if (count != BUFSIZ) /* some characters read in */
1002 {
1003 uint32_t c = next_char (aR);
1004 if (c != NOCHAR)
1005 return c;
1006 }
1007 }
1008#ifdef TRANSPARENT
1009 if (R->want_full_refresh) {
1010 R->want_full_refresh = 0;
1011 rxvt_scr_clear(aR);
1012 rxvt_scr_touch(aR_ False);
1013 R->want_refresh = 1;
1014 }
1015#endif
1016 if (R->want_refresh) {
1017 rxvt_scr_refresh(aR_ R->refresh_type);
1018 rxvt_scrollbar_show(aR_ 1);
1019#ifdef USE_XIM
1020 rxvt_IMSendSpot(aR);
1021#endif
1022 }
1023 }
1024/* NOTREACHED */
1025} 1014}
1026/*}}} */
1027 1015
1028/* EXTPROTO */
1029void 1016void
1030rxvt_pointer_unblank(pR) 1017rxvt_term::pointer_unblank ()
1031{ 1018{
1032 XDefineCursor(R->Xdisplay, R->TermWin.vt, R->TermWin_cursor); 1019 XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor);
1033 rxvt_recolour_cursor(aR); 1020 rxvt_recolour_cursor (this);
1021
1034#ifdef POINTER_BLANK 1022#ifdef POINTER_BLANK
1035 R->hidden_pointer = 0; 1023 hidden_pointer = 0;
1036 if (R->pointerBlankDelay > 0) {
1037 struct timeval tp;
1038 1024
1039 (void)gettimeofday(&tp, NULL); 1025 if (Options & Opt_pointerBlank)
1040 R->lastmotion.tv_sec = tp.tv_sec; 1026 pointer_ev.start (NOW + pointerBlankDelay);
1041 R->lastmotion.tv_usec = tp.tv_usec;
1042 }
1043#endif 1027#endif
1044} 1028}
1045 1029
1046#ifdef POINTER_BLANK 1030#ifdef POINTER_BLANK
1047/* INTPROTO */
1048void 1031void
1049rxvt_pointer_blank(pR) 1032rxvt_term::pointer_blank ()
1050{ 1033{
1034 pointer_ev.stop ();
1035
1036 if (!(Options & Opt_pointerBlank))
1037 return;
1038
1051 XDefineCursor(R->Xdisplay, R->TermWin.vt, R->pointer_blank); 1039 XDefineCursor (Xdisplay, TermWin.vt, blank_cursor);
1052 XFlush(R->Xdisplay); 1040 XFlush (Xdisplay);
1041
1053 R->hidden_pointer = 1; 1042 hidden_pointer = 1;
1043}
1044
1045void
1046rxvt_term::pointer_cb (time_watcher &w)
1047{
1048 pointer_blank ();
1054} 1049}
1055#endif 1050#endif
1056 1051
1057/* INTPROTO */ 1052/* INTPROTO */
1058void 1053void
1299 * in the GraphicsExpose parts, which means that after each refresh, 1294 * in the GraphicsExpose parts, which means that after each refresh,
1300 * we need to wait for the graphics expose or Noexpose events, 1295 * we need to wait for the graphics expose or Noexpose events,
1301 * which ought to make things real slow! 1296 * which ought to make things real slow!
1302 */ 1297 */
1303 case VisibilityNotify: 1298 case VisibilityNotify:
1304 switch (ev->xvisibility.state) { 1299 switch (ev->xvisibility.state)
1300 {
1305 case VisibilityUnobscured: 1301 case VisibilityUnobscured:
1306 R->refresh_type = FAST_REFRESH; 1302 R->refresh_type = FAST_REFRESH;
1307 break; 1303 break;
1308 case VisibilityPartiallyObscured: 1304 case VisibilityPartiallyObscured:
1309 R->refresh_type = SLOW_REFRESH; 1305 R->refresh_type = SLOW_REFRESH;
1310 break; 1306 break;
1311 default: 1307 default:
1312 R->refresh_type = NO_REFRESH; 1308 R->refresh_type = NO_REFRESH;
1313 break; 1309 break;
1314 } 1310 }
1315 break; 1311 break;
1316 1312
1317 case FocusIn: 1313 case FocusIn:
1318 if (!R->TermWin.focus) { 1314 if (!R->TermWin.focus) {
1319 R->TermWin.focus = 1; 1315 R->TermWin.focus = 1;
1320 R->want_refresh = 1; 1316 R->want_refresh = 1;
1321#ifdef USE_XIM 1317#ifdef USE_XIM
1322 if (R->Input_Context != NULL) 1318 if (R->Input_Context != NULL)
1323 XSetICFocus(R->Input_Context); 1319 XSetICFocus(R->Input_Context);
1324#endif 1320#endif
1321#ifdef CURSOR_BLINK
1322 if (R->Options & Opt_cursorBlink)
1323 R->blink_ev.start (NOW + BLINK_INTERVAL);
1324#endif
1325 } 1325 }
1326 break; 1326 break;
1327 1327
1328 case FocusOut: 1328 case FocusOut:
1329 if (R->TermWin.focus) { 1329 if (R->TermWin.focus) {
1330 R->TermWin.focus = 0; 1330 R->TermWin.focus = 0;
1331 R->want_refresh = 1; 1331 R->want_refresh = 1;
1332#ifdef USE_XIM 1332#ifdef USE_XIM
1333 if (R->Input_Context != NULL) 1333 if (R->Input_Context != NULL)
1334 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;
1335#endif 1340#endif
1336 } 1341 }
1337 break; 1342 break;
1338 1343
1339 case ConfigureNotify: 1344 case ConfigureNotify:
1452 break; 1457 break;
1453 1458
1454 case MotionNotify: 1459 case MotionNotify:
1455#ifdef POINTER_BLANK 1460#ifdef POINTER_BLANK
1456 if (R->hidden_pointer) 1461 if (R->hidden_pointer)
1457 rxvt_pointer_unblank(aR); 1462 R->pointer_unblank ();
1458#endif 1463#endif
1459#if MENUBAR 1464#if MENUBAR
1460 if (isMenuBarWindow(ev->xany.window)) { 1465 if (isMenuBarWindow(ev->xany.window)) {
1461 rxvt_menubar_control(aR_ &(ev->xbutton)); 1466 rxvt_menubar_control(aR_ &(ev->xbutton));
1462 break; 1467 break;
3392} 3397}
3393/*}}} */ 3398/*}}} */
3394 3399
3395/* ------------------------------------------------------------------------- */ 3400/* ------------------------------------------------------------------------- */
3396 3401
3397/*{{{ Read and process output from the application */
3398/* LIBPROTO */
3399void
3400rxvt_main_loop(pR)
3401{
3402 uint32_t ch, *str, buf[BUFSIZ];
3403 int nlines, refreshnow;
3404
3405 R->cmdbuf_ptr = R->cmdbuf_endp = R->cmdbuf_base;
3406
3407 /* once we know the shell is running, send the screen size. Again! */
3408 ch = rxvt_cmd_getc(aR); /* wait for something */
3409 rxvt_tt_winsize(R->cmd_fd, R->TermWin.ncol, R->TermWin.nrow, R->cmd_pid);
3410
3411 refreshnow = 0;
3412 for (;;) {
3413 if (ch == NOCHAR)
3414 ch = rxvt_cmd_getc(aR);
3415
3416 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
3417 {
3418 /* Read a text string from the input buffer */
3419 nlines = 0;
3420 str = buf;
3421 *str++ = ch;
3422 for (;;)
3423 {
3424 ch = next_char (aR);
3425
3426 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
3427 break;
3428 else
3429 {
3430 *str++ = ch;
3431
3432 if (ch == '\n')
3433 {
3434 nlines++;
3435 R->refresh_count++;
3436 if (!(R->Options & Opt_jumpScroll)
3437 || (R->refresh_count >= (R->refresh_limit
3438 * (R->TermWin.nrow - 1))))
3439 {
3440 refreshnow = 1;
3441 ch = NOCHAR;
3442 break;
3443 }
3444 }
3445
3446 if (str >= buf + BUFSIZ)
3447 {
3448 ch = NOCHAR;
3449 break;
3450 }
3451 }
3452 }
3453
3454 rxvt_scr_add_lines(aR_ buf, nlines, str - buf);
3455
3456 /*
3457 * If there have been a lot of new lines, then update the screen
3458 * What the heck I'll cheat and only refresh less than every page-full.
3459 * the number of pages between refreshes is R->refresh_limit, which
3460 * is incremented here because we must be doing flat-out scrolling.
3461 *
3462 * refreshing should be correct for small scrolls, because of the
3463 * time-out
3464 */
3465
3466 //TODO: REFRESH_PERIOD is one, fix it
3467 if (refreshnow)
3468 {
3469 refreshnow = 0;
3470
3471 if ((R->Options & Opt_jumpScroll) && R->refresh_limit < REFRESH_PERIOD)
3472 R->refresh_limit++;
3473
3474 rxvt_scr_refresh(aR_ R->refresh_type);
3475 }
3476
3477 }
3478 else
3479 {
3480 switch (ch)
3481 {
3482 default:
3483 rxvt_process_nonprinting(aR_ ch);
3484 break;
3485 case C0_ESC: /* escape char */
3486 rxvt_process_escape_seq(aR);
3487 break;
3488 /* case 0x9b: */ /* CSI */
3489 /* rxvt_process_csi_seq(aR); */
3490 }
3491
3492 ch = NOCHAR;
3493 }
3494 }
3495/* NOTREACHED */
3496}
3497
3498/* 3402/*
3499 * Send printf() formatted output to the command. 3403 * Send printf() formatted output to the command.
3500 * Only use for small amounts of data. 3404 * Only use for small amounts of data.
3501 */ 3405 */
3502/* EXTPROTO */ 3406/* EXTPROTO */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines