diff options
| author | Richard M. Stallman | 1996-02-01 06:01:15 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-02-01 06:01:15 +0000 |
| commit | 7ea13e12ee48674e951e49bf9d5ac69324107a10 (patch) | |
| tree | cb94a327a8f007ff964dbe7421f7afe5d9b00df3 /src | |
| parent | 059a4a904fbf63a77b2c727b9458b9012bfa22eb (diff) | |
| download | emacs-7ea13e12ee48674e951e49bf9d5ac69324107a10.tar.gz emacs-7ea13e12ee48674e951e49bf9d5ac69324107a10.zip | |
(make_lispy_event): Timer event is a list, not just cons.
(timer_check): When DO_IT_NOW is true, handle events by running
the definition of timer-event. Don't get the current time if there
are no pending timers. If an event was generated, return 0,
If all timers were handled, return -1. Add gcpros.
(readable_events): Tell timer_check to execute events.
Diffstat (limited to 'src')
| -rw-r--r-- | src/keyboard.c | 56 |
1 files changed, 46 insertions, 10 deletions
diff --git a/src/keyboard.c b/src/keyboard.c index 3dd9304a577..7db3082cc58 100644 --- a/src/keyboard.c +++ b/src/keyboard.c | |||
| @@ -2341,7 +2341,7 @@ some_mouse_moved () | |||
| 2341 | static int | 2341 | static int |
| 2342 | readable_events () | 2342 | readable_events () |
| 2343 | { | 2343 | { |
| 2344 | timer_check (0); | 2344 | timer_check (1); |
| 2345 | if (kbd_fetch_ptr != kbd_store_ptr) | 2345 | if (kbd_fetch_ptr != kbd_store_ptr) |
| 2346 | return 1; | 2346 | return 1; |
| 2347 | #ifdef HAVE_MOUSE | 2347 | #ifdef HAVE_MOUSE |
| @@ -2881,16 +2881,25 @@ timer_check (do_it_now) | |||
| 2881 | { | 2881 | { |
| 2882 | EMACS_TIME nexttime; | 2882 | EMACS_TIME nexttime; |
| 2883 | EMACS_TIME now; | 2883 | EMACS_TIME now; |
| 2884 | Lisp_Object timers = Vtimer_list; | 2884 | Lisp_Object timers, timer; |
| 2885 | /* Nonzero if we generate some events. */ | ||
| 2886 | int events_generated = 0; | ||
| 2887 | struct gcpro gcpro1, gcpro2; | ||
| 2885 | 2888 | ||
| 2886 | EMACS_GET_TIME (now); | ||
| 2887 | EMACS_SET_SECS (nexttime, -1); | 2889 | EMACS_SET_SECS (nexttime, -1); |
| 2888 | EMACS_SET_USECS (nexttime, -1); | 2890 | EMACS_SET_USECS (nexttime, -1); |
| 2889 | 2891 | ||
| 2892 | timers = Vtimer_list; | ||
| 2893 | timer = Qnil; | ||
| 2894 | GCPRO2 (timers, timer); | ||
| 2895 | |||
| 2896 | if (CONSP (timers)) | ||
| 2897 | EMACS_GET_TIME (now); | ||
| 2898 | |||
| 2890 | while (CONSP (timers)) | 2899 | while (CONSP (timers)) |
| 2891 | { | 2900 | { |
| 2892 | int triggertime; | 2901 | int triggertime; |
| 2893 | Lisp_Object timer, *vector; | 2902 | Lisp_Object *vector; |
| 2894 | EMACS_TIME timer_time; | 2903 | EMACS_TIME timer_time; |
| 2895 | EMACS_TIME difference; | 2904 | EMACS_TIME difference; |
| 2896 | 2905 | ||
| @@ -2909,14 +2918,30 @@ timer_check (do_it_now) | |||
| 2909 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); | 2918 | (XINT (vector[1]) << 16) | (XINT (vector[2]))); |
| 2910 | EMACS_SET_USECS (timer_time, XINT (vector[3])); | 2919 | EMACS_SET_USECS (timer_time, XINT (vector[3])); |
| 2911 | EMACS_SUB_TIME (difference, timer_time, now); | 2920 | EMACS_SUB_TIME (difference, timer_time, now); |
| 2921 | /* If event is past, run it if it hasn't been run. */ | ||
| 2912 | if (EMACS_TIME_NEG_P (difference)) | 2922 | if (EMACS_TIME_NEG_P (difference)) |
| 2913 | { | 2923 | { |
| 2914 | if (NILP (vector[0])) | 2924 | if (NILP (vector[0])) |
| 2915 | { | 2925 | { |
| 2926 | /* Mark the timer as triggered to prevent problems if the lisp | ||
| 2927 | code fails to reschedule it right. */ | ||
| 2928 | vector[0] = Qt; | ||
| 2929 | |||
| 2930 | /* Run the timer or queue a timer event. */ | ||
| 2916 | if (do_it_now) | 2931 | if (do_it_now) |
| 2917 | apply1 (vector[5], vector[6]); | 2932 | { |
| 2933 | Lisp_Object tem, event; | ||
| 2934 | tem = get_keymap_1 (Vspecial_event_map, 0, 0); | ||
| 2935 | tem = get_keyelt (access_keymap (tem, Qtimer_event, 0, 0), | ||
| 2936 | 1); | ||
| 2937 | event = Fcons (Qtimer_event, Fcons (timer, Qnil)); | ||
| 2938 | Fcommand_execute (tem, Qnil, Fvector (1, &event)); | ||
| 2939 | /* Since we have handled the event, | ||
| 2940 | we don't need to tell the caller to wake up and do it. */ | ||
| 2941 | } | ||
| 2918 | else | 2942 | else |
| 2919 | { | 2943 | { |
| 2944 | /* Generate a timer event so the caller will handle it. */ | ||
| 2920 | struct input_event event; | 2945 | struct input_event event; |
| 2921 | 2946 | ||
| 2922 | event.kind = timer_event; | 2947 | event.kind = timer_event; |
| @@ -2927,17 +2952,28 @@ timer_check (do_it_now) | |||
| 2927 | event.frame_or_window = Fcons (Fselected_frame (), timer); | 2952 | event.frame_or_window = Fcons (Fselected_frame (), timer); |
| 2928 | kbd_buffer_store_event (&event); | 2953 | kbd_buffer_store_event (&event); |
| 2929 | 2954 | ||
| 2930 | /* Mark the timer as triggered to prevent problems if the lisp | 2955 | /* Tell caller to handle this event right away. */ |
| 2931 | code fails to reschedule it right. */ | 2956 | events_generated = 1; |
| 2932 | vector[0] = Qt; | ||
| 2933 | EMACS_SET_SECS (nexttime, 0); | 2957 | EMACS_SET_SECS (nexttime, 0); |
| 2934 | EMACS_SET_USECS (nexttime, 0); | 2958 | EMACS_SET_USECS (nexttime, 0); |
| 2935 | } | 2959 | } |
| 2936 | } | 2960 | } |
| 2937 | } | 2961 | } |
| 2938 | else | 2962 | else |
| 2939 | return difference; | 2963 | /* When we encounter a timer that is still waiting, |
| 2964 | return the amount of time to wait before it is ripe. */ | ||
| 2965 | { | ||
| 2966 | UNGCPRO; | ||
| 2967 | /* But if we generated an event, | ||
| 2968 | tell the caller to handle it now. */ | ||
| 2969 | if (events_generated) | ||
| 2970 | return nexttime; | ||
| 2971 | return difference; | ||
| 2972 | } | ||
| 2940 | } | 2973 | } |
| 2974 | /* No timers are pending in the future. */ | ||
| 2975 | /* Return 0 if we generated an event, and -1 if not. */ | ||
| 2976 | UNGCPRO; | ||
| 2941 | return nexttime; | 2977 | return nexttime; |
| 2942 | } | 2978 | } |
| 2943 | 2979 | ||
| @@ -3409,7 +3445,7 @@ make_lispy_event (event) | |||
| 3409 | break; | 3445 | break; |
| 3410 | 3446 | ||
| 3411 | case timer_event: | 3447 | case timer_event: |
| 3412 | return Fcons (Qtimer_event, Fcdr (event->frame_or_window)); | 3448 | return Fcons (Qtimer_event, Fcons (Fcdr (event->frame_or_window), Qnil)); |
| 3413 | 3449 | ||
| 3414 | #ifdef HAVE_MOUSE | 3450 | #ifdef HAVE_MOUSE |
| 3415 | /* A mouse click. Figure out where it is, decide whether it's | 3451 | /* A mouse click. Figure out where it is, decide whether it's |