Initial git import
[sxemacs] / src / events / events.h
1 /* Definitions for the new event model;
2    created 16-jul-91 by Jamie Zawinski
3    Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
4    Copyright (C) 1995, 1996 Ben Wing.
5    Copyright (C) 2007 Sebastian Freundt
6
7 This file is part of SXEmacs
8
9 SXEmacs is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 SXEmacs is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program.  If not, see <http://www.gnu.org/licenses/>. */
21
22
23 /* Synched up with: Not in FSF. */
24
25 #ifndef INCLUDED_events_h_
26 #define INCLUDED_events_h_
27
28 #include "systime.h"
29
30 /* There is one object called an event_stream.  This object contains
31    callback functions for doing the window-system-dependent operations
32    that SXEmacs requires.
33
34    If SXEmacs is compiled with support for X11 and the X Toolkit, then this
35    event_stream structure will contain functions that can cope with input
36    on SXEmacs windows on multiple displays, as well as input from dumb tty
37    frames.
38
39    If it is desired to have SXEmacs able to open frames on the displays of
40    multiple heterogeneous machines, X11 and SunView, or X11 and NeXT, for
41    example, then it will be necessary to construct an event_stream structure
42    that can cope with the given types.  Currently, the only implemented
43    event_streams are for dumb-ttys, and for X11 plus dumb-ttys,
44    and for mswindows.
45
46    To implement this for one window system is relatively simple.
47    To implement this for multiple window systems is trickier and may
48    not be possible in all situations, but it's been done for X and TTY.
49
50    Note that these callbacks are *NOT* console methods; that's because
51    the routines are not specific to a particular console type but must
52    be able to simultaneously cope with all allowable console types.
53
54   The slots of the event_stream structure:
55
56  next_event_cb          A function which fills in an SXEmacs_event structure
57                         with the next event available.  If there is no event
58                         available, then this should block.
59
60                         IMPORTANT: timer events and especially process
61                         events *must not* be returned if there are
62                         events of other types available; otherwise you
63                         can end up with an infinite loop in Fdiscard_input().
64
65  event_pending_cb       A function which says whether there are events to be
66                         read.  If called with an argument of 0, then this
67                         should say whether calling the next_event_cb will
68                         block.  If called with an argument of 1, then this
69                         should say whether there are user-generated events
70                         pending (that is, keypresses or mouse-clicks).  This
71                         is used for redisplay optimization, among other
72                         things.  On dumb ttys, these two results are the
73                         same, but under a window system, they are not.
74
75                         If this function is not sure whether there are events
76                         to be read, it *must* return 0.  Otherwise various
77                         undesirable effects will occur, such as redisplay
78                         not occurring until the next event occurs.
79
80  handle_magic_event_cb  SXEmacs calls this with an event structure which
81                         contains window-system dependent information that
82                         SXEmacs doesn't need to know about, but which must
83                         happen in order.  If the next_event_cb never returns
84                         an event of type "magic", this will never be used.
85
86  add_timeout_cb         Called with an EMACS_TIME, the absolute time at
87                         which a wakeup event should be generated; and a
88                         void *, which is an arbitrary value that will be
89                         returned in the timeout event.  The timeouts
90                         generated by this function should be one-shots:
91                         they fire once and then disappear.  This callback
92                         should return an int id-number which uniquely
93                         identifies this wakeup.  If an implementation
94                         doesn't have microseconds or millisecond
95                         granularity, it should round up to the closest
96                         value it can deal with.
97
98  remove_timeout_cb      Called with an int, the id number of a wakeup to
99                         discard.  This id number must have been returned by
100                         the add_timeout_cb.  If the given wakeup has
101                         already expired, this should do nothing.
102
103  select_process_cb      These callbacks tell the underlying implementation to
104  unselect_process_cb    add or remove a file descriptor from the list of fds
105                         which are polled for inferior-process input.  When
106                         input becomes available on the given process
107                         connection, an event of type "process" should be
108                         generated.
109
110  select_console_cb      These callbacks tell the underlying implementation
111  unselect_console_cb    to add or remove a console from the list of consoles
112                         which are polled for user-input.
113
114  select_device_cb       These callbacks are used by Unixoid event loops
115  unselect_device_cb     (those that use select() and file descriptors and
116                         have a separate input fd per device).
117
118  create_stream_pair_cb  These callbacks are called by process code to
119  delete_stream_pair_cb  create and delete a pair of input and output lstreams
120                         which are used for subprocess I/O.
121
122  quitp_cb               A handler function called from the `QUIT' macro which
123                         should check whether the quit character has been
124                         typed.  On systems with SIGIO, this will not be called
125                         unless the `sigio_happened' flag is true (it is set
126                         from the SIGIO handler).
127
128  SXEmacs has its own event structures, which are distinct from the event
129  structures used by X or any other window system.  It is the job of the
130  event_stream layer to translate to this format.
131
132  NOTE: #### All timestamps should be measured as milliseconds since SXEmacs
133        started.  Currently they are raw server timestamps. (The X protocol
134        doesn't provide any easy way of translating between server time and
135        real process time; yuck.)
136
137  Every event type has the following structures:
138
139  channel                Where this event occurred on.  This will be
140                         a frame, device, console, or nil, depending on the
141                         event type.  It is important that an object of
142                         a more specific type than is actually generated
143                         is not substituted -- e.g. there should not be
144                         a frame inserted when a key-press event occurs,
145                         because events on dead channels are automatically
146                         ignored.
147
148                         Specifically:
149
150                         -- for button and mouse-motion events, channel
151                            will be a frame. (The translation to a window
152                            occurs later.)
153                         -- for keyboard events, channel will be a console.
154                            Note that fake keyboard events (generated
155                            by `character-to-event' or something that
156                            calls this, such as macros) need to have
157                            the selected console stored into them when
158                            the event is created.  This is so that the
159                            correct console-local variables (e.g. the
160                            command builder) will get affected.
161                         -- for timer, process, magic-eval, and eval events,
162                            channel will be nil.
163                         -- for misc-user events, channel will be a frame.
164                         -- for magic events, channel will be a frame
165                            (usually) or a device.
166
167  timestamp              When this event occurred -- if not known, this
168                         is made up.
169
170  In addition, the following structures are specific to particular event
171  types:
172
173  key_press_event
174     key                 What keysym this is; an integer or a symbol.
175                         If this is an integer, it will be in the printing
176                         ASCII range: >32 and <127.
177     modifiers           Bucky-bits on that key: control, meta, etc.
178                         Also includes buttons.
179                         For many keys, Shift is not a bit; that is implicit
180                         in the keyboard layout.
181
182  button_press_event
183  button_release_event
184     button              What button went down or up.
185     modifiers           Bucky-bits on that button: shift, control, meta, etc.
186                         Also includes other buttons (not the one pressed).
187     x, y                Where it was at the button-state-change (in pixels).
188
189  pointer_motion_event
190     x, y                Where it was after it moved (in pixels).
191     modifiers           Bucky-bits down when the motion was detected.
192
193  process_event
194     process             the SXEmacs "process" object in question
195
196  timeout_event
197     interval_id         The ID returned when the associated call to
198                         add_timeout_cb() was made
199         ------ the rest of the fields are filled in by SXEmacs -----
200     id_number           The SXEmacs timeout ID for this timeout (more
201                         than one timeout event can have the same value
202                         here, since SXEmacs timeouts, as opposed to
203                         add_timeout_cb() timeouts, can resignal
204                         themselves)
205     function            An elisp function to call when this timeout is
206                         processed.
207     object              The object passed to that function.
208
209  eval_event
210     function            An elisp function to call with this event object.
211     internal_function   An unexported function to call with this event
212                         object.  This allows eval events to call internal
213                         functions.  For a normal eval event, this field
214                         will always be 0.
215     object              Anything.
216                         This kind of event is used internally; sometimes the
217                         window system interface would like to inform SXEmacs of
218                         some user action (such as focusing on another frame)
219                         but needs that to happen synchronously with the other
220                         user input, like keypresses.  This is useful when
221                         events are reported through callbacks rather
222                         than in the standard event stream.
223
224  misc_user_event
225     function            An elisp function to call with this event object.
226     internal_function   Ignored.
227     object              Anything.
228     button              What button went down or up.
229     modifiers           Bucky-bits on that button: shift, control, meta, etc.
230     x, y                Where it was at the button-state-change (in pixels).
231                         This is similar to an eval_event, except that it is
232                         generated by user actions: selections in the
233                         menubar, scrollbar actions, or drag and drop actions.
234                         It is a "command" event, like key and mouse presses
235                         (and unlike mouse motion, process output, and enter
236                         and leave window hooks).  In many ways, eval_events
237                         are not the same as keypresses or misc_user_events.
238                         The button, modifiers, x, and y parts are only used
239                         by the SXEmacs Drag'n'Drop system. Don't depend on their
240                         values for other types of misc_user_events.
241
242  magic_event
243                         No user-serviceable parts within.  This is for things
244                         like KeymapNotify and ExposeRegion events and so on
245                         that SXEmacs itself doesn't care about, but which it
246                         must do something with for proper interaction with
247                         the window system.
248
249                         Magic_events are handled somewhat asynchronously, just
250                         like subprocess filters.  However, occasionally a
251                         magic_event needs to be handled synchronously; in that
252                         case, the asynchronous handling of the magic_event will
253                         push an eval_event back onto the queue, which will be
254                         handled synchronously later.  This is one of the
255                         reasons why eval_events exist; I'm not entirely happy
256                         with this aspect of this event model.
257
258  magic_eval_event
259                         This is like an eval event but its contents are
260                         not Lisp-accessible.  This allows for "internal
261                         eval events" that call non-Lisp-accessible functions.
262                         Externally, a magic_eval_event just appears as
263                         a magic_event; the Lisp programmer need not know
264                         anything more.
265
266 */
267
268 /*
269   Stream pairs description
270   ------------------------
271
272   Since there are many possible processes/event loop combinations, the event
273   code is responsible for creating an appropriate lstream type. The process
274   implementation does not care about that implementation.
275
276   The Create stream pair function is passed two void* values, which identify
277   process-dependent 'handles'. The process implementation uses these handles to
278   communicate with child processes. The function must be prepared to receive
279   handle types of any process implementation. Since only one process
280   implementation exists in a particular SXEmacs configuration, preprocessing is
281   a means of compiling in the support for the code which deals with particular
282   handle types.
283
284   For example, a unixoid type loop, which relies on file descriptors, may be
285   asked to create a pair of streams by a unix-style process implementation.
286   In this case, the handles passed are unix file descriptors, and the code
287   may deal with these directly. Although, the same code may be used on Win32
288   system with X-Windows. In this case, Win32 process implementation passes
289   handles of type HANDLE, and the create_stream_pair function must call
290   appropriate function to get file descriptors given HANDLEs, so that these
291   descriptors may be passed to XtAddInput.
292
293   The handle given may have special denying value, in which case the
294   corresponding lstream should not be created.
295
296   The return value of the function is a unique stream identifier. It is used
297   by processes implementation, in its  platform-independent part. There is
298   the get_process_from_usid function, which returns process object given its
299   USID. The event stream is responsible for converting its internal handle
300   type into USID.
301
302   Example is the TTY event stream. When a file descriptor signals input, the
303   event loop must determine process to which the input is destined. Thus,
304   the implementation uses process input stream file descriptor as USID, by
305   simply casting the fd value to USID type.
306
307   There are two special USID values. One, USID_ERROR, indicates that the stream
308   pair cannot be created. The second, USID_DONTHASH, indicates that streams are
309   created, but the event stream does not wish to be able to find the process
310   by its USID. Specifically, if an event stream implementation never calls
311   get_process_from_usid, this value should always be returned, to prevent
312   accumulating useless information on USID to process relationship.
313 */
314
315 /* typedef unsigned int USID; in lisp.h */
316 #define USID_ERROR ((USID)-1)
317 #define USID_DONTHASH ((USID)0)
318
319 #ifdef ALL_DEBUG_FLAGS
320 #undef EVENTS_DEBUG_FLAG
321 #define EVENTS_DEBUG_FLAG
322 #endif
323
324 #define __EVENTS_DEBUG__(args...)       fprintf(stderr, "events " args)
325 #ifndef EVENTS_DEBUG_FLAG
326 #define EVENTS_DEBUG(args...)
327 #else
328 #define EVENTS_DEBUG(args...)           __EVENTS_DEBUG__(args)
329 #endif
330 #define EVENTS_CRITICAL(args...)        __EVENTS_DEBUG__("CRITICAL: " args)
331
332 typedef Lisp_Event *sxe_event_t;
333 \f
334 struct event_stream {
335         int (*event_pending_p) (int);
336         void (*next_event_cb) (Lisp_Event *);
337         void (*handle_magic_event_cb) (Lisp_Event *);
338         int (*add_timeout_cb) (EMACS_TIME);
339         void (*remove_timeout_cb) (int);
340         void (*select_console_cb) (struct console *);
341         void (*unselect_console_cb) (struct console *);
342         void (*select_process_cb) (Lisp_Process *);
343         void (*unselect_process_cb) (Lisp_Process *);
344         void (*quit_p_cb) (void);
345         void (*force_event_pending) (struct frame * f);
346         USID(*create_stream_pair_cb) (void * /* inhandle */ ,
347                                       void * /*outhandle */ ,
348                                       Lisp_Object * /* instream */ ,
349                                       Lisp_Object * /* outstream */ ,
350                                       int /* flags */ );
351         USID(*delete_stream_pair_cb) (Lisp_Object /* instream */ ,
352                                       Lisp_Object /* outstream */ );
353         int (*current_event_timestamp_cb) (struct console *);
354 };
355
356 /* Flags for create_stream_pair_cb() FLAGS parameter */
357 #define STREAM_PTY_FLUSHING                     0x0001
358 #define STREAM_NETWORK_CONNECTION               0x0002
359 #define STREAM_NETWORK_SERVER_CONNECTION        0x0004
360
361 extern struct event_stream *event_stream;
362
363 typedef enum emacs_event_type {
364         empty_event,
365         key_press_event,
366         button_press_event,
367         button_release_event,
368         pointer_motion_event,
369         process_event,
370         timeout_event,
371         magic_event,
372         magic_eval_event,
373         eval_event,
374         misc_user_event,
375 #ifdef EF_USE_ASYNEQ
376         eaten_myself_event,
377         work_started_event,
378         work_finished_event,
379 #endif
380         dead_event
381 } emacs_event_type;
382
383 #define first_event_type empty_event
384 #define last_event_type dead_event
385
386 #if defined INCLUDE_EVENTS_H_PRIVATE_SPHERE
387 struct key_data {
388         Lisp_Object keysym;
389         int modifiers;
390 };
391
392 struct button_data {
393         int button;
394         int modifiers;
395         int x, y;
396 };
397
398 struct motion_data {
399         int x, y;
400         int modifiers;
401 };
402
403 struct process_data {
404         Lisp_Object process;
405 };
406
407 struct timeout_data {
408         int interval_id;
409         int id_number;
410         Lisp_Object function;
411         Lisp_Object object;
412 };
413
414 struct eval_data {
415         Lisp_Object function;
416         Lisp_Object object;
417 };
418
419 struct misc_user_data {
420         Lisp_Object function;
421         Lisp_Object object;
422         int button;
423         int modifiers;
424         int x, y;
425 };
426
427 struct magic_eval_data {
428         void (*internal_function) (Lisp_Object);
429         Lisp_Object object;
430 };
431
432 #ifdef EF_USE_ASYNEQ
433 struct work_started_s {
434         Lisp_Object job;
435 };
436
437 struct work_finished_s {
438         Lisp_Object job;
439 };
440
441 struct eaten_myself_s {
442         void *worker;
443 };
444 #endif
445
446 #if defined (HAVE_X_WINDOWS) && defined(emacs) && defined(HAVE_X11_XLIB_H)
447 # include <X11/Xlib.h>
448 #endif
449 #ifdef HAVE_GTK
450 # include <gdk/gdk.h>
451 #endif
452
453 union magic_data {
454 #ifdef HAVE_TTY
455         char underlying_tty_event;
456 #endif
457 #if defined HAVE_GTK
458         GdkEvent underlying_gdk_event;
459 #endif
460 #ifdef HAVE_X_WINDOWS
461         XEvent underlying_x_event;
462 #endif
463 };
464
465 struct Lisp_Timeout {
466         struct lcrecord_header header;
467         int id;                 /* Id we use to identify the timeout over its lifetime */
468         int interval_id;        /* Id for this particular interval; this may
469                                    be different each time the timeout is
470                                    signalled. */
471         Lisp_Object function, object;   /* Function and object associated
472                                            with timeout. */
473         EMACS_TIME next_signal_time;    /* Absolute time when the timeout
474                                            is next going to be signalled. */
475         unsigned int resignal_msecs;    /* How far after the next timeout
476                                            should the one after that
477                                            occur? */
478 };
479 typedef struct Lisp_Timeout Lisp_Timeout;
480
481 DECLARE_LRECORD(timeout, Lisp_Timeout);
482 #define XTIMEOUT(x) XRECORD (x, timeout, Lisp_Timeout)
483 #define XSETTIMEOUT(x, p) XSETRECORD (x, p, timeout)
484 #define TIMEOUTP(x) RECORDP (x, timeout)
485 #define CHECK_TIMEOUT(x) CHECK_RECORD (x, timeout)
486 #define CONCHECK_TIMEOUT(x) CONCHECK_RECORD (x, timeout)
487
488 struct Lisp_Event {
489         /* header->next (aka XEVENT_NEXT ()) is used as follows:
490            - For dead events, this is the next dead one.
491            - For events on the command_event_queue, the next one on the queue.
492            - Likewise for events chained in the command builder.
493            - Otherwise it's Qnil.
494          */
495         struct lrecord_header lheader;
496         Lisp_Object next;
497         emacs_event_type event_type;
498         Lisp_Object channel;
499         unsigned int timestamp;
500         union {
501                 struct key_data key;
502                 struct button_data button;
503                 struct motion_data motion;
504                 struct process_data process;
505                 struct timeout_data timeout;
506                 struct eval_data eval;  /* misc_user_event no longer uses this */
507                 struct misc_user_data misc;     /* because it needs position information */
508                 union magic_data magic;
509                 struct magic_eval_data magic_eval;
510 #ifdef EF_USE_ASYNEQ
511                 struct eaten_myself_s eaten_myself;
512                 struct work_started_s work_started;
513                 struct work_finished_s work_finished;
514 #endif
515         } event;
516 };
517
518 DECLARE_LRECORD(event, Lisp_Event);
519 #define XEVENT(x) XRECORD (x, event, Lisp_Event)
520 #define XSETEVENT(x, p) XSETRECORD (x, p, event)
521 #define EVENTP(x) RECORDP (x, event)
522 #define CHECK_EVENT(x) CHECK_RECORD (x, event)
523 #define CONCHECK_EVENT(x) CONCHECK_RECORD (x, event)
524
525 DECLARE_LRECORD(command_builder, struct command_builder);
526
527 #define EVENT_CHANNEL(a) ((a)->channel)
528 #define EVENT_TYPE(a) ((a)->event_type)
529 #define XEVENT_TYPE(a) (XEVENT (a)->event_type)
530 #define EVENT_NEXT(a) ((a)->next)
531 #define XEVENT_NEXT(e) (XEVENT (e)->next)
532 #define XSET_EVENT_NEXT(e, n) do { (XEVENT (e)->next = (n)); } while (0)
533
534 #define EVENT_CHAIN_LOOP(event, chain)                                  \
535         for (event = chain; !NILP (event); event = XEVENT_NEXT (event))
536
537 #define EVENT_LIVE_P(a) (EVENT_TYPE (a) != dead_event)
538
539 #define CHECK_LIVE_EVENT(x)                                             \
540         do {                                                            \
541                 CHECK_EVENT (x);                                        \
542                 if (! EVENT_LIVE_P (XEVENT (x)))                        \
543                         dead_wrong_type_argument (Qevent_live_p, (x));  \
544         } while (0)
545 #define CONCHECK_LIVE_EVENT(x)                                          \
546         do {                                                            \
547                 CONCHECK_EVENT (x);                                     \
548                 if (! EVENT_LIVE_P (XEVENT (x)))                        \
549                         x = wrong_type_argument (Qevent_live_p, (x));   \
550         } while (0)
551
552 #endif  /* INCLUDE_EVENTS_H_PRIVATE_SPHERE */
553
554 EXFUN(Fcharacter_to_event, 4);
555 EXFUN(Fdeallocate_event, 1);
556 EXFUN(Fevent_glyph_extent, 1);
557 EXFUN(Fevent_modeline_position, 1);
558 EXFUN(Fevent_over_modeline_p, 1);
559 EXFUN(Fevent_over_toolbar_p, 1);
560 EXFUN(Fevent_over_vertical_divider_p, 1);
561 EXFUN(Fevent_point, 1);
562 EXFUN(Fevent_window, 1);
563 EXFUN(Fmake_event, 2);
564
565 extern Lisp_Object make_empty_event(void);
566 extern sxe_event_t make_noseeum_event(emacs_event_type);
567
568 extern Lisp_Object QKbackspace, QKdelete, QKescape, QKlinefeed, QKreturn;
569 extern Lisp_Object QKspace, QKtab, Qmouse_event_p, Vcharacter_set_property;
570 extern Lisp_Object Qcancel_mode_internal;
571 extern Lisp_Object Vmodifier_keys_sticky_time;
572
573 /* Note: under X Windows, XEMACS_MOD_ALT is generated by the Alt key if there are
574    both Alt and Meta keys.  If there are no Meta keys, then Alt generates
575    XEMACS_MOD_META instead.
576  */
577
578 #ifdef emacs
579 /* Maybe this should be trickier */
580 #define KEYSYM(x) (intern (x))
581
582 /* from events.c */
583 void format_event_object(char *buf, Lisp_Event * e, int brief);
584 void character_to_event(Emchar c, Lisp_Event * event,
585                         struct console *con,
586                         int use_console_meta_flag, int do_backspace_mapping);
587 void zero_event(Lisp_Event * e);
588 void deallocate_event_chain(Lisp_Object event);
589 Lisp_Object event_chain_tail(Lisp_Object event);
590 void enqueue_event(Lisp_Object event, Lisp_Object * head, Lisp_Object * tail);
591 Lisp_Object dequeue_event(Lisp_Object * head, Lisp_Object * tail);
592 void enqueue_event_chain(Lisp_Object event_chain, Lisp_Object * head,
593                          Lisp_Object * tail);
594 int event_chain_count(Lisp_Object event_chain);
595 void nth_of_key_sequence_as_event(Lisp_Object seq, int n, Lisp_Object event);
596 Lisp_Object key_sequence_to_event_chain(Lisp_Object seq);
597 Lisp_Object event_chain_find_previous(Lisp_Object event_chain,
598                                       Lisp_Object event);
599 Lisp_Object event_chain_nth(Lisp_Object event_chain, int n);
600 Lisp_Object copy_event_chain(Lisp_Object event_chain);
601 /* True if this is a non-internal event
602    (keyboard press, menu, scrollbar, mouse button) */
603 int command_event_p(Lisp_Object event);
604 void define_self_inserting_symbol(Lisp_Object, Lisp_Object);
605 Emchar event_to_character(Lisp_Event *, int, int, int);
606 struct console *event_console_or_selected(Lisp_Object event);
607
608 /* from event-stream.c */
609 Lisp_Object allocate_command_builder(Lisp_Object console);
610 void enqueue_magic_eval_event(void (*fun) (Lisp_Object), Lisp_Object object);
611 void event_stream_next_event(Lisp_Event * event);
612 void event_stream_handle_magic_event(Lisp_Event * event);
613 void event_stream_select_console(struct console *con);
614 void event_stream_unselect_console(struct console *con);
615 void event_stream_select_process(Lisp_Process * proc);
616 void event_stream_unselect_process(Lisp_Process * proc);
617 USID event_stream_create_stream_pair(void *inhandle, void *outhandle,
618                                      Lisp_Object * instream,
619                                      Lisp_Object * outstream, int flags);
620 USID event_stream_delete_stream_pair(Lisp_Object instream,
621                                      Lisp_Object outstream);
622 void event_stream_quit_p(void);
623
624 struct low_level_timeout {
625         int id;
626         EMACS_TIME time;
627         struct low_level_timeout *next;
628 };
629
630 int add_low_level_timeout(struct low_level_timeout **timeout_list,
631                           EMACS_TIME thyme);
632 void remove_low_level_timeout(struct low_level_timeout **timeout_list, int id);
633 int get_low_level_timeout_interval(struct low_level_timeout *timeout_list,
634                                    EMACS_TIME * interval);
635 int pop_low_level_timeout(struct low_level_timeout **timeout_list,
636                           EMACS_TIME * time_out);
637 int event_stream_generate_wakeup(unsigned int milliseconds,
638                                  unsigned int vanilliseconds,
639                                  Lisp_Object function, Lisp_Object object,
640                                  int async_p);
641 void event_stream_disable_wakeup(int id, int async_p);
642 void event_stream_deal_with_async_timeout(int interval_id);
643
644 int event_stream_add_async_timeout(EMACS_TIME thyme);
645 void event_stream_remove_async_timeout(int id);
646
647 /* from event-stream.c -- focus sanity */
648 extern int focus_follows_mouse;
649 void investigate_frame_change(void);
650
651 void emacs_handle_focus_change_preliminary(Lisp_Object frame_inp_and_dev);
652 void emacs_handle_focus_change_final(Lisp_Object frame_inp_and_dev);
653
654 Lisp_Object extract_this_command_keys_nth_mouse_event(int n);
655 Lisp_Object extract_vector_nth_mouse_event(Lisp_Object vector, int n);
656
657 void single_console_state(void);
658 void any_console_state(void);
659 int in_single_console_state(void);
660
661 extern int emacs_is_blocking;
662
663 extern volatile int sigint_happened;
664
665 #ifdef HAVE_UNIXOID_EVENT_LOOP
666 /* from event-unixoid.c */
667
668 /* Ceci n'est pas un pipe. */
669 extern int signal_event_pipe[];
670
671 void signal_fake_event(void);
672 void drain_signal_event_pipe(void);
673
674 extern int fake_event_occurred;
675
676 int event_stream_unixoid_select_console(struct console *con);
677 int event_stream_unixoid_unselect_console(struct console *con);
678 int event_stream_unixoid_select_process(Lisp_Process * proc);
679 int event_stream_unixoid_unselect_process(Lisp_Process * proc);
680 int read_event_from_tty_or_stream_desc(Lisp_Event * event,
681                                        struct console *con, int fd);
682 USID event_stream_unixoid_create_stream_pair(void *inhandle, void *outhandle,
683                                              Lisp_Object * instream,
684                                              Lisp_Object * outstream,
685                                              int flags);
686 USID event_stream_unixoid_delete_stream_pair(Lisp_Object instream,
687                                              Lisp_Object outstream);
688
689 /* Beware: this evil macro evaluates its arg many times */
690 #define FD_TO_USID(fd) ((fd)==0 ? (USID)999999 : ((fd)<0 ? USID_DONTHASH : (USID)(fd)))
691
692 #endif                          /* HAVE_UNIXOID_EVENT_LOOP */
693
694 /* Define this if you want the tty event stream to be used when the
695    first console is tty, even if HAVE_X_WINDOWS is defined */
696 /* #define DEBUG_TTY_EVENT_STREAM */
697
698 #endif                          /* emacs */
699
700 /* #### a hack, until accelerator shit is cleaned up */
701
702 /* This structure is what we use to encapsulate the state of a command sequence
703    being composed; key events are executed by adding themselves to the command
704    builder; if the command builder is then complete (does not still represent
705    a prefix key sequence) it executes the corresponding command.
706  */
707 struct command_builder {
708         struct lcrecord_header header;
709         Lisp_Object console;    /* back pointer to the console this command
710                                    builder is for */
711         /* Qnil, or a Lisp_Event representing the first event read
712          *  after the last command completed.  Threaded. */
713         /* #### NYI */
714         Lisp_Object prefix_events;
715         /* Qnil, or a Lisp_Event representing event in the current
716          *  keymap-lookup sequence.  Subsequent events are threaded via
717          *  the event's next slot */
718         Lisp_Object current_events;
719         /* Last elt of above  */
720         Lisp_Object most_current_event;
721         /* Last elt before function map code took over. What this means is:
722            All prefixes up to (but not including) this event have non-nil
723            bindings, but the prefix including this event has a nil binding.
724            Any events in the chain after this one were read solely because
725            we're part of a possible function key.  If we end up with
726            something that's not part of a possible function key, we have to
727            unread all of those events. */
728         Lisp_Object last_non_munged_event;
729         /* One set of values for function-key-map, one for key-translation-map */
730         struct munging_key_translation {
731                 /* First event that can begin a possible function key sequence
732                    (to be translated according to function-key-map).  Normally
733                    this is the first event in the chain.  However, once we've
734                    translated a sequence through function-key-map, this will point
735                    to the first event after the translated sequence: we don't ever
736                    want to translate any events twice through function-key-map, or
737                    things could get really screwed up (e.g. if the user created a
738                    translation loop).  If this is nil, then the next-read event is
739                    the first that can begin a function key sequence. */
740                 Lisp_Object first_mungeable_event;
741         } munge_me[2];
742
743         Bufbyte *echo_buf;
744         Bytecount echo_buf_length;      /* size of echo_buf */
745         Bytecount echo_buf_index;       /* index into echo_buf
746                                          * -1 before doing echoing for new cmd */
747         /* Self-insert-command is magic in that it doesn't always push an undo-
748            boundary: up to 20 consecutive self-inserts can happen before an undo-
749            boundary is pushed.  This variable is that counter.
750          */
751         int self_insert_countdown;
752 };
753
754 #endif  /* INCLUDED_events_h_ */