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.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.3 2003/11/25 11:52:42 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>
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 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 ();
723
724 flush ();
706} 725}
707 726
708// read the next character, currently handles UTF-8 727// read the next character, currently handles UTF-8
709// will probably handle all sorts of other stuff in the future 728// will probably handle all sorts of other stuff in the future
710static uint32_t 729uint32_t
711next_char (pR) 730rxvt_term::next_char ()
712{ 731{
713 mbstate &s = R->mbstate; 732 struct mbstate &s = mbstate;
714 733
715 while (R->cmdbuf_ptr < R->cmdbuf_endp) 734 while (cmdbuf_ptr < cmdbuf_endp)
716 { 735 {
717 uint8_t ch = *R->cmdbuf_ptr; 736 uint8_t ch = *cmdbuf_ptr;
718 737
719 if (s.cnt) 738 if (s.cnt)
720 { 739 {
721 if ((ch & 0xc0) == 0x80) 740 if ((ch & 0xc0) == 0x80)
722 { 741 {
723 R->cmdbuf_ptr++; 742 cmdbuf_ptr++;
724 743
725 /* continuation */ 744 /* continuation */
726 s.reg = (s.reg << 6) | (ch & 0x7f); 745 s.reg = (s.reg << 6) | (ch & 0x7f);
727 746
728 if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or Racking */ 747 if (--s.cnt == 0 && s.reg >= 128) /* if !inrange then corruption or Racking */
737 } 756 }
738 } 757 }
739 758
740 if ((ch & 0xc0) == 0xc0) 759 if ((ch & 0xc0) == 0xc0)
741 { 760 {
742 R->cmdbuf_ptr++; 761 cmdbuf_ptr++;
743 762
744 /* first byte */ 763 /* first byte */
745 s.orig = ch; /* for broken encodings */ 764 s.orig = ch; /* for broken encodings */
746 s.reg = ch; 765 s.reg = ch;
747 if ((ch & 0xe0) == 0xc0) { s.reg &= 0x1f; s.cnt = 1; } 766 if ((ch & 0xe0) == 0xc0) { s.reg &= 0x1f; s.cnt = 1; }
750 if ((ch & 0xfc) == 0xf8) { s.reg &= 0x03; s.cnt = 4; } 769 if ((ch & 0xfc) == 0xf8) { s.reg &= 0x03; s.cnt = 4; }
751 if ((ch & 0xfe) == 0xfc) { s.reg &= 0x01; s.cnt = 5; } 770 if ((ch & 0xfe) == 0xfc) { s.reg &= 0x01; s.cnt = 5; }
752 } 771 }
753 else 772 else
754 { 773 {
755 R->cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */ 774 cmdbuf_ptr++; /* _occasional_ non-utf8 may slip through... */
756 return ch; 775 return ch;
757 } 776 }
758 } 777 }
759 778
760 return NOCHAR; 779 return NOCHAR;
761} 780}
762 781
782bool
783rxvt_term::pty_fill ()
784{
785 ssize_t n = cmdbuf_endp - cmdbuf_ptr;
786
787 memmove (cmdbuf_base, cmdbuf_ptr, n);
788 cmdbuf_ptr = cmdbuf_base;
789 cmdbuf_endp = cmdbuf_ptr + n;
790
791 n = read (cmd_fd, cmdbuf_endp, BUFSIZ - n);
792
793 if (n > 0)
794 {
795 cmdbuf_endp += n;
796 return true;
797 }
798 else if (n < 0 && errno == EAGAIN)
799 return false;
800
801 destroy ();
802}
803
763void 804void
764rxvt_term::pty_cb (io_watcher &w, short revents) 805rxvt_term::pty_cb (io_watcher &w, short revents)
765{ 806{
766 int n; 807 SET_R (this);
767 unsigned int count;
768 808
769 if (count = (cmdbuf_endp - cmdbuf_ptr)) 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 (); )
770 { 812 {
771 memmove (cmdbuf_base, cmdbuf_ptr, count); 813 //TODO:
772 cmdbuf_ptr = cmdbuf_base; 814 /* once we know the shell is running, send the screen size. Again! */
773 cmdbuf_endp = cmdbuf_ptr + count; 815 //ch = rxvt_cmd_getc(aR); /* wait for something */
774 } 816 //rxvt_tt_winsize(cmd_fd, TermWin.ncol, TermWin.nrow, cmd_pid);
775
776 817
777 for (count = BUFSIZ - count; count; count -= n, cmdbuf_endp += n) 818 uint32_t ch = NOCHAR;
778 if ((n = read(cmd_fd, cmdbuf_endp, count)) > 0) 819
779 continue; 820 for (;;)
780 else if (n == 0 || (n < 0 && errno == EAGAIN))
781 break;
782 else
783 { 821 {
784 rxvt_clean_exit(); 822 if (ch == NOCHAR)
785 exit(EXIT_FAILURE); /* bad order of events? */ 823 ch = next_char ();
824
825 if (ch == NOCHAR) // TODO: improve
826 break;
827
828 if (ch >= ' ' || ch == '\t' || ch == '\n' || ch == '\r')
829 {
830 /* Read a text string from the input buffer */
831 uint32_t buf[BUFSIZ];
832 bool refreshnow = false;
833 int nlines = 0;
834 uint32_t *str = buf;
835
836 *str++ = ch;
837
838 for (;;)
839 {
840 ch = next_char ();
841
842 if (ch == NOCHAR || (ch < ' ' && ch != '\t' && ch != '\n' && ch != '\r'))
843 break;
844 else
845 {
846 *str++ = ch;
847
848 if (ch == '\n')
849 {
850 nlines++;
851 refresh_count++;
852
853 if (!(Options & Opt_jumpScroll)
854 || (refresh_count >= (refresh_limit * (TermWin.nrow - 1))))
855 {
856 refreshnow = true;
857 ch = NOCHAR;
858 break;
859 }
860 }
861
862 if (str >= buf + BUFSIZ)
863 {
864 ch = NOCHAR;
865 break;
866 }
867 }
868 }
869
870 rxvt_scr_add_lines (this, buf, nlines, str - buf);
871
872 /*
873 * If there have been a lot of new lines, then update the screen
874 * What the heck I'll cheat and only refresh less than every page-full.
875 * the number of pages between refreshes is refresh_limit, which
876 * is incremented here because we must be doing flat-out scrolling.
877 *
878 * refreshing should be correct for small scrolls, because of the
879 * time-out
880 */
881 if (refreshnow)
882 {
883 if ((Options & Opt_jumpScroll) && refresh_limit < REFRESH_PERIOD)
884 refresh_limit++;
885
886 rxvt_scr_refresh (this, refresh_type);
887 }
888
889 }
890 else
891 {
892 switch (ch)
893 {
894 default:
895 rxvt_process_nonprinting (this, ch);
896 break;
897 case C0_ESC: /* escape char */
898 rxvt_process_escape_seq (this);
899 break;
900 /*case 0x9b: */ /* CSI */
901 /* rxvt_process_csi_seq (this); */
902 }
903
904 ch = NOCHAR;
905 }
786 } 906 }
907 }
787 908
788 if (count != BUFSIZ) /* some characters read in */ 909 flush ();
910}
911
912void
913rxvt_term::flush ()
914{
915#ifdef TRANSPARENT
916 if (want_full_refresh)
789 { 917 {
790 uint32_t c = next_char (this); 918 want_full_refresh = 0;
791 919 rxvt_scr_clear (this);
792#if 0 920 rxvt_scr_touch (this, False);
793 if (c != NOCHAR) 921 want_refresh = 1;
794 return c; 922 }
795#endif 923#endif
924
925 if (want_refresh)
796 } 926 {
927 rxvt_scr_refresh (this, refresh_type);
928 rxvt_scrollbar_show (this, 1);
929#ifdef USE_XIM
930 rxvt_IMSendSpot (this);
931#endif
932 }
933
934 if (XPending (Xdisplay)) process_x_events ();
935 XFlush (Xdisplay);
936 if (XPending (Xdisplay)) process_x_events ();
797} 937}
798 938
799/* rxvt_cmd_getc() - Return next input character */ 939/* rxvt_cmd_getc() - Return next input character */
800/* 940/*
801 * Return the next input character after first passing any keyboard input 941 * Return the next input character after first passing any keyboard input
803 */ 943 */
804/* INTPROTO */ 944/* INTPROTO */
805uint32_t 945uint32_t
806rxvt_cmd_getc(pR) 946rxvt_cmd_getc(pR)
807{ 947{
948 for (;;)
949 {
950 uint32_t c = R->next_char ();
951 if (c != NOCHAR)
952 return c;
953
954 // incomplete sequences should occur rarely, still, a better solution
955 // would be preferred. either setjmp/longjmp or better design.
956 fcntl (R->cmd_fd, F_SETFL, 0);
957 R->pty_fill ();
958 fcntl (R->cmd_fd, F_SETFL, O_NONBLOCK);
959 }
960
961#if 0
808#define TIMEOUT_USEC 5000 962#define TIMEOUT_USEC 5000
809 fd_set readfds; 963 fd_set readfds;
810 int quick_timeout, select_res; 964 int quick_timeout, select_res;
811 int want_motion_time, want_keypress_time; 965 int want_motion_time, want_keypress_time;
812 struct timeval value; 966 struct timeval value;
813#if defined(POINTER_BLANK) || defined(CURSOR_BLINK) 967#if defined(POINTER_BLANK) || defined(CURSOR_BLINK)
814 struct timeval tp; 968 struct timeval tp;
815#endif 969#endif
816 970
817 uint32_t c = next_char (aR);
818 if (c != NOCHAR)
819 return c;
820
821 for (;;) { 971 for (;;) {
822 /* loop until we can return something */ 972 /* loop until we can return something */
823 973
824 if (R->v_bufstr < R->v_bufptr) /* output any pending chars */ 974 if (R->v_bufstr < R->v_bufptr) /* output any pending chars */
825 rxvt_tt_write(aR_ NULL, 0); 975 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 976
867#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING) 977#if defined(MOUSE_WHEEL) && defined(MOUSE_SLIP_WHEELING)
868 if (R->mouse_slip_wheel_speed) { 978 if (R->mouse_slip_wheel_speed) {
869 quick_timeout = 1; 979 quick_timeout = 1;
870 if (!R->mouse_slip_wheel_delay-- 980 if (!R->mouse_slip_wheel_delay--
900 R->want_refresh = 1; 1010 R->want_refresh = 1;
901 } 1011 }
902 } 1012 }
903#endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */ 1013#endif /* NO_SCROLLBAR_BUTTON_CONTINUAL_SCROLLING */
904 1014
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 1015#ifdef TRANSPARENT
916 quick_timeout |= R->want_full_refresh; 1016 quick_timeout |= R->want_full_refresh;
917#endif 1017#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 1018#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} 1019}
1026/*}}} */
1027 1020
1028/* EXTPROTO */
1029void 1021void
1030rxvt_pointer_unblank(pR) 1022rxvt_term::pointer_unblank ()
1031{ 1023{
1032 XDefineCursor(R->Xdisplay, R->TermWin.vt, R->TermWin_cursor); 1024 XDefineCursor (Xdisplay, TermWin.vt, TermWin_cursor);
1033 rxvt_recolour_cursor(aR); 1025 rxvt_recolour_cursor (this);
1026
1034#ifdef POINTER_BLANK 1027#ifdef POINTER_BLANK
1035 R->hidden_pointer = 0; 1028 hidden_pointer = 0;
1036 if (R->pointerBlankDelay > 0) {
1037 struct timeval tp;
1038 1029
1039 (void)gettimeofday(&tp, NULL); 1030 if (Options & Opt_pointerBlank)
1040 R->lastmotion.tv_sec = tp.tv_sec; 1031 pointer_ev.start (NOW + pointerBlankDelay);
1041 R->lastmotion.tv_usec = tp.tv_usec;
1042 }
1043#endif 1032#endif
1044} 1033}
1045 1034
1046#ifdef POINTER_BLANK 1035#ifdef POINTER_BLANK
1047/* INTPROTO */
1048void 1036void
1049rxvt_pointer_blank(pR) 1037rxvt_term::pointer_blank ()
1050{ 1038{
1039 pointer_ev.stop ();
1040
1041 if (!(Options & Opt_pointerBlank))
1042 return;
1043
1051 XDefineCursor(R->Xdisplay, R->TermWin.vt, R->pointer_blank); 1044 XDefineCursor (Xdisplay, TermWin.vt, blank_cursor);
1052 XFlush(R->Xdisplay); 1045 XFlush (Xdisplay);
1046
1053 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 ();
1054} 1056}
1055#endif 1057#endif
1056 1058
1057/* INTPROTO */ 1059/* INTPROTO */
1058void 1060void
1254 break; 1256 break;
1255 1257
1256 case ClientMessage: 1258 case ClientMessage:
1257 if (ev->xclient.format == 32 1259 if (ev->xclient.format == 32
1258 && (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW]) 1260 && (Atom)ev->xclient.data.l[0] == R->xa[XA_WMDELETEWINDOW])
1259 exit(EXIT_SUCCESS); 1261 R->destroy ();
1260#ifdef OFFIX_DND 1262#ifdef OFFIX_DND
1261 /* OffiX Dnd (drag 'n' drop) protocol */ 1263 /* OffiX Dnd (drag 'n' drop) protocol */
1262 if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL] 1264 else if (ev->xclient.message_type == R->xa[XA_DNDPROTOCOL]
1263 && (ev->xclient.data.l[0] == DndFile 1265 && (ev->xclient.data.l[0] == DndFile
1264 || ev->xclient.data.l[0] == DndDir 1266 || ev->xclient.data.l[0] == DndDir
1265 || ev->xclient.data.l[0] == DndLink)) { 1267 || ev->xclient.data.l[0] == DndLink)) {
1266 /* Get Dnd data */ 1268 /* Get Dnd data */
1267 Atom ActualType; 1269 Atom ActualType;
1299 * in the GraphicsExpose parts, which means that after each refresh, 1301 * in the GraphicsExpose parts, which means that after each refresh,
1300 * we need to wait for the graphics expose or Noexpose events, 1302 * we need to wait for the graphics expose or Noexpose events,
1301 * which ought to make things real slow! 1303 * which ought to make things real slow!
1302 */ 1304 */
1303 case VisibilityNotify: 1305 case VisibilityNotify:
1304 switch (ev->xvisibility.state) { 1306 switch (ev->xvisibility.state)
1307 {
1305 case VisibilityUnobscured: 1308 case VisibilityUnobscured:
1306 R->refresh_type = FAST_REFRESH; 1309 R->refresh_type = FAST_REFRESH;
1307 break; 1310 break;
1308 case VisibilityPartiallyObscured: 1311 case VisibilityPartiallyObscured:
1309 R->refresh_type = SLOW_REFRESH; 1312 R->refresh_type = SLOW_REFRESH;
1310 break; 1313 break;
1311 default: 1314 default:
1312 R->refresh_type = NO_REFRESH; 1315 R->refresh_type = NO_REFRESH;
1313 break; 1316 break;
1314 } 1317 }
1315 break; 1318 break;
1316 1319
1317 case FocusIn: 1320 case FocusIn:
1318 if (!R->TermWin.focus) { 1321 if (!R->TermWin.focus) {
1319 R->TermWin.focus = 1; 1322 R->TermWin.focus = 1;
1320 R->want_refresh = 1; 1323 R->want_refresh = 1;
1321#ifdef USE_XIM 1324#ifdef USE_XIM
1322 if (R->Input_Context != NULL) 1325 if (R->Input_Context != NULL)
1323 XSetICFocus(R->Input_Context); 1326 XSetICFocus(R->Input_Context);
1324#endif 1327#endif
1328#ifdef CURSOR_BLINK
1329 if (R->Options & Opt_cursorBlink)
1330 R->blink_ev.start (NOW + BLINK_INTERVAL);
1331#endif
1325 } 1332 }
1326 break; 1333 break;
1327 1334
1328 case FocusOut: 1335 case FocusOut:
1329 if (R->TermWin.focus) { 1336 if (R->TermWin.focus) {
1330 R->TermWin.focus = 0; 1337 R->TermWin.focus = 0;
1331 R->want_refresh = 1; 1338 R->want_refresh = 1;
1332#ifdef USE_XIM 1339#ifdef USE_XIM
1333 if (R->Input_Context != NULL) 1340 if (R->Input_Context != NULL)
1334 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;
1335#endif 1347#endif
1336 } 1348 }
1337 break; 1349 break;
1338 1350
1339 case ConfigureNotify: 1351 case ConfigureNotify:
1452 break; 1464 break;
1453 1465
1454 case MotionNotify: 1466 case MotionNotify:
1455#ifdef POINTER_BLANK 1467#ifdef POINTER_BLANK
1456 if (R->hidden_pointer) 1468 if (R->hidden_pointer)
1457 rxvt_pointer_unblank(aR); 1469 R->pointer_unblank ();
1458#endif 1470#endif
1459#if MENUBAR 1471#if MENUBAR
1460 if (isMenuBarWindow(ev->xany.window)) { 1472 if (isMenuBarWindow(ev->xany.window)) {
1461 rxvt_menubar_control(aR_ &(ev->xbutton)); 1473 rxvt_menubar_control(aR_ &(ev->xbutton));
1462 break; 1474 break;
3392} 3404}
3393/*}}} */ 3405/*}}} */
3394 3406
3395/* ------------------------------------------------------------------------- */ 3407/* ------------------------------------------------------------------------- */
3396 3408
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/* 3409/*
3499 * Send printf() formatted output to the command. 3410 * Send printf() formatted output to the command.
3500 * Only use for small amounts of data. 3411 * Only use for small amounts of data.
3501 */ 3412 */
3502/* EXTPROTO */ 3413/* EXTPROTO */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines