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