comparison src/keyboard.c @ 83038:30ccd595ccb0

Merged in changes from CVS HEAD Patches applied: * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-98 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-99 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-100 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-101 Update from CVS * miles@gnu.org--gnu-2004/emacs--cvs-trunk--0--patch-102 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-78
author Karoly Lorentey <lorentey@elte.hu>
date Wed, 18 Feb 2004 17:10:32 +0000
parents 03a73693678e 812301ea706a
children 55d4fe5962fd
comparison
equal deleted inserted replaced
83037:03a73693678e 83038:30ccd595ccb0
6558 } 6558 }
6559 } 6559 }
6560 6560
6561 #ifndef VMS 6561 #ifndef VMS
6562 6562
6563 /* We make the read_avail_input buffer static to avoid zeroing out the
6564 whole struct input_event buf on every call. */
6565 static struct input_event read_avail_input_buf[KBD_BUFFER_SIZE];
6566
6567 /* I don't know whether it is necessary, but make read_avail_input
6568 re-entrant. */
6569 static int in_read_avail_input = 0;
6570
6563 /* Read any terminal input already buffered up by the system 6571 /* Read any terminal input already buffered up by the system
6564 into the kbd_buffer, but do not wait. 6572 into the kbd_buffer, but do not wait.
6565 6573
6566 EXPECTED should be nonzero if the caller knows there is some input. 6574 EXPECTED should be nonzero if the caller knows there is some input.
6567 6575
6574 6582
6575 static int 6583 static int
6576 read_avail_input (expected) 6584 read_avail_input (expected)
6577 int expected; 6585 int expected;
6578 { 6586 {
6579 struct input_event buf[KBD_BUFFER_SIZE]; 6587 struct input_event *buf = read_avail_input_buf;
6588 struct input_event tmp_buf[KBD_BUFFER_SIZE];
6580 register int i; 6589 register int i;
6590 int nread = 0;
6581 struct display *d; 6591 struct display *d;
6582 int nread = 0;
6583 6592
6584 for (i = 0; i < KBD_BUFFER_SIZE; i++) 6593 /* Trivial hack to make read_avail_input re-entrant. */
6585 EVENT_INIT (buf[i]); 6594 if (in_read_avail_input++)
6586 6595 {
6596 buf = tmp_buf;
6597 for (i = 0; i < KBD_BUFFER_SIZE; i++)
6598 EVENT_INIT (buf[i]);
6599 }
6600
6601 /* Loop through the available displays, and call their input hooks. */
6587 d = display_list; 6602 d = display_list;
6588 while (d) 6603 while (d)
6589 { 6604 {
6590 struct display *next = d->next_display; 6605 struct display *next = d->next_display;
6591 6606
6592 if (d->read_socket_hook) 6607 if (d->read_socket_hook)
6593 /* No need for FIONREAD or fcntl; just say don't wait. */ 6608 /* No need for FIONREAD or fcntl; just say don't wait. */
6594 nread = (*d->read_socket_hook) (d, buf, KBD_BUFFER_SIZE, expected); 6609 nread = (*d->read_socket_hook) (d, buf, KBD_BUFFER_SIZE, expected);
6595 6610
6596 if (nread == -2) 6611 if (nread == -2) /* -2 means non-transient error */
6597 { 6612 {
6598 /* The display device terminated; it should be closed. */ 6613 /* The display device terminated; it should be closed. */
6599 6614
6600 /* Kill Emacs if this was our last display. */ 6615 /* Kill Emacs if this was our last display. */
6601 if (! display_list->next_display) 6616 if (! display_list->next_display)
6625 if (buf[i].kind == ASCII_KEYSTROKE_EVENT 6640 if (buf[i].kind == ASCII_KEYSTROKE_EVENT
6626 && buf[i].code == quit_char) 6641 && buf[i].code == quit_char)
6627 break; 6642 break;
6628 } 6643 }
6629 6644
6645 /* Clear used events */
6646 if (--in_read_avail_input == 0)
6647 for (i = 0; i < nread; i++)
6648 EVENT_INIT (buf[i]);
6649
6630 return nread; 6650 return nread;
6631 } 6651 }
6632 6652
6633 /* This is the tty way of reading available input. 6653 /* This is the tty way of reading available input.
6634 6654
6645 the kbd_buffer can really hold. That may prevent loss 6665 the kbd_buffer can really hold. That may prevent loss
6646 of characters on some systems when input is stuffed at us. */ 6666 of characters on some systems when input is stuffed at us. */
6647 unsigned char cbuf[KBD_BUFFER_SIZE - 1]; 6667 unsigned char cbuf[KBD_BUFFER_SIZE - 1];
6648 int n_to_read, i; 6668 int n_to_read, i;
6649 struct tty_display_info *tty = display->display_info.tty; 6669 struct tty_display_info *tty = display->display_info.tty;
6650 Lisp_Object frame;
6651 int nread = 0; 6670 int nread = 0;
6652 6671
6653 if (display->type != output_termcap) 6672 if (display->type != output_termcap)
6654 abort (); 6673 abort ();
6655 6674
6656 /* XXX I think the following code should be moved to separate 6675 /* XXX I think the following code should be moved to separate hook
6657 functions in system-dependent files. */ 6676 functions in system-dependent files. */
6658 #ifdef WINDOWSNT 6677 #ifdef WINDOWSNT
6659 return 0; 6678 return 0;
6660 #else /* not WINDOWSNT */ 6679 #else /* not WINDOWSNT */
6661 #ifdef MSDOS 6680 #ifdef MSDOS
6666 cbuf[0] = dos_keyread (); 6685 cbuf[0] = dos_keyread ();
6667 nread = 1; 6686 nread = 1;
6668 6687
6669 #else /* not MSDOS */ 6688 #else /* not MSDOS */
6670 6689
6671 if (! tty->term_initted) 6690 if (! tty->term_initted) /* In case we get called during bootstrap. */
6672 return 0; 6691 return 0;
6673 6692
6674 /* Determine how many characters we should *try* to read. */ 6693 /* Determine how many characters we should *try* to read. */
6675 #ifdef FIONREAD 6694 #ifdef FIONREAD
6676 /* Find out how much input is available. */ 6695 /* Find out how much input is available. */
6702 nread = emacs_read (fileno (TTY_INPUT (tty)), cbuf, n_to_read); 6721 nread = emacs_read (fileno (TTY_INPUT (tty)), cbuf, n_to_read);
6703 /* POSIX infers that processes which are not in the session leader's 6722 /* POSIX infers that processes which are not in the session leader's
6704 process group won't get SIGHUP's at logout time. BSDI adheres to 6723 process group won't get SIGHUP's at logout time. BSDI adheres to
6705 this part standard and returns -1 from read (0) with errno==EIO 6724 this part standard and returns -1 from read (0) with errno==EIO
6706 when the control tty is taken away. 6725 when the control tty is taken away.
6707 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */ 6726 Jeffrey Honig <jch@bsdi.com> says this is generally safe. */
6708 if (nread == -1 && errno == EIO) 6727 if (nread == -1 && errno == EIO)
6709 { 6728 return -2; /* Close this display. */
6710 return -2; /* Close this display. */
6711 }
6712 #if defined (AIX) && (! defined (aix386) && defined (_BSD)) 6729 #if defined (AIX) && (! defined (aix386) && defined (_BSD))
6713 /* The kernel sometimes fails to deliver SIGHUP for ptys. 6730 /* The kernel sometimes fails to deliver SIGHUP for ptys.
6714 This looks incorrect, but it isn't, because _BSD causes 6731 This looks incorrect, but it isn't, because _BSD causes
6715 O_NDELAY to be defined in fcntl.h as O_NONBLOCK, 6732 O_NDELAY to be defined in fcntl.h as O_NONBLOCK,
6716 and that causes a value other than 0 when there is no input. */ 6733 and that causes a value other than 0 when there is no input. */
6717 if (nread == 0) 6734 if (nread == 0)
6718 { 6735 return -2; /* Close this display. */
6719 return -2; /* Close this display. */
6720 }
6721 #endif 6736 #endif
6722 } 6737 }
6723 while ( 6738 while (
6724 /* We used to retry the read if it was interrupted. 6739 /* We used to retry the read if it was interrupted.
6725 But this does the wrong thing when O_NDELAY causes 6740 But this does the wrong thing when O_NDELAY causes
6749 return nread; 6764 return nread;
6750 6765
6751 #endif /* not MSDOS */ 6766 #endif /* not MSDOS */
6752 #endif /* not WINDOWSNT */ 6767 #endif /* not WINDOWSNT */
6753 6768
6754 /* Select the frame corresponding to the active tty. Note that the
6755 value of selected_frame is not reliable here, redisplay tends to
6756 temporarily change it. */
6757 frame = tty->top_frame;
6758
6759 for (i = 0; i < nread; i++) 6769 for (i = 0; i < nread; i++)
6760 { 6770 {
6761 buf[i].kind = ASCII_KEYSTROKE_EVENT; 6771 buf[i].kind = ASCII_KEYSTROKE_EVENT;
6762 buf[i].modifiers = 0; 6772 buf[i].modifiers = 0;
6763 if (tty->meta_key == 1 && (cbuf[i] & 0x80)) 6773 if (tty->meta_key == 1 && (cbuf[i] & 0x80))
6764 buf[i].modifiers = meta_modifier; 6774 buf[i].modifiers = meta_modifier;
6765 if (tty->meta_key != 2) 6775 if (tty->meta_key != 2)
6766 cbuf[i] &= ~0x80; 6776 cbuf[i] &= ~0x80;
6767 6777
6768 buf[i].code = cbuf[i]; 6778 buf[i].code = cbuf[i];
6769 buf[i].frame_or_window = frame; 6779 /* Set the frame corresponding to the active tty. Note that the
6780 value of selected_frame is not reliable here, redisplay tends
6781 to temporarily change it. */
6782 buf[i].frame_or_window = tty->top_frame;
6770 buf[i].arg = Qnil; 6783 buf[i].arg = Qnil;
6771 } 6784 }
6772 6785
6773 return nread; 6786 return nread;
6774 } 6787 }
10656 kbd_store_ptr = kbd_buffer; 10669 kbd_store_ptr = kbd_buffer;
10657 #ifdef HAVE_MOUSE 10670 #ifdef HAVE_MOUSE
10658 do_mouse_tracking = Qnil; 10671 do_mouse_tracking = Qnil;
10659 #endif 10672 #endif
10660 input_pending = 0; 10673 input_pending = 0;
10674 #ifndef VMS
10675 {
10676 int i;
10677 for (i = 0; i < KBD_BUFFER_SIZE; i++)
10678 EVENT_INIT (read_avail_input_buf[i]);
10679 }
10680 #endif
10661 10681
10662 /* This means that command_loop_1 won't try to select anything the first 10682 /* This means that command_loop_1 won't try to select anything the first
10663 time through. */ 10683 time through. */
10664 internal_last_event_frame = Qnil; 10684 internal_last_event_frame = Qnil;
10665 Vlast_event_frame = internal_last_event_frame; 10685 Vlast_event_frame = internal_last_event_frame;