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