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
|
|
51 #include <events-mod.h>
|
|
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
|
|
66 Lisp_Object Qkey_press, Qbutton_press, Qbutton_release, Qmisc_user;
|
|
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
|
|
164 switch (XEVENT (obj)->event_type)
|
|
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 {
|
|
189 write_c_string ("#<process-event ", printcharfun);
|
|
190 print_internal (XEVENT (obj)->event.process.process, printcharfun, 1);
|
|
191 break;
|
|
192 }
|
|
193 case timeout_event:
|
|
194 {
|
|
195 write_c_string ("#<timeout-event ", printcharfun);
|
|
196 print_internal (XEVENT (obj)->event.timeout.object, printcharfun, 1);
|
|
197 break;
|
|
198 }
|
|
199 case empty_event:
|
|
200 {
|
|
201 write_c_string ("#<empty-event", printcharfun);
|
|
202 break;
|
|
203 }
|
|
204 case misc_user_event:
|
|
205 case eval_event:
|
|
206 {
|
|
207 write_c_string ("#<", printcharfun);
|
|
208 if (XEVENT (obj)->event_type == misc_user_event)
|
|
209 write_c_string ("misc-user", printcharfun);
|
|
210 else
|
|
211 write_c_string ("eval", printcharfun);
|
|
212 write_c_string ("-event (", printcharfun);
|
|
213 print_internal (XEVENT (obj)->event.eval.function, printcharfun, 1);
|
|
214 write_c_string (" ", printcharfun);
|
|
215 print_internal (XEVENT (obj)->event.eval.object, printcharfun, 1);
|
|
216 write_c_string (")", printcharfun);
|
|
217 break;
|
|
218 }
|
|
219 case dead_event:
|
|
220 {
|
|
221 write_c_string ("#<DEALLOCATED-EVENT", printcharfun);
|
|
222 break;
|
|
223 }
|
|
224 default:
|
|
225 {
|
|
226 write_c_string ("#<UNKNOWN-EVENT-TYPE", printcharfun);
|
|
227 break;
|
|
228 }
|
|
229 }
|
|
230 write_c_string (">", printcharfun);
|
|
231 }
|
|
232
|
|
233 static int
|
|
234 event_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
235 {
|
|
236 struct Lisp_Event *e1 = XEVENT (o1);
|
|
237 struct Lisp_Event *e2 = XEVENT (o2);
|
|
238
|
|
239 if (e1->event_type != e2->event_type) return 0;
|
|
240 if (!EQ (e1->channel, e2->channel)) return 0;
|
|
241 /* if (e1->timestamp != e2->timestamp) return 0; */
|
|
242 switch (e1->event_type)
|
|
243 {
|
|
244 case process_event:
|
|
245 return (EQ (e1->event.process.process,
|
|
246 e2->event.process.process));
|
|
247
|
|
248 case timeout_event:
|
|
249 if (NILP (Fequal (e1->event.timeout.function,
|
|
250 e2->event.timeout.function)))
|
|
251 return 0;
|
|
252 if (NILP (Fequal (e1->event.timeout.object,
|
|
253 e2->event.timeout.object)))
|
|
254 return 0;
|
|
255 return 1;
|
|
256
|
|
257 case key_press_event:
|
|
258 return ((EQ (e1->event.key.keysym,
|
|
259 e2->event.key.keysym)
|
|
260 && (e1->event.key.modifiers
|
|
261 == e2->event.key.modifiers)));
|
|
262
|
|
263 case button_press_event:
|
|
264 case button_release_event:
|
|
265 return (((e1->event.button.button
|
|
266 == e2->event.button.button)
|
|
267 && (e1->event.button.modifiers
|
|
268 == e2->event.button.modifiers)));
|
|
269
|
|
270 case pointer_motion_event:
|
|
271 return ((e1->event.motion.x == e2->event.motion.x
|
|
272 && e1->event.motion.y == e2->event.motion.y));
|
|
273
|
|
274 case misc_user_event:
|
|
275 case eval_event:
|
|
276 if (NILP (Fequal (e1->event.eval.function,
|
|
277 e2->event.eval.function)))
|
|
278 return 0;
|
|
279 if (NILP (Fequal (e1->event.eval.object,
|
|
280 e2->event.eval.object)))
|
|
281 return 0;
|
|
282 return 1;
|
|
283
|
|
284 case magic_eval_event:
|
|
285 if (e1->event.magic_eval.internal_function !=
|
|
286 e2->event.magic_eval.internal_function)
|
|
287 return 0;
|
|
288 if (NILP (Fequal (e1->event.magic_eval.object,
|
|
289 e2->event.magic_eval.object)))
|
|
290 return 0;
|
|
291 return 1;
|
|
292
|
|
293 case magic_event:
|
|
294 {
|
|
295 Lisp_Object console;
|
|
296
|
|
297 console = CDFW_CONSOLE (e1->channel);
|
|
298
|
|
299 #ifdef HAVE_X_WINDOWS
|
|
300 /* XEvent is actually a union which means that we can't just use == */
|
|
301 if (CONSOLE_X_P (XCONSOLE (console)))
|
|
302 return (!memcmp ((XEvent *) &e1->event.magic.underlying_x_event,
|
|
303 (XEvent *) &e2->event.magic.underlying_x_event,
|
|
304 sizeof (e1->event.magic.underlying_x_event)));
|
|
305 #endif
|
|
306 return (e1->event.magic.underlying_tty_event ==
|
|
307 e2->event.magic.underlying_tty_event);
|
|
308 }
|
|
309
|
|
310 case empty_event: /* Empty and deallocated events are equal. */
|
|
311 case dead_event:
|
|
312 return 1;
|
|
313
|
|
314 default:
|
|
315 abort ();
|
|
316 return 0; /* not reached; warning suppression */
|
|
317 }
|
|
318 }
|
|
319
|
|
320 static unsigned long
|
|
321 event_hash (Lisp_Object obj, int depth)
|
|
322 {
|
|
323 struct Lisp_Event *e = XEVENT (obj);
|
|
324 unsigned long hash;
|
|
325
|
|
326 hash = HASH2 (e->event_type, LISP_HASH (e->channel));
|
|
327 switch (e->event_type)
|
|
328 {
|
|
329 case process_event:
|
|
330 return HASH2 (hash, LISP_HASH (e->event.process.process));
|
|
331
|
|
332 case timeout_event:
|
|
333 return HASH3 (hash, internal_hash (e->event.timeout.function, depth + 1),
|
|
334 internal_hash (e->event.timeout.object, depth + 1));
|
|
335
|
|
336 case key_press_event:
|
|
337 return HASH3 (hash, LISP_HASH (e->event.key.keysym),
|
|
338 e->event.key.modifiers);
|
|
339
|
|
340 case button_press_event:
|
|
341 case button_release_event:
|
|
342 return HASH3 (hash, e->event.button.button, e->event.button.modifiers);
|
|
343
|
|
344 case pointer_motion_event:
|
|
345 return HASH3 (hash, e->event.motion.x, e->event.motion.y);
|
|
346
|
|
347 case misc_user_event:
|
|
348 case eval_event:
|
|
349 return HASH3 (hash, internal_hash (e->event.eval.function, depth + 1),
|
|
350 internal_hash (e->event.eval.object, depth + 1));
|
|
351
|
|
352 case magic_eval_event:
|
|
353 return HASH3 (hash,
|
|
354 (unsigned long) e->event.magic_eval.internal_function,
|
|
355 internal_hash (e->event.magic_eval.object, depth + 1));
|
|
356
|
|
357 case magic_event:
|
|
358 {
|
|
359 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (e));
|
|
360 #ifdef HAVE_X_WINDOWS
|
|
361 if (CONSOLE_X_P (XCONSOLE (console)))
|
|
362 return
|
|
363 HASH2 (hash,
|
|
364 memory_hash (&e->event.magic.underlying_x_event,
|
|
365 sizeof (e->event.magic.underlying_x_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
|
70
|
673 #ifndef MULE
|
0
|
674 c &= 255;
|
70
|
675 #endif
|
0
|
676 if (c > 127 && c <= 255)
|
|
677 {
|
|
678 int meta_flag = 1;
|
|
679 if (use_console_meta_flag && CONSOLE_TTY_P (con))
|
|
680 meta_flag = TTY_FLAGS (con).meta_key;
|
|
681 switch (meta_flag)
|
|
682 {
|
|
683 case 0: /* ignore top bit; it's parity */
|
|
684 c -= 128;
|
|
685 break;
|
|
686 case 1: /* top bit is meta */
|
|
687 c -= 128;
|
|
688 m = MOD_META;
|
|
689 break;
|
|
690 default: /* this is a real character */
|
|
691 break;
|
|
692 }
|
|
693 }
|
|
694 if (c < ' ') c += '@', m |= MOD_CONTROL;
|
|
695 if (m & MOD_CONTROL)
|
|
696 {
|
|
697 switch (c)
|
|
698 {
|
|
699 case 'I': k = QKtab; m &= ~MOD_CONTROL; break;
|
|
700 case 'J': k = QKlinefeed; m &= ~MOD_CONTROL; break;
|
|
701 case 'M': k = QKreturn; m &= ~MOD_CONTROL; break;
|
|
702 case '[': k = QKescape; m &= ~MOD_CONTROL; break;
|
|
703 # if 0
|
|
704 /* This is probably too controversial... */
|
|
705 case 'H': k = QKbackspace; m &= ~MOD_CONTROL; break;
|
|
706 # endif
|
|
707 }
|
|
708 if (c >= 'A' && c <= 'Z') c -= 'A'-'a';
|
|
709 }
|
|
710 else if (c == 127)
|
|
711 k = QKdelete;
|
|
712 else if (c == ' ')
|
|
713 k = QKspace;
|
|
714
|
2
|
715 event->event_type = key_press_event;
|
|
716 event->timestamp = 0; /* #### */
|
|
717 event->channel = make_console (con);
|
|
718 event->event.key.keysym = (!NILP (k) ? k : make_char (c));
|
|
719 event->event.key.modifiers = m;
|
0
|
720 }
|
|
721
|
|
722
|
|
723 /* This variable controls what character name -> character code mapping
|
|
724 we are using. Window-system-specific code sets this to some symbol,
|
|
725 and we use that symbol as the plist key to convert keysyms into 8-bit
|
|
726 codes. In this way one can have several character sets predefined and
|
|
727 switch them by changing this.
|
|
728 */
|
|
729 Lisp_Object Vcharacter_set_property;
|
|
730
|
|
731 Emchar
|
|
732 event_to_character (struct Lisp_Event *event,
|
|
733 int allow_extra_modifiers,
|
|
734 int allow_meta,
|
|
735 int allow_non_ascii)
|
|
736 {
|
|
737 Emchar c = 0;
|
|
738 Lisp_Object code;
|
|
739
|
|
740 if (event->event_type != key_press_event)
|
|
741 {
|
|
742 if (event->event_type == dead_event) abort ();
|
|
743 return -1;
|
|
744 }
|
|
745 if (!allow_extra_modifiers &&
|
|
746 event->event.key.modifiers & (MOD_SUPER|MOD_HYPER|MOD_ALT))
|
|
747 return -1;
|
|
748 if (CHAR_OR_CHAR_INTP (event->event.key.keysym))
|
|
749 c = XCHAR_OR_CHAR_INT (event->event.key.keysym);
|
|
750 else if (!SYMBOLP (event->event.key.keysym))
|
|
751 abort ();
|
|
752 else if (allow_non_ascii && !NILP (Vcharacter_set_property)
|
|
753 /* Allow window-system-specific extensibility of
|
|
754 keysym->code mapping */
|
|
755 && CHAR_OR_CHAR_INTP (code = Fget (event->event.key.keysym,
|
|
756 Vcharacter_set_property,
|
|
757 Qnil)))
|
|
758 c = XCHAR_OR_CHAR_INT (code);
|
|
759 else if (CHAR_OR_CHAR_INTP (code = Fget (event->event.key.keysym,
|
|
760 Qascii_character, Qnil)))
|
|
761 c = XCHAR_OR_CHAR_INT (code);
|
|
762 else
|
|
763 return -1;
|
|
764
|
|
765 if (event->event.key.modifiers & MOD_CONTROL)
|
|
766 {
|
|
767 if (c >= 'a' && c <= 'z')
|
|
768 c -= ('a' - 'A');
|
|
769 else
|
|
770 /* reject Control-Shift- keys */
|
|
771 if (c >= 'A' && c <= 'Z' && !allow_extra_modifiers)
|
|
772 return -1;
|
|
773
|
|
774 if (c >= '@' && c <= '_')
|
|
775 c -= '@';
|
|
776 else if (c == ' ') /* C-space and C-@ are the same. */
|
|
777 c = 0;
|
|
778 else
|
|
779 /* reject keys that can't take Control- modifiers */
|
|
780 if (! allow_extra_modifiers) return -1;
|
|
781 }
|
|
782
|
|
783 if (event->event.key.modifiers & MOD_META)
|
|
784 {
|
|
785 if (! allow_meta) return -1;
|
|
786 if (c & 0200) return -1; /* don't allow M-oslash (overlap) */
|
70
|
787 #ifdef MULE
|
|
788 if (c >= 256) return -1;
|
|
789 #endif
|
0
|
790 c |= 0200;
|
|
791 }
|
|
792 return c;
|
|
793 }
|
|
794
|
20
|
795 DEFUN ("event-to-character", Fevent_to_character, 1, 4, 0, /*
|
0
|
796 Return the closest ASCII approximation to the given event object.
|
|
797 If the event isn't a keypress, this returns nil.
|
|
798 If the ALLOW-EXTRA-MODIFIERS argument is non-nil, then this is lenient in
|
|
799 its translation; it will ignore modifier keys other than control and meta,
|
|
800 and will ignore the shift modifier on those characters which have no
|
|
801 shifted ASCII equivalent (Control-Shift-A for example, will be mapped to
|
|
802 the same ASCII code as Control-A).
|
|
803 If the ALLOW-META argument is non-nil, then the Meta modifier will be
|
|
804 represented by turning on the high bit of the byte returned; otherwise, nil
|
|
805 will be returned for events containing the Meta modifier.
|
|
806 If the ALLOW-NON-ASCII argument is non-nil, then characters which are
|
|
807 present in the prevailing character set (see the `character-set-property'
|
|
808 variable) will be returned as their code in that character set, instead of
|
|
809 the return value being restricted to ASCII.
|
|
810 Note that specifying both ALLOW-META and ALLOW-NON-ASCII is ambiguous, as
|
|
811 both use the high bit; `M-x' and `oslash' will be indistinguishable.
|
20
|
812 */
|
70
|
813 (event, allow_extra_modifiers, allow_meta, allow_non_ascii))
|
0
|
814 {
|
|
815 Emchar c;
|
|
816 CHECK_LIVE_EVENT (event);
|
|
817 c = event_to_character (XEVENT (event),
|
|
818 !NILP (allow_extra_modifiers),
|
|
819 !NILP (allow_meta),
|
|
820 !NILP (allow_non_ascii));
|
|
821 return (c < 0 ? Qnil : make_char (c));
|
|
822 }
|
|
823
|
20
|
824 DEFUN ("character-to-event", Fcharacter_to_event, 1, 4, 0, /*
|
2
|
825 Converts a keystroke specifier into an event structure, replete with
|
0
|
826 bucky bits. The keystroke is the first argument, and the event to fill
|
|
827 in is the second. This function contains knowledge about what the codes
|
|
828 ``mean'' -- for example, the number 9 is converted to the character ``Tab'',
|
|
829 not the distinct character ``Control-I''.
|
|
830
|
|
831 Note that CH (the keystroke specifier) can be an integer, a character,
|
2
|
832 a symbol such as 'clear, or a list such as '(control backspace).
|
0
|
833
|
2
|
834 If the optional second argument is an event, it is modified;
|
|
835 otherwise, a new event object is created.
|
0
|
836
|
2
|
837 Optional third arg CONSOLE is the console to store in the event, and
|
|
838 defaults to the selected console.
|
0
|
839
|
|
840 If CH is an integer or character, the high bit may be interpreted as the
|
2
|
841 meta key. (This is done for backward compatibility in lots of places.)
|
|
842 If USE-CONSOLE-META-FLAG is nil, this will always be the case. If
|
|
843 USE-CONSOLE-META-FLAG is non-nil, the `meta' flag for CONSOLE affects
|
|
844 whether the high bit is interpreted as a meta key. (See `set-input-mode'.)
|
|
845 If you don't want this silly meta interpretation done, you should pass
|
|
846 in a list containing the character.
|
0
|
847
|
|
848 Beware that character-to-event and event-to-character are not strictly
|
2
|
849 inverse functions, since events contain much more information than the
|
|
850 ASCII character set can encode.
|
20
|
851 */
|
|
852 (ch, event, console, use_console_meta_flag))
|
0
|
853 {
|
|
854 struct console *con = decode_console (console);
|
|
855 if (NILP (event))
|
|
856 event = Fmake_event ();
|
|
857 else
|
|
858 CHECK_LIVE_EVENT (event);
|
|
859 if (CONSP (ch) || SYMBOLP (ch))
|
|
860 key_desc_list_to_event (ch, event, 1);
|
|
861 else
|
|
862 {
|
|
863 CHECK_CHAR_COERCE_INT (ch);
|
|
864 character_to_event (XCHAR (ch), XEVENT (event), con,
|
|
865 !NILP (use_console_meta_flag));
|
|
866 }
|
|
867 return event;
|
|
868 }
|
|
869
|
|
870 void
|
|
871 nth_of_key_sequence_as_event (Lisp_Object seq, int n, Lisp_Object event)
|
|
872 {
|
|
873 assert (STRINGP (seq) || VECTORP (seq));
|
|
874 assert (n < XINT (Flength (seq)));
|
|
875
|
|
876 if (STRINGP (seq))
|
|
877 {
|
|
878 Emchar ch = string_char (XSTRING (seq), n);
|
|
879 Fcharacter_to_event (make_char (ch), event, Qnil, Qnil);
|
|
880 }
|
|
881 else
|
|
882 {
|
|
883 Lisp_Object keystroke = vector_data (XVECTOR (seq))[n];
|
|
884 if (EVENTP (keystroke))
|
|
885 Fcopy_event (keystroke, event);
|
|
886 else
|
|
887 Fcharacter_to_event (keystroke, event, Qnil, Qnil);
|
|
888 }
|
|
889 }
|
|
890
|
|
891 Lisp_Object
|
|
892 key_sequence_to_event_chain (Lisp_Object seq)
|
|
893 {
|
|
894 int len = XINT (Flength (seq));
|
|
895 int i;
|
|
896 Lisp_Object head = Qnil, tail = Qnil;
|
|
897
|
|
898 for (i = 0; i < len; i++)
|
|
899 {
|
|
900 Lisp_Object event = Fmake_event ();
|
|
901 nth_of_key_sequence_as_event (seq, i, event);
|
|
902 enqueue_event (event, &head, &tail);
|
|
903 }
|
|
904
|
|
905 return head;
|
|
906 }
|
|
907
|
|
908 void
|
|
909 format_event_object (char *buf, struct Lisp_Event *event, int brief)
|
|
910 {
|
|
911 int mouse_p = 0;
|
|
912 int mod = 0;
|
|
913 Lisp_Object key;
|
|
914
|
|
915 switch (event->event_type)
|
|
916 {
|
|
917 case key_press_event:
|
|
918 {
|
|
919 mod = event->event.key.modifiers;
|
|
920 key = event->event.key.keysym;
|
|
921 /* Hack. */
|
|
922 if (! brief && CHARP (key) &&
|
|
923 mod & (MOD_CONTROL | MOD_META | MOD_SUPER | MOD_HYPER))
|
|
924 {
|
|
925 int k = XCHAR (key);
|
|
926 if (k >= 'a' && k <= 'z')
|
|
927 key = make_char (k - ('a' - 'A'));
|
|
928 else if (k >= 'A' && k <= 'Z')
|
|
929 mod |= MOD_SHIFT;
|
|
930 }
|
|
931 break;
|
|
932 }
|
|
933 case button_release_event:
|
|
934 mouse_p++;
|
|
935 /* Fall through */
|
|
936 case button_press_event:
|
|
937 {
|
|
938 mouse_p++;
|
|
939 mod = event->event.button.modifiers;
|
|
940 key = make_char (event->event.button.button + '0');
|
|
941 break;
|
|
942 }
|
|
943 case magic_event:
|
|
944 {
|
|
945 CONST char *name = 0;
|
|
946 Lisp_Object console = CDFW_CONSOLE (EVENT_CHANNEL (event));
|
|
947
|
|
948 #ifdef HAVE_X_WINDOWS
|
|
949 if (CONSOLE_X_P (XCONSOLE (console)))
|
|
950 name =
|
|
951 x_event_name (event->event.magic.underlying_x_event.xany.type);
|
|
952 #endif
|
|
953 if (name) strcpy (buf, name);
|
|
954 else strcpy (buf, "???");
|
|
955 return;
|
|
956 }
|
|
957 case magic_eval_event: strcpy (buf, "magic-eval"); return;
|
|
958 case pointer_motion_event: strcpy (buf, "motion"); return;
|
|
959 case misc_user_event: strcpy (buf, "misc-user"); return;
|
|
960 case eval_event: strcpy (buf, "eval"); return;
|
|
961 case process_event: strcpy (buf, "process");return;
|
|
962 case timeout_event: strcpy (buf, "timeout");return;
|
|
963 case empty_event: strcpy (buf, "EMPTY-EVENT"); return;
|
|
964 case dead_event: strcpy (buf, "DEAD-EVENT"); return;
|
|
965 default:
|
|
966 abort ();
|
|
967 }
|
|
968 #define modprint1(x) { strcpy (buf, (x)); buf += sizeof (x)-1; }
|
|
969 #define modprint(x,y) { if (brief) modprint1 (y) else modprint1 (x) }
|
|
970 if (mod & MOD_CONTROL) modprint ("control-", "C-");
|
|
971 if (mod & MOD_META) modprint ("meta-", "M-");
|
|
972 if (mod & MOD_SUPER) modprint ("super-", "S-");
|
|
973 if (mod & MOD_HYPER) modprint ("hyper-", "H-");
|
|
974 if (mod & MOD_ALT) modprint ("alt-", "A-");
|
|
975 if (mod & MOD_SHIFT) modprint ("shift-", "Sh-");
|
|
976 if (mouse_p)
|
|
977 {
|
|
978 modprint1 ("button");
|
|
979 --mouse_p;
|
|
980 }
|
|
981 #undef modprint
|
|
982 #undef modprint1
|
|
983
|
|
984 if (CHARP (key))
|
|
985 {
|
|
986 buf += set_charptr_emchar ((Bufbyte *) buf, XCHAR (key));
|
|
987 *buf = 0;
|
|
988 }
|
|
989 else if (SYMBOLP (key))
|
|
990 {
|
|
991 CONST char *str = 0;
|
|
992 if (brief)
|
|
993 {
|
|
994 if (EQ (key, QKlinefeed)) str = "LFD";
|
|
995 else if (EQ (key, QKtab)) str = "TAB";
|
|
996 else if (EQ (key, QKreturn)) str = "RET";
|
|
997 else if (EQ (key, QKescape)) str = "ESC";
|
|
998 else if (EQ (key, QKdelete)) str = "DEL";
|
|
999 else if (EQ (key, QKspace)) str = "SPC";
|
|
1000 else if (EQ (key, QKbackspace)) str = "BS";
|
|
1001 }
|
|
1002 if (str)
|
|
1003 {
|
|
1004 int i = strlen (str);
|
|
1005 memcpy (buf, str, i+1);
|
|
1006 str += i;
|
|
1007 }
|
|
1008 else
|
|
1009 {
|
|
1010 memcpy (buf, string_data (XSYMBOL (key)->name),
|
|
1011 string_length (XSYMBOL (key)->name) + 1);
|
|
1012 str += string_length (XSYMBOL (key)->name);
|
|
1013 }
|
|
1014 }
|
|
1015 else
|
|
1016 abort ();
|
|
1017 if (mouse_p)
|
|
1018 strncpy (buf, "up", 4);
|
|
1019 }
|
|
1020
|
20
|
1021 DEFUN ("eventp", Feventp, 1, 1, 0, /*
|
0
|
1022 True if OBJECT is an event object.
|
20
|
1023 */
|
|
1024 (object))
|
0
|
1025 {
|
|
1026 return ((EVENTP (object)) ? Qt : Qnil);
|
|
1027 }
|
|
1028
|
20
|
1029 DEFUN ("event-live-p", Fevent_live_p, 1, 1, 0, /*
|
0
|
1030 True if OBJECT is an event object that has not been deallocated.
|
20
|
1031 */
|
|
1032 (object))
|
0
|
1033 {
|
|
1034 return ((EVENTP (object) && XEVENT (object)->event_type != dead_event)
|
|
1035 ? Qt : Qnil);
|
|
1036 }
|
|
1037
|
|
1038 #if 0 /* debugging functions */
|
|
1039
|
|
1040 xxDEFUN ("event-next", Fevent_next, Sevent_next, 1, 1, 0 /*
|
|
1041 Return the event object's `next' event, or nil if it has none.
|
|
1042 The `next-event' field is changed by calling `set-next-event'.
|
|
1043 */ )
|
|
1044 (event)
|
|
1045 Lisp_Object event;
|
|
1046 {
|
|
1047 struct Lisp_Event *e;
|
|
1048 CHECK_LIVE_EVENT (event);
|
|
1049
|
|
1050 return XEVENT_NEXT (event);
|
|
1051 }
|
|
1052
|
|
1053 xxDEFUN ("set-event-next", Fset_event_next, Sset_event_next, 2, 2, 0 /*
|
|
1054 Set the `next event' of EVENT to NEXT-EVENT.
|
|
1055 NEXT-EVENT must be an event object or nil.
|
|
1056 */ )
|
|
1057 (event, next_event)
|
|
1058 Lisp_Object event, next_event;
|
|
1059 {
|
|
1060 Lisp_Object ev;
|
|
1061
|
|
1062 CHECK_LIVE_EVENT (event);
|
|
1063 if (NILP (next_event))
|
|
1064 {
|
|
1065 XSET_EVENT_NEXT (event, Qnil);
|
|
1066 return (Qnil);
|
|
1067 }
|
|
1068
|
|
1069 CHECK_LIVE_EVENT (next_event);
|
|
1070
|
|
1071 EVENT_CHAIN_LOOP (ev, XEVENT_NEXT (event))
|
|
1072 {
|
|
1073 QUIT;
|
|
1074 if (EQ (ev, event))
|
|
1075 signal_error (Qerror,
|
|
1076 list3 (build_string ("Cyclic event-next"),
|
|
1077 event,
|
|
1078 next_event));
|
|
1079 }
|
|
1080 XSET_EVENT_NEXT (event, next_event);
|
|
1081 return (next_event);
|
|
1082 }
|
|
1083
|
|
1084 #endif /* 0 */
|
|
1085
|
20
|
1086 DEFUN ("event-type", Fevent_type, 1, 1, 0, /*
|
0
|
1087 Return the type of EVENT.
|
|
1088 This will be a symbol; one of
|
|
1089
|
|
1090 key-press A key was pressed.
|
|
1091 button-press A mouse button was pressed.
|
|
1092 button-release A mouse button was released.
|
|
1093 misc-user Some other user action happened; typically, this is
|
|
1094 a menu selection or scrollbar action.
|
|
1095 motion The mouse moved.
|
|
1096 process Input is available from a subprocess.
|
|
1097 timeout A timeout has expired.
|
|
1098 eval This causes a specified action to occur when dispatched.
|
|
1099 magic Some window-system-specific event has occurred.
|
122
|
1100 empty The event has been allocated but not assigned.
|
|
1101
|
20
|
1102 */
|
|
1103 (event))
|
0
|
1104 {
|
|
1105 CHECK_LIVE_EVENT (event);
|
|
1106 switch (XEVENT (event)->event_type)
|
|
1107 {
|
|
1108 case key_press_event:
|
|
1109 return Qkey_press;
|
|
1110
|
|
1111 case button_press_event:
|
|
1112 return Qbutton_press;
|
|
1113
|
|
1114 case button_release_event:
|
|
1115 return Qbutton_release;
|
|
1116
|
|
1117 case misc_user_event:
|
|
1118 return Qmisc_user;
|
|
1119
|
|
1120 case pointer_motion_event:
|
|
1121 return Qmotion;
|
|
1122
|
|
1123 case process_event:
|
|
1124 return Qprocess;
|
|
1125
|
|
1126 case timeout_event:
|
|
1127 return Qtimeout;
|
|
1128
|
|
1129 case eval_event:
|
|
1130 return Qeval;
|
|
1131
|
|
1132 case magic_event:
|
|
1133 case magic_eval_event:
|
|
1134 return Qmagic;
|
|
1135
|
122
|
1136 case empty_event:
|
|
1137 return Qempty;
|
|
1138
|
0
|
1139 default:
|
|
1140 abort ();
|
|
1141 return Qnil;
|
|
1142 }
|
|
1143 }
|
|
1144
|
20
|
1145 DEFUN ("event-timestamp", Fevent_timestamp, 1, 1, 0, /*
|
0
|
1146 Return the timestamp of the given event object.
|
20
|
1147 */
|
|
1148 (event))
|
0
|
1149 {
|
|
1150 CHECK_LIVE_EVENT (event);
|
|
1151 /* This junk is so that timestamps don't get to be negative, but contain
|
|
1152 as many bits as this particular emacs will allow.
|
|
1153 */
|
|
1154 return make_int (((1L << (VALBITS - 1)) - 1) &
|
|
1155 XEVENT (event)->timestamp);
|
|
1156 }
|
|
1157
|
|
1158 #define CHECK_EVENT_TYPE(e,t1,sym) \
|
|
1159 { CHECK_LIVE_EVENT (e); \
|
|
1160 if (XEVENT(e)->event_type != (t1)) \
|
|
1161 e = wrong_type_argument ((sym),(e)); \
|
|
1162 }
|
|
1163
|
|
1164 #define CHECK_EVENT_TYPE2(e,t1,t2,sym) \
|
|
1165 { CHECK_LIVE_EVENT (e); \
|
|
1166 if (XEVENT(e)->event_type != (t1) && XEVENT(e)->event_type != (t2)) \
|
|
1167 e = wrong_type_argument ((sym),(e)); \
|
|
1168 }
|
|
1169
|
20
|
1170 DEFUN ("event-key", Fevent_key, 1, 1, 0, /*
|
0
|
1171 Return the Keysym of the given key-press event.
|
|
1172 This will be the ASCII code of a printing character, or a symbol.
|
20
|
1173 */
|
|
1174 (event))
|
0
|
1175 {
|
|
1176 CHECK_EVENT_TYPE (event, key_press_event, Qkey_press_event_p);
|
|
1177 return (XEVENT (event)->event.key.keysym);
|
|
1178 }
|
|
1179
|
20
|
1180 DEFUN ("event-button", Fevent_button, 1, 1, 0, /*
|
0
|
1181 Return the button-number of the given mouse-button-press event.
|
20
|
1182 */
|
|
1183 (event))
|
0
|
1184 {
|
|
1185 CHECK_EVENT_TYPE2 (event, button_press_event, button_release_event,
|
|
1186 Qbutton_event_p);
|
|
1187 #ifdef HAVE_WINDOW_SYSTEM
|
|
1188 return make_int (XEVENT (event)->event.button.button);
|
|
1189 #else /* !HAVE_WINDOW_SYSTEM */
|
|
1190 return Qzero;
|
|
1191 #endif /* !HAVE_WINDOW_SYSTEM */
|
|
1192 }
|
|
1193
|
20
|
1194 DEFUN ("event-modifier-bits", Fevent_modifier_bits, 1, 1, 0, /*
|
0
|
1195 Return a number representing the modifier keys which were down
|
|
1196 when the given mouse or keyboard event was produced. See also the function
|
|
1197 event-modifiers.
|
20
|
1198 */
|
|
1199 (event))
|
0
|
1200 {
|
|
1201 again:
|
|
1202 CHECK_LIVE_EVENT (event);
|
|
1203 if (XEVENT (event)->event_type == key_press_event)
|
|
1204 return make_int (XEVENT (event)->event.key.modifiers);
|
|
1205 else if (XEVENT (event)->event_type == button_press_event ||
|
|
1206 XEVENT (event)->event_type == button_release_event)
|
|
1207 return make_int (XEVENT (event)->event.button.modifiers);
|
|
1208 else if (XEVENT (event)->event_type == pointer_motion_event)
|
|
1209 return make_int (XEVENT (event)->event.motion.modifiers);
|
|
1210 else
|
|
1211 {
|
|
1212 event = wrong_type_argument (intern ("key-or-mouse-event-p"), event);
|
|
1213 goto again;
|
|
1214 }
|
|
1215 }
|
|
1216
|
20
|
1217 DEFUN ("event-modifiers", Fevent_modifiers, 1, 1, 0, /*
|
0
|
1218 Return a list of symbols, the names of the modifier keys
|
|
1219 which were down when the given mouse or keyboard event was produced.
|
|
1220 See also the function event-modifier-bits.
|
20
|
1221 */
|
|
1222 (event))
|
0
|
1223 {
|
|
1224 int mod = XINT (Fevent_modifier_bits (event));
|
|
1225 Lisp_Object result = Qnil;
|
|
1226 if (mod & MOD_SHIFT) result = Fcons (Qshift, result);
|
|
1227 if (mod & MOD_ALT) result = Fcons (Qalt, result);
|
|
1228 if (mod & MOD_HYPER) result = Fcons (Qhyper, result);
|
|
1229 if (mod & MOD_SUPER) result = Fcons (Qsuper, result);
|
|
1230 if (mod & MOD_META) result = Fcons (Qmeta, result);
|
|
1231 if (mod & MOD_CONTROL) result = Fcons (Qcontrol, result);
|
|
1232 return result;
|
|
1233 }
|
|
1234
|
|
1235 static int
|
|
1236 event_x_y_pixel_internal (Lisp_Object event, int *x, int *y, int relative)
|
|
1237 {
|
|
1238 struct window *w;
|
|
1239 struct frame *f;
|
|
1240
|
|
1241 if (XEVENT (event)->event_type == pointer_motion_event)
|
|
1242 {
|
|
1243 *x = XEVENT (event)->event.motion.x;
|
|
1244 *y = XEVENT (event)->event.motion.y;
|
|
1245 }
|
|
1246 else if (XEVENT (event)->event_type == button_press_event ||
|
|
1247 XEVENT (event)->event_type == button_release_event)
|
|
1248 {
|
|
1249 *x = XEVENT (event)->event.button.x;
|
|
1250 *y = XEVENT (event)->event.button.y;
|
|
1251 }
|
|
1252 else
|
|
1253 return 0;
|
|
1254
|
|
1255 f = XFRAME (EVENT_CHANNEL (XEVENT (event)));
|
|
1256
|
|
1257 if (relative)
|
|
1258 {
|
|
1259 w = find_window_by_pixel_pos (*x, *y, f->root_window);
|
|
1260
|
|
1261 if (!w)
|
|
1262 return 1; /* #### What should really happen here. */
|
|
1263
|
|
1264 *x -= w->pixel_left;
|
|
1265 *y -= w->pixel_top;
|
|
1266 }
|
|
1267 else
|
|
1268 {
|
|
1269 *y -= FRAME_REAL_TOP_TOOLBAR_HEIGHT (f);
|
|
1270 *x -= FRAME_REAL_LEFT_TOOLBAR_WIDTH (f);
|
|
1271 }
|
|
1272
|
|
1273 return 1;
|
|
1274 }
|
|
1275
|
20
|
1276 DEFUN ("event-window-x-pixel", Fevent_window_x_pixel, 1, 1, 0, /*
|
0
|
1277 Return the X position in pixels of the given mouse event.
|
|
1278 The value returned is relative to the window the event occurred in.
|
|
1279 This will signal an error if the event is not a mouse-motion, button-press,
|
|
1280 or button-release event. See also `event-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, 1))
|
|
1289 return wrong_type_argument (Qmouse_event_p, event);
|
|
1290 else
|
|
1291 return make_int (x);
|
|
1292 }
|
|
1293
|
20
|
1294 DEFUN ("event-window-y-pixel", Fevent_window_y_pixel, 1, 1, 0, /*
|
0
|
1295 Return the Y position in pixels of the given mouse event.
|
|
1296 The value returned is relative to the window the event occurred in.
|
|
1297 This will signal an error if the event is not a mouse-motion, button-press,
|
|
1298 or button-release event. See also `event-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, 1))
|
|
1307 return wrong_type_argument (Qmouse_event_p, event);
|
|
1308 else
|
|
1309 return make_int (y);
|
|
1310 }
|
|
1311
|
20
|
1312 DEFUN ("event-x-pixel", Fevent_x_pixel, 1, 1, 0, /*
|
0
|
1313 Return the X position in pixels of the given mouse event.
|
|
1314 The value returned is relative to the frame the event occurred in.
|
|
1315 This will signal an error if the event is not a mouse-motion, button-press,
|
|
1316 or button-release event. See also `event-window-x-pixel'.
|
20
|
1317 */
|
|
1318 (event))
|
0
|
1319 {
|
|
1320 int x, y;
|
|
1321
|
|
1322 CHECK_LIVE_EVENT (event);
|
|
1323
|
|
1324 if (!event_x_y_pixel_internal (event, &x, &y, 0))
|
|
1325 return wrong_type_argument (Qmouse_event_p, event);
|
|
1326 else
|
|
1327 return make_int (x);
|
|
1328 }
|
|
1329
|
20
|
1330 DEFUN ("event-y-pixel", Fevent_y_pixel, 1, 1, 0, /*
|
0
|
1331 Return the Y position in pixels of the given mouse event.
|
|
1332 The value returned is relative to the frame the event occurred in.
|
|
1333 This will signal an error if the event is not a mouse-motion, button-press,
|
|
1334 or button-release event. See also `event-window-y-pixel'.
|
20
|
1335 */
|
|
1336 (event))
|
0
|
1337 {
|
|
1338 int x, y;
|
|
1339
|
|
1340 CHECK_LIVE_EVENT (event);
|
|
1341
|
|
1342 if (!event_x_y_pixel_internal (event, &x, &y, 0))
|
|
1343 return wrong_type_argument (Qmouse_event_p, event);
|
|
1344 else
|
|
1345 return make_int (y);
|
|
1346 }
|
|
1347
|
|
1348 /* Given an event, return a value:
|
|
1349
|
|
1350 OVER_TOOLBAR: over one of the 4 frame toolbars
|
|
1351 OVER_MODELINE: over a modeline
|
|
1352 OVER_BORDER: over an internal border
|
|
1353 OVER_NOTHING: over the text area, but not over text
|
|
1354 OVER_OUTSIDE: outside of the frame border
|
|
1355 OVER_TEXT: over text in the text area
|
|
1356
|
|
1357 and return:
|
|
1358
|
|
1359 The X char position in CHAR_X, if not a null pointer.
|
|
1360 The Y char position in CHAR_Y, if not a null pointer.
|
|
1361 (These last two values are relative to the window the event is over.)
|
|
1362 The window it's over in W, if not a null pointer.
|
|
1363 The buffer position it's over in BUFP, if not a null pointer.
|
|
1364 The closest buffer position in CLOSEST, if not a null pointer.
|
|
1365
|
|
1366 OBJ_X, OBJ_Y, OBJ1, and OBJ2 are as in pixel_to_glyph_translation().
|
|
1367 */
|
|
1368
|
|
1369 static int
|
|
1370 event_pixel_translation (Lisp_Object event, int *char_x, int *char_y,
|
|
1371 int *obj_x, int *obj_y,
|
|
1372 struct window **w, Bufpos *bufp, Bufpos *closest,
|
|
1373 Charcount *modeline_closest,
|
|
1374 Lisp_Object *obj1, Lisp_Object *obj2)
|
|
1375 {
|
|
1376 int pix_x = 0;
|
|
1377 int pix_y = 0;
|
|
1378 int result;
|
|
1379 Lisp_Object frame;
|
|
1380
|
|
1381 int ret_x, ret_y, ret_obj_x, ret_obj_y;
|
|
1382 struct window *ret_w;
|
|
1383 Bufpos ret_bufp, ret_closest;
|
|
1384 Charcount ret_modeline_closest;
|
|
1385 Lisp_Object ret_obj1, ret_obj2;
|
|
1386
|
|
1387 CHECK_LIVE_EVENT (event);
|
|
1388 if (XEVENT (event)->event_type == pointer_motion_event)
|
|
1389 {
|
|
1390 pix_x = XEVENT (event)->event.motion.x;
|
|
1391 pix_y = XEVENT (event)->event.motion.y;
|
|
1392 frame = XEVENT (event)->channel;
|
|
1393 }
|
|
1394 else if (XEVENT (event)->event_type == button_press_event ||
|
|
1395 XEVENT (event)->event_type == button_release_event)
|
|
1396 {
|
|
1397 pix_x = XEVENT (event)->event.button.x;
|
|
1398 pix_y = XEVENT (event)->event.button.y;
|
|
1399 frame = XEVENT (event)->channel;
|
|
1400 }
|
|
1401 else
|
|
1402 wrong_type_argument (Qmouse_event_p, event);
|
|
1403
|
|
1404 result = pixel_to_glyph_translation (XFRAME (frame), pix_x, pix_y,
|
|
1405 &ret_x, &ret_y, &ret_obj_x, &ret_obj_y,
|
|
1406 &ret_w, &ret_bufp, &ret_closest,
|
|
1407 &ret_modeline_closest,
|
|
1408 &ret_obj1, &ret_obj2);
|
|
1409
|
|
1410 if (result == OVER_NOTHING || result == OVER_OUTSIDE)
|
|
1411 ret_bufp = 0;
|
|
1412 else if (ret_w && NILP (ret_w->buffer))
|
|
1413 /* Why does this happen? (Does it still happen?)
|
|
1414 I guess the window has gotten reused as a non-leaf... */
|
|
1415 ret_w = 0;
|
|
1416
|
|
1417 /* #### pixel_to_glyph_translation() sometimes returns garbage...
|
|
1418 The word has type Lisp_Record (presumably meaning `extent') but the
|
|
1419 pointer points to random memory, often filled with 0, sometimes not.
|
|
1420 */
|
|
1421 /* #### Chuck, do we still need this crap? */
|
|
1422 if (!NILP (ret_obj1) && !(GLYPHP (ret_obj1)
|
|
1423 #ifdef HAVE_TOOLBARS
|
|
1424 || TOOLBAR_BUTTONP (ret_obj1)
|
|
1425 #endif
|
|
1426 ))
|
|
1427 abort ();
|
|
1428 if (!NILP (ret_obj2) && !(EXTENTP (ret_obj2)
|
|
1429 || CONSP (ret_obj2)))
|
|
1430 abort ();
|
|
1431
|
|
1432 if (char_x)
|
|
1433 *char_x = ret_x;
|
|
1434 if (char_y)
|
|
1435 *char_y = ret_y;
|
|
1436 if (obj_x)
|
|
1437 *obj_x = ret_obj_x;
|
|
1438 if (obj_y)
|
|
1439 *obj_y = ret_obj_y;
|
|
1440 if (w)
|
|
1441 *w = ret_w;
|
|
1442 if (bufp)
|
|
1443 *bufp = ret_bufp;
|
|
1444 if (closest)
|
|
1445 *closest = ret_closest;
|
|
1446 if (modeline_closest)
|
|
1447 *modeline_closest = ret_modeline_closest;
|
|
1448 if (obj1)
|
|
1449 *obj1 = ret_obj1;
|
|
1450 if (obj2)
|
|
1451 *obj2 = ret_obj2;
|
|
1452
|
|
1453 return result;
|
|
1454 }
|
|
1455
|
20
|
1456 DEFUN ("event-over-text-area-p", Fevent_over_text_area_p, 1, 1, 0, /*
|
0
|
1457 Return whether the given mouse event occurred over the text area of a window.
|
|
1458 The modeline is not considered to be part of the text area.
|
20
|
1459 */
|
|
1460 (event))
|
0
|
1461 {
|
|
1462 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1463
|
|
1464 if (result == OVER_TEXT || result == OVER_NOTHING)
|
|
1465 return Qt;
|
|
1466 else
|
|
1467 return Qnil;
|
|
1468 }
|
|
1469
|
20
|
1470 DEFUN ("event-over-modeline-p", Fevent_over_modeline_p, 1, 1, 0, /*
|
0
|
1471 Return whether the given mouse event occurred over the modeline of a window.
|
20
|
1472 */
|
|
1473 (event))
|
0
|
1474 {
|
|
1475 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1476
|
|
1477 if (result == OVER_MODELINE)
|
|
1478 return Qt;
|
|
1479 else
|
|
1480 return Qnil;
|
|
1481 }
|
|
1482
|
20
|
1483 DEFUN ("event-over-border-p", Fevent_over_border_p, 1, 1, 0, /*
|
0
|
1484 Return whether the given mouse event occurred over an internal border.
|
20
|
1485 */
|
|
1486 (event))
|
0
|
1487 {
|
|
1488 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1489
|
|
1490 if (result == OVER_BORDER)
|
|
1491 return Qt;
|
|
1492 else
|
|
1493 return Qnil;
|
|
1494 }
|
|
1495
|
20
|
1496 DEFUN ("event-over-toolbar-p", Fevent_over_toolbar_p, 1, 1, 0, /*
|
0
|
1497 Return whether the given mouse event occurred over a toolbar.
|
20
|
1498 */
|
|
1499 (event))
|
0
|
1500 {
|
|
1501 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1502
|
|
1503 if (result == OVER_TOOLBAR)
|
|
1504 return Qt;
|
|
1505 else
|
|
1506 return Qnil;
|
|
1507 }
|
|
1508
|
|
1509 struct console *
|
|
1510 event_console_or_selected (Lisp_Object event)
|
|
1511 {
|
|
1512 Lisp_Object channel = EVENT_CHANNEL (XEVENT (event));
|
|
1513 Lisp_Object console = CDFW_CONSOLE (channel);
|
|
1514
|
|
1515 if (NILP (console))
|
|
1516 console = Vselected_console;
|
|
1517
|
|
1518 return XCONSOLE (console);
|
|
1519 }
|
|
1520
|
20
|
1521 DEFUN ("event-channel", Fevent_channel, 1, 1, 0, /*
|
0
|
1522 Return the channel that the given event occurred on.
|
|
1523 This will be a frame, device, console, or nil for some types
|
|
1524 of events (e.g. eval events).
|
20
|
1525 */
|
|
1526 (event))
|
0
|
1527 {
|
|
1528 CHECK_LIVE_EVENT (event);
|
|
1529 return EVENT_CHANNEL (XEVENT (event));
|
|
1530 }
|
|
1531
|
20
|
1532 DEFUN ("event-window", Fevent_window, 1, 1, 0, /*
|
0
|
1533 Return the window of the given mouse event.
|
|
1534 This may be nil if the event occurred in the border or over a toolbar.
|
|
1535 The modeline is considered to be in the window it represents.
|
20
|
1536 */
|
|
1537 (event))
|
0
|
1538 {
|
|
1539 struct window *w;
|
|
1540 Lisp_Object window;
|
|
1541
|
|
1542 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, 0, 0);
|
|
1543
|
|
1544 if (!w)
|
|
1545 return Qnil;
|
|
1546 else
|
|
1547 {
|
|
1548 XSETWINDOW (window, w);
|
|
1549 return window;
|
|
1550 }
|
|
1551 }
|
|
1552
|
20
|
1553 DEFUN ("event-point", Fevent_point, 1, 1, 0, /*
|
0
|
1554 Return the character position of the given mouse event.
|
|
1555 If the event did not occur over a window, or did not occur over text,
|
|
1556 then this returns nil. Otherwise, it returns an index into the buffer
|
|
1557 visible in the event's window.
|
20
|
1558 */
|
|
1559 (event))
|
0
|
1560 {
|
|
1561 Bufpos bufp;
|
|
1562 struct window *w;
|
|
1563
|
|
1564 event_pixel_translation (event, 0, 0, 0, 0, &w, &bufp, 0, 0, 0, 0);
|
|
1565
|
|
1566 if (!w)
|
|
1567 return Qnil;
|
|
1568 else if (!bufp)
|
|
1569 return Qnil;
|
|
1570 else
|
|
1571 return make_int (bufp);
|
|
1572 }
|
|
1573
|
20
|
1574 DEFUN ("event-closest-point", Fevent_closest_point, 1, 1, 0, /*
|
0
|
1575 Return the character position of the given mouse event.
|
|
1576 If the event did not occur over a window or over text, return the
|
|
1577 closest point to the location of the event. If the Y pixel position
|
|
1578 overlaps a window and the X pixel position is to the left of that
|
|
1579 window, the closest point is the beginning of the line containing the
|
|
1580 Y position. If the Y pixel position overlaps a window and the X pixel
|
|
1581 position is to the right of that window, the closest point is the end
|
|
1582 of the line containing the Y position. If the Y pixel position is
|
|
1583 above a window, return 0. If it is below a window, return the value
|
|
1584 of (window-end).
|
20
|
1585 */
|
|
1586 (event))
|
0
|
1587 {
|
|
1588 Bufpos bufp;
|
|
1589
|
|
1590 event_pixel_translation (event, 0, 0, 0, 0, 0, 0, &bufp, 0, 0, 0);
|
|
1591
|
|
1592 if (!bufp)
|
|
1593 return Qnil;
|
|
1594 else
|
|
1595 return make_int (bufp);
|
|
1596 }
|
|
1597
|
20
|
1598 DEFUN ("event-x", Fevent_x, 1, 1, 0, /*
|
0
|
1599 Return the X position of the given mouse event in characters.
|
|
1600 This is relative to the window the event occurred over.
|
20
|
1601 */
|
|
1602 (event))
|
0
|
1603 {
|
|
1604 int char_x;
|
|
1605
|
|
1606 event_pixel_translation (event, &char_x, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1607
|
|
1608 return make_int (char_x);
|
|
1609 }
|
|
1610
|
20
|
1611 DEFUN ("event-y", Fevent_y, 1, 1, 0, /*
|
0
|
1612 Return the Y position of the given mouse event in characters.
|
|
1613 This is relative to the window the event occurred over.
|
20
|
1614 */
|
|
1615 (event))
|
0
|
1616 {
|
|
1617 int char_y;
|
|
1618
|
|
1619 event_pixel_translation (event, 0, &char_y, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1620
|
|
1621 return make_int (char_y);
|
|
1622 }
|
|
1623
|
20
|
1624 DEFUN ("event-modeline-position", Fevent_modeline_position, 1, 1, 0, /*
|
0
|
1625 Return the character position in the modeline that EVENT occurred over.
|
|
1626 EVENT should be a mouse event. If EVENT did not occur over a modeline,
|
|
1627 nil is returned. You can determine the actual character that the
|
|
1628 event occurred over by looking in `generated-modeline-string' at the
|
|
1629 returned character position. Note that `generated-modeline-string'
|
|
1630 is buffer-local, and you must use EVENT's buffer when retrieving
|
|
1631 `generated-modeline-string' in order to get accurate results.
|
20
|
1632 */
|
|
1633 (event))
|
0
|
1634 {
|
|
1635 Charcount mbufp;
|
|
1636
|
|
1637 event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, &mbufp, 0, 0);
|
|
1638
|
|
1639 if (mbufp < 0)
|
|
1640 return Qnil;
|
|
1641 else
|
|
1642 return make_int (mbufp);
|
|
1643 }
|
|
1644
|
20
|
1645 DEFUN ("event-glyph", Fevent_glyph, 1, 1, 0, /*
|
0
|
1646 Return the glyph that the given mouse event occurred over, or nil.
|
20
|
1647 */
|
|
1648 (event))
|
0
|
1649 {
|
|
1650 Lisp_Object glyph;
|
|
1651 struct window *w;
|
|
1652
|
|
1653 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, &glyph, 0);
|
|
1654
|
|
1655 if (!w)
|
|
1656 return Qnil;
|
|
1657 else if (GLYPHP (glyph))
|
|
1658 return glyph;
|
|
1659 else
|
|
1660 return Qnil;
|
|
1661 }
|
|
1662
|
20
|
1663 DEFUN ("event-glyph-extent", Fevent_glyph_extent, 1, 1, 0, /*
|
0
|
1664 Return the extent of the glyph that the given mouse event occurred over.
|
|
1665 If the event did not occur over a glyph, nil is returned.
|
20
|
1666 */
|
|
1667 (event))
|
0
|
1668 {
|
|
1669 Lisp_Object extent;
|
|
1670 struct window *w;
|
|
1671
|
|
1672 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, 0, &extent);
|
|
1673
|
|
1674 if (!w)
|
|
1675 return Qnil;
|
|
1676 else if (EXTENTP (extent))
|
|
1677 return extent;
|
|
1678 else
|
|
1679 return Qnil;
|
|
1680 }
|
|
1681
|
20
|
1682 DEFUN ("event-glyph-x-pixel", Fevent_glyph_x_pixel, 1, 1, 0, /*
|
0
|
1683 Return the X pixel position of EVENT relative to the glyph it occurred over.
|
|
1684 EVENT should be a mouse event. If the event did not occur over a glyph,
|
|
1685 nil is returned.
|
20
|
1686 */
|
|
1687 (event))
|
0
|
1688 {
|
|
1689 Lisp_Object extent;
|
|
1690 struct window *w;
|
|
1691 int obj_x;
|
|
1692
|
|
1693 event_pixel_translation (event, 0, 0, &obj_x, 0, &w, 0, 0, 0, 0, &extent);
|
|
1694
|
|
1695 if (w && EXTENTP (extent))
|
|
1696 return make_int (obj_x);
|
|
1697 else
|
|
1698 return Qnil;
|
|
1699 }
|
|
1700
|
20
|
1701 DEFUN ("event-glyph-y-pixel", Fevent_glyph_y_pixel, 1, 1, 0, /*
|
0
|
1702 Return the Y pixel position of EVENT relative to the glyph it occurred over.
|
|
1703 EVENT should be a mouse event. If the event did not occur over a glyph,
|
|
1704 nil is returned.
|
20
|
1705 */
|
|
1706 (event))
|
0
|
1707 {
|
|
1708 Lisp_Object extent;
|
|
1709 struct window *w;
|
|
1710 int obj_y;
|
|
1711
|
|
1712 event_pixel_translation (event, 0, 0, 0, &obj_y, &w, 0, 0, 0, 0, &extent);
|
|
1713
|
|
1714 if (w && EXTENTP (extent))
|
|
1715 return make_int (obj_y);
|
|
1716 else
|
|
1717 return Qnil;
|
|
1718 }
|
|
1719
|
20
|
1720 DEFUN ("event-toolbar-button", Fevent_toolbar_button, 1, 1, 0, /*
|
0
|
1721 Return the toolbar button that the given mouse event occurred over.
|
|
1722 If the event did not occur over a toolbar, nil is returned.
|
20
|
1723 */
|
|
1724 (event))
|
0
|
1725 {
|
|
1726 #ifdef HAVE_TOOLBARS
|
|
1727 Lisp_Object button;
|
|
1728 int result;
|
|
1729
|
|
1730 result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, &button, 0);
|
|
1731
|
|
1732 if (result == OVER_TOOLBAR)
|
|
1733 {
|
|
1734 if (TOOLBAR_BUTTONP (button))
|
|
1735 return button;
|
|
1736 else
|
|
1737 return Qnil;
|
|
1738 }
|
|
1739 else
|
|
1740 #endif
|
|
1741 return Qnil;
|
|
1742 }
|
|
1743
|
20
|
1744 DEFUN ("event-process", Fevent_process, 1, 1, 0, /*
|
0
|
1745 Return the process of the given process-output event.
|
20
|
1746 */
|
|
1747 (event))
|
0
|
1748 {
|
|
1749 CHECK_EVENT_TYPE (event, process_event, Qprocess_event_p);
|
|
1750 return (XEVENT (event)->event.process.process);
|
|
1751 }
|
|
1752
|
20
|
1753 DEFUN ("event-function", Fevent_function, 1, 1, 0, /*
|
0
|
1754 Return the callback function of EVENT.
|
|
1755 EVENT should be a timeout, misc-user, or eval event.
|
20
|
1756 */
|
|
1757 (event))
|
0
|
1758 {
|
|
1759 CHECK_LIVE_EVENT (event);
|
|
1760 switch (XEVENT (event)->event_type)
|
|
1761 {
|
|
1762 case timeout_event:
|
|
1763 return (XEVENT (event)->event.timeout.function);
|
|
1764 case misc_user_event:
|
|
1765 case eval_event:
|
|
1766 return (XEVENT (event)->event.eval.function);
|
|
1767 default:
|
|
1768 return wrong_type_argument (intern ("timeout-or-eval-event-p"), event);
|
|
1769 }
|
|
1770 }
|
|
1771
|
20
|
1772 DEFUN ("event-object", Fevent_object, 1, 1, 0, /*
|
0
|
1773 Return the callback function argument of EVENT.
|
|
1774 EVENT should be a timeout, misc-user, or eval event.
|
20
|
1775 */
|
|
1776 (event))
|
0
|
1777 {
|
|
1778 again:
|
|
1779 CHECK_LIVE_EVENT (event);
|
|
1780 switch (XEVENT (event)->event_type)
|
|
1781 {
|
|
1782 case timeout_event:
|
|
1783 return (XEVENT (event)->event.timeout.object);
|
|
1784 case misc_user_event:
|
|
1785 case eval_event:
|
|
1786 return (XEVENT (event)->event.eval.object);
|
|
1787 default:
|
|
1788 event = wrong_type_argument (intern ("timeout-or-eval-event-p"), event);
|
|
1789 goto again;
|
|
1790 }
|
|
1791 }
|
|
1792
|
20
|
1793 DEFUN ("event-properties", Fevent_properties, 1, 1, 0, /*
|
0
|
1794 Return a list of all of the properties of EVENT.
|
|
1795 This is in the form of a property list (alternating keyword/value pairs).
|
20
|
1796 */
|
|
1797 (event))
|
0
|
1798 {
|
|
1799 Lisp_Object props = Qnil;
|
|
1800 struct Lisp_Event *e;
|
|
1801 struct gcpro gcpro1;
|
|
1802
|
|
1803 CHECK_LIVE_EVENT (event);
|
|
1804 e = XEVENT (event);
|
|
1805 GCPRO1 (props);
|
|
1806
|
|
1807 props = Fcons (Qtimestamp, Fcons (Fevent_timestamp (event), props));
|
|
1808
|
|
1809 switch (e->event_type)
|
|
1810 {
|
|
1811 case process_event:
|
|
1812 props = Fcons (Qprocess, Fcons (e->event.process.process, props));
|
|
1813 break;
|
|
1814
|
|
1815 case timeout_event:
|
|
1816 props = Fcons (Qobject, Fcons (Fevent_object (event), props));
|
|
1817 props = Fcons (Qfunction, Fcons (Fevent_function (event), props));
|
|
1818 props = Fcons (Qid, Fcons (make_int (e->event.timeout.id_number),
|
|
1819 props));
|
|
1820 break;
|
|
1821
|
|
1822 case key_press_event:
|
|
1823 props = Fcons (Qmodifiers, Fcons (Fevent_modifiers (event), props));
|
|
1824 props = Fcons (Qkey, Fcons (Fevent_key (event), props));
|
|
1825 break;
|
|
1826
|
|
1827 case button_press_event:
|
|
1828 case button_release_event:
|
|
1829 props = Fcons (Qy, Fcons (Fevent_y_pixel (event), props));
|
|
1830 props = Fcons (Qx, Fcons (Fevent_x_pixel (event), props));
|
|
1831 props = Fcons (Qmodifiers, Fcons (Fevent_modifiers (event), props));
|
|
1832 props = Fcons (Qbutton, Fcons (Fevent_button (event), props));
|
|
1833 break;
|
|
1834
|
|
1835 case pointer_motion_event:
|
|
1836 props = Fcons (Qmodifiers, Fcons (Fevent_modifiers (event), props));
|
|
1837 props = Fcons (Qy, Fcons (Fevent_y_pixel (event), props));
|
|
1838 props = Fcons (Qx, Fcons (Fevent_x_pixel (event), props));
|
|
1839 break;
|
|
1840
|
|
1841 case misc_user_event:
|
|
1842 case eval_event:
|
|
1843 props = Fcons (Qobject, Fcons (Fevent_object (event), props));
|
|
1844 props = Fcons (Qfunction, Fcons (Fevent_function (event), props));
|
|
1845 break;
|
|
1846
|
|
1847 case magic_eval_event:
|
|
1848 case magic_event:
|
122
|
1849 case empty_event:
|
0
|
1850 break;
|
|
1851
|
|
1852 default:
|
|
1853 abort ();
|
|
1854 break; /* not reached; warning suppression */
|
|
1855 }
|
|
1856
|
|
1857 props = Fcons (Qchannel, Fcons (Fevent_channel (event), props));
|
|
1858 UNGCPRO;
|
|
1859
|
|
1860 return props;
|
|
1861 }
|
|
1862
|
|
1863
|
|
1864 /************************************************************************/
|
|
1865 /* initialization */
|
|
1866 /************************************************************************/
|
|
1867
|
|
1868 void
|
|
1869 syms_of_events (void)
|
|
1870 {
|
20
|
1871 DEFSUBR (Fcharacter_to_event);
|
|
1872 DEFSUBR (Fevent_to_character);
|
0
|
1873
|
20
|
1874 DEFSUBR (Fmake_event);
|
|
1875 DEFSUBR (Fdeallocate_event);
|
|
1876 DEFSUBR (Fcopy_event);
|
|
1877 DEFSUBR (Feventp);
|
|
1878 DEFSUBR (Fevent_live_p);
|
|
1879 DEFSUBR (Fevent_type);
|
|
1880 DEFSUBR (Fevent_properties);
|
0
|
1881
|
20
|
1882 DEFSUBR (Fevent_timestamp);
|
|
1883 DEFSUBR (Fevent_key);
|
|
1884 DEFSUBR (Fevent_button);
|
|
1885 DEFSUBR (Fevent_modifier_bits);
|
|
1886 DEFSUBR (Fevent_modifiers);
|
|
1887 DEFSUBR (Fevent_x_pixel);
|
|
1888 DEFSUBR (Fevent_y_pixel);
|
|
1889 DEFSUBR (Fevent_window_x_pixel);
|
|
1890 DEFSUBR (Fevent_window_y_pixel);
|
|
1891 DEFSUBR (Fevent_over_text_area_p);
|
|
1892 DEFSUBR (Fevent_over_modeline_p);
|
|
1893 DEFSUBR (Fevent_over_border_p);
|
|
1894 DEFSUBR (Fevent_over_toolbar_p);
|
|
1895 DEFSUBR (Fevent_channel);
|
|
1896 DEFSUBR (Fevent_window);
|
|
1897 DEFSUBR (Fevent_point);
|
|
1898 DEFSUBR (Fevent_closest_point);
|
|
1899 DEFSUBR (Fevent_x);
|
|
1900 DEFSUBR (Fevent_y);
|
|
1901 DEFSUBR (Fevent_modeline_position);
|
|
1902 DEFSUBR (Fevent_glyph);
|
|
1903 DEFSUBR (Fevent_glyph_extent);
|
|
1904 DEFSUBR (Fevent_glyph_x_pixel);
|
|
1905 DEFSUBR (Fevent_glyph_y_pixel);
|
|
1906 DEFSUBR (Fevent_toolbar_button);
|
|
1907 DEFSUBR (Fevent_process);
|
|
1908 DEFSUBR (Fevent_function);
|
|
1909 DEFSUBR (Fevent_object);
|
0
|
1910
|
|
1911 defsymbol (&Qeventp, "eventp");
|
|
1912 defsymbol (&Qevent_live_p, "event-live-p");
|
|
1913 defsymbol (&Qkey_press_event_p, "key-press-event-p");
|
|
1914 defsymbol (&Qbutton_event_p, "button-event-p");
|
|
1915 defsymbol (&Qmouse_event_p, "mouse-event-p");
|
|
1916 defsymbol (&Qprocess_event_p, "process-event-p");
|
|
1917 defsymbol (&Qkey_press, "key-press");
|
|
1918 defsymbol (&Qbutton_press, "button-press");
|
|
1919 defsymbol (&Qbutton_release, "button-release");
|
|
1920 defsymbol (&Qmisc_user, "misc-user");
|
|
1921 defsymbol (&Qascii_character, "ascii-character");
|
|
1922 }
|
|
1923
|
|
1924 void
|
|
1925 vars_of_events (void)
|
|
1926 {
|
|
1927 DEFVAR_LISP ("character-set-property", &Vcharacter_set_property /*
|
|
1928 A symbol used to look up the 8-bit character of a keysym.
|
|
1929 To convert a keysym symbol to an 8-bit code, as when that key is
|
|
1930 bound to self-insert-command, we will look up the property that this
|
|
1931 variable names on the property list of the keysym-symbol. The window-
|
|
1932 system-specific code will set up appropriate properties and set this
|
|
1933 variable.
|
|
1934 */ );
|
|
1935 Vcharacter_set_property = Qnil;
|
|
1936
|
|
1937 Vevent_resource = Qnil;
|
|
1938
|
|
1939 QKbackspace = KEYSYM ("backspace");
|
|
1940 QKtab = KEYSYM ("tab");
|
|
1941 QKlinefeed = KEYSYM ("linefeed");
|
|
1942 QKreturn = KEYSYM ("return");
|
|
1943 QKescape = KEYSYM ("escape");
|
|
1944 QKspace = KEYSYM ("space");
|
|
1945 QKdelete = KEYSYM ("delete");
|
|
1946
|
|
1947 staticpro (&QKbackspace);
|
|
1948 staticpro (&QKtab);
|
|
1949 staticpro (&QKlinefeed);
|
|
1950 staticpro (&QKreturn);
|
|
1951 staticpro (&QKescape);
|
|
1952 staticpro (&QKspace);
|
|
1953 staticpro (&QKdelete);
|
|
1954 }
|