diff options
| author | Kim F. Storm | 2004-02-27 23:46:31 +0000 |
|---|---|---|
| committer | Kim F. Storm | 2004-02-27 23:46:31 +0000 |
| commit | 0fc0bac9c461f3358286ff1d4064ed52d709dbe9 (patch) | |
| tree | d6e177dd280762379be19a6f3355fb8923b0fe3a | |
| parent | 9022d4219b27cdeaa15213fb1a4e6faf9e67da43 (diff) | |
| download | emacs-0fc0bac9c461f3358286ff1d4064ed52d709dbe9.tar.gz emacs-0fc0bac9c461f3358286ff1d4064ed52d709dbe9.zip | |
(kbd_buffer_store_event_hold): New function to store
an event into kbd fifo, but with special handling of quit event;
a quit event is saved for later, and further events are discarded
until the saved quit event has been processed.
(kbd_buffer_store_event): Use kbd_buffer_store_event_hold.
(gen_help_event): Store help event in kbd fifo.
(NREAD_INPUT_EVENTS): Remove.
(read_avail_input): Adapt to new read_socket_hook interface.
Remove allocation and initialization of local input_event buffer,
as read_socket_hook stores events directly in fifo. Allocate and
initialize local hold_quit event to handle postponed quit event
(and store it if set by kbd_buffer_store_event_hold).
| -rw-r--r-- | src/keyboard.c | 106 |
1 files changed, 57 insertions, 49 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index 27813bdc770..7037ee93afd 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -3519,9 +3519,32 @@ void | |||
| 3519 | kbd_buffer_store_event (event) | 3519 | kbd_buffer_store_event (event) |
| 3520 | register struct input_event *event; | 3520 | register struct input_event *event; |
| 3521 | { | 3521 | { |
| 3522 | kbd_buffer_store_event_hold (event, 0); | ||
| 3523 | } | ||
| 3524 | |||
| 3525 | /* Store EVENT obtained at interrupt level into kbd_buffer, fifo. | ||
| 3526 | |||
| 3527 | If HOLD_QUIT is 0, just stuff EVENT into the fifo. | ||
| 3528 | Else, if HOLD_QUIT.kind != NO_EVENT, discard EVENT. | ||
| 3529 | Else, if EVENT is a quit event, store the quit event | ||
| 3530 | in HOLD_QUIT, and return (thus ignoring further events). | ||
| 3531 | |||
| 3532 | This is used in read_avail_input to postpone the processing | ||
| 3533 | of the quit event until all subsequent input events have been | ||
| 3534 | parsed (and discarded). | ||
| 3535 | */ | ||
| 3536 | |||
| 3537 | void | ||
| 3538 | kbd_buffer_store_event_hold (event, hold_quit) | ||
| 3539 | register struct input_event *event; | ||
| 3540 | struct input_event *hold_quit; | ||
| 3541 | { | ||
| 3522 | if (event->kind == NO_EVENT) | 3542 | if (event->kind == NO_EVENT) |
| 3523 | abort (); | 3543 | abort (); |
| 3524 | 3544 | ||
| 3545 | if (hold_quit && hold_quit->kind != NO_EVENT) | ||
| 3546 | return; | ||
| 3547 | |||
| 3525 | if (event->kind == ASCII_KEYSTROKE_EVENT) | 3548 | if (event->kind == ASCII_KEYSTROKE_EVENT) |
| 3526 | { | 3549 | { |
| 3527 | register int c = event->code & 0377; | 3550 | register int c = event->code & 0377; |
| @@ -3563,6 +3586,12 @@ kbd_buffer_store_event (event) | |||
| 3563 | } | 3586 | } |
| 3564 | #endif | 3587 | #endif |
| 3565 | 3588 | ||
| 3589 | if (hold_quit) | ||
| 3590 | { | ||
| 3591 | bcopy (event, (char *) hold_quit, sizeof (*event)); | ||
| 3592 | return; | ||
| 3593 | } | ||
| 3594 | |||
| 3566 | /* If this results in a quit_char being returned to Emacs as | 3595 | /* If this results in a quit_char being returned to Emacs as |
| 3567 | input, set Vlast_event_frame properly. If this doesn't | 3596 | input, set Vlast_event_frame properly. If this doesn't |
| 3568 | get returned to Emacs as an event, the next event read | 3597 | get returned to Emacs as an event, the next event read |
| @@ -3592,7 +3621,9 @@ kbd_buffer_store_event (event) | |||
| 3592 | Just ignore the second one. */ | 3621 | Just ignore the second one. */ |
| 3593 | else if (event->kind == BUFFER_SWITCH_EVENT | 3622 | else if (event->kind == BUFFER_SWITCH_EVENT |
| 3594 | && kbd_fetch_ptr != kbd_store_ptr | 3623 | && kbd_fetch_ptr != kbd_store_ptr |
| 3595 | && kbd_store_ptr->kind == BUFFER_SWITCH_EVENT) | 3624 | && ((kbd_store_ptr == kbd_buffer |
| 3625 | ? kbd_buffer + KBD_BUFFER_SIZE - 1 | ||
| 3626 | : kbd_store_ptr - 1)->kind) == BUFFER_SWITCH_EVENT) | ||
| 3596 | return; | 3627 | return; |
| 3597 | 3628 | ||
| 3598 | if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE) | 3629 | if (kbd_store_ptr - kbd_buffer == KBD_BUFFER_SIZE) |
| @@ -3651,24 +3682,22 @@ kbd_buffer_store_event (event) | |||
| 3651 | 3682 | ||
| 3652 | Value is the number of input_events generated. */ | 3683 | Value is the number of input_events generated. */ |
| 3653 | 3684 | ||
| 3654 | int | 3685 | void |
| 3655 | gen_help_event (bufp, size, help, frame, window, object, pos) | 3686 | gen_help_event (help, frame, window, object, pos) |
| 3656 | struct input_event *bufp; | ||
| 3657 | int size; | ||
| 3658 | Lisp_Object help, frame, object, window; | 3687 | Lisp_Object help, frame, object, window; |
| 3659 | int pos; | 3688 | int pos; |
| 3660 | { | 3689 | { |
| 3661 | if (size >= 1) | 3690 | struct input_event event; |
| 3662 | { | 3691 | |
| 3663 | bufp->kind = HELP_EVENT; | 3692 | EVENT_INIT (event); |
| 3664 | bufp->frame_or_window = frame; | 3693 | |
| 3665 | bufp->arg = object; | 3694 | event.kind = HELP_EVENT; |
| 3666 | bufp->x = WINDOWP (window) ? window : frame; | 3695 | event.frame_or_window = frame; |
| 3667 | bufp->y = help; | 3696 | event.arg = object; |
| 3668 | bufp->code = pos; | 3697 | event.x = WINDOWP (window) ? window : frame; |
| 3669 | return 1; | 3698 | event.y = help; |
| 3670 | } | 3699 | event.code = pos; |
| 3671 | return 0; | 3700 | kbd_buffer_store_event (&event); |
| 3672 | } | 3701 | } |
| 3673 | 3702 | ||
| 3674 | 3703 | ||
| @@ -6566,15 +6595,7 @@ record_asynch_buffer_change () | |||
| 6566 | only when SIGIO is blocked. | 6595 | only when SIGIO is blocked. |
| 6567 | 6596 | ||
| 6568 | Returns the number of keyboard chars read, or -1 meaning | 6597 | Returns the number of keyboard chars read, or -1 meaning |
| 6569 | this is a bad time to try to read input. | 6598 | 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 | |||
| 6577 | #define NREAD_INPUT_EVENTS 512 | ||
| 6578 | 6599 | ||
| 6579 | static int | 6600 | static int |
| 6580 | read_avail_input (expected) | 6601 | read_avail_input (expected) |
| @@ -6587,32 +6608,19 @@ read_avail_input (expected) | |||
| 6587 | { | 6608 | { |
| 6588 | int discard = 0; | 6609 | int discard = 0; |
| 6589 | int nr; | 6610 | int nr; |
| 6611 | struct input_event hold_quit; | ||
| 6590 | 6612 | ||
| 6591 | do { | 6613 | EVENT_INIT (hold_quit); |
| 6592 | struct input_event buf[NREAD_INPUT_EVENTS]; | 6614 | hold_quit.kind = NO_EVENT; |
| 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 | 6615 | ||
| 6605 | /* Scan the chars for C-g and store them in kbd_buffer. */ | 6616 | /* No need for FIONREAD or fcntl; just say don't wait. */ |
| 6606 | for (i = 0; !discard && i < nr; i++) | 6617 | while (nr = (*read_socket_hook) (input_fd, expected, &hold_quit), nr > 0) |
| 6607 | { | 6618 | { |
| 6608 | kbd_buffer_store_event (&buf[i]); | 6619 | nread += nr; |
| 6609 | /* Don't look at input that follows a C-g too closely. | 6620 | expected = 0; |
| 6610 | This reduces lossage due to autorepeat on C-g. */ | 6621 | } |
| 6611 | if (buf[i].kind == ASCII_KEYSTROKE_EVENT | 6622 | if (hold_quit.kind != NO_EVENT) |
| 6612 | && buf[i].code == quit_char) | 6623 | kbd_buffer_store_event (&hold_quit); |
| 6613 | discard = 1; | ||
| 6614 | } | ||
| 6615 | } while (nr == NREAD_INPUT_EVENTS); | ||
| 6616 | } | 6624 | } |
| 6617 | else | 6625 | else |
| 6618 | { | 6626 | { |