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