0
|
1 /* Events: printing them, converting them to and from characters.
|
|
2 Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1994, 1995 Board of Trustees, University of Illinois.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Not in FSF. */
|
|
23
|
|
24 /* This file has been Mule-ized. */
|
|
25
|
|
26 #include <config.h>
|
|
27 #include "lisp.h"
|
|
28 #include "buffer.h"
|
|
29 #include "console.h"
|
|
30 #include "console-tty.h" /* for stuff in character_to_event */
|
|
31 #include "device.h"
|
|
32 #include "console-x.h" /* for x_event_name prototype */
|
|
33 #include "extents.h" /* Just for the EXTENTP abort check... */
|
|
34 #include "events.h"
|
|
35 #include "frame.h"
|
|
36 #include "glyphs.h"
|
|
37 #include "keymap.h" /* for key_desc_list_to_event() */
|
|
38 #include "redisplay.h"
|
|
39 #include "window.h"
|
|
40
|
100
|
41 #ifdef WINDOWSNT
|
|
42 /* Hmm, under unix we want X modifiers, under NT we want X modifiers if
|
|
43 we are running X and Windows modifiers otherwise.
|
|
44 gak. This is a kludge until we support multiple native GUIs!
|
|
45 */
|
|
46 #undef MOD_ALT
|
|
47 #undef MOD_CONTROL
|
|
48 #undef MOD_SHIFT
|
|
49 #endif
|
|
50
|
157
|
51 #include "events-mod.h"
|
100
|
52
|
0
|
53 /* Where old events go when they are explicitly deallocated.
|
|
54 The event chain here is cut loose before GC, so these will be freed
|
|
55 eventually.
|
|
56 */
|
|
57 static Lisp_Object Vevent_resource;
|
|
58
|
|
59 Lisp_Object Qeventp;
|
|
60 Lisp_Object Qevent_live_p;
|
|
61 Lisp_Object Qkey_press_event_p;
|
|
62 Lisp_Object Qbutton_event_p;
|
|
63 Lisp_Object Qmouse_event_p;
|
|
64 Lisp_Object Qprocess_event_p;
|
|
65
|
163
|
66 Lisp_Object Qkey_press, Qbutton_press, Qbutton_release, Qmisc_user;
|
0
|
67 Lisp_Object Qascii_character;
|
|
68
|
|
69 /* #### Ad-hoc hack. Should be part of define_lrecord_implementation */
|
|
70 void
|
|
71 clear_event_resource (void)
|
|
72 {
|
|
73 Vevent_resource = Qnil;
|
|
74 }
|
|
75
|
|
76 static Lisp_Object mark_event (Lisp_Object, void (*) (Lisp_Object));
|
|
77 static void print_event (Lisp_Object, Lisp_Object, int);
|
|
78 static int event_equal (Lisp_Object, Lisp_Object, int);
|
|
79 static unsigned long event_hash (Lisp_Object obj, int depth);
|
|
80 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("event", event,
|
|
81 mark_event, print_event, 0, event_equal,
|
|
82 event_hash, struct Lisp_Event);
|
|
83
|
|
84 /* Make sure we lose quickly if we try to use this event */
|
|
85 static void
|
|
86 deinitialize_event (Lisp_Object ev)
|
|
87 {
|
|
88 int i;
|
|
89 struct Lisp_Event *event = XEVENT (ev);
|
|
90
|
|
91 for (i = 0; i < ((sizeof (struct Lisp_Event)) / sizeof (int)); i++)
|
|
92 ((int *) event) [i] = 0xdeadbeef;
|
|
93 event->event_type = dead_event;
|
|
94 event->channel = Qnil;
|
|
95 set_lheader_implementation (&(event->lheader), lrecord_event);
|
|
96 XSET_EVENT_NEXT (ev, Qnil);
|
|
97 }
|
|
98
|
|
99 /* Set everything to zero or nil so that it's predictable. */
|
|
100 void
|
|
101 zero_event (struct Lisp_Event *e)
|
|
102 {
|
|
103 memset (e, 0, sizeof (*e));
|
|
104 set_lheader_implementation (&(e->lheader), lrecord_event);
|
|
105 e->event_type = empty_event;
|
|
106 e->next = Qnil;
|
|
107 e->channel = Qnil;
|
|
108 }
|
|
109
|
|
110 static Lisp_Object
|
|
111 mark_event (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
112 {
|
|
113 struct Lisp_Event *event = XEVENT (obj);
|
|
114
|
|
115 switch (event->event_type)
|
|
116 {
|
|
117 case key_press_event:
|
|
118 ((markobj) (event->event.key.keysym));
|
|
119 break;
|
|
120 case process_event:
|
|
121 ((markobj) (event->event.process.process));
|
|
122 break;
|
|
123 case timeout_event:
|
|
124 ((markobj) (event->event.timeout.function));
|
|
125 ((markobj) (event->event.timeout.object));
|
|
126 break;
|
|
127 case eval_event:
|
|
128 case misc_user_event:
|
|
129 ((markobj) (event->event.eval.function));
|
|
130 ((markobj) (event->event.eval.object));
|
|
131 break;
|
|
132 case magic_eval_event:
|
|
133 ((markobj) (event->event.magic_eval.object));
|
|
134 break;
|
|
135 case button_press_event:
|
|
136 case button_release_event:
|
|
137 case pointer_motion_event:
|
|
138 case magic_event:
|
|
139 case empty_event:
|
|
140 case dead_event:
|
|
141 break;
|
|
142 default:
|
|
143 abort ();
|
|
144 }
|
|
145 ((markobj) (event->channel));
|
|
146 return event->next;
|
|
147 }
|
|
148
|
|
149 static void
|
|
150 print_event_1 (CONST char *str, Lisp_Object obj, Lisp_Object printcharfun)
|
|
151 {
|
|
152 char buf[255];
|
|
153 write_c_string (str, printcharfun);
|
|
154 format_event_object (buf, XEVENT (obj), 0);
|
|
155 write_c_string (buf, printcharfun);
|
|
156 }
|
|
157
|
|
158 static void
|
|
159 print_event (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
160 {
|
|
161 if (print_readably)
|
|
162 error ("printing unreadable object #<event>");
|
|
163
|
173
|
164 switch (XEVENT (obj)->event_type)
|
0
|
165 {
|
|
166 case key_press_event:
|
|
167 print_event_1 ("#<keypress-event ", obj, printcharfun);
|
|
168 break;
|
|
169 case button_press_event:
|
|
170 print_event_1 ("#<buttondown-event ", obj, printcharfun);
|
|
171 break;
|
|
172 case button_release_event:
|
|
173 print_event_1 ("#<buttonup-event ", obj, printcharfun);
|
|
174 break;
|
|
175 case magic_event:
|
|
176 case magic_eval_event:
|
|
177 print_event_1 ("#<magic-event ", obj, printcharfun);
|
|
178 break;
|
|
179 case pointer_motion_event:
|
|
180 {
|
|
181 char buf[100];
|
|
182 sprintf (buf, "#<motion-event %d, %d",
|
|
183 XEVENT (obj)->event.motion.x, XEVENT (obj)->event.motion.y);
|
|
184 write_c_string (buf, printcharfun);
|
|
185 break;
|
|
186 }
|
|
187 case process_event:
|
|
188 write_c_string ("#<process-event ", printcharfun);
|
|
189 print_internal (XEVENT (obj)->event.process.process, printcharfun, 1);
|
|
190 break;
|
|
191 case timeout_event:
|
|
192 write_c_string ("#<timeout-event ", printcharfun);
|
|
193 print_internal (XEVENT (obj)->event.timeout.object, printcharfun, 1);
|
|
194 break;
|
|
195 case empty_event:
|
|
196 write_c_string ("#<empty-event", printcharfun);
|
|
197 break;
|
|
198 case misc_user_event:
|
|
199 case eval_event:
|
|
200 write_c_string ("#<", printcharfun);
|
|
201 if (XEVENT (obj)->event_type == misc_user_event)
|
|
202 write_c_string ("misc-user", printcharfun);
|
|
203 else
|
|
204 write_c_string ("eval", printcharfun);
|
|
205 write_c_string ("-event (", printcharfun);
|
|
206 print_internal (XEVENT (obj)->event.eval.function, printcharfun, 1);
|
|
207 write_c_string (" ", printcharfun);
|
|
208 print_internal (XEVENT (obj)->event.eval.object, printcharfun, 1);
|
|
209 write_c_string (")", printcharfun);
|
|
210 break;
|
|
211 case dead_event:
|
|
212 write_c_string ("#<DEALLOCATED-EVENT", printcharfun);
|
|
213 break;
|
|
214 default:
|
|
215 write_c_string ("#<UNKNOWN-EVENT-TYPE", printcharfun);
|
|
216 break;
|
|
217 }
|
|
218 write_c_string (">", printcharfun);
|
|
219 }
|
173
|
220
|
0
|
221 static int
|
|
222 event_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
223 {
|
|
224 struct Lisp_Event *e1 = XEVENT (o1);
|
|
225 struct Lisp_Event *e2 = XEVENT (o2);
|
|
226
|
|
227 if (e1->event_type != e2->event_type) return 0;
|
|
228 if (!EQ (e1->channel, e2->channel)) return 0;
|
|
229 /* if (e1->timestamp != e2->timestamp) return 0; */
|
|
230 switch (e1->event_type)
|
|
231 {
|
|
232 case process_event:
|
149
|
233 return EQ (e1->event.process.process, e2->event.process.process);
|
173
|
234
|
0
|
235 case timeout_event:
|
149
|
236 return (!NILP (Fequal (e1->event.timeout.function,
|
|
237 e2->event.timeout.function)) &&
|
|
238 !NILP (Fequal (e1->event.timeout.object,
|
|
239 e2->event.timeout.object)));
|
173
|
240
|
0
|
241 case key_press_event:
|
149
|
242 return (EQ (e1->event.key.keysym, e2->event.key.keysym) &&
|
|
243 (e1->event.key.modifiers == e2->event.key.modifiers));
|
0
|
244
|
|
245 case button_press_event:
|
|
246 case button_release_event:
|
149
|
247 return (e1->event.button.button == e2->event.button.button &&
|
|
248 e1->event.button.modifiers == e2->event.button.modifiers);
|
0
|
249
|
|
250 case pointer_motion_event:
|
149
|
251 return (e1->event.motion.x == e2->event.motion.x &&
|
|
252 e1->event.motion.y == e2->event.motion.y);
|
0
|
253
|
|
254 case misc_user_event:
|
|
255 case eval_event:
|
149
|
256 return (!NILP (Fequal (e1->event.eval.function,
|
|
257 e2->event.eval.function)) &&
|
|
258 !NILP (Fequal (e1->event.eval.object,
|
|
259 e2->event.eval.object)));
|
0
|
260
|
|
261 case magic_eval_event:
|
149
|
262 return (e1->event.magic_eval.internal_function ==
|
|
263 e2->event.magic_eval.internal_function &&
|
|
264 !NILP (Fequal (e1->event.magic_eval.object,
|
|
265 e2->event.magic_eval.object)));
|
0
|
266
|
|
267 case magic_event:
|
|
268 {
|
|
269 Lisp_Object console;
|
|
270
|
|
271 console = CDFW_CONSOLE (e1->channel);
|
|
272
|
|
273 #ifdef HAVE_X_WINDOWS
|
|
274 /* XEvent is actually a union which means that we can't just use == */
|
|
275 if (CONSOLE_X_P (XCONSOLE (console)))
|
149
|
276 return !memcmp ((XEvent *) &e1->event.magic.underlying_x_event,
|
0
|
277 (XEvent *) &e2->event.magic.underlying_x_event,
|
149
|
278 sizeof (e1->event.magic.underlying_x_event));
|
0
|
279 #endif
|
149
|
280 #ifdef HAVE_TTY
|
|
281 if (CONSOLE_TTY_P (XCONSOLE (console)))
|
0
|
282 return (e1->event.magic.underlying_tty_event ==
|
|
283 e2->event.magic.underlying_tty_event);
|
149
|
284 #endif
|
|
285 return 1;
|
0
|
286 }
|
|
287
|
|
288 case empty_event: /* Empty and deallocated events are equal. */
|
|
289 case dead_event:
|
|
290 return 1;
|
|
291
|
|
292 default:
|
|
293 abort ();
|
|
294 return 0; /* not reached; warning suppression */
|
|
295 }
|
|
296 }
|
|
297
|
|
298 static unsigned long
|
|
299 event_hash (Lisp_Object obj, int depth)
|
|
300 {
|
|
301 struct Lisp_Event *e = XEVENT (obj);
|
|
302 unsigned long hash;
|
|
303
|
|
304 hash = HASH2 (e->event_type, LISP_HASH (e->channel));
|
|
305 switch (e->event_type)
|
|
306 {
|
|
307 case process_event:
|
|
308 return HASH2 (hash, LISP_HASH (e->event.process.process));
|
173
|
309
|
0
|
310 case timeout_event:
|
|
311 return HASH3 (hash, internal_hash (e->event.timeout.function, depth + 1),
|
|
312 internal_hash (e->event.timeout.object, depth + 1));
|
173
|
313
|
0
|
314 case key_press_event:
|
|
315 return HASH3 (hash, LISP_HASH (e->event.key.keysym),
|
|
316 e->event.key.modifiers);
|
|
317
|
|
318 case button_press_event:
|
|
319 case button_release_event:
|
|
320 return HASH3 (hash, e->event.button.button, e->event.button.modifiers);
|
|
321
|
|
322 case pointer_motion_event:
|
|
323 return HASH3 (hash, e->event.motion.x, e->event.motion.y);
|
|
324
|
|
325 case misc_user_event:
|
|
326 case eval_event:
|
|
327 return HASH3 (hash, internal_hash (e->event.eval.function, depth + 1),
|
|
328 internal_hash (e->event.eval.object, depth + 1));
|
|
329
|
|
330 case magic_eval_event:
|
|
331 return HASH3 (hash,
|
|
332 (unsigned long) e->event.magic_eval.internal_function,
|
|
333 internal_hash (e->event.magic_eval.object, depth + 1));
|
|
334
|
|
335 case magic_event:
|
|
336 {
|
|
337 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (e));
|
|
338 #ifdef HAVE_X_WINDOWS
|
|
339 if (CONSOLE_X_P (XCONSOLE (console)))
|
|
340 return
|
|
341 HASH2 (hash,
|
|
342 memory_hash (&e->event.magic.underlying_x_event,
|
|
343 sizeof (e->event.magic.underlying_x_event)));
|
|
344 #endif
|
|
345 return
|
|
346 HASH2 (hash,
|
|
347 memory_hash (&e->event.magic.underlying_tty_event,
|
|
348 sizeof (e->event.magic.underlying_tty_event)));
|
|
349 }
|
|
350
|
|
351 case empty_event:
|
|
352 case dead_event:
|
|
353 return hash;
|
|
354
|
|
355 default:
|
|
356 abort ();
|
|
357 }
|
|
358
|
|
359 return 0;
|
|
360 }
|
|
361
|
|
362
|
|
363 /* #### This should accept a type and props (as returned by
|
|
364 event-properties) to allow creation of any type of event.
|
|
365 This is useful, for example, in Lisp code that might want
|
|
366 to determine if, for a given button-down event, what the
|
|
367 binding for the corresponding button-up event is. */
|
|
368
|
20
|
369 DEFUN ("make-event", Fmake_event, 0, 0, 0, /*
|
0
|
370 Create a new empty event.
|
|
371 WARNING, the event object returned may be a reused one; see the function
|
|
372 `deallocate-event'.
|
20
|
373 */
|
|
374 ())
|
0
|
375 {
|
|
376 Lisp_Object event;
|
|
377
|
|
378 if (!NILP (Vevent_resource))
|
|
379 {
|
|
380 event = Vevent_resource;
|
|
381 Vevent_resource = XEVENT_NEXT (event);
|
|
382 }
|
|
383 else
|
|
384 {
|
|
385 event = allocate_event ();
|
|
386 }
|
|
387 zero_event (XEVENT (event));
|
|
388 return event;
|
|
389 }
|
|
390
|
20
|
391 DEFUN ("deallocate-event", Fdeallocate_event, 1, 1, 0, /*
|
0
|
392 Allow the given event structure to be reused.
|
|
393 You MUST NOT use this event object after calling this function with it.
|
|
394 You will lose. It is not necessary to call this function, as event
|
|
395 objects are garbage-collected like all other objects; however, it may
|
|
396 be more efficient to explicitly deallocate events when you are sure
|
2
|
397 that it is safe to do so.
|
20
|
398 */
|
|
399 (event))
|
0
|
400 {
|
|
401 CHECK_EVENT (event);
|
|
402
|
|
403 if (XEVENT_TYPE (event) == dead_event)
|
|
404 error ("this event is already deallocated!");
|
|
405
|
|
406 assert (XEVENT_TYPE (event) <= last_event_type);
|
|
407
|
|
408 #if 0
|
173
|
409 {
|
|
410 int i, len;
|
0
|
411 extern Lisp_Object Vlast_command_event;
|
|
412 extern Lisp_Object Vlast_input_event, Vunread_command_event;
|
|
413 extern Lisp_Object Vthis_command_keys, Vrecent_keys_ring;
|
|
414
|
173
|
415 if (EQ (event, Vlast_command_event) ||
|
|
416 EQ (event, Vlast_input_event) ||
|
|
417 EQ (event, Vunread_command_event))
|
0
|
418 abort ();
|
173
|
419
|
|
420 len = XVECTOR_LENGTH (Vthis_command_keys);
|
|
421 for (i = 0; i < len; i++)
|
|
422 if (EQ (event, XVECTOR_DATA (Vthis_command_keys) [i]))
|
0
|
423 abort ();
|
153
|
424 if (!NILP (Vrecent_keys_ring))
|
|
425 {
|
173
|
426 int recent_ring_len = XVECTOR_LENGTH (Vrecent_keys_ring);
|
|
427 for (i = 0; i < recent_ring_len; i++)
|
|
428 if (EQ (event, XVECTOR_DATA (Vrecent_keys_ring) [i]))
|
153
|
429 abort ();
|
|
430 }
|
0
|
431 }
|
|
432 #endif /* 0 */
|
|
433
|
|
434 assert (!EQ (event, Vevent_resource));
|
|
435 deinitialize_event (event);
|
|
436 #ifndef ALLOC_NO_POOLS
|
|
437 XSET_EVENT_NEXT (event, Vevent_resource);
|
|
438 Vevent_resource = event;
|
|
439 #endif
|
|
440 return Qnil;
|
|
441 }
|
|
442
|
20
|
443 DEFUN ("copy-event", Fcopy_event, 1, 2, 0, /*
|
0
|
444 Make a copy of the given event object.
|
|
445 If a second argument is given, the first event is copied into the second
|
|
446 and the second is returned. If the second argument is not supplied (or
|
|
447 is nil) then a new event will be made as with `allocate-event.' See also
|
|
448 the function `deallocate-event'.
|
20
|
449 */
|
|
450 (event1, event2))
|
0
|
451 {
|
|
452 CHECK_LIVE_EVENT (event1);
|
|
453 if (NILP (event2))
|
|
454 event2 = Fmake_event ();
|
|
455 else CHECK_LIVE_EVENT (event2);
|
|
456 if (EQ (event1, event2))
|
|
457 return signal_simple_continuable_error_2
|
|
458 ("copy-event called with `eq' events", event1, event2);
|
|
459
|
|
460 assert (XEVENT_TYPE (event1) <= last_event_type);
|
|
461 assert (XEVENT_TYPE (event2) <= last_event_type);
|
|
462
|
|
463 {
|
|
464 Lisp_Object save_next = XEVENT_NEXT (event2);
|
|
465
|
|
466 *XEVENT (event2) = *XEVENT (event1);
|
|
467 XSET_EVENT_NEXT (event2, save_next);
|
173
|
468 return event2;
|
0
|
469 }
|
|
470 }
|
|
471
|
|
472
|
|
473
|
|
474 /* Given a chain of events (or possibly nil), deallocate them all. */
|
|
475
|
|
476 void
|
|
477 deallocate_event_chain (Lisp_Object event_chain)
|
|
478 {
|
|
479 while (!NILP (event_chain))
|
|
480 {
|
|
481 Lisp_Object next = XEVENT_NEXT (event_chain);
|
|
482 Fdeallocate_event (event_chain);
|
|
483 event_chain = next;
|
|
484 }
|
|
485 }
|
|
486
|
|
487 /* Return the last event in a chain.
|
|
488 NOTE: You cannot pass nil as a value here! The routine will
|
|
489 abort if you do. */
|
|
490
|
|
491 Lisp_Object
|
|
492 event_chain_tail (Lisp_Object event_chain)
|
|
493 {
|
|
494 while (1)
|
|
495 {
|
|
496 Lisp_Object next = XEVENT_NEXT (event_chain);
|
|
497 if (NILP (next))
|
|
498 return event_chain;
|
|
499 event_chain = next;
|
|
500 }
|
|
501 }
|
|
502
|
|
503 /* Enqueue a single event onto the end of a chain of events.
|
|
504 HEAD points to the first event in the chain, TAIL to the last event.
|
|
505 If the chain is empty, both values should be nil. */
|
|
506
|
|
507 void
|
|
508 enqueue_event (Lisp_Object event, Lisp_Object *head, Lisp_Object *tail)
|
|
509 {
|
|
510 assert (NILP (XEVENT_NEXT (event)));
|
|
511 assert (!EQ (*tail, event));
|
|
512
|
|
513 if (!NILP (*tail))
|
|
514 XSET_EVENT_NEXT (*tail, event);
|
|
515 else
|
|
516 *head = event;
|
|
517 *tail = event;
|
|
518
|
|
519 assert (!EQ (event, XEVENT_NEXT (event)));
|
|
520 }
|
|
521
|
|
522 /* Remove an event off the head of a chain of events and return it.
|
|
523 HEAD points to the first event in the chain, TAIL to the last event. */
|
173
|
524
|
0
|
525 Lisp_Object
|
|
526 dequeue_event (Lisp_Object *head, Lisp_Object *tail)
|
|
527 {
|
|
528 Lisp_Object event;
|
|
529
|
|
530 event = *head;
|
|
531 *head = XEVENT_NEXT (event);
|
|
532 XSET_EVENT_NEXT (event, Qnil);
|
|
533 if (NILP (*head))
|
|
534 *tail = Qnil;
|
|
535 return event;
|
|
536 }
|
|
537
|
|
538 /* Enqueue a chain of events (or possibly nil) onto the end of another
|
|
539 chain of events. HEAD points to the first event in the chain being
|
|
540 queued onto, TAIL to the last event. If the chain is empty, both values
|
|
541 should be nil. */
|
|
542
|
|
543 void
|
|
544 enqueue_event_chain (Lisp_Object event_chain, Lisp_Object *head,
|
|
545 Lisp_Object *tail)
|
|
546 {
|
|
547 if (NILP (event_chain))
|
|
548 return;
|
|
549
|
|
550 if (NILP (*head))
|
|
551 {
|
|
552 *head = event_chain;
|
|
553 *tail = event_chain;
|
|
554 }
|
|
555 else
|
|
556 {
|
|
557 XSET_EVENT_NEXT (*tail, event_chain);
|
|
558 *tail = event_chain_tail (event_chain);
|
|
559 }
|
|
560 }
|
|
561
|
|
562 /* Return the number of events (possibly 0) on an event chain. */
|
|
563
|
|
564 int
|
|
565 event_chain_count (Lisp_Object event_chain)
|
|
566 {
|
|
567 Lisp_Object event;
|
|
568 int n = 0;
|
|
569
|
|
570 EVENT_CHAIN_LOOP (event, event_chain)
|
|
571 n++;
|
|
572
|
|
573 return n;
|
|
574 }
|
|
575
|
|
576 /* Find the event before EVENT in an event chain. This aborts
|
|
577 if the event is not in the chain. */
|
|
578
|
|
579 Lisp_Object
|
|
580 event_chain_find_previous (Lisp_Object event_chain, Lisp_Object event)
|
|
581 {
|
|
582 Lisp_Object previous = Qnil;
|
|
583
|
|
584 while (!NILP (event_chain))
|
|
585 {
|
|
586 if (EQ (event_chain, event))
|
|
587 return previous;
|
|
588 previous = event_chain;
|
|
589 event_chain = XEVENT_NEXT (event_chain);
|
|
590 }
|
|
591
|
|
592 abort ();
|
|
593 return Qnil;
|
|
594 }
|
|
595
|
|
596 Lisp_Object
|
|
597 event_chain_nth (Lisp_Object event_chain, int n)
|
|
598 {
|
|
599 Lisp_Object event;
|
|
600 EVENT_CHAIN_LOOP (event, event_chain)
|
|
601 {
|
|
602 if (!n)
|
|
603 return event;
|
|
604 n--;
|
|
605 }
|
|
606 return Qnil;
|
|
607 }
|
|
608
|
|
609 Lisp_Object
|
|
610 copy_event_chain (Lisp_Object event_chain)
|
|
611 {
|
|
612 Lisp_Object new_chain = Qnil;
|
|
613 Lisp_Object new_chain_tail = Qnil;
|
|
614 Lisp_Object event;
|
|
615
|
|
616 EVENT_CHAIN_LOOP (event, event_chain)
|
|
617 {
|
|
618 Lisp_Object copy = Fcopy_event (event, Qnil);
|
|
619 enqueue_event (copy, &new_chain, &new_chain_tail);
|
|
620 }
|
|
621
|
|
622 return new_chain;
|
|
623 }
|
|
624
|
|
625
|
|
626
|
|
627 Lisp_Object QKbackspace, QKtab, QKlinefeed, QKreturn, QKescape,
|
|
628 QKspace, QKdelete;
|
|
629
|
|
630 int
|
|
631 command_event_p (Lisp_Object event)
|
|
632 {
|
|
633 switch (XEVENT_TYPE (event))
|
|
634 {
|
|
635 case key_press_event:
|
|
636 case button_press_event:
|
|
637 case button_release_event:
|
|
638 case misc_user_event:
|
173
|
639 return 1;
|
0
|
640 default:
|
173
|
641 return 0;
|
0
|
642 }
|
|
643 }
|
|
644
|
|
645
|
|
646 void
|
|
647 character_to_event (Emchar c, struct Lisp_Event *event, struct console *con,
|
|
648 int use_console_meta_flag)
|
|
649 {
|
|
650 Lisp_Object k = Qnil;
|
|
651 unsigned int m = 0;
|
|
652 if (event->event_type == dead_event)
|
|
653 error ("character-to-event called with a deallocated event!");
|
|
654
|
70
|
655 #ifndef MULE
|
0
|
656 c &= 255;
|
70
|
657 #endif
|
0
|
658 if (c > 127 && c <= 255)
|
|
659 {
|
|
660 int meta_flag = 1;
|
|
661 if (use_console_meta_flag && CONSOLE_TTY_P (con))
|
|
662 meta_flag = TTY_FLAGS (con).meta_key;
|
|
663 switch (meta_flag)
|
|
664 {
|
|
665 case 0: /* ignore top bit; it's parity */
|
|
666 c -= 128;
|
|
667 break;
|
|
668 case 1: /* top bit is meta */
|
|
669 c -= 128;
|
|
670 m = MOD_META;
|
|
671 break;
|
|
672 default: /* this is a real character */
|
|
673 break;
|
|
674 }
|
|
675 }
|
|
676 if (c < ' ') c += '@', m |= MOD_CONTROL;
|
|
677 if (m & MOD_CONTROL)
|
|
678 {
|
|
679 switch (c)
|
|
680 {
|
|
681 case 'I': k = QKtab; m &= ~MOD_CONTROL; break;
|
|
682 case 'J': k = QKlinefeed; m &= ~MOD_CONTROL; break;
|
|
683 case 'M': k = QKreturn; m &= ~MOD_CONTROL; break;
|
|
684 case '[': k = QKescape; m &= ~MOD_CONTROL; break;
|
|
685 # if 0
|
|
686 /* This is probably too controversial... */
|
|
687 case 'H': k = QKbackspace; m &= ~MOD_CONTROL; break;
|
|
688 # endif
|
|
689 }
|
|
690 if (c >= 'A' && c <= 'Z') c -= 'A'-'a';
|
|
691 }
|
|
692 else if (c == 127)
|
|
693 k = QKdelete;
|
|
694 else if (c == ' ')
|
|
695 k = QKspace;
|
173
|
696
|
2
|
697 event->event_type = key_press_event;
|
|
698 event->timestamp = 0; /* #### */
|
|
699 event->channel = make_console (con);
|
|
700 event->event.key.keysym = (!NILP (k) ? k : make_char (c));
|
|
701 event->event.key.modifiers = m;
|
0
|
702 }
|
|
703
|
|
704
|
|
705 /* This variable controls what character name -> character code mapping
|
|
706 we are using. Window-system-specific code sets this to some symbol,
|
|
707 and we use that symbol as the plist key to convert keysyms into 8-bit
|
|
708 codes. In this way one can have several character sets predefined and
|
|
709 switch them by changing this.
|
|
710 */
|
|
711 Lisp_Object Vcharacter_set_property;
|
|
712
|
|
713 Emchar
|
|
714 event_to_character (struct Lisp_Event *event,
|
|
715 int allow_extra_modifiers,
|
|
716 int allow_meta,
|
|
717 int allow_non_ascii)
|
|
718 {
|
|
719 Emchar c = 0;
|
|
720 Lisp_Object code;
|
|
721
|
|
722 if (event->event_type != key_press_event)
|
|
723 {
|
|
724 if (event->event_type == dead_event) abort ();
|
|
725 return -1;
|
|
726 }
|
|
727 if (!allow_extra_modifiers &&
|
|
728 event->event.key.modifiers & (MOD_SUPER|MOD_HYPER|MOD_ALT))
|
|
729 return -1;
|
|
730 if (CHAR_OR_CHAR_INTP (event->event.key.keysym))
|
|
731 c = XCHAR_OR_CHAR_INT (event->event.key.keysym);
|
|
732 else if (!SYMBOLP (event->event.key.keysym))
|
|
733 abort ();
|
|
734 else if (allow_non_ascii && !NILP (Vcharacter_set_property)
|
|
735 /* Allow window-system-specific extensibility of
|
|
736 keysym->code mapping */
|
|
737 && CHAR_OR_CHAR_INTP (code = Fget (event->event.key.keysym,
|
|
738 Vcharacter_set_property,
|
|
739 Qnil)))
|
|
740 c = XCHAR_OR_CHAR_INT (code);
|
|
741 else if (CHAR_OR_CHAR_INTP (code = Fget (event->event.key.keysym,
|
|
742 Qascii_character, Qnil)))
|
|
743 c = XCHAR_OR_CHAR_INT (code);
|
|
744 else
|
|
745 return -1;
|
|
746
|
|
747 if (event->event.key.modifiers & MOD_CONTROL)
|
|
748 {
|
|
749 if (c >= 'a' && c <= 'z')
|
|
750 c -= ('a' - 'A');
|
|
751 else
|
|
752 /* reject Control-Shift- keys */
|
|
753 if (c >= 'A' && c <= 'Z' && !allow_extra_modifiers)
|
|
754 return -1;
|
173
|
755
|
0
|
756 if (c >= '@' && c <= '_')
|
|
757 c -= '@';
|
|
758 else if (c == ' ') /* C-space and C-@ are the same. */
|
|
759 c = 0;
|
|
760 else
|
|
761 /* reject keys that can't take Control- modifiers */
|
|
762 if (! allow_extra_modifiers) return -1;
|
|
763 }
|
|
764
|
|
765 if (event->event.key.modifiers & MOD_META)
|
|
766 {
|
|
767 if (! allow_meta) return -1;
|
|
768 if (c & 0200) return -1; /* don't allow M-oslash (overlap) */
|
70
|
769 #ifdef MULE
|
|
770 if (c >= 256) return -1;
|
|
771 #endif
|
0
|
772 c |= 0200;
|
|
773 }
|
|
774 return c;
|
|
775 }
|
|
776
|
20
|
777 DEFUN ("event-to-character", Fevent_to_character, 1, 4, 0, /*
|
0
|
778 Return the closest ASCII approximation to the given event object.
|
|
779 If the event isn't a keypress, this returns nil.
|
|
780 If the ALLOW-EXTRA-MODIFIERS argument is non-nil, then this is lenient in
|
|
781 its translation; it will ignore modifier keys other than control and meta,
|
|
782 and will ignore the shift modifier on those characters which have no
|
|
783 shifted ASCII equivalent (Control-Shift-A for example, will be mapped to
|
|
784 the same ASCII code as Control-A).
|
|
785 If the ALLOW-META argument is non-nil, then the Meta modifier will be
|
|
786 represented by turning on the high bit of the byte returned; otherwise, nil
|
|
787 will be returned for events containing the Meta modifier.
|
|
788 If the ALLOW-NON-ASCII argument is non-nil, then characters which are
|
|
789 present in the prevailing character set (see the `character-set-property'
|
|
790 variable) will be returned as their code in that character set, instead of
|
|
791 the return value being restricted to ASCII.
|
|
792 Note that specifying both ALLOW-META and ALLOW-NON-ASCII is ambiguous, as
|
|
793 both use the high bit; `M-x' and `oslash' will be indistinguishable.
|
20
|
794 */
|
70
|
795 (event, allow_extra_modifiers, allow_meta, allow_non_ascii))
|
0
|
796 {
|
|
797 Emchar c;
|
|
798 CHECK_LIVE_EVENT (event);
|
|
799 c = event_to_character (XEVENT (event),
|
|
800 !NILP (allow_extra_modifiers),
|
|
801 !NILP (allow_meta),
|
|
802 !NILP (allow_non_ascii));
|
173
|
803 return c < 0 ? Qnil : make_char (c);
|
0
|
804 }
|
|
805
|
20
|
806 DEFUN ("character-to-event", Fcharacter_to_event, 1, 4, 0, /*
|
2
|
807 Converts a keystroke specifier into an event structure, replete with
|
0
|
808 bucky bits. The keystroke is the first argument, and the event to fill
|
|
809 in is the second. This function contains knowledge about what the codes
|
|
810 ``mean'' -- for example, the number 9 is converted to the character ``Tab'',
|
|
811 not the distinct character ``Control-I''.
|
|
812
|
|
813 Note that CH (the keystroke specifier) can be an integer, a character,
|
2
|
814 a symbol such as 'clear, or a list such as '(control backspace).
|
0
|
815
|
2
|
816 If the optional second argument is an event, it is modified;
|
|
817 otherwise, a new event object is created.
|
0
|
818
|
2
|
819 Optional third arg CONSOLE is the console to store in the event, and
|
|
820 defaults to the selected console.
|
0
|
821
|
|
822 If CH is an integer or character, the high bit may be interpreted as the
|
2
|
823 meta key. (This is done for backward compatibility in lots of places.)
|
|
824 If USE-CONSOLE-META-FLAG is nil, this will always be the case. If
|
|
825 USE-CONSOLE-META-FLAG is non-nil, the `meta' flag for CONSOLE affects
|
|
826 whether the high bit is interpreted as a meta key. (See `set-input-mode'.)
|
|
827 If you don't want this silly meta interpretation done, you should pass
|
|
828 in a list containing the character.
|
0
|
829
|
|
830 Beware that character-to-event and event-to-character are not strictly
|
2
|
831 inverse functions, since events contain much more information than the
|
|
832 ASCII character set can encode.
|
20
|
833 */
|
|
834 (ch, event, console, use_console_meta_flag))
|
0
|
835 {
|
|
836 struct console *con = decode_console (console);
|
|
837 if (NILP (event))
|
|
838 event = Fmake_event ();
|
|
839 else
|
|
840 CHECK_LIVE_EVENT (event);
|
|
841 if (CONSP (ch) || SYMBOLP (ch))
|
|
842 key_desc_list_to_event (ch, event, 1);
|
|
843 else
|
|
844 {
|
|
845 CHECK_CHAR_COERCE_INT (ch);
|
|
846 character_to_event (XCHAR (ch), XEVENT (event), con,
|
|
847 !NILP (use_console_meta_flag));
|
|
848 }
|
|
849 return event;
|
|
850 }
|
|
851
|
|
852 void
|
|
853 nth_of_key_sequence_as_event (Lisp_Object seq, int n, Lisp_Object event)
|
|
854 {
|
|
855 assert (STRINGP (seq) || VECTORP (seq));
|
|
856 assert (n < XINT (Flength (seq)));
|
|
857
|
|
858 if (STRINGP (seq))
|
|
859 {
|
|
860 Emchar ch = string_char (XSTRING (seq), n);
|
|
861 Fcharacter_to_event (make_char (ch), event, Qnil, Qnil);
|
|
862 }
|
|
863 else
|
|
864 {
|
173
|
865 Lisp_Object keystroke = XVECTOR_DATA (seq)[n];
|
0
|
866 if (EVENTP (keystroke))
|
|
867 Fcopy_event (keystroke, event);
|
|
868 else
|
|
869 Fcharacter_to_event (keystroke, event, Qnil, Qnil);
|
|
870 }
|
|
871 }
|
|
872
|
|
873 Lisp_Object
|
|
874 key_sequence_to_event_chain (Lisp_Object seq)
|
|
875 {
|
|
876 int len = XINT (Flength (seq));
|
|
877 int i;
|
|
878 Lisp_Object head = Qnil, tail = Qnil;
|
|
879
|
|
880 for (i = 0; i < len; i++)
|
|
881 {
|
|
882 Lisp_Object event = Fmake_event ();
|
|
883 nth_of_key_sequence_as_event (seq, i, event);
|
|
884 enqueue_event (event, &head, &tail);
|
|
885 }
|
|
886
|
|
887 return head;
|
|
888 }
|
|
889
|
|
890 void
|
|
891 format_event_object (char *buf, struct Lisp_Event *event, int brief)
|
|
892 {
|
|
893 int mouse_p = 0;
|
|
894 int mod = 0;
|
|
895 Lisp_Object key;
|
|
896
|
|
897 switch (event->event_type)
|
|
898 {
|
|
899 case key_press_event:
|
|
900 {
|
|
901 mod = event->event.key.modifiers;
|
|
902 key = event->event.key.keysym;
|
|
903 /* Hack. */
|
|
904 if (! brief && CHARP (key) &&
|
|
905 mod & (MOD_CONTROL | MOD_META | MOD_SUPER | MOD_HYPER))
|
|
906 {
|
|
907 int k = XCHAR (key);
|
|
908 if (k >= 'a' && k <= 'z')
|
|
909 key = make_char (k - ('a' - 'A'));
|
|
910 else if (k >= 'A' && k <= 'Z')
|
|
911 mod |= MOD_SHIFT;
|
|
912 }
|
|
913 break;
|
|
914 }
|
|
915 case button_release_event:
|
|
916 mouse_p++;
|
|
917 /* Fall through */
|
|
918 case button_press_event:
|
|
919 {
|
|
920 mouse_p++;
|
|
921 mod = event->event.button.modifiers;
|
|
922 key = make_char (event->event.button.button + '0');
|
|
923 break;
|
|
924 }
|
|
925 case magic_event:
|
|
926 {
|
|
927 CONST char *name = 0;
|
|
928 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (event));
|
|
929
|
|
930 #ifdef HAVE_X_WINDOWS
|
|
931 if (CONSOLE_X_P (XCONSOLE (console)))
|
|
932 name =
|
|
933 x_event_name (event->event.magic.underlying_x_event.xany.type);
|
|
934 #endif
|
|
935 if (name) strcpy (buf, name);
|
|
936 else strcpy (buf, "???");
|
|
937 return;
|
|
938 }
|
|
939 case magic_eval_event: strcpy (buf, "magic-eval"); return;
|
|
940 case pointer_motion_event: strcpy (buf, "motion"); return;
|
|
941 case misc_user_event: strcpy (buf, "misc-user"); return;
|
|
942 case eval_event: strcpy (buf, "eval"); return;
|
|
943 case process_event: strcpy (buf, "process");return;
|
|
944 case timeout_event: strcpy (buf, "timeout");return;
|
149
|
945 case empty_event: strcpy (buf, "empty"); return;
|
0
|
946 case dead_event: strcpy (buf, "DEAD-EVENT"); return;
|
|
947 default:
|
|
948 abort ();
|
|
949 }
|
|
950 #define modprint1(x) { strcpy (buf, (x)); buf += sizeof (x)-1; }
|
|
951 #define modprint(x,y) { if (brief) modprint1 (y) else modprint1 (x) }
|
|
952 if (mod & MOD_CONTROL) modprint ("control-", "C-");
|
|
953 if (mod & MOD_META) modprint ("meta-", "M-");
|
|
954 if (mod & MOD_SUPER) modprint ("super-", "S-");
|
|
955 if (mod & MOD_HYPER) modprint ("hyper-", "H-");
|
|
956 if (mod & MOD_ALT) modprint ("alt-", "A-");
|
|
957 if (mod & MOD_SHIFT) modprint ("shift-", "Sh-");
|
|
958 if (mouse_p)
|
|
959 {
|
|
960 modprint1 ("button");
|
|
961 --mouse_p;
|
|
962 }
|
|
963 #undef modprint
|
|
964 #undef modprint1
|
|
965
|
|
966 if (CHARP (key))
|
|
967 {
|
|
968 buf += set_charptr_emchar ((Bufbyte *) buf, XCHAR (key));
|
|
969 *buf = 0;
|
|
970 }
|
|
971 else if (SYMBOLP (key))
|
|
972 {
|
|
973 CONST char *str = 0;
|
|
974 if (brief)
|
|
975 {
|
|
976 if (EQ (key, QKlinefeed)) str = "LFD";
|
|
977 else if (EQ (key, QKtab)) str = "TAB";
|
|
978 else if (EQ (key, QKreturn)) str = "RET";
|
|
979 else if (EQ (key, QKescape)) str = "ESC";
|
|
980 else if (EQ (key, QKdelete)) str = "DEL";
|
|
981 else if (EQ (key, QKspace)) str = "SPC";
|
|
982 else if (EQ (key, QKbackspace)) str = "BS";
|
|
983 }
|
|
984 if (str)
|
|
985 {
|
|
986 int i = strlen (str);
|
|
987 memcpy (buf, str, i+1);
|
|
988 str += i;
|
|
989 }
|
|
990 else
|
|
991 {
|
|
992 memcpy (buf, string_data (XSYMBOL (key)->name),
|
|
993 string_length (XSYMBOL (key)->name) + 1);
|
|
994 str += string_length (XSYMBOL (key)->name);
|
|
995 }
|
|
996 }
|
|
997 else
|
|
998 abort ();
|
|
999 if (mouse_p)
|
|
1000 strncpy (buf, "up", 4);
|
|
1001 }
|
|
1002
|
20
|
1003 DEFUN ("eventp", Feventp, 1, 1, 0, /*
|
0
|
1004 True if OBJECT is an event object.
|
20
|
1005 */
|
|
1006 (object))
|
0
|
1007 {
|
149
|
1008 return EVENTP (object) ? Qt : Qnil;
|
0
|
1009 }
|
|
1010
|
20
|
1011 DEFUN ("event-live-p", Fevent_live_p, 1, 1, 0, /*
|
0
|
1012 True if OBJECT is an event object that has not been deallocated.
|
20
|
1013 */
|
|
1014 (object))
|
0
|
1015 {
|
149
|
1016 return EVENTP (object) && XEVENT (object)->event_type != dead_event ?
|
|
1017 Qt : Qnil;
|
0
|
1018 }
|
|
1019
|
|
1020 #if 0 /* debugging functions */
|
|
1021
|
149
|
1022 xxDEFUN ("event-next", Fevent_next, 1, 1, 0, /*
|
0
|
1023 Return the event object's `next' event, or nil if it has none.
|
|
1024 The `next-event' field is changed by calling `set-next-event'.
|
149
|
1025 */
|
|
1026 (event))
|
0
|
1027 {
|
|
1028 struct Lisp_Event *e;
|
|
1029 CHECK_LIVE_EVENT (event);
|
|
1030
|
|
1031 return XEVENT_NEXT (event);
|
|
1032 }
|
|
1033
|
149
|
1034 xxDEFUN ("set-event-next", Fset_event_next, 2, 2, 0, /*
|
0
|
1035 Set the `next event' of EVENT to NEXT-EVENT.
|
|
1036 NEXT-EVENT must be an event object or nil.
|
149
|
1037 */
|
|
1038 (event, next_event))
|
0
|
1039 {
|
|
1040 Lisp_Object ev;
|
|
1041
|
|
1042 CHECK_LIVE_EVENT (event);
|
|
1043 if (NILP (next_event))
|
|
1044 {
|
|
1045 XSET_EVENT_NEXT (event, Qnil);
|
173
|
1046 return Qnil;
|
0
|
1047 }
|
|
1048
|
|
1049 CHECK_LIVE_EVENT (next_event);
|
|
1050
|
|
1051 EVENT_CHAIN_LOOP (ev, XEVENT_NEXT (event))
|
|
1052 {
|
|
1053 QUIT;
|
|
1054 if (EQ (ev, event))
|
173
|
1055 signal_error (Qerror,
|
0
|
1056 list3 (build_string ("Cyclic event-next"),
|
173
|
1057 event,
|
0
|
1058 next_event));
|
|
1059 }
|
|
1060 XSET_EVENT_NEXT (event, next_event);
|
149
|
1061 return next_event;
|
0
|
1062 }
|
|
1063
|
|
1064 #endif /* 0 */
|
|
1065
|
20
|
1066 DEFUN ("event-type", Fevent_type, 1, 1, 0, /*
|
0
|
1067 Return the type of EVENT.
|
|
1068 This will be a symbol; one of
|
|
1069
|
|
1070 key-press A key was pressed.
|
|
1071 button-press A mouse button was pressed.
|
|
1072 button-release A mouse button was released.
|
|
1073 misc-user Some other user action happened; typically, this is
|
|
1074 a menu selection or scrollbar action.
|
|
1075 motion The mouse moved.
|
|
1076 process Input is available from a subprocess.
|
|
1077 timeout A timeout has expired.
|
|
1078 eval This causes a specified action to occur when dispatched.
|
|
1079 magic Some window-system-specific event has occurred.
|
122
|
1080 empty The event has been allocated but not assigned.
|
|
1081
|
20
|
1082 */
|
|
1083 (event))
|
0
|
1084 {
|
|
1085 CHECK_LIVE_EVENT (event);
|
|
1086 switch (XEVENT (event)->event_type)
|
|
1087 {
|
149
|
1088 case key_press_event: return Qkey_press;
|
|
1089 case button_press_event: return Qbutton_press;
|
|
1090 case button_release_event: return Qbutton_release;
|
|
1091 case misc_user_event: return Qmisc_user;
|
|
1092 case pointer_motion_event: return Qmotion;
|
|
1093 case process_event: return Qprocess;
|
|
1094 case timeout_event: return Qtimeout;
|
|
1095 case eval_event: return Qeval;
|
0
|
1096 case magic_event:
|
|
1097 case magic_eval_event:
|
|
1098 return Qmagic;
|
|
1099
|
122
|
1100 case empty_event:
|
|
1101 return Qempty;
|
|
1102
|
0
|
1103 default:
|
|
1104 abort ();
|
|
1105 return Qnil;
|
|
1106 }
|
|
1107 }
|
|
1108
|
20
|
1109 DEFUN ("event-timestamp", Fevent_timestamp, 1, 1, 0, /*
|
149
|
1110 Return the timestamp of the event object EVENT.
|
20
|
1111 */
|
|
1112 (event))
|
0
|
1113 {
|
|
1114 CHECK_LIVE_EVENT (event);
|
|
1115 /* This junk is so that timestamps don't get to be negative, but contain
|
|
1116 as many bits as this particular emacs will allow.
|
|
1117 */
|
|
1118 return make_int (((1L << (VALBITS - 1)) - 1) &
|
|
1119 XEVENT (event)->timestamp);
|
|
1120 }
|
|
1121
|
|
1122 #define CHECK_EVENT_TYPE(e,t1,sym) \
|
|
1123 { CHECK_LIVE_EVENT (e); \
|
|
1124 if (XEVENT(e)->event_type != (t1)) \
|
|
1125 e = wrong_type_argument ((sym),(e)); \
|
|
1126 }
|
|
1127
|
|
1128 #define CHECK_EVENT_TYPE2(e,t1,t2,sym) \
|
|
1129 { CHECK_LIVE_EVENT (e); \
|
|
1130 if (XEVENT(e)->event_type != (t1) && XEVENT(e)->event_type != (t2)) \
|
|
1131 e = wrong_type_argument ((sym),(e)); \
|
|
1132 }
|
|
1133
|
20
|
1134 DEFUN ("event-key", Fevent_key, 1, 1, 0, /*
|
149
|
1135 Return the Keysym of the key-press event EVENT.
|
|
1136 This will be a character if the event is associated with one, else a symbol.
|
20
|
1137 */
|
|
1138 (event))
|
0
|
1139 {
|
|
1140 CHECK_EVENT_TYPE (event, key_press_event, Qkey_press_event_p);
|
149
|
1141 return XEVENT (event)->event.key.keysym;
|
0
|
1142 }
|
|
1143
|
20
|
1144 DEFUN ("event-button", Fevent_button, 1, 1, 0, /*
|
149
|
1145 Return the button-number of the given button-press or button-release event.
|
20
|
1146 */
|
|
1147 (event))
|
0
|
1148 {
|
|
1149 CHECK_EVENT_TYPE2 (event, button_press_event, button_release_event,
|
|
1150 Qbutton_event_p);
|
|
1151 #ifdef HAVE_WINDOW_SYSTEM
|
|
1152 return make_int (XEVENT (event)->event.button.button);
|
|
1153 #else /* !HAVE_WINDOW_SYSTEM */
|
|
1154 return Qzero;
|
|
1155 #endif /* !HAVE_WINDOW_SYSTEM */
|
|
1156 }
|
|
1157
|
20
|
1158 DEFUN ("event-modifier-bits", Fevent_modifier_bits, 1, 1, 0, /*
|
0
|
1159 Return a number representing the modifier keys which were down
|
|
1160 when the given mouse or keyboard event was produced. See also the function
|
|
1161 event-modifiers.
|
20
|
1162 */
|
|
1163 (event))
|
0
|
1164 {
|
|
1165 again:
|
|
1166 CHECK_LIVE_EVENT (event);
|
|
1167 if (XEVENT (event)->event_type == key_press_event)
|
|
1168 return make_int (XEVENT (event)->event.key.modifiers);
|
|
1169 else if (XEVENT (event)->event_type == button_press_event ||
|
|
1170 XEVENT (event)->event_type == button_release_event)
|
|
1171 return make_int (XEVENT (event)->event.button.modifiers);
|
|
1172 else if (XEVENT (event)->event_type == pointer_motion_event)
|
|
1173 return make_int (XEVENT (event)->event.motion.modifiers);
|
|
1174 else
|
|
1175 {
|
|
1176 event = wrong_type_argument (intern ("key-or-mouse-event-p"), event);
|
|
1177 goto again;
|
|
1178 }
|
|
1179 }
|
|
1180
|
20
|
1181 DEFUN ("event-modifiers", Fevent_modifiers, 1, 1, 0, /*
|
0
|
1182 Return a list of symbols, the names of the modifier keys
|
|
1183 which were down when the given mouse or keyboard event was produced.
|
|
1184 See also the function event-modifier-bits.
|
20
|
1185 */
|
|
1186 (event))
|
0
|
1187 {
|
|
1188 int mod = XINT (Fevent_modifier_bits (event));
|
|
1189 Lisp_Object result = Qnil;
|
|
1190 if (mod & MOD_SHIFT) result = Fcons (Qshift, result);
|
|
1191 if (mod & MOD_ALT) result = Fcons (Qalt, result);
|
|
1192 if (mod & MOD_HYPER) result = Fcons (Qhyper, result);
|
|
1193 if (mod & MOD_SUPER) result = Fcons (Qsuper, result);
|
|
1194 if (mod & MOD_META) result = Fcons (Qmeta, result);
|
|
1195 if (mod & MOD_CONTROL) result = Fcons (Qcontrol, result);
|
|
1196 return result;
|
|
1197 }
|
|
1198
|
|
1199 static int
|
|
1200 event_x_y_pixel_internal (Lisp_Object event, int *x, int *y, int relative)
|
|
1201 {
|
|
1202 struct window *w;
|
|
1203 struct frame *f;
|
|
1204
|
|
1205 if (XEVENT (event)->event_type == pointer_motion_event)
|
|
1206 {
|
|
1207 *x = XEVENT (event)->event.motion.x;
|
|
1208 *y = XEVENT (event)->event.motion.y;
|
|
1209 }
|
|
1210 else if (XEVENT (event)->event_type == button_press_event ||
|
|
1211 XEVENT (event)->event_type == button_release_event)
|
|
1212 {
|
|
1213 *x = XEVENT (event)->event.button.x;
|
|
1214 *y = XEVENT (event)->event.button.y;
|
|
1215 }
|
|
1216 else
|
|
1217 return 0;
|
|
1218
|
|
1219 f = XFRAME (EVENT_CHANNEL (XEVENT (event)));
|
|
1220
|
|
1221 if (relative)
|
|
1222 {
|
|
1223 w = find_window_by_pixel_pos (*x, *y, f->root_window);
|
|
1224
|
|
1225 if (!w)
|
|
1226 return 1; /* #### What should really happen here. */
|
|
1227
|
|
1228 *x -= w->pixel_left;
|
|
1229 *y -= w->pixel_top;
|
|
1230 }
|
|
1231 else
|
|
1232 {
|
|
1233 *y -= FRAME_REAL_TOP_TOOLBAR_HEIGHT (f);
|
|
1234 *x -= FRAME_REAL_LEFT_TOOLBAR_WIDTH (f);
|
|
1235 }
|
|
1236
|
|
1237 return 1;
|
|
1238 }
|
|
1239
|
20
|
1240 DEFUN ("event-window-x-pixel", Fevent_window_x_pixel, 1, 1, 0, /*
|
149
|
1241 Return the X position in pixels of mouse event EVENT.
|
0
|
1242 The value returned is relative to the window the event occurred in.
|
149
|
1243 This will signal an error if the event is not a mouse event.
|
|
1244 See also `mouse-event-p' and `event-x-pixel'.
|
20
|
1245 */
|
|
1246 (event))
|
0
|
1247 {
|
|
1248 int x, y;
|
|
1249
|
|
1250 CHECK_LIVE_EVENT (event);
|
|
1251
|
|
1252 if (!event_x_y_pixel_internal (event, &x, &y, 1))
|
|
1253 return wrong_type_argument (Qmouse_event_p, event);
|
|
1254 else
|
|
1255 return make_int (x);
|
|
1256 }
|
|
1257
|
20
|
1258 DEFUN ("event-window-y-pixel", Fevent_window_y_pixel, 1, 1, 0, /*
|
149
|
1259 Return the Y position in pixels of mouse event EVENT.
|
0
|
1260 The value returned is relative to the window the event occurred in.
|
149
|
1261 This will signal an error if the event is not a mouse event.
|
|
1262 See also `mouse-event-p' and `event-y-pixel'.
|
20
|
1263 */
|
|
1264 (event))
|
0
|
1265 {
|
|
1266 int x, y;
|
|
1267
|
|
1268 CHECK_LIVE_EVENT (event);
|
|
1269
|
|
1270 if (!event_x_y_pixel_internal (event, &x, &y, 1))
|
|
1271 return wrong_type_argument (Qmouse_event_p, event);
|
|
1272 else
|
|
1273 return make_int (y);
|
|
1274 }
|
|
1275
|
20
|
1276 DEFUN ("event-x-pixel", Fevent_x_pixel, 1, 1, 0, /*
|
149
|
1277 Return the X position in pixels of mouse event EVENT.
|
0
|
1278 The value returned is relative to the frame the event occurred in.
|
149
|
1279 This will signal an error if the event is not a mouse event.
|
|
1280 See also `mouse-event-p' and `event-window-x-pixel'.
|
20
|
1281 */
|
|
1282 (event))
|
0
|
1283 {
|
|
1284 int x, y;
|
|
1285
|
|
1286 CHECK_LIVE_EVENT (event);
|
|
1287
|
|
1288 if (!event_x_y_pixel_internal (event, &x, &y, 0))
|
|
1289 return wrong_type_argument (Qmouse_event_p, event);
|
|
1290 else
|
|
1291 return make_int (x);
|
|
1292 }
|
|
1293
|
20
|
1294 DEFUN ("event-y-pixel", Fevent_y_pixel, 1, 1, 0, /*
|
149
|
1295 Return the Y position in pixels of mouse event EVENT.
|
0
|
1296 The value returned is relative to the frame the event occurred in.
|
149
|
1297 This will signal an error if the event is not a mouse event.
|
|
1298 See also `mouse-event-p' `event-window-y-pixel'.
|
20
|
1299 */
|
|
1300 (event))
|
0
|
1301 {
|
|
1302 int x, y;
|
|
1303
|
|
1304 CHECK_LIVE_EVENT (event);
|
|
1305
|
|
1306 if (!event_x_y_pixel_internal (event, &x, &y, 0))
|
|
1307 return wrong_type_argument (Qmouse_event_p, event);
|
|
1308 else
|
|
1309 return make_int (y);
|
|
1310 }
|
|
1311
|
|
1312 /* Given an event, return a value:
|
|
1313
|
|
1314 OVER_TOOLBAR: over one of the 4 frame toolbars
|
|
1315 OVER_MODELINE: over a modeline
|
|
1316 OVER_BORDER: over an internal border
|
|
1317 OVER_NOTHING: over the text area, but not over text
|
|
1318 OVER_OUTSIDE: outside of the frame border
|
|
1319 OVER_TEXT: over text in the text area
|
|
1320
|
|
1321 and return:
|
|
1322
|
|
1323 The X char position in CHAR_X, if not a null pointer.
|
|
1324 The Y char position in CHAR_Y, if not a null pointer.
|
|
1325 (These last two values are relative to the window the event is over.)
|
|
1326 The window it's over in W, if not a null pointer.
|
|
1327 The buffer position it's over in BUFP, if not a null pointer.
|
|
1328 The closest buffer position in CLOSEST, if not a null pointer.
|
|
1329
|
|
1330 OBJ_X, OBJ_Y, OBJ1, and OBJ2 are as in pixel_to_glyph_translation().
|
|
1331 */
|
173
|
1332
|
0
|
1333 static int
|
|
1334 event_pixel_translation (Lisp_Object event, int *char_x, int *char_y,
|
|
1335 int *obj_x, int *obj_y,
|
|
1336 struct window **w, Bufpos *bufp, Bufpos *closest,
|
|
1337 Charcount *modeline_closest,
|
|
1338 Lisp_Object *obj1, Lisp_Object *obj2)
|
|
1339 {
|
|
1340 int pix_x = 0;
|
|
1341 int pix_y = 0;
|
|
1342 int result;
|
173
|
1343 Lisp_Object frame = Qnil;
|
0
|
1344
|
|
1345 int ret_x, ret_y, ret_obj_x, ret_obj_y;
|
|
1346 struct window *ret_w;
|
|
1347 Bufpos ret_bufp, ret_closest;
|
|
1348 Charcount ret_modeline_closest;
|
|
1349 Lisp_Object ret_obj1, ret_obj2;
|
173
|
1350
|
0
|
1351 CHECK_LIVE_EVENT (event);
|
173
|
1352 frame = XEVENT (event)->channel;
|
|
1353 switch (XEVENT (event)->event_type)
|
0
|
1354 {
|
173
|
1355 case pointer_motion_event :
|
0
|
1356 pix_x = XEVENT (event)->event.motion.x;
|
|
1357 pix_y = XEVENT (event)->event.motion.y;
|
173
|
1358 break;
|
|
1359 case button_press_event :
|
|
1360 case button_release_event :
|
0
|
1361 pix_x = XEVENT (event)->event.button.x;
|
|
1362 pix_y = XEVENT (event)->event.button.y;
|
173
|
1363 break;
|
|
1364 default:
|
|
1365 dead_wrong_type_argument (Qmouse_event_p, event);
|
0
|
1366 }
|
|
1367
|
|
1368 result = pixel_to_glyph_translation (XFRAME (frame), pix_x, pix_y,
|
|
1369 &ret_x, &ret_y, &ret_obj_x, &ret_obj_y,
|
|
1370 &ret_w, &ret_bufp, &ret_closest,
|
|
1371 &ret_modeline_closest,
|
|
1372 &ret_obj1, &ret_obj2);
|
|
1373
|
|
1374 if (result == OVER_NOTHING || result == OVER_OUTSIDE)
|
|
1375 ret_bufp = 0;
|
|
1376 else if (ret_w && NILP (ret_w->buffer))
|
|
1377 /* Why does this happen? (Does it still happen?)
|
|
1378 I guess the window has gotten reused as a non-leaf... */
|
|
1379 ret_w = 0;
|
|
1380
|
|
1381 /* #### pixel_to_glyph_translation() sometimes returns garbage...
|
|
1382 The word has type Lisp_Record (presumably meaning `extent') but the
|
|
1383 pointer points to random memory, often filled with 0, sometimes not.
|
|
1384 */
|
|
1385 /* #### Chuck, do we still need this crap? */
|
|
1386 if (!NILP (ret_obj1) && !(GLYPHP (ret_obj1)
|
|
1387 #ifdef HAVE_TOOLBARS
|
|
1388 || TOOLBAR_BUTTONP (ret_obj1)
|
|
1389 #endif
|
|
1390 ))
|
|
1391 abort ();
|
173
|
1392 if (!NILP (ret_obj2) && !(EXTENTP (ret_obj2) || CONSP (ret_obj2)))
|
0
|
1393 abort ();
|
|
1394
|
|
1395 if (char_x)
|
|
1396 *char_x = ret_x;
|
|
1397 if (char_y)
|
|
1398 *char_y = ret_y;
|
|
1399 if (obj_x)
|
|
1400 *obj_x = ret_obj_x;
|
|
1401 if (obj_y)
|
|
1402 *obj_y = ret_obj_y;
|
|
1403 if (w)
|
|
1404 *w = ret_w;
|
|
1405 if (bufp)
|
|
1406 *bufp = ret_bufp;
|
|
1407 if (closest)
|
|
1408 *closest = ret_closest;
|
|
1409 if (modeline_closest)
|
|
1410 *modeline_closest = ret_modeline_closest;
|
|
1411 if (obj1)
|
|
1412 *obj1 = ret_obj1;
|
|
1413 if (obj2)
|
|
1414 *obj2 = ret_obj2;
|
|
1415
|
|
1416 return result;
|
|
1417 }
|
|
1418
|
20
|
1419 DEFUN ("event-over-text-area-p", Fevent_over_text_area_p, 1, 1, 0, /*
|
149
|
1420 Return t if the mouse event EVENT occurred over the text area of a window.
|
0
|
1421 The modeline is not considered to be part of the text area.
|
20
|
1422 */
|
|
1423 (event))
|
0
|
1424 {
|
|
1425 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1426
|
149
|
1427 return result == OVER_TEXT || result == OVER_NOTHING ? Qt : Qnil;
|
0
|
1428 }
|
|
1429
|
20
|
1430 DEFUN ("event-over-modeline-p", Fevent_over_modeline_p, 1, 1, 0, /*
|
149
|
1431 Return t if the mouse event EVENT occurred over the modeline of a window.
|
20
|
1432 */
|
|
1433 (event))
|
0
|
1434 {
|
|
1435 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1436
|
149
|
1437 return result == OVER_MODELINE ? Qt : Qnil;
|
0
|
1438 }
|
|
1439
|
20
|
1440 DEFUN ("event-over-border-p", Fevent_over_border_p, 1, 1, 0, /*
|
149
|
1441 Return t if the mouse event EVENT occurred over an internal border.
|
20
|
1442 */
|
|
1443 (event))
|
0
|
1444 {
|
|
1445 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1446
|
149
|
1447 return result == OVER_BORDER ? Qt : Qnil;
|
0
|
1448 }
|
|
1449
|
20
|
1450 DEFUN ("event-over-toolbar-p", Fevent_over_toolbar_p, 1, 1, 0, /*
|
149
|
1451 Return t if the mouse event EVENT occurred over a toolbar.
|
20
|
1452 */
|
|
1453 (event))
|
0
|
1454 {
|
|
1455 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1456
|
149
|
1457 return result == OVER_TOOLBAR ? Qt : Qnil;
|
0
|
1458 }
|
|
1459
|
|
1460 struct console *
|
|
1461 event_console_or_selected (Lisp_Object event)
|
|
1462 {
|
|
1463 Lisp_Object channel = EVENT_CHANNEL (XEVENT (event));
|
|
1464 Lisp_Object console = CDFW_CONSOLE (channel);
|
|
1465
|
|
1466 if (NILP (console))
|
|
1467 console = Vselected_console;
|
|
1468
|
|
1469 return XCONSOLE (console);
|
|
1470 }
|
|
1471
|
20
|
1472 DEFUN ("event-channel", Fevent_channel, 1, 1, 0, /*
|
149
|
1473 Return the channel that the event EVENT occurred on.
|
0
|
1474 This will be a frame, device, console, or nil for some types
|
|
1475 of events (e.g. eval events).
|
20
|
1476 */
|
|
1477 (event))
|
0
|
1478 {
|
|
1479 CHECK_LIVE_EVENT (event);
|
|
1480 return EVENT_CHANNEL (XEVENT (event));
|
|
1481 }
|
|
1482
|
20
|
1483 DEFUN ("event-window", Fevent_window, 1, 1, 0, /*
|
149
|
1484 Return the window over which mouse event EVENT occurred.
|
0
|
1485 This may be nil if the event occurred in the border or over a toolbar.
|
149
|
1486 The modeline is considered to be within the window it describes.
|
20
|
1487 */
|
|
1488 (event))
|
0
|
1489 {
|
|
1490 struct window *w;
|
|
1491
|
|
1492 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, 0, 0);
|
|
1493
|
|
1494 if (!w)
|
|
1495 return Qnil;
|
|
1496 else
|
|
1497 {
|
149
|
1498 Lisp_Object window;
|
|
1499
|
0
|
1500 XSETWINDOW (window, w);
|
|
1501 return window;
|
|
1502 }
|
|
1503 }
|
|
1504
|
20
|
1505 DEFUN ("event-point", Fevent_point, 1, 1, 0, /*
|
149
|
1506 Return the character position of the mouse event EVENT.
|
0
|
1507 If the event did not occur over a window, or did not occur over text,
|
149
|
1508 then this returns nil. Otherwise, it returns a position in the buffer
|
0
|
1509 visible in the event's window.
|
20
|
1510 */
|
|
1511 (event))
|
0
|
1512 {
|
|
1513 Bufpos bufp;
|
|
1514 struct window *w;
|
|
1515
|
|
1516 event_pixel_translation (event, 0, 0, 0, 0, &w, &bufp, 0, 0, 0, 0);
|
|
1517
|
149
|
1518 return w && bufp ? make_int (bufp) : Qnil;
|
0
|
1519 }
|
|
1520
|
20
|
1521 DEFUN ("event-closest-point", Fevent_closest_point, 1, 1, 0, /*
|
149
|
1522 Return the character position closest to the mouse event EVENT.
|
0
|
1523 If the event did not occur over a window or over text, return the
|
|
1524 closest point to the location of the event. If the Y pixel position
|
|
1525 overlaps a window and the X pixel position is to the left of that
|
|
1526 window, the closest point is the beginning of the line containing the
|
|
1527 Y position. If the Y pixel position overlaps a window and the X pixel
|
|
1528 position is to the right of that window, the closest point is the end
|
|
1529 of the line containing the Y position. If the Y pixel position is
|
149
|
1530 above a window, return 0. If it is below the last character in a window,
|
|
1531 return the value of (window-end).
|
20
|
1532 */
|
|
1533 (event))
|
0
|
1534 {
|
|
1535 Bufpos bufp;
|
|
1536
|
|
1537 event_pixel_translation (event, 0, 0, 0, 0, 0, 0, &bufp, 0, 0, 0);
|
|
1538
|
149
|
1539 return bufp ? make_int (bufp) : Qnil;
|
0
|
1540 }
|
|
1541
|
20
|
1542 DEFUN ("event-x", Fevent_x, 1, 1, 0, /*
|
149
|
1543 Return the X position of the mouse event EVENT in characters.
|
0
|
1544 This is relative to the window the event occurred over.
|
20
|
1545 */
|
|
1546 (event))
|
0
|
1547 {
|
|
1548 int char_x;
|
|
1549
|
|
1550 event_pixel_translation (event, &char_x, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1551
|
|
1552 return make_int (char_x);
|
|
1553 }
|
|
1554
|
20
|
1555 DEFUN ("event-y", Fevent_y, 1, 1, 0, /*
|
149
|
1556 Return the Y position of the mouse event EVENT in characters.
|
0
|
1557 This is relative to the window the event occurred over.
|
20
|
1558 */
|
|
1559 (event))
|
0
|
1560 {
|
|
1561 int char_y;
|
|
1562
|
|
1563 event_pixel_translation (event, 0, &char_y, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1564
|
|
1565 return make_int (char_y);
|
|
1566 }
|
|
1567
|
20
|
1568 DEFUN ("event-modeline-position", Fevent_modeline_position, 1, 1, 0, /*
|
0
|
1569 Return the character position in the modeline that EVENT occurred over.
|
|
1570 EVENT should be a mouse event. If EVENT did not occur over a modeline,
|
|
1571 nil is returned. You can determine the actual character that the
|
|
1572 event occurred over by looking in `generated-modeline-string' at the
|
|
1573 returned character position. Note that `generated-modeline-string'
|
|
1574 is buffer-local, and you must use EVENT's buffer when retrieving
|
|
1575 `generated-modeline-string' in order to get accurate results.
|
20
|
1576 */
|
|
1577 (event))
|
0
|
1578 {
|
|
1579 Charcount mbufp;
|
|
1580
|
|
1581 event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, &mbufp, 0, 0);
|
|
1582
|
149
|
1583 return mbufp < 0 ? Qnil : make_int (mbufp);
|
0
|
1584 }
|
|
1585
|
20
|
1586 DEFUN ("event-glyph", Fevent_glyph, 1, 1, 0, /*
|
149
|
1587 Return the glyph that the mouse event EVENT occurred over, or nil.
|
20
|
1588 */
|
|
1589 (event))
|
0
|
1590 {
|
|
1591 Lisp_Object glyph;
|
|
1592 struct window *w;
|
|
1593
|
|
1594 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, &glyph, 0);
|
|
1595
|
149
|
1596 return w && GLYPHP (glyph) ? glyph : Qnil;
|
0
|
1597 }
|
|
1598
|
20
|
1599 DEFUN ("event-glyph-extent", Fevent_glyph_extent, 1, 1, 0, /*
|
149
|
1600 Return the extent of the glyph that the mouse event EVENT occurred over.
|
0
|
1601 If the event did not occur over a glyph, nil is returned.
|
20
|
1602 */
|
|
1603 (event))
|
0
|
1604 {
|
|
1605 Lisp_Object extent;
|
|
1606 struct window *w;
|
|
1607
|
|
1608 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, 0, &extent);
|
|
1609
|
149
|
1610 return w && EXTENTP (extent) ? extent : Qnil;
|
0
|
1611 }
|
|
1612
|
20
|
1613 DEFUN ("event-glyph-x-pixel", Fevent_glyph_x_pixel, 1, 1, 0, /*
|
0
|
1614 Return the X pixel position of EVENT relative to the glyph it occurred over.
|
|
1615 EVENT should be a mouse event. If the event did not occur over a glyph,
|
|
1616 nil is returned.
|
20
|
1617 */
|
|
1618 (event))
|
0
|
1619 {
|
|
1620 Lisp_Object extent;
|
|
1621 struct window *w;
|
|
1622 int obj_x;
|
|
1623
|
|
1624 event_pixel_translation (event, 0, 0, &obj_x, 0, &w, 0, 0, 0, 0, &extent);
|
|
1625
|
149
|
1626 return w && EXTENTP (extent) ? make_int (obj_x) : Qnil;
|
0
|
1627 }
|
|
1628
|
20
|
1629 DEFUN ("event-glyph-y-pixel", Fevent_glyph_y_pixel, 1, 1, 0, /*
|
0
|
1630 Return the Y pixel position of EVENT relative to the glyph it occurred over.
|
|
1631 EVENT should be a mouse event. If the event did not occur over a glyph,
|
|
1632 nil is returned.
|
20
|
1633 */
|
|
1634 (event))
|
0
|
1635 {
|
|
1636 Lisp_Object extent;
|
|
1637 struct window *w;
|
|
1638 int obj_y;
|
|
1639
|
|
1640 event_pixel_translation (event, 0, 0, 0, &obj_y, &w, 0, 0, 0, 0, &extent);
|
|
1641
|
149
|
1642 return w && EXTENTP (extent) ? make_int (obj_y) : Qnil;
|
0
|
1643 }
|
|
1644
|
20
|
1645 DEFUN ("event-toolbar-button", Fevent_toolbar_button, 1, 1, 0, /*
|
149
|
1646 Return the toolbar button that the mouse event EVENT occurred over.
|
|
1647 If the event did not occur over a toolbar button, nil is returned.
|
20
|
1648 */
|
|
1649 (event))
|
0
|
1650 {
|
|
1651 #ifdef HAVE_TOOLBARS
|
|
1652 Lisp_Object button;
|
|
1653
|
149
|
1654 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, &button, 0);
|
0
|
1655
|
149
|
1656 return result == OVER_TOOLBAR && TOOLBAR_BUTTONP (button) ? button : Qnil;
|
|
1657 #else
|
0
|
1658 return Qnil;
|
|
1659 #endif
|
|
1660 }
|
|
1661
|
20
|
1662 DEFUN ("event-process", Fevent_process, 1, 1, 0, /*
|
0
|
1663 Return the process of the given process-output event.
|
20
|
1664 */
|
|
1665 (event))
|
0
|
1666 {
|
|
1667 CHECK_EVENT_TYPE (event, process_event, Qprocess_event_p);
|
149
|
1668 return XEVENT (event)->event.process.process;
|
0
|
1669 }
|
|
1670
|
20
|
1671 DEFUN ("event-function", Fevent_function, 1, 1, 0, /*
|
0
|
1672 Return the callback function of EVENT.
|
|
1673 EVENT should be a timeout, misc-user, or eval event.
|
20
|
1674 */
|
|
1675 (event))
|
0
|
1676 {
|
|
1677 CHECK_LIVE_EVENT (event);
|
|
1678 switch (XEVENT (event)->event_type)
|
|
1679 {
|
|
1680 case timeout_event:
|
173
|
1681 return XEVENT (event)->event.timeout.function;
|
0
|
1682 case misc_user_event:
|
|
1683 case eval_event:
|
173
|
1684 return XEVENT (event)->event.eval.function;
|
0
|
1685 default:
|
|
1686 return wrong_type_argument (intern ("timeout-or-eval-event-p"), event);
|
|
1687 }
|
|
1688 }
|
|
1689
|
20
|
1690 DEFUN ("event-object", Fevent_object, 1, 1, 0, /*
|
0
|
1691 Return the callback function argument of EVENT.
|
|
1692 EVENT should be a timeout, misc-user, or eval event.
|
20
|
1693 */
|
|
1694 (event))
|
0
|
1695 {
|
|
1696 again:
|
|
1697 CHECK_LIVE_EVENT (event);
|
|
1698 switch (XEVENT (event)->event_type)
|
|
1699 {
|
|
1700 case timeout_event:
|
173
|
1701 return XEVENT (event)->event.timeout.object;
|
0
|
1702 case misc_user_event:
|
|
1703 case eval_event:
|
173
|
1704 return XEVENT (event)->event.eval.object;
|
0
|
1705 default:
|
|
1706 event = wrong_type_argument (intern ("timeout-or-eval-event-p"), event);
|
|
1707 goto again;
|
|
1708 }
|
|
1709 }
|
|
1710
|
20
|
1711 DEFUN ("event-properties", Fevent_properties, 1, 1, 0, /*
|
0
|
1712 Return a list of all of the properties of EVENT.
|
|
1713 This is in the form of a property list (alternating keyword/value pairs).
|
20
|
1714 */
|
|
1715 (event))
|
0
|
1716 {
|
|
1717 Lisp_Object props = Qnil;
|
|
1718 struct Lisp_Event *e;
|
|
1719 struct gcpro gcpro1;
|
|
1720
|
|
1721 CHECK_LIVE_EVENT (event);
|
|
1722 e = XEVENT (event);
|
|
1723 GCPRO1 (props);
|
|
1724
|
|
1725 props = Fcons (Qtimestamp, Fcons (Fevent_timestamp (event), props));
|
|
1726
|
|
1727 switch (e->event_type)
|
|
1728 {
|
|
1729 case process_event:
|
|
1730 props = Fcons (Qprocess, Fcons (e->event.process.process, props));
|
|
1731 break;
|
173
|
1732
|
0
|
1733 case timeout_event:
|
|
1734 props = Fcons (Qobject, Fcons (Fevent_object (event), props));
|
|
1735 props = Fcons (Qfunction, Fcons (Fevent_function (event), props));
|
|
1736 props = Fcons (Qid, Fcons (make_int (e->event.timeout.id_number),
|
|
1737 props));
|
|
1738 break;
|
|
1739
|
|
1740 case key_press_event:
|
|
1741 props = Fcons (Qmodifiers, Fcons (Fevent_modifiers (event), props));
|
|
1742 props = Fcons (Qkey, Fcons (Fevent_key (event), props));
|
|
1743 break;
|
|
1744
|
|
1745 case button_press_event:
|
|
1746 case button_release_event:
|
|
1747 props = Fcons (Qy, Fcons (Fevent_y_pixel (event), props));
|
|
1748 props = Fcons (Qx, Fcons (Fevent_x_pixel (event), props));
|
|
1749 props = Fcons (Qmodifiers, Fcons (Fevent_modifiers (event), props));
|
|
1750 props = Fcons (Qbutton, Fcons (Fevent_button (event), props));
|
|
1751 break;
|
|
1752
|
|
1753 case pointer_motion_event:
|
|
1754 props = Fcons (Qmodifiers, Fcons (Fevent_modifiers (event), props));
|
|
1755 props = Fcons (Qy, Fcons (Fevent_y_pixel (event), props));
|
|
1756 props = Fcons (Qx, Fcons (Fevent_x_pixel (event), props));
|
|
1757 break;
|
|
1758
|
|
1759 case misc_user_event:
|
|
1760 case eval_event:
|
|
1761 props = Fcons (Qobject, Fcons (Fevent_object (event), props));
|
|
1762 props = Fcons (Qfunction, Fcons (Fevent_function (event), props));
|
|
1763 break;
|
|
1764
|
|
1765 case magic_eval_event:
|
|
1766 case magic_event:
|
149
|
1767 break;
|
|
1768
|
122
|
1769 case empty_event:
|
149
|
1770 RETURN_UNGCPRO (Qnil);
|
0
|
1771 break;
|
|
1772
|
|
1773 default:
|
|
1774 abort ();
|
|
1775 break; /* not reached; warning suppression */
|
|
1776 }
|
|
1777
|
|
1778 props = Fcons (Qchannel, Fcons (Fevent_channel (event), props));
|
|
1779 UNGCPRO;
|
|
1780
|
|
1781 return props;
|
|
1782 }
|
|
1783
|
|
1784
|
|
1785 /************************************************************************/
|
|
1786 /* initialization */
|
|
1787 /************************************************************************/
|
|
1788
|
|
1789 void
|
|
1790 syms_of_events (void)
|
|
1791 {
|
20
|
1792 DEFSUBR (Fcharacter_to_event);
|
|
1793 DEFSUBR (Fevent_to_character);
|
0
|
1794
|
20
|
1795 DEFSUBR (Fmake_event);
|
|
1796 DEFSUBR (Fdeallocate_event);
|
|
1797 DEFSUBR (Fcopy_event);
|
|
1798 DEFSUBR (Feventp);
|
|
1799 DEFSUBR (Fevent_live_p);
|
|
1800 DEFSUBR (Fevent_type);
|
|
1801 DEFSUBR (Fevent_properties);
|
0
|
1802
|
20
|
1803 DEFSUBR (Fevent_timestamp);
|
|
1804 DEFSUBR (Fevent_key);
|
|
1805 DEFSUBR (Fevent_button);
|
|
1806 DEFSUBR (Fevent_modifier_bits);
|
|
1807 DEFSUBR (Fevent_modifiers);
|
|
1808 DEFSUBR (Fevent_x_pixel);
|
|
1809 DEFSUBR (Fevent_y_pixel);
|
|
1810 DEFSUBR (Fevent_window_x_pixel);
|
|
1811 DEFSUBR (Fevent_window_y_pixel);
|
|
1812 DEFSUBR (Fevent_over_text_area_p);
|
|
1813 DEFSUBR (Fevent_over_modeline_p);
|
|
1814 DEFSUBR (Fevent_over_border_p);
|
|
1815 DEFSUBR (Fevent_over_toolbar_p);
|
|
1816 DEFSUBR (Fevent_channel);
|
|
1817 DEFSUBR (Fevent_window);
|
|
1818 DEFSUBR (Fevent_point);
|
|
1819 DEFSUBR (Fevent_closest_point);
|
|
1820 DEFSUBR (Fevent_x);
|
|
1821 DEFSUBR (Fevent_y);
|
|
1822 DEFSUBR (Fevent_modeline_position);
|
|
1823 DEFSUBR (Fevent_glyph);
|
|
1824 DEFSUBR (Fevent_glyph_extent);
|
|
1825 DEFSUBR (Fevent_glyph_x_pixel);
|
|
1826 DEFSUBR (Fevent_glyph_y_pixel);
|
|
1827 DEFSUBR (Fevent_toolbar_button);
|
|
1828 DEFSUBR (Fevent_process);
|
|
1829 DEFSUBR (Fevent_function);
|
|
1830 DEFSUBR (Fevent_object);
|
0
|
1831
|
|
1832 defsymbol (&Qeventp, "eventp");
|
|
1833 defsymbol (&Qevent_live_p, "event-live-p");
|
|
1834 defsymbol (&Qkey_press_event_p, "key-press-event-p");
|
|
1835 defsymbol (&Qbutton_event_p, "button-event-p");
|
|
1836 defsymbol (&Qmouse_event_p, "mouse-event-p");
|
|
1837 defsymbol (&Qprocess_event_p, "process-event-p");
|
|
1838 defsymbol (&Qkey_press, "key-press");
|
|
1839 defsymbol (&Qbutton_press, "button-press");
|
|
1840 defsymbol (&Qbutton_release, "button-release");
|
|
1841 defsymbol (&Qmisc_user, "misc-user");
|
|
1842 defsymbol (&Qascii_character, "ascii-character");
|
|
1843 }
|
|
1844
|
|
1845 void
|
|
1846 vars_of_events (void)
|
|
1847 {
|
|
1848 DEFVAR_LISP ("character-set-property", &Vcharacter_set_property /*
|
|
1849 A symbol used to look up the 8-bit character of a keysym.
|
|
1850 To convert a keysym symbol to an 8-bit code, as when that key is
|
|
1851 bound to self-insert-command, we will look up the property that this
|
|
1852 variable names on the property list of the keysym-symbol. The window-
|
|
1853 system-specific code will set up appropriate properties and set this
|
|
1854 variable.
|
|
1855 */ );
|
|
1856 Vcharacter_set_property = Qnil;
|
|
1857
|
|
1858 Vevent_resource = Qnil;
|
|
1859
|
|
1860 QKbackspace = KEYSYM ("backspace");
|
|
1861 QKtab = KEYSYM ("tab");
|
|
1862 QKlinefeed = KEYSYM ("linefeed");
|
|
1863 QKreturn = KEYSYM ("return");
|
|
1864 QKescape = KEYSYM ("escape");
|
|
1865 QKspace = KEYSYM ("space");
|
|
1866 QKdelete = KEYSYM ("delete");
|
|
1867
|
|
1868 staticpro (&QKbackspace);
|
|
1869 staticpro (&QKtab);
|
|
1870 staticpro (&QKlinefeed);
|
|
1871 staticpro (&QKreturn);
|
|
1872 staticpro (&QKescape);
|
|
1873 staticpro (&QKspace);
|
|
1874 staticpro (&QKdelete);
|
|
1875 }
|