aboutsummaryrefslogtreecommitdiffstats
path: root/src/keyboard.c
diff options
context:
space:
mode:
authorKim F. Storm2004-02-19 23:21:51 +0000
committerKim F. Storm2004-02-19 23:21:51 +0000
commit351d2e147ac308bfbb3bd06255cfbad7b639883b (patch)
tree4234f79bc387a4369443520c6c7d367447d7186b /src/keyboard.c
parentb0e225fd5028669d46013c09f6993cda06000d96 (diff)
downloademacs-351d2e147ac308bfbb3bd06255cfbad7b639883b.tar.gz
emacs-351d2e147ac308bfbb3bd06255cfbad7b639883b.zip
Undo 2004-02-16 and 2004-02-17 changes.
The following changes are relative to the 2004-01-21 revision. (NREAD_INPUT_EVENTS): Define as max number of input events to read in one call to read_socket_hook. Value is 8. (read_avail_input): Separate and rework handling of read_socket_hook and non-read_socket_hook cases. Use smaller input_event buffer in read_socket_hook case, and repeat if full buffer is read. Use new local variable 'discard' to skip input after C-g. In non-read_socket_hook case, just use a single input_event, and call kbd_buffer_store_event on the fly for each character.
Diffstat (limited to 'src/keyboard.c')
-rw-r--r--src/keyboard.c116
1 files changed, 56 insertions, 60 deletions
diff --git a/src/keyboard.c b/src/keyboard.c
index 7c317660cc2..39ac2695548 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -6556,14 +6556,6 @@ record_asynch_buffer_change ()
6556 6556
6557#ifndef VMS 6557#ifndef VMS
6558 6558
6559/* We make the read_avail_input buffer static to avoid zeroing out the
6560 whole struct input_event buf on every call. */
6561static struct input_event read_avail_input_buf[KBD_BUFFER_SIZE];
6562
6563/* I don't know whether it is necessary, but make read_avail_input
6564 re-entrant. */
6565static int in_read_avail_input = 0;
6566
6567/* Read any terminal input already buffered up by the system 6559/* Read any terminal input already buffered up by the system
6568 into the kbd_buffer, but do not wait. 6560 into the kbd_buffer, but do not wait.
6569 6561
@@ -6574,28 +6566,54 @@ static int in_read_avail_input = 0;
6574 only when SIGIO is blocked. 6566 only when SIGIO is blocked.
6575 6567
6576 Returns the number of keyboard chars read, or -1 meaning 6568 Returns the number of keyboard chars read, or -1 meaning
6577 this is a bad time to try to read input. */ 6569 this is a bad time to try to read input.
6570
6571 Typically, there are just a few available input events to be read
6572 here, so we really don't need to allocate and initialize a big
6573 buffer of input_events as we used to do. Instead, we just allocate
6574 a small buffer of input events -- and then poll for more input if we
6575 read a full buffer of input events. */
6576#define NREAD_INPUT_EVENTS 8
6578 6577
6579static int 6578static int
6580read_avail_input (expected) 6579read_avail_input (expected)
6581 int expected; 6580 int expected;
6582{ 6581{
6583 struct input_event *buf = read_avail_input_buf;
6584 struct input_event tmp_buf[KBD_BUFFER_SIZE];
6585 register int i; 6582 register int i;
6586 int nread; 6583 int nread = 0;
6587 6584
6588 /* Trivial hack to make read_avail_input re-entrant. */ 6585 if (read_socket_hook)
6589 if (in_read_avail_input++)
6590 { 6586 {
6591 buf = tmp_buf; 6587 int discard = 0;
6592 for (i = 0; i < KBD_BUFFER_SIZE; i++) 6588 int nr;
6593 EVENT_INIT (buf[i]);
6594 }
6595 6589
6596 if (read_socket_hook) 6590
6597 /* No need for FIONREAD or fcntl; just say don't wait. */ 6591 do {
6598 nread = (*read_socket_hook) (input_fd, buf, KBD_BUFFER_SIZE, expected); 6592 struct input_event buf[NREAD_INPUT_EVENTS];
6593
6594 for (i = 0; i < NREAD_INPUT_EVENTS; i++)
6595 EVENT_INIT (buf[i]);
6596
6597 /* No need for FIONREAD or fcntl; just say don't wait. */
6598 nr = (*read_socket_hook) (input_fd, buf, NREAD_INPUT_EVENTS, expected);
6599 if (nr <= 0)
6600 break;
6601
6602 nread += nr;
6603 expected = 0;
6604
6605 /* Scan the chars for C-g and store them in kbd_buffer. */
6606 for (i = 0; !discard && i < nr; i++)
6607 {
6608 kbd_buffer_store_event (&buf[i]);
6609 /* Don't look at input that follows a C-g too closely.
6610 This reduces lossage due to autorepeat on C-g. */
6611 if (buf[i].kind == ASCII_KEYSTROKE_EVENT
6612 && buf[i].code == quit_char)
6613 discard = 1;
6614 }
6615 } while (nr == NREAD_INPUT_EVENTS);
6616 }
6599 else 6617 else
6600 { 6618 {
6601 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than 6619 /* Using KBD_BUFFER_SIZE - 1 here avoids reading more than
@@ -6606,16 +6624,12 @@ read_avail_input (expected)
6606 6624
6607 /* Determine how many characters we should *try* to read. */ 6625 /* Determine how many characters we should *try* to read. */
6608#ifdef WINDOWSNT 6626#ifdef WINDOWSNT
6609 --in_read_avail_input;
6610 return 0; 6627 return 0;
6611#else /* not WINDOWSNT */ 6628#else /* not WINDOWSNT */
6612#ifdef MSDOS 6629#ifdef MSDOS
6613 n_to_read = dos_keysns (); 6630 n_to_read = dos_keysns ();
6614 if (n_to_read == 0) 6631 if (n_to_read == 0)
6615 { 6632 return 0;
6616 --in_read_avail_input;
6617 return 0;
6618 }
6619#else /* not MSDOS */ 6633#else /* not MSDOS */
6620#ifdef FIONREAD 6634#ifdef FIONREAD
6621 /* Find out how much input is available. */ 6635 /* Find out how much input is available. */
@@ -6633,10 +6647,7 @@ read_avail_input (expected)
6633 n_to_read = 0; 6647 n_to_read = 0;
6634 } 6648 }
6635 if (n_to_read == 0) 6649 if (n_to_read == 0)
6636 { 6650 return 0;
6637 --in_read_avail_input;
6638 return 0;
6639 }
6640 if (n_to_read > sizeof cbuf) 6651 if (n_to_read > sizeof cbuf)
6641 n_to_read = sizeof cbuf; 6652 n_to_read = sizeof cbuf;
6642#else /* no FIONREAD */ 6653#else /* no FIONREAD */
@@ -6703,35 +6714,28 @@ read_avail_input (expected)
6703#endif /* no FIONREAD */ 6714#endif /* no FIONREAD */
6704 for (i = 0; i < nread; i++) 6715 for (i = 0; i < nread; i++)
6705 { 6716 {
6706 buf[i].kind = ASCII_KEYSTROKE_EVENT; 6717 struct input_event buf;
6707 buf[i].modifiers = 0; 6718 EVENT_INIT (buf);
6719 buf.kind = ASCII_KEYSTROKE_EVENT;
6720 buf.modifiers = 0;
6708 if (meta_key == 1 && (cbuf[i] & 0x80)) 6721 if (meta_key == 1 && (cbuf[i] & 0x80))
6709 buf[i].modifiers = meta_modifier; 6722 buf.modifiers = meta_modifier;
6710 if (meta_key != 2) 6723 if (meta_key != 2)
6711 cbuf[i] &= ~0x80; 6724 cbuf[i] &= ~0x80;
6712 6725
6713 buf[i].code = cbuf[i]; 6726 buf.code = cbuf[i];
6714 buf[i].frame_or_window = selected_frame; 6727 buf.frame_or_window = selected_frame;
6715 buf[i].arg = Qnil; 6728 buf.arg = Qnil;
6729
6730 kbd_buffer_store_event (&buf);
6731 /* Don't look at input that follows a C-g too closely.
6732 This reduces lossage due to autorepeat on C-g. */
6733 if (buf.kind == ASCII_KEYSTROKE_EVENT
6734 && buf.code == quit_char)
6735 break;
6716 } 6736 }
6717 } 6737 }
6718 6738
6719 /* Scan the chars for C-g and store them in kbd_buffer. */
6720 for (i = 0; i < nread; i++)
6721 {
6722 kbd_buffer_store_event (&buf[i]);
6723 /* Don't look at input that follows a C-g too closely.
6724 This reduces lossage due to autorepeat on C-g. */
6725 if (buf[i].kind == ASCII_KEYSTROKE_EVENT
6726 && buf[i].code == quit_char)
6727 break;
6728 }
6729
6730 /* Clear used events */
6731 if (--in_read_avail_input == 0)
6732 for (i = 0; i < nread; i++)
6733 EVENT_INIT (buf[i]);
6734
6735 return nread; 6739 return nread;
6736} 6740}
6737#endif /* not VMS */ 6741#endif /* not VMS */
@@ -10562,14 +10566,6 @@ init_keyboard ()
10562 do_mouse_tracking = Qnil; 10566 do_mouse_tracking = Qnil;
10563#endif 10567#endif
10564 input_pending = 0; 10568 input_pending = 0;
10565#ifndef VMS
10566 {
10567 int i;
10568 for (i = 0; i < KBD_BUFFER_SIZE; i++)
10569 EVENT_INIT (read_avail_input_buf[i]);
10570 }
10571#endif
10572
10573 10569
10574 /* This means that command_loop_1 won't try to select anything the first 10570 /* This means that command_loop_1 won't try to select anything the first
10575 time through. */ 10571 time through. */