428
|
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.
|
788
|
4 Copyright (C) 2001, 2002 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Not in FSF. */
|
|
24
|
|
25 /* This file has been Mule-ized. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29 #include "buffer.h"
|
|
30 #include "console.h"
|
|
31 #include "console-tty.h" /* for stuff in character_to_event */
|
|
32 #include "device.h"
|
788
|
33 #include "extents.h"
|
428
|
34 #include "events.h"
|
|
35 #include "frame.h"
|
|
36 #include "glyphs.h"
|
|
37 #include "keymap.h" /* for key_desc_list_to_event() */
|
788
|
38 #include "lstream.h"
|
428
|
39 #include "redisplay.h"
|
|
40 #include "window.h"
|
|
41
|
|
42 /* Where old events go when they are explicitly deallocated.
|
|
43 The event chain here is cut loose before GC, so these will be freed
|
|
44 eventually.
|
|
45 */
|
|
46 static Lisp_Object Vevent_resource;
|
|
47
|
|
48 Lisp_Object Qeventp;
|
|
49 Lisp_Object Qevent_live_p;
|
|
50 Lisp_Object Qkey_press_event_p;
|
|
51 Lisp_Object Qbutton_event_p;
|
|
52 Lisp_Object Qmouse_event_p;
|
|
53 Lisp_Object Qprocess_event_p;
|
|
54
|
|
55 Lisp_Object Qkey_press, Qbutton_press, Qbutton_release, Qmisc_user;
|
|
56 Lisp_Object Qascii_character;
|
|
57
|
771
|
58
|
|
59 /************************************************************************/
|
|
60 /* definition of event object */
|
|
61 /************************************************************************/
|
428
|
62
|
|
63 /* #### Ad-hoc hack. Should be part of define_lrecord_implementation */
|
|
64 void
|
|
65 clear_event_resource (void)
|
|
66 {
|
|
67 Vevent_resource = Qnil;
|
|
68 }
|
|
69
|
|
70 /* Make sure we lose quickly if we try to use this event */
|
|
71 static void
|
|
72 deinitialize_event (Lisp_Object ev)
|
|
73 {
|
|
74 int i;
|
440
|
75 Lisp_Event *event = XEVENT (ev);
|
428
|
76
|
440
|
77 for (i = 0; i < (int) (sizeof (Lisp_Event) / sizeof (int)); i++)
|
428
|
78 ((int *) event) [i] = 0xdeadbeef;
|
|
79 event->event_type = dead_event;
|
|
80 event->channel = Qnil;
|
442
|
81 set_lheader_implementation (&event->lheader, &lrecord_event);
|
428
|
82 XSET_EVENT_NEXT (ev, Qnil);
|
|
83 }
|
|
84
|
|
85 /* Set everything to zero or nil so that it's predictable. */
|
|
86 void
|
440
|
87 zero_event (Lisp_Event *e)
|
428
|
88 {
|
|
89 xzero (*e);
|
442
|
90 set_lheader_implementation (&e->lheader, &lrecord_event);
|
428
|
91 e->event_type = empty_event;
|
|
92 e->next = Qnil;
|
|
93 e->channel = Qnil;
|
|
94 }
|
|
95
|
|
96 static Lisp_Object
|
|
97 mark_event (Lisp_Object obj)
|
|
98 {
|
440
|
99 Lisp_Event *event = XEVENT (obj);
|
428
|
100
|
|
101 switch (event->event_type)
|
|
102 {
|
|
103 case key_press_event:
|
|
104 mark_object (event->event.key.keysym);
|
|
105 break;
|
|
106 case process_event:
|
|
107 mark_object (event->event.process.process);
|
|
108 break;
|
|
109 case timeout_event:
|
|
110 mark_object (event->event.timeout.function);
|
|
111 mark_object (event->event.timeout.object);
|
|
112 break;
|
|
113 case eval_event:
|
|
114 case misc_user_event:
|
|
115 mark_object (event->event.eval.function);
|
|
116 mark_object (event->event.eval.object);
|
|
117 break;
|
|
118 case magic_eval_event:
|
|
119 mark_object (event->event.magic_eval.object);
|
|
120 break;
|
|
121 case button_press_event:
|
|
122 case button_release_event:
|
|
123 case pointer_motion_event:
|
|
124 case magic_event:
|
|
125 case empty_event:
|
|
126 case dead_event:
|
|
127 break;
|
|
128 default:
|
|
129 abort ();
|
|
130 }
|
|
131 mark_object (event->channel);
|
|
132 return event->next;
|
|
133 }
|
|
134
|
|
135 static void
|
442
|
136 print_event_1 (const char *str, Lisp_Object obj, Lisp_Object printcharfun)
|
428
|
137 {
|
|
138 char buf[255];
|
|
139 write_c_string (str, printcharfun);
|
|
140 format_event_object (buf, XEVENT (obj), 0);
|
|
141 write_c_string (buf, printcharfun);
|
|
142 }
|
|
143
|
|
144 static void
|
|
145 print_event (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
146 {
|
|
147 if (print_readably)
|
563
|
148 printing_unreadable_object ("#<event>");
|
428
|
149
|
|
150 switch (XEVENT (obj)->event_type)
|
|
151 {
|
|
152 case key_press_event:
|
|
153 print_event_1 ("#<keypress-event ", obj, printcharfun);
|
|
154 break;
|
|
155 case button_press_event:
|
|
156 print_event_1 ("#<buttondown-event ", obj, printcharfun);
|
|
157 break;
|
|
158 case button_release_event:
|
|
159 print_event_1 ("#<buttonup-event ", obj, printcharfun);
|
|
160 break;
|
|
161 case magic_event:
|
|
162 case magic_eval_event:
|
|
163 print_event_1 ("#<magic-event ", obj, printcharfun);
|
|
164 break;
|
|
165 case pointer_motion_event:
|
|
166 {
|
|
167 char buf[64];
|
|
168 Lisp_Object Vx, Vy;
|
|
169 Vx = Fevent_x_pixel (obj);
|
|
170 assert (INTP (Vx));
|
|
171 Vy = Fevent_y_pixel (obj);
|
|
172 assert (INTP (Vy));
|
|
173 sprintf (buf, "#<motion-event %ld, %ld", (long) XINT (Vx), (long) XINT (Vy));
|
|
174 write_c_string (buf, printcharfun);
|
|
175 break;
|
|
176 }
|
|
177 case process_event:
|
|
178 write_c_string ("#<process-event ", printcharfun);
|
|
179 print_internal (XEVENT (obj)->event.process.process, printcharfun, 1);
|
|
180 break;
|
|
181 case timeout_event:
|
|
182 write_c_string ("#<timeout-event ", printcharfun);
|
|
183 print_internal (XEVENT (obj)->event.timeout.object, printcharfun, 1);
|
|
184 break;
|
|
185 case empty_event:
|
|
186 write_c_string ("#<empty-event", printcharfun);
|
|
187 break;
|
|
188 case misc_user_event:
|
|
189 write_c_string ("#<misc-user-event (", printcharfun);
|
|
190 print_internal (XEVENT (obj)->event.misc.function, printcharfun, 1);
|
|
191 write_c_string (" ", printcharfun);
|
|
192 print_internal (XEVENT (obj)->event.misc.object, printcharfun, 1);
|
|
193 write_c_string (")", printcharfun);
|
|
194 break;
|
|
195 case eval_event:
|
|
196 write_c_string ("#<eval-event (", printcharfun);
|
|
197 print_internal (XEVENT (obj)->event.eval.function, printcharfun, 1);
|
|
198 write_c_string (" ", printcharfun);
|
|
199 print_internal (XEVENT (obj)->event.eval.object, printcharfun, 1);
|
|
200 write_c_string (")", printcharfun);
|
|
201 break;
|
|
202 case dead_event:
|
|
203 write_c_string ("#<DEALLOCATED-EVENT", printcharfun);
|
|
204 break;
|
|
205 default:
|
|
206 write_c_string ("#<UNKNOWN-EVENT-TYPE", printcharfun);
|
|
207 break;
|
|
208 }
|
|
209 write_c_string (">", printcharfun);
|
|
210 }
|
|
211
|
|
212 static int
|
|
213 event_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
214 {
|
440
|
215 Lisp_Event *e1 = XEVENT (obj1);
|
|
216 Lisp_Event *e2 = XEVENT (obj2);
|
428
|
217
|
|
218 if (e1->event_type != e2->event_type) return 0;
|
|
219 if (!EQ (e1->channel, e2->channel)) return 0;
|
|
220 /* if (e1->timestamp != e2->timestamp) return 0; */
|
|
221 switch (e1->event_type)
|
|
222 {
|
|
223 default: abort ();
|
|
224
|
|
225 case process_event:
|
|
226 return EQ (e1->event.process.process, e2->event.process.process);
|
|
227
|
|
228 case timeout_event:
|
|
229 return (internal_equal (e1->event.timeout.function,
|
|
230 e2->event.timeout.function, 0) &&
|
|
231 internal_equal (e1->event.timeout.object,
|
|
232 e2->event.timeout.object, 0));
|
|
233
|
|
234 case key_press_event:
|
|
235 return (EQ (e1->event.key.keysym, e2->event.key.keysym) &&
|
|
236 (e1->event.key.modifiers == e2->event.key.modifiers));
|
|
237
|
|
238 case button_press_event:
|
|
239 case button_release_event:
|
|
240 return (e1->event.button.button == e2->event.button.button &&
|
|
241 e1->event.button.modifiers == e2->event.button.modifiers);
|
|
242
|
|
243 case pointer_motion_event:
|
|
244 return (e1->event.motion.x == e2->event.motion.x &&
|
|
245 e1->event.motion.y == e2->event.motion.y);
|
|
246
|
|
247 case misc_user_event:
|
|
248 return (internal_equal (e1->event.eval.function,
|
|
249 e2->event.eval.function, 0) &&
|
|
250 internal_equal (e1->event.eval.object,
|
|
251 e2->event.eval.object, 0) &&
|
|
252 /* is this really needed for equality
|
|
253 or is x and y also important? */
|
|
254 e1->event.misc.button == e2->event.misc.button &&
|
|
255 e1->event.misc.modifiers == e2->event.misc.modifiers);
|
|
256
|
|
257 case eval_event:
|
|
258 return (internal_equal (e1->event.eval.function,
|
|
259 e2->event.eval.function, 0) &&
|
|
260 internal_equal (e1->event.eval.object,
|
|
261 e2->event.eval.object, 0));
|
|
262
|
|
263 case magic_eval_event:
|
|
264 return (e1->event.magic_eval.internal_function ==
|
|
265 e2->event.magic_eval.internal_function &&
|
|
266 internal_equal (e1->event.magic_eval.object,
|
|
267 e2->event.magic_eval.object, 0));
|
|
268
|
|
269 case magic_event:
|
788
|
270 return event_stream_compare_magic_event (e1, e2);
|
428
|
271
|
|
272 case empty_event: /* Empty and deallocated events are equal. */
|
|
273 case dead_event:
|
|
274 return 1;
|
|
275 }
|
|
276 }
|
|
277
|
665
|
278 static Hashcode
|
428
|
279 event_hash (Lisp_Object obj, int depth)
|
|
280 {
|
440
|
281 Lisp_Event *e = XEVENT (obj);
|
665
|
282 Hashcode hash;
|
428
|
283
|
|
284 hash = HASH2 (e->event_type, LISP_HASH (e->channel));
|
|
285 switch (e->event_type)
|
|
286 {
|
|
287 case process_event:
|
|
288 return HASH2 (hash, LISP_HASH (e->event.process.process));
|
|
289
|
|
290 case timeout_event:
|
|
291 return HASH3 (hash, internal_hash (e->event.timeout.function, depth + 1),
|
|
292 internal_hash (e->event.timeout.object, depth + 1));
|
|
293
|
|
294 case key_press_event:
|
|
295 return HASH3 (hash, LISP_HASH (e->event.key.keysym),
|
|
296 e->event.key.modifiers);
|
|
297
|
|
298 case button_press_event:
|
|
299 case button_release_event:
|
|
300 return HASH3 (hash, e->event.button.button, e->event.button.modifiers);
|
|
301
|
|
302 case pointer_motion_event:
|
|
303 return HASH3 (hash, e->event.motion.x, e->event.motion.y);
|
|
304
|
|
305 case misc_user_event:
|
|
306 return HASH5 (hash, internal_hash (e->event.misc.function, depth + 1),
|
|
307 internal_hash (e->event.misc.object, depth + 1),
|
|
308 e->event.misc.button, e->event.misc.modifiers);
|
|
309
|
|
310 case eval_event:
|
|
311 return HASH3 (hash, internal_hash (e->event.eval.function, depth + 1),
|
|
312 internal_hash (e->event.eval.object, depth + 1));
|
|
313
|
|
314 case magic_eval_event:
|
|
315 return HASH3 (hash,
|
665
|
316 (Hashcode) e->event.magic_eval.internal_function,
|
428
|
317 internal_hash (e->event.magic_eval.object, depth + 1));
|
|
318
|
|
319 case magic_event:
|
788
|
320 return HASH2 (hash, event_stream_hash_magic_event (e));
|
428
|
321
|
|
322 case empty_event:
|
|
323 case dead_event:
|
|
324 return hash;
|
|
325
|
|
326 default:
|
|
327 abort ();
|
|
328 }
|
|
329
|
|
330 return 0; /* unreached */
|
|
331 }
|
|
332
|
|
333 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("event", event,
|
|
334 mark_event, print_event, 0, event_equal,
|
440
|
335 event_hash, 0, Lisp_Event);
|
428
|
336
|
|
337 DEFUN ("make-event", Fmake_event, 0, 2, 0, /*
|
|
338 Return a new event of type TYPE, with properties described by PLIST.
|
|
339
|
|
340 TYPE is a symbol, either `empty', `key-press', `button-press',
|
|
341 `button-release', `misc-user' or `motion'. If TYPE is nil, it
|
|
342 defaults to `empty'.
|
|
343
|
|
344 PLIST is a property list, the properties being compatible to those
|
|
345 returned by `event-properties'. The following properties are
|
|
346 allowed:
|
|
347
|
|
348 channel -- The event channel, a frame or a console. For
|
|
349 button-press, button-release, misc-user and motion events,
|
|
350 this must be a frame. For key-press events, it must be
|
|
351 a console. If channel is unspecified, it will be set to
|
|
352 the selected frame or selected console, as appropriate.
|
|
353 key -- The event key, a symbol or character. Allowed only for
|
|
354 keypress events.
|
|
355 button -- The event button, integer 1, 2 or 3. Allowed for
|
|
356 button-press, button-release and misc-user events.
|
|
357 modifiers -- The event modifiers, a list of modifier symbols. Allowed
|
|
358 for key-press, button-press, button-release, motion and
|
|
359 misc-user events.
|
|
360 function -- Function. Allowed for misc-user events only.
|
|
361 object -- An object, function's parameter. Allowed for misc-user
|
|
362 events only.
|
|
363 x -- The event X coordinate, an integer. This is relative
|
|
364 to the left of CHANNEL's root window. Allowed for
|
|
365 motion, button-press, button-release and misc-user events.
|
|
366 y -- The event Y coordinate, an integer. This is relative
|
|
367 to the top of CHANNEL's root window. Allowed for
|
|
368 motion, button-press, button-release and misc-user events.
|
|
369 timestamp -- The event timestamp, a non-negative integer. Allowed for
|
|
370 all types of events. If unspecified, it will be set to 0
|
|
371 by default.
|
|
372
|
|
373 For event type `empty', PLIST must be nil.
|
|
374 `button-release', or `motion'. If TYPE is left out, it defaults to
|
|
375 `empty'.
|
|
376 PLIST is a list of properties, as returned by `event-properties'. Not
|
|
377 all properties are allowed for all kinds of events, and some are
|
|
378 required.
|
|
379
|
|
380 WARNING: the event object returned may be a reused one; see the function
|
|
381 `deallocate-event'.
|
|
382 */
|
|
383 (type, plist))
|
|
384 {
|
|
385 Lisp_Object event = Qnil;
|
440
|
386 Lisp_Event *e;
|
428
|
387 EMACS_INT coord_x = 0, coord_y = 0;
|
|
388 struct gcpro gcpro1;
|
|
389
|
|
390 GCPRO1 (event);
|
|
391
|
|
392 if (NILP (type))
|
|
393 type = Qempty;
|
|
394
|
|
395 if (!NILP (Vevent_resource))
|
|
396 {
|
|
397 event = Vevent_resource;
|
|
398 Vevent_resource = XEVENT_NEXT (event);
|
|
399 }
|
|
400 else
|
|
401 {
|
|
402 event = allocate_event ();
|
|
403 }
|
|
404 e = XEVENT (event);
|
|
405 zero_event (e);
|
|
406
|
|
407 if (EQ (type, Qempty))
|
|
408 {
|
|
409 /* For empty event, we return immediately, without processing
|
|
410 PLIST. In fact, processing PLIST would be wrong, because the
|
|
411 sanitizing process would fill in the properties
|
|
412 (e.g. CHANNEL), which we don't want in empty events. */
|
|
413 e->event_type = empty_event;
|
|
414 if (!NILP (plist))
|
563
|
415 invalid_operation ("Cannot set properties of empty event", plist);
|
428
|
416 UNGCPRO;
|
|
417 return event;
|
|
418 }
|
|
419 else if (EQ (type, Qkey_press))
|
|
420 {
|
|
421 e->event_type = key_press_event;
|
|
422 e->event.key.keysym = Qunbound;
|
|
423 }
|
|
424 else if (EQ (type, Qbutton_press))
|
|
425 e->event_type = button_press_event;
|
|
426 else if (EQ (type, Qbutton_release))
|
|
427 e->event_type = button_release_event;
|
|
428 else if (EQ (type, Qmotion))
|
|
429 e->event_type = pointer_motion_event;
|
|
430 else if (EQ (type, Qmisc_user))
|
|
431 {
|
|
432 e->event_type = misc_user_event;
|
|
433 e->event.eval.function = e->event.eval.object = Qnil;
|
|
434 }
|
|
435 else
|
|
436 {
|
|
437 /* Not allowed: Qprocess, Qtimeout, Qmagic, Qeval, Qmagic_eval. */
|
563
|
438 invalid_constant ("Invalid event type", type);
|
428
|
439 }
|
|
440
|
|
441 EVENT_CHANNEL (e) = Qnil;
|
|
442
|
|
443 plist = Fcopy_sequence (plist);
|
|
444 Fcanonicalize_plist (plist, Qnil);
|
|
445
|
442
|
446 #define WRONG_EVENT_TYPE_FOR_PROPERTY(event_type, prop) \
|
563
|
447 invalid_argument_2 ("Invalid property for event type", prop, event_type)
|
428
|
448
|
442
|
449 {
|
|
450 EXTERNAL_PROPERTY_LIST_LOOP_3 (keyword, value, plist)
|
|
451 {
|
|
452 if (EQ (keyword, Qchannel))
|
|
453 {
|
|
454 if (e->event_type == key_press_event)
|
|
455 {
|
|
456 if (!CONSOLEP (value))
|
|
457 value = wrong_type_argument (Qconsolep, value);
|
|
458 }
|
|
459 else
|
|
460 {
|
|
461 if (!FRAMEP (value))
|
|
462 value = wrong_type_argument (Qframep, value);
|
|
463 }
|
|
464 EVENT_CHANNEL (e) = value;
|
|
465 }
|
|
466 else if (EQ (keyword, Qkey))
|
|
467 {
|
|
468 switch (e->event_type)
|
|
469 {
|
|
470 case key_press_event:
|
|
471 if (!SYMBOLP (value) && !CHARP (value))
|
563
|
472 invalid_argument ("Invalid event key", value);
|
442
|
473 e->event.key.keysym = value;
|
|
474 break;
|
|
475 default:
|
|
476 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
|
|
477 break;
|
|
478 }
|
|
479 }
|
|
480 else if (EQ (keyword, Qbutton))
|
|
481 {
|
|
482 CHECK_NATNUM (value);
|
|
483 check_int_range (XINT (value), 0, 7);
|
428
|
484
|
442
|
485 switch (e->event_type)
|
|
486 {
|
|
487 case button_press_event:
|
|
488 case button_release_event:
|
|
489 e->event.button.button = XINT (value);
|
|
490 break;
|
|
491 case misc_user_event:
|
|
492 e->event.misc.button = XINT (value);
|
|
493 break;
|
|
494 default:
|
|
495 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
|
|
496 break;
|
|
497 }
|
|
498 }
|
|
499 else if (EQ (keyword, Qmodifiers))
|
|
500 {
|
|
501 int modifiers = 0;
|
428
|
502
|
442
|
503 EXTERNAL_LIST_LOOP_2 (sym, value)
|
|
504 {
|
|
505 if (EQ (sym, Qcontrol)) modifiers |= XEMACS_MOD_CONTROL;
|
|
506 else if (EQ (sym, Qmeta)) modifiers |= XEMACS_MOD_META;
|
|
507 else if (EQ (sym, Qsuper)) modifiers |= XEMACS_MOD_SUPER;
|
|
508 else if (EQ (sym, Qhyper)) modifiers |= XEMACS_MOD_HYPER;
|
|
509 else if (EQ (sym, Qalt)) modifiers |= XEMACS_MOD_ALT;
|
|
510 else if (EQ (sym, Qsymbol)) modifiers |= XEMACS_MOD_ALT;
|
|
511 else if (EQ (sym, Qshift)) modifiers |= XEMACS_MOD_SHIFT;
|
|
512 else if (EQ (sym, Qbutton1)) modifiers |= XEMACS_MOD_BUTTON1;
|
|
513 else if (EQ (sym, Qbutton2)) modifiers |= XEMACS_MOD_BUTTON2;
|
|
514 else if (EQ (sym, Qbutton3)) modifiers |= XEMACS_MOD_BUTTON3;
|
|
515 else if (EQ (sym, Qbutton4)) modifiers |= XEMACS_MOD_BUTTON4;
|
|
516 else if (EQ (sym, Qbutton5)) modifiers |= XEMACS_MOD_BUTTON5;
|
|
517 else
|
563
|
518 invalid_constant ("Invalid key modifier", sym);
|
442
|
519 }
|
428
|
520
|
442
|
521 switch (e->event_type)
|
|
522 {
|
|
523 case key_press_event:
|
|
524 e->event.key.modifiers = modifiers;
|
|
525 break;
|
|
526 case button_press_event:
|
|
527 case button_release_event:
|
|
528 e->event.button.modifiers = modifiers;
|
|
529 break;
|
|
530 case pointer_motion_event:
|
|
531 e->event.motion.modifiers = modifiers;
|
|
532 break;
|
|
533 case misc_user_event:
|
|
534 e->event.misc.modifiers = modifiers;
|
|
535 break;
|
|
536 default:
|
|
537 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
|
|
538 break;
|
|
539 }
|
|
540 }
|
|
541 else if (EQ (keyword, Qx))
|
|
542 {
|
|
543 switch (e->event_type)
|
|
544 {
|
|
545 case pointer_motion_event:
|
|
546 case button_press_event:
|
|
547 case button_release_event:
|
|
548 case misc_user_event:
|
|
549 /* Allow negative values, so we can specify toolbar
|
|
550 positions. */
|
|
551 CHECK_INT (value);
|
|
552 coord_x = XINT (value);
|
|
553 break;
|
|
554 default:
|
|
555 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
|
|
556 break;
|
|
557 }
|
|
558 }
|
|
559 else if (EQ (keyword, Qy))
|
|
560 {
|
|
561 switch (e->event_type)
|
|
562 {
|
|
563 case pointer_motion_event:
|
|
564 case button_press_event:
|
|
565 case button_release_event:
|
|
566 case misc_user_event:
|
|
567 /* Allow negative values; see above. */
|
|
568 CHECK_INT (value);
|
|
569 coord_y = XINT (value);
|
|
570 break;
|
|
571 default:
|
|
572 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
|
|
573 break;
|
|
574 }
|
|
575 }
|
|
576 else if (EQ (keyword, Qtimestamp))
|
|
577 {
|
|
578 CHECK_NATNUM (value);
|
|
579 e->timestamp = XINT (value);
|
|
580 }
|
|
581 else if (EQ (keyword, Qfunction))
|
|
582 {
|
|
583 switch (e->event_type)
|
|
584 {
|
|
585 case misc_user_event:
|
|
586 e->event.eval.function = value;
|
|
587 break;
|
|
588 default:
|
|
589 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
|
|
590 break;
|
|
591 }
|
|
592 }
|
|
593 else if (EQ (keyword, Qobject))
|
|
594 {
|
|
595 switch (e->event_type)
|
|
596 {
|
|
597 case misc_user_event:
|
|
598 e->event.eval.object = value;
|
|
599 break;
|
|
600 default:
|
|
601 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
|
|
602 break;
|
|
603 }
|
|
604 }
|
|
605 else
|
563
|
606 invalid_constant_2 ("Invalid property", keyword, value);
|
442
|
607 }
|
|
608 }
|
428
|
609
|
|
610 /* Insert the channel, if missing. */
|
|
611 if (NILP (EVENT_CHANNEL (e)))
|
|
612 {
|
|
613 if (e->event_type == key_press_event)
|
|
614 EVENT_CHANNEL (e) = Vselected_console;
|
|
615 else
|
|
616 EVENT_CHANNEL (e) = Fselected_frame (Qnil);
|
|
617 }
|
|
618
|
|
619 /* Fevent_properties, Fevent_x_pixel, etc. work with pixels relative
|
|
620 to the frame, so we must adjust accordingly. */
|
|
621 if (FRAMEP (EVENT_CHANNEL (e)))
|
|
622 {
|
|
623 coord_x += FRAME_REAL_LEFT_TOOLBAR_WIDTH (XFRAME (EVENT_CHANNEL (e)));
|
|
624 coord_y += FRAME_REAL_TOP_TOOLBAR_HEIGHT (XFRAME (EVENT_CHANNEL (e)));
|
|
625
|
|
626 switch (e->event_type)
|
|
627 {
|
|
628 case pointer_motion_event:
|
|
629 e->event.motion.x = coord_x;
|
|
630 e->event.motion.y = coord_y;
|
|
631 break;
|
|
632 case button_press_event:
|
|
633 case button_release_event:
|
|
634 e->event.button.x = coord_x;
|
|
635 e->event.button.y = coord_y;
|
|
636 break;
|
|
637 case misc_user_event:
|
|
638 e->event.misc.x = coord_x;
|
|
639 e->event.misc.y = coord_y;
|
|
640 break;
|
|
641 default:
|
|
642 abort();
|
|
643 }
|
|
644 }
|
|
645
|
|
646 /* Finally, do some more validation. */
|
|
647 switch (e->event_type)
|
|
648 {
|
|
649 case key_press_event:
|
|
650 if (UNBOUNDP (e->event.key.keysym))
|
563
|
651 sferror ("A key must be specified to make a keypress event",
|
442
|
652 plist);
|
428
|
653 break;
|
|
654 case button_press_event:
|
|
655 if (!e->event.button.button)
|
563
|
656 sferror
|
442
|
657 ("A button must be specified to make a button-press event",
|
|
658 plist);
|
428
|
659 break;
|
|
660 case button_release_event:
|
|
661 if (!e->event.button.button)
|
563
|
662 sferror
|
442
|
663 ("A button must be specified to make a button-release event",
|
|
664 plist);
|
428
|
665 break;
|
|
666 case misc_user_event:
|
|
667 if (NILP (e->event.misc.function))
|
563
|
668 sferror ("A function must be specified to make a misc-user event",
|
442
|
669 plist);
|
428
|
670 break;
|
|
671 default:
|
|
672 break;
|
|
673 }
|
|
674
|
|
675 UNGCPRO;
|
|
676 return event;
|
|
677 }
|
|
678
|
|
679 DEFUN ("deallocate-event", Fdeallocate_event, 1, 1, 0, /*
|
|
680 Allow the given event structure to be reused.
|
|
681 You MUST NOT use this event object after calling this function with it.
|
|
682 You will lose. It is not necessary to call this function, as event
|
|
683 objects are garbage-collected like all other objects; however, it may
|
|
684 be more efficient to explicitly deallocate events when you are sure
|
|
685 that it is safe to do so.
|
|
686 */
|
|
687 (event))
|
|
688 {
|
|
689 CHECK_EVENT (event);
|
|
690
|
|
691 if (XEVENT_TYPE (event) == dead_event)
|
563
|
692 invalid_argument ("this event is already deallocated!", Qunbound);
|
428
|
693
|
|
694 assert (XEVENT_TYPE (event) <= last_event_type);
|
|
695
|
|
696 #if 0
|
|
697 {
|
|
698 int i, len;
|
|
699
|
|
700 if (EQ (event, Vlast_command_event) ||
|
|
701 EQ (event, Vlast_input_event) ||
|
|
702 EQ (event, Vunread_command_event))
|
|
703 abort ();
|
|
704
|
|
705 len = XVECTOR_LENGTH (Vthis_command_keys);
|
|
706 for (i = 0; i < len; i++)
|
|
707 if (EQ (event, XVECTOR_DATA (Vthis_command_keys) [i]))
|
|
708 abort ();
|
|
709 if (!NILP (Vrecent_keys_ring))
|
|
710 {
|
|
711 int recent_ring_len = XVECTOR_LENGTH (Vrecent_keys_ring);
|
|
712 for (i = 0; i < recent_ring_len; i++)
|
|
713 if (EQ (event, XVECTOR_DATA (Vrecent_keys_ring) [i]))
|
|
714 abort ();
|
|
715 }
|
|
716 }
|
|
717 #endif /* 0 */
|
|
718
|
|
719 assert (!EQ (event, Vevent_resource));
|
|
720 deinitialize_event (event);
|
|
721 #ifndef ALLOC_NO_POOLS
|
|
722 XSET_EVENT_NEXT (event, Vevent_resource);
|
|
723 Vevent_resource = event;
|
|
724 #endif
|
|
725 return Qnil;
|
|
726 }
|
|
727
|
|
728 DEFUN ("copy-event", Fcopy_event, 1, 2, 0, /*
|
444
|
729 Make a copy of the event object EVENT1.
|
|
730 If a second event argument EVENT2 is given, EVENT1 is copied into
|
|
731 EVENT2 and EVENT2 is returned. If EVENT2 is not supplied (or is nil)
|
|
732 then a new event will be made as with `make-event'. See also the
|
|
733 function `deallocate-event'.
|
428
|
734 */
|
|
735 (event1, event2))
|
|
736 {
|
|
737 CHECK_LIVE_EVENT (event1);
|
|
738 if (NILP (event2))
|
|
739 event2 = Fmake_event (Qnil, Qnil);
|
430
|
740 else
|
|
741 {
|
|
742 CHECK_LIVE_EVENT (event2);
|
|
743 if (EQ (event1, event2))
|
563
|
744 return signal_continuable_error_2
|
|
745 (Qinvalid_argument,
|
|
746 "copy-event called with `eq' events", event1, event2);
|
430
|
747 }
|
428
|
748
|
|
749 assert (XEVENT_TYPE (event1) <= last_event_type);
|
|
750 assert (XEVENT_TYPE (event2) <= last_event_type);
|
|
751
|
|
752 {
|
430
|
753 Lisp_Event *ev2 = XEVENT (event2);
|
|
754 Lisp_Event *ev1 = XEVENT (event1);
|
428
|
755
|
430
|
756 ev2->event_type = ev1->event_type;
|
|
757 ev2->channel = ev1->channel;
|
|
758 ev2->timestamp = ev1->timestamp;
|
|
759 ev2->event = ev1->event;
|
|
760
|
428
|
761 return event2;
|
|
762 }
|
|
763 }
|
|
764
|
|
765
|
771
|
766 /************************************************************************/
|
|
767 /* event chain functions */
|
|
768 /************************************************************************/
|
428
|
769
|
|
770 /* Given a chain of events (or possibly nil), deallocate them all. */
|
|
771
|
|
772 void
|
|
773 deallocate_event_chain (Lisp_Object event_chain)
|
|
774 {
|
|
775 while (!NILP (event_chain))
|
|
776 {
|
|
777 Lisp_Object next = XEVENT_NEXT (event_chain);
|
|
778 Fdeallocate_event (event_chain);
|
|
779 event_chain = next;
|
|
780 }
|
|
781 }
|
|
782
|
|
783 /* Return the last event in a chain.
|
|
784 NOTE: You cannot pass nil as a value here! The routine will
|
|
785 abort if you do. */
|
|
786
|
|
787 Lisp_Object
|
|
788 event_chain_tail (Lisp_Object event_chain)
|
|
789 {
|
|
790 while (1)
|
|
791 {
|
|
792 Lisp_Object next = XEVENT_NEXT (event_chain);
|
|
793 if (NILP (next))
|
|
794 return event_chain;
|
|
795 event_chain = next;
|
|
796 }
|
|
797 }
|
|
798
|
|
799 /* Enqueue a single event onto the end of a chain of events.
|
|
800 HEAD points to the first event in the chain, TAIL to the last event.
|
|
801 If the chain is empty, both values should be nil. */
|
|
802
|
|
803 void
|
|
804 enqueue_event (Lisp_Object event, Lisp_Object *head, Lisp_Object *tail)
|
|
805 {
|
|
806 assert (NILP (XEVENT_NEXT (event)));
|
|
807 assert (!EQ (*tail, event));
|
|
808
|
|
809 if (!NILP (*tail))
|
|
810 XSET_EVENT_NEXT (*tail, event);
|
|
811 else
|
|
812 *head = event;
|
|
813 *tail = event;
|
|
814
|
|
815 assert (!EQ (event, XEVENT_NEXT (event)));
|
|
816 }
|
|
817
|
|
818 /* Remove an event off the head of a chain of events and return it.
|
|
819 HEAD points to the first event in the chain, TAIL to the last event. */
|
|
820
|
|
821 Lisp_Object
|
|
822 dequeue_event (Lisp_Object *head, Lisp_Object *tail)
|
|
823 {
|
|
824 Lisp_Object event;
|
|
825
|
|
826 event = *head;
|
|
827 *head = XEVENT_NEXT (event);
|
|
828 XSET_EVENT_NEXT (event, Qnil);
|
|
829 if (NILP (*head))
|
|
830 *tail = Qnil;
|
|
831 return event;
|
|
832 }
|
|
833
|
|
834 /* Enqueue a chain of events (or possibly nil) onto the end of another
|
|
835 chain of events. HEAD points to the first event in the chain being
|
|
836 queued onto, TAIL to the last event. If the chain is empty, both values
|
|
837 should be nil. */
|
|
838
|
|
839 void
|
|
840 enqueue_event_chain (Lisp_Object event_chain, Lisp_Object *head,
|
|
841 Lisp_Object *tail)
|
|
842 {
|
|
843 if (NILP (event_chain))
|
|
844 return;
|
|
845
|
|
846 if (NILP (*head))
|
|
847 {
|
|
848 *head = event_chain;
|
|
849 *tail = event_chain;
|
|
850 }
|
|
851 else
|
|
852 {
|
|
853 XSET_EVENT_NEXT (*tail, event_chain);
|
|
854 *tail = event_chain_tail (event_chain);
|
|
855 }
|
|
856 }
|
|
857
|
|
858 /* Return the number of events (possibly 0) on an event chain. */
|
|
859
|
|
860 int
|
|
861 event_chain_count (Lisp_Object event_chain)
|
|
862 {
|
|
863 Lisp_Object event;
|
|
864 int n = 0;
|
|
865
|
|
866 EVENT_CHAIN_LOOP (event, event_chain)
|
|
867 n++;
|
|
868
|
|
869 return n;
|
|
870 }
|
|
871
|
|
872 /* Find the event before EVENT in an event chain. This aborts
|
|
873 if the event is not in the chain. */
|
|
874
|
|
875 Lisp_Object
|
|
876 event_chain_find_previous (Lisp_Object event_chain, Lisp_Object event)
|
|
877 {
|
|
878 Lisp_Object previous = Qnil;
|
|
879
|
|
880 while (!NILP (event_chain))
|
|
881 {
|
|
882 if (EQ (event_chain, event))
|
|
883 return previous;
|
|
884 previous = event_chain;
|
|
885 event_chain = XEVENT_NEXT (event_chain);
|
|
886 }
|
|
887
|
|
888 abort ();
|
|
889 return Qnil;
|
|
890 }
|
|
891
|
|
892 Lisp_Object
|
|
893 event_chain_nth (Lisp_Object event_chain, int n)
|
|
894 {
|
|
895 Lisp_Object event;
|
|
896 EVENT_CHAIN_LOOP (event, event_chain)
|
|
897 {
|
|
898 if (!n)
|
|
899 return event;
|
|
900 n--;
|
|
901 }
|
|
902 return Qnil;
|
|
903 }
|
|
904
|
771
|
905 /* Return a freshly allocated copy of all events in the given chain. */
|
|
906
|
428
|
907 Lisp_Object
|
|
908 copy_event_chain (Lisp_Object event_chain)
|
|
909 {
|
|
910 Lisp_Object new_chain = Qnil;
|
|
911 Lisp_Object new_chain_tail = Qnil;
|
|
912 Lisp_Object event;
|
|
913
|
|
914 EVENT_CHAIN_LOOP (event, event_chain)
|
|
915 {
|
|
916 Lisp_Object copy = Fcopy_event (event, Qnil);
|
|
917 enqueue_event (copy, &new_chain, &new_chain_tail);
|
|
918 }
|
|
919
|
|
920 return new_chain;
|
|
921 }
|
|
922
|
771
|
923 /* Given a pointer (maybe nil) into an old chain (also maybe nil, if
|
|
924 pointer is nil) and a new chain which is a copy of the old, return
|
|
925 the corresponding new pointer. */
|
|
926 Lisp_Object
|
|
927 transfer_event_chain_pointer (Lisp_Object pointer, Lisp_Object old_chain,
|
|
928 Lisp_Object new_chain)
|
|
929 {
|
|
930 if (NILP (pointer))
|
|
931 return Qnil;
|
|
932 assert (!NILP (old_chain));
|
|
933 #ifdef ERROR_CHECK_TYPECHECK
|
|
934 /* make sure we're actually in the chain */
|
|
935 event_chain_find_previous (old_chain, pointer);
|
|
936 assert (event_chain_count (old_chain) == event_chain_count (new_chain));
|
|
937 #endif /* ERROR_CHECK_TYPECHECK */
|
|
938 return event_chain_nth (new_chain,
|
|
939 event_chain_count (old_chain) -
|
|
940 event_chain_count (pointer));
|
|
941 }
|
|
942
|
428
|
943
|
771
|
944 /************************************************************************/
|
|
945 /* higher level functions */
|
|
946 /************************************************************************/
|
428
|
947
|
|
948 Lisp_Object QKbackspace, QKtab, QKlinefeed, QKreturn, QKescape,
|
|
949 QKspace, QKdelete;
|
|
950
|
|
951 int
|
|
952 command_event_p (Lisp_Object event)
|
|
953 {
|
|
954 switch (XEVENT_TYPE (event))
|
|
955 {
|
|
956 case key_press_event:
|
|
957 case button_press_event:
|
|
958 case button_release_event:
|
|
959 case misc_user_event:
|
|
960 return 1;
|
|
961 default:
|
|
962 return 0;
|
|
963 }
|
|
964 }
|
|
965
|
|
966
|
|
967 void
|
440
|
968 character_to_event (Emchar c, Lisp_Event *event, struct console *con,
|
428
|
969 int use_console_meta_flag, int do_backspace_mapping)
|
|
970 {
|
|
971 Lisp_Object k = Qnil;
|
442
|
972 int m = 0;
|
428
|
973 if (event->event_type == dead_event)
|
563
|
974 invalid_argument ("character-to-event called with a deallocated event!", Qunbound);
|
428
|
975
|
|
976 #ifndef MULE
|
|
977 c &= 255;
|
|
978 #endif
|
|
979 if (c > 127 && c <= 255)
|
|
980 {
|
|
981 int meta_flag = 1;
|
|
982 if (use_console_meta_flag && CONSOLE_TTY_P (con))
|
|
983 meta_flag = TTY_FLAGS (con).meta_key;
|
|
984 switch (meta_flag)
|
|
985 {
|
|
986 case 0: /* ignore top bit; it's parity */
|
|
987 c -= 128;
|
|
988 break;
|
|
989 case 1: /* top bit is meta */
|
|
990 c -= 128;
|
442
|
991 m = XEMACS_MOD_META;
|
428
|
992 break;
|
|
993 default: /* this is a real character */
|
|
994 break;
|
|
995 }
|
|
996 }
|
442
|
997 if (c < ' ') c += '@', m |= XEMACS_MOD_CONTROL;
|
|
998 if (m & XEMACS_MOD_CONTROL)
|
428
|
999 {
|
|
1000 switch (c)
|
|
1001 {
|
442
|
1002 case 'I': k = QKtab; m &= ~XEMACS_MOD_CONTROL; break;
|
|
1003 case 'J': k = QKlinefeed; m &= ~XEMACS_MOD_CONTROL; break;
|
|
1004 case 'M': k = QKreturn; m &= ~XEMACS_MOD_CONTROL; break;
|
|
1005 case '[': k = QKescape; m &= ~XEMACS_MOD_CONTROL; break;
|
428
|
1006 default:
|
|
1007 #if defined(HAVE_TTY)
|
|
1008 if (do_backspace_mapping &&
|
|
1009 CHARP (con->tty_erase_char) &&
|
|
1010 c - '@' == XCHAR (con->tty_erase_char))
|
|
1011 {
|
|
1012 k = QKbackspace;
|
442
|
1013 m &= ~XEMACS_MOD_CONTROL;
|
428
|
1014 }
|
442
|
1015 #endif /* defined(HAVE_TTY) && !defined(CYGWIN) */
|
428
|
1016 break;
|
|
1017 }
|
|
1018 if (c >= 'A' && c <= 'Z') c -= 'A'-'a';
|
|
1019 }
|
|
1020 #if defined(HAVE_TTY)
|
|
1021 else if (do_backspace_mapping &&
|
|
1022 CHARP (con->tty_erase_char) && c == XCHAR (con->tty_erase_char))
|
|
1023 k = QKbackspace;
|
442
|
1024 #endif /* defined(HAVE_TTY) && !defined(CYGWIN) */
|
428
|
1025 else if (c == 127)
|
|
1026 k = QKdelete;
|
|
1027 else if (c == ' ')
|
|
1028 k = QKspace;
|
|
1029
|
|
1030 event->event_type = key_press_event;
|
|
1031 event->timestamp = 0; /* #### */
|
771
|
1032 event->channel = wrap_console (con);
|
428
|
1033 event->event.key.keysym = (!NILP (k) ? k : make_char (c));
|
|
1034 event->event.key.modifiers = m;
|
|
1035 }
|
|
1036
|
|
1037 /* This variable controls what character name -> character code mapping
|
|
1038 we are using. Window-system-specific code sets this to some symbol,
|
|
1039 and we use that symbol as the plist key to convert keysyms into 8-bit
|
|
1040 codes. In this way one can have several character sets predefined and
|
|
1041 switch them by changing this.
|
440
|
1042
|
|
1043 #### This is utterly bogus and should be removed.
|
428
|
1044 */
|
|
1045 Lisp_Object Vcharacter_set_property;
|
|
1046
|
|
1047 Emchar
|
440
|
1048 event_to_character (Lisp_Event *event,
|
428
|
1049 int allow_extra_modifiers,
|
|
1050 int allow_meta,
|
|
1051 int allow_non_ascii)
|
|
1052 {
|
|
1053 Emchar c = 0;
|
|
1054 Lisp_Object code;
|
|
1055
|
|
1056 if (event->event_type != key_press_event)
|
|
1057 {
|
438
|
1058 assert (event->event_type != dead_event);
|
428
|
1059 return -1;
|
|
1060 }
|
|
1061 if (!allow_extra_modifiers &&
|
442
|
1062 event->event.key.modifiers & (XEMACS_MOD_SUPER|XEMACS_MOD_HYPER|XEMACS_MOD_ALT))
|
428
|
1063 return -1;
|
|
1064 if (CHAR_OR_CHAR_INTP (event->event.key.keysym))
|
|
1065 c = XCHAR_OR_CHAR_INT (event->event.key.keysym);
|
|
1066 else if (!SYMBOLP (event->event.key.keysym))
|
|
1067 abort ();
|
|
1068 else if (allow_non_ascii && !NILP (Vcharacter_set_property)
|
|
1069 /* Allow window-system-specific extensibility of
|
|
1070 keysym->code mapping */
|
|
1071 && CHAR_OR_CHAR_INTP (code = Fget (event->event.key.keysym,
|
|
1072 Vcharacter_set_property,
|
|
1073 Qnil)))
|
|
1074 c = XCHAR_OR_CHAR_INT (code);
|
|
1075 else if (CHAR_OR_CHAR_INTP (code = Fget (event->event.key.keysym,
|
|
1076 Qascii_character, Qnil)))
|
|
1077 c = XCHAR_OR_CHAR_INT (code);
|
|
1078 else
|
|
1079 return -1;
|
|
1080
|
442
|
1081 if (event->event.key.modifiers & XEMACS_MOD_CONTROL)
|
428
|
1082 {
|
|
1083 if (c >= 'a' && c <= 'z')
|
|
1084 c -= ('a' - 'A');
|
|
1085 else
|
|
1086 /* reject Control-Shift- keys */
|
|
1087 if (c >= 'A' && c <= 'Z' && !allow_extra_modifiers)
|
|
1088 return -1;
|
|
1089
|
|
1090 if (c >= '@' && c <= '_')
|
|
1091 c -= '@';
|
|
1092 else if (c == ' ') /* C-space and C-@ are the same. */
|
|
1093 c = 0;
|
|
1094 else
|
|
1095 /* reject keys that can't take Control- modifiers */
|
|
1096 if (! allow_extra_modifiers) return -1;
|
|
1097 }
|
|
1098
|
442
|
1099 if (event->event.key.modifiers & XEMACS_MOD_META)
|
428
|
1100 {
|
|
1101 if (! allow_meta) return -1;
|
|
1102 if (c & 0200) return -1; /* don't allow M-oslash (overlap) */
|
|
1103 #ifdef MULE
|
|
1104 if (c >= 256) return -1;
|
|
1105 #endif
|
|
1106 c |= 0200;
|
|
1107 }
|
|
1108 return c;
|
|
1109 }
|
|
1110
|
|
1111 DEFUN ("event-to-character", Fevent_to_character, 1, 4, 0, /*
|
|
1112 Return the closest ASCII approximation to the given event object.
|
|
1113 If the event isn't a keypress, this returns nil.
|
|
1114 If the ALLOW-EXTRA-MODIFIERS argument is non-nil, then this is lenient in
|
|
1115 its translation; it will ignore modifier keys other than control and meta,
|
|
1116 and will ignore the shift modifier on those characters which have no
|
|
1117 shifted ASCII equivalent (Control-Shift-A for example, will be mapped to
|
|
1118 the same ASCII code as Control-A).
|
|
1119 If the ALLOW-META argument is non-nil, then the Meta modifier will be
|
|
1120 represented by turning on the high bit of the byte returned; otherwise, nil
|
|
1121 will be returned for events containing the Meta modifier.
|
|
1122 If the ALLOW-NON-ASCII argument is non-nil, then characters which are
|
|
1123 present in the prevailing character set (see the `character-set-property'
|
|
1124 variable) will be returned as their code in that character set, instead of
|
|
1125 the return value being restricted to ASCII.
|
|
1126 Note that specifying both ALLOW-META and ALLOW-NON-ASCII is ambiguous, as
|
|
1127 both use the high bit; `M-x' and `oslash' will be indistinguishable.
|
|
1128 */
|
|
1129 (event, allow_extra_modifiers, allow_meta, allow_non_ascii))
|
|
1130 {
|
|
1131 Emchar c;
|
|
1132 CHECK_LIVE_EVENT (event);
|
|
1133 c = event_to_character (XEVENT (event),
|
|
1134 !NILP (allow_extra_modifiers),
|
|
1135 !NILP (allow_meta),
|
|
1136 !NILP (allow_non_ascii));
|
|
1137 return c < 0 ? Qnil : make_char (c);
|
|
1138 }
|
|
1139
|
|
1140 DEFUN ("character-to-event", Fcharacter_to_event, 1, 4, 0, /*
|
444
|
1141 Convert KEY-DESCRIPTION into an event structure, replete with bucky bits.
|
428
|
1142
|
444
|
1143 KEY-DESCRIPTION is the first argument, and the event to fill in is the
|
|
1144 second. This function contains knowledge about what various kinds of
|
|
1145 arguments ``mean'' -- for example, the number 9 is converted to the
|
|
1146 character ``Tab'', not the distinct character ``Control-I''.
|
428
|
1147
|
444
|
1148 KEY-DESCRIPTION can be an integer, a character, a symbol such as 'clear,
|
|
1149 or a list such as '(control backspace).
|
|
1150
|
|
1151 If the optional second argument EVENT is an event, it is modified and
|
|
1152 returned; otherwise, a new event object is created and returned.
|
428
|
1153
|
|
1154 Optional third arg CONSOLE is the console to store in the event, and
|
|
1155 defaults to the selected console.
|
|
1156
|
444
|
1157 If KEY-DESCRIPTION is an integer or character, the high bit may be
|
|
1158 interpreted as the meta key. (This is done for backward compatibility
|
|
1159 in lots of places.) If USE-CONSOLE-META-FLAG is nil, this will always
|
|
1160 be the case. If USE-CONSOLE-META-FLAG is non-nil, the `meta' flag for
|
|
1161 CONSOLE affects whether the high bit is interpreted as a meta
|
|
1162 key. (See `set-input-mode'.) If you don't want this silly meta
|
|
1163 interpretation done, you should pass in a list containing the
|
|
1164 character.
|
428
|
1165
|
|
1166 Beware that character-to-event and event-to-character are not strictly
|
|
1167 inverse functions, since events contain much more information than the
|
444
|
1168 Lisp character object type can encode.
|
428
|
1169 */
|
444
|
1170 (keystroke, event, console, use_console_meta_flag))
|
428
|
1171 {
|
|
1172 struct console *con = decode_console (console);
|
|
1173 if (NILP (event))
|
|
1174 event = Fmake_event (Qnil, Qnil);
|
|
1175 else
|
|
1176 CHECK_LIVE_EVENT (event);
|
444
|
1177 if (CONSP (keystroke) || SYMBOLP (keystroke))
|
|
1178 key_desc_list_to_event (keystroke, event, 1);
|
428
|
1179 else
|
|
1180 {
|
444
|
1181 CHECK_CHAR_COERCE_INT (keystroke);
|
|
1182 character_to_event (XCHAR (keystroke), XEVENT (event), con,
|
428
|
1183 !NILP (use_console_meta_flag), 1);
|
|
1184 }
|
|
1185 return event;
|
|
1186 }
|
|
1187
|
|
1188 void
|
|
1189 nth_of_key_sequence_as_event (Lisp_Object seq, int n, Lisp_Object event)
|
|
1190 {
|
|
1191 assert (STRINGP (seq) || VECTORP (seq));
|
|
1192 assert (n < XINT (Flength (seq)));
|
|
1193
|
|
1194 if (STRINGP (seq))
|
|
1195 {
|
|
1196 Emchar ch = string_char (XSTRING (seq), n);
|
|
1197 Fcharacter_to_event (make_char (ch), event, Qnil, Qnil);
|
|
1198 }
|
|
1199 else
|
|
1200 {
|
|
1201 Lisp_Object keystroke = XVECTOR_DATA (seq)[n];
|
|
1202 if (EVENTP (keystroke))
|
|
1203 Fcopy_event (keystroke, event);
|
|
1204 else
|
|
1205 Fcharacter_to_event (keystroke, event, Qnil, Qnil);
|
|
1206 }
|
|
1207 }
|
|
1208
|
|
1209 Lisp_Object
|
|
1210 key_sequence_to_event_chain (Lisp_Object seq)
|
|
1211 {
|
|
1212 int len = XINT (Flength (seq));
|
|
1213 int i;
|
|
1214 Lisp_Object head = Qnil, tail = Qnil;
|
|
1215
|
|
1216 for (i = 0; i < len; i++)
|
|
1217 {
|
|
1218 Lisp_Object event = Fmake_event (Qnil, Qnil);
|
|
1219 nth_of_key_sequence_as_event (seq, i, event);
|
|
1220 enqueue_event (event, &head, &tail);
|
|
1221 }
|
|
1222
|
|
1223 return head;
|
|
1224 }
|
|
1225
|
|
1226 void
|
440
|
1227 format_event_object (char *buf, Lisp_Event *event, int brief)
|
428
|
1228 {
|
|
1229 int mouse_p = 0;
|
|
1230 int mod = 0;
|
|
1231 Lisp_Object key;
|
|
1232
|
|
1233 switch (event->event_type)
|
|
1234 {
|
|
1235 case key_press_event:
|
|
1236 {
|
|
1237 mod = event->event.key.modifiers;
|
|
1238 key = event->event.key.keysym;
|
|
1239 /* Hack. */
|
|
1240 if (! brief && CHARP (key) &&
|
442
|
1241 mod & (XEMACS_MOD_CONTROL | XEMACS_MOD_META | XEMACS_MOD_SUPER | XEMACS_MOD_HYPER))
|
428
|
1242 {
|
|
1243 int k = XCHAR (key);
|
|
1244 if (k >= 'a' && k <= 'z')
|
|
1245 key = make_char (k - ('a' - 'A'));
|
|
1246 else if (k >= 'A' && k <= 'Z')
|
442
|
1247 mod |= XEMACS_MOD_SHIFT;
|
428
|
1248 }
|
|
1249 break;
|
|
1250 }
|
|
1251 case button_release_event:
|
|
1252 mouse_p++;
|
|
1253 /* Fall through */
|
|
1254 case button_press_event:
|
|
1255 {
|
|
1256 mouse_p++;
|
|
1257 mod = event->event.button.modifiers;
|
|
1258 key = make_char (event->event.button.button + '0');
|
|
1259 break;
|
|
1260 }
|
|
1261 case magic_event:
|
|
1262 {
|
788
|
1263 Lisp_Object stream;
|
|
1264 struct gcpro gcpro1;
|
|
1265 GCPRO1 (stream);
|
428
|
1266
|
788
|
1267 stream = make_resizing_buffer_output_stream ();
|
|
1268 event_stream_format_magic_event (event, stream);
|
|
1269 Lstream_flush (XLSTREAM (stream));
|
|
1270 strncpy (buf, resizing_buffer_stream_ptr (XLSTREAM (stream)),
|
|
1271 Lstream_byte_count (XLSTREAM (stream)));
|
|
1272 Lstream_delete (XLSTREAM (stream));
|
|
1273 UNGCPRO;
|
428
|
1274 return;
|
|
1275 }
|
|
1276 case magic_eval_event: strcpy (buf, "magic-eval"); return;
|
|
1277 case pointer_motion_event: strcpy (buf, "motion"); return;
|
|
1278 case misc_user_event: strcpy (buf, "misc-user"); return;
|
|
1279 case eval_event: strcpy (buf, "eval"); return;
|
|
1280 case process_event: strcpy (buf, "process"); return;
|
|
1281 case timeout_event: strcpy (buf, "timeout"); return;
|
|
1282 case empty_event: strcpy (buf, "empty"); return;
|
|
1283 case dead_event: strcpy (buf, "DEAD-EVENT"); return;
|
|
1284 default:
|
|
1285 abort ();
|
442
|
1286 return;
|
428
|
1287 }
|
|
1288 #define modprint1(x) do { strcpy (buf, (x)); buf += sizeof (x)-1; } while (0)
|
|
1289 #define modprint(x,y) do { if (brief) modprint1 (y); else modprint1 (x); } while (0)
|
442
|
1290 if (mod & XEMACS_MOD_CONTROL) modprint ("control-", "C-");
|
|
1291 if (mod & XEMACS_MOD_META) modprint ("meta-", "M-");
|
|
1292 if (mod & XEMACS_MOD_SUPER) modprint ("super-", "S-");
|
|
1293 if (mod & XEMACS_MOD_HYPER) modprint ("hyper-", "H-");
|
|
1294 if (mod & XEMACS_MOD_ALT) modprint ("alt-", "A-");
|
|
1295 if (mod & XEMACS_MOD_SHIFT) modprint ("shift-", "Sh-");
|
428
|
1296 if (mouse_p)
|
|
1297 {
|
|
1298 modprint1 ("button");
|
|
1299 --mouse_p;
|
|
1300 }
|
|
1301
|
|
1302 #undef modprint
|
|
1303 #undef modprint1
|
|
1304
|
|
1305 if (CHARP (key))
|
|
1306 {
|
665
|
1307 buf += set_charptr_emchar ((Intbyte *) buf, XCHAR (key));
|
428
|
1308 *buf = 0;
|
|
1309 }
|
|
1310 else if (SYMBOLP (key))
|
|
1311 {
|
442
|
1312 const char *str = 0;
|
428
|
1313 if (brief)
|
|
1314 {
|
|
1315 if (EQ (key, QKlinefeed)) str = "LFD";
|
|
1316 else if (EQ (key, QKtab)) str = "TAB";
|
|
1317 else if (EQ (key, QKreturn)) str = "RET";
|
|
1318 else if (EQ (key, QKescape)) str = "ESC";
|
|
1319 else if (EQ (key, QKdelete)) str = "DEL";
|
|
1320 else if (EQ (key, QKspace)) str = "SPC";
|
|
1321 else if (EQ (key, QKbackspace)) str = "BS";
|
|
1322 }
|
|
1323 if (str)
|
|
1324 {
|
|
1325 int i = strlen (str);
|
|
1326 memcpy (buf, str, i+1);
|
|
1327 str += i;
|
|
1328 }
|
|
1329 else
|
|
1330 {
|
440
|
1331 Lisp_String *name = XSYMBOL (key)->name;
|
428
|
1332 memcpy (buf, string_data (name), string_length (name) + 1);
|
|
1333 str += string_length (name);
|
|
1334 }
|
|
1335 }
|
|
1336 else
|
|
1337 abort ();
|
|
1338 if (mouse_p)
|
|
1339 strncpy (buf, "up", 4);
|
|
1340 }
|
|
1341
|
|
1342 DEFUN ("eventp", Feventp, 1, 1, 0, /*
|
|
1343 True if OBJECT is an event object.
|
|
1344 */
|
|
1345 (object))
|
|
1346 {
|
|
1347 return EVENTP (object) ? Qt : Qnil;
|
|
1348 }
|
|
1349
|
|
1350 DEFUN ("event-live-p", Fevent_live_p, 1, 1, 0, /*
|
|
1351 True if OBJECT is an event object that has not been deallocated.
|
|
1352 */
|
|
1353 (object))
|
|
1354 {
|
|
1355 return EVENTP (object) && XEVENT (object)->event_type != dead_event ?
|
|
1356 Qt : Qnil;
|
|
1357 }
|
|
1358
|
|
1359 #if 0 /* debugging functions */
|
|
1360
|
|
1361 xxDEFUN ("event-next", Fevent_next, 1, 1, 0, /*
|
|
1362 Return the event object's `next' event, or nil if it has none.
|
|
1363 The `next-event' field is changed by calling `set-next-event'.
|
|
1364 */
|
|
1365 (event))
|
|
1366 {
|
440
|
1367 Lisp_Event *e;
|
428
|
1368 CHECK_LIVE_EVENT (event);
|
|
1369
|
|
1370 return XEVENT_NEXT (event);
|
|
1371 }
|
|
1372
|
|
1373 xxDEFUN ("set-event-next", Fset_event_next, 2, 2, 0, /*
|
|
1374 Set the `next event' of EVENT to NEXT-EVENT.
|
|
1375 NEXT-EVENT must be an event object or nil.
|
|
1376 */
|
|
1377 (event, next_event))
|
|
1378 {
|
|
1379 Lisp_Object ev;
|
|
1380
|
|
1381 CHECK_LIVE_EVENT (event);
|
|
1382 if (NILP (next_event))
|
|
1383 {
|
|
1384 XSET_EVENT_NEXT (event, Qnil);
|
|
1385 return Qnil;
|
|
1386 }
|
|
1387
|
|
1388 CHECK_LIVE_EVENT (next_event);
|
|
1389
|
|
1390 EVENT_CHAIN_LOOP (ev, XEVENT_NEXT (event))
|
|
1391 {
|
|
1392 QUIT;
|
|
1393 if (EQ (ev, event))
|
563
|
1394 invalid_operation_2 ("Cyclic event-next", event, next_event);
|
428
|
1395 }
|
|
1396 XSET_EVENT_NEXT (event, next_event);
|
|
1397 return next_event;
|
|
1398 }
|
|
1399
|
|
1400 #endif /* 0 */
|
|
1401
|
|
1402 DEFUN ("event-type", Fevent_type, 1, 1, 0, /*
|
|
1403 Return the type of EVENT.
|
|
1404 This will be a symbol; one of
|
|
1405
|
|
1406 key-press A key was pressed.
|
|
1407 button-press A mouse button was pressed.
|
|
1408 button-release A mouse button was released.
|
|
1409 misc-user Some other user action happened; typically, this is
|
|
1410 a menu selection or scrollbar action.
|
|
1411 motion The mouse moved.
|
|
1412 process Input is available from a subprocess.
|
|
1413 timeout A timeout has expired.
|
|
1414 eval This causes a specified action to occur when dispatched.
|
|
1415 magic Some window-system-specific event has occurred.
|
|
1416 empty The event has been allocated but not assigned.
|
|
1417
|
|
1418 */
|
|
1419 (event))
|
|
1420 {
|
|
1421 CHECK_LIVE_EVENT (event);
|
|
1422 switch (XEVENT (event)->event_type)
|
|
1423 {
|
|
1424 case key_press_event: return Qkey_press;
|
|
1425 case button_press_event: return Qbutton_press;
|
|
1426 case button_release_event: return Qbutton_release;
|
|
1427 case misc_user_event: return Qmisc_user;
|
|
1428 case pointer_motion_event: return Qmotion;
|
|
1429 case process_event: return Qprocess;
|
|
1430 case timeout_event: return Qtimeout;
|
|
1431 case eval_event: return Qeval;
|
|
1432 case magic_event:
|
|
1433 case magic_eval_event:
|
|
1434 return Qmagic;
|
|
1435
|
|
1436 case empty_event:
|
|
1437 return Qempty;
|
|
1438
|
|
1439 default:
|
|
1440 abort ();
|
|
1441 return Qnil;
|
|
1442 }
|
|
1443 }
|
|
1444
|
|
1445 DEFUN ("event-timestamp", Fevent_timestamp, 1, 1, 0, /*
|
|
1446 Return the timestamp of the event object EVENT.
|
442
|
1447 Timestamps are measured in milliseconds since the start of the window system.
|
|
1448 They are NOT related to any current time measurement.
|
|
1449 They should be compared with `event-timestamp<'.
|
|
1450 See also `current-event-timestamp'.
|
428
|
1451 */
|
|
1452 (event))
|
|
1453 {
|
|
1454 CHECK_LIVE_EVENT (event);
|
|
1455 /* This junk is so that timestamps don't get to be negative, but contain
|
|
1456 as many bits as this particular emacs will allow.
|
|
1457 */
|
|
1458 return make_int (((1L << (VALBITS - 1)) - 1) &
|
|
1459 XEVENT (event)->timestamp);
|
|
1460 }
|
|
1461
|
442
|
1462 #define TIMESTAMP_HALFSPACE (1L << (VALBITS - 2))
|
|
1463
|
|
1464 DEFUN ("event-timestamp<", Fevent_timestamp_lessp, 2, 2, 0, /*
|
|
1465 Return true if timestamp TIME1 is earlier than timestamp TIME2.
|
|
1466 This correctly handles timestamp wrap.
|
|
1467 See also `event-timestamp' and `current-event-timestamp'.
|
|
1468 */
|
|
1469 (time1, time2))
|
|
1470 {
|
|
1471 EMACS_INT t1, t2;
|
|
1472
|
|
1473 CHECK_NATNUM (time1);
|
|
1474 CHECK_NATNUM (time2);
|
|
1475 t1 = XINT (time1);
|
|
1476 t2 = XINT (time2);
|
|
1477
|
|
1478 if (t1 < t2)
|
|
1479 return t2 - t1 < TIMESTAMP_HALFSPACE ? Qt : Qnil;
|
|
1480 else
|
|
1481 return t1 - t2 < TIMESTAMP_HALFSPACE ? Qnil : Qt;
|
|
1482 }
|
|
1483
|
428
|
1484 #define CHECK_EVENT_TYPE(e,t1,sym) do { \
|
|
1485 CHECK_LIVE_EVENT (e); \
|
|
1486 if (XEVENT(e)->event_type != (t1)) \
|
|
1487 e = wrong_type_argument (sym,e); \
|
|
1488 } while (0)
|
|
1489
|
|
1490 #define CHECK_EVENT_TYPE2(e,t1,t2,sym) do { \
|
|
1491 CHECK_LIVE_EVENT (e); \
|
|
1492 { \
|
|
1493 emacs_event_type CET_type = XEVENT (e)->event_type; \
|
|
1494 if (CET_type != (t1) && \
|
|
1495 CET_type != (t2)) \
|
|
1496 e = wrong_type_argument (sym,e); \
|
|
1497 } \
|
|
1498 } while (0)
|
|
1499
|
|
1500 #define CHECK_EVENT_TYPE3(e,t1,t2,t3,sym) do { \
|
|
1501 CHECK_LIVE_EVENT (e); \
|
|
1502 { \
|
|
1503 emacs_event_type CET_type = XEVENT (e)->event_type; \
|
|
1504 if (CET_type != (t1) && \
|
|
1505 CET_type != (t2) && \
|
|
1506 CET_type != (t3)) \
|
|
1507 e = wrong_type_argument (sym,e); \
|
|
1508 } \
|
|
1509 } while (0)
|
|
1510
|
|
1511 DEFUN ("event-key", Fevent_key, 1, 1, 0, /*
|
|
1512 Return the Keysym of the key-press event EVENT.
|
|
1513 This will be a character if the event is associated with one, else a symbol.
|
|
1514 */
|
|
1515 (event))
|
|
1516 {
|
|
1517 CHECK_EVENT_TYPE (event, key_press_event, Qkey_press_event_p);
|
|
1518 return XEVENT (event)->event.key.keysym;
|
|
1519 }
|
|
1520
|
|
1521 DEFUN ("event-button", Fevent_button, 1, 1, 0, /*
|
444
|
1522 Return the button-number of the button-press or button-release event EVENT.
|
428
|
1523 */
|
|
1524 (event))
|
|
1525 {
|
|
1526
|
|
1527 CHECK_EVENT_TYPE3 (event, button_press_event, button_release_event,
|
|
1528 misc_user_event, Qbutton_event_p);
|
|
1529 #ifdef HAVE_WINDOW_SYSTEM
|
|
1530 if ( XEVENT (event)->event_type == misc_user_event)
|
|
1531 return make_int (XEVENT (event)->event.misc.button);
|
|
1532 else
|
|
1533 return make_int (XEVENT (event)->event.button.button);
|
|
1534 #else /* !HAVE_WINDOW_SYSTEM */
|
|
1535 return Qzero;
|
|
1536 #endif /* !HAVE_WINDOW_SYSTEM */
|
|
1537
|
|
1538 }
|
|
1539
|
|
1540 DEFUN ("event-modifier-bits", Fevent_modifier_bits, 1, 1, 0, /*
|
442
|
1541 Return a number representing the modifier keys and buttons which were down
|
428
|
1542 when the given mouse or keyboard event was produced.
|
442
|
1543 See also the function `event-modifiers'.
|
428
|
1544 */
|
|
1545 (event))
|
|
1546 {
|
|
1547 again:
|
|
1548 CHECK_LIVE_EVENT (event);
|
|
1549 switch (XEVENT (event)->event_type)
|
|
1550 {
|
|
1551 case key_press_event:
|
|
1552 return make_int (XEVENT (event)->event.key.modifiers);
|
|
1553 case button_press_event:
|
|
1554 case button_release_event:
|
|
1555 return make_int (XEVENT (event)->event.button.modifiers);
|
|
1556 case pointer_motion_event:
|
|
1557 return make_int (XEVENT (event)->event.motion.modifiers);
|
|
1558 case misc_user_event:
|
|
1559 return make_int (XEVENT (event)->event.misc.modifiers);
|
|
1560 default:
|
|
1561 event = wrong_type_argument (intern ("key-or-mouse-event-p"), event);
|
|
1562 goto again;
|
|
1563 }
|
|
1564 }
|
|
1565
|
|
1566 DEFUN ("event-modifiers", Fevent_modifiers, 1, 1, 0, /*
|
442
|
1567 Return a list of symbols, the names of the modifier keys and buttons
|
428
|
1568 which were down when the given mouse or keyboard event was produced.
|
442
|
1569 See also the function `event-modifier-bits'.
|
|
1570
|
|
1571 The possible symbols in the list are
|
|
1572
|
|
1573 `shift': The Shift key. Will not appear, in general, on key events
|
|
1574 where the keysym is an ASCII character, because using Shift
|
|
1575 on such a character converts it into another character rather
|
|
1576 than actually just adding a Shift modifier.
|
|
1577
|
|
1578 `control': The Control key.
|
|
1579
|
|
1580 `meta': The Meta key. On PC's and PC-style keyboards, this is generally
|
|
1581 labelled \"Alt\"; Meta is a holdover from early Lisp Machines and
|
|
1582 such, propagated through the X Window System. On Sun keyboards,
|
|
1583 this key is labelled with a diamond.
|
|
1584
|
|
1585 `alt': The \"Alt\" key. Alt is in quotes because this does not refer
|
|
1586 to what it obviously should refer to, namely the Alt key on PC
|
|
1587 keyboards. Instead, it refers to the key labelled Alt on Sun
|
|
1588 keyboards, and to no key at all on PC keyboards.
|
|
1589
|
|
1590 `super': The Super key. Most keyboards don't have any such key, but
|
|
1591 under X Windows using `xmodmap' you can assign any key (such as
|
|
1592 an underused right-shift, right-control, or right-alt key) to
|
|
1593 this key modifier. No support currently exists under MS Windows
|
|
1594 for generating these modifiers.
|
|
1595
|
|
1596 `hyper': The Hyper key. Works just like the Super key.
|
|
1597
|
|
1598 `button1': The mouse buttons. This means that the specified button was held
|
|
1599 `button2': down at the time the event occurred. NOTE: For button-press
|
|
1600 `button3': events, the button that was just pressed down does NOT appear in
|
|
1601 `button4': the modifiers.
|
|
1602 `button5':
|
|
1603
|
|
1604 Button modifiers are currently ignored when defining and looking up key and
|
|
1605 mouse strokes in keymaps. This could be changed, which would allow a user to
|
|
1606 create button-chord actions, use a button as a key modifier and do other
|
|
1607 clever things.
|
428
|
1608 */
|
|
1609 (event))
|
|
1610 {
|
|
1611 int mod = XINT (Fevent_modifier_bits (event));
|
|
1612 Lisp_Object result = Qnil;
|
442
|
1613 struct gcpro gcpro1;
|
|
1614
|
|
1615 GCPRO1 (result);
|
|
1616 if (mod & XEMACS_MOD_SHIFT) result = Fcons (Qshift, result);
|
|
1617 if (mod & XEMACS_MOD_ALT) result = Fcons (Qalt, result);
|
|
1618 if (mod & XEMACS_MOD_HYPER) result = Fcons (Qhyper, result);
|
|
1619 if (mod & XEMACS_MOD_SUPER) result = Fcons (Qsuper, result);
|
|
1620 if (mod & XEMACS_MOD_META) result = Fcons (Qmeta, result);
|
|
1621 if (mod & XEMACS_MOD_CONTROL) result = Fcons (Qcontrol, result);
|
|
1622 if (mod & XEMACS_MOD_BUTTON1) result = Fcons (Qbutton1, result);
|
|
1623 if (mod & XEMACS_MOD_BUTTON2) result = Fcons (Qbutton2, result);
|
|
1624 if (mod & XEMACS_MOD_BUTTON3) result = Fcons (Qbutton3, result);
|
|
1625 if (mod & XEMACS_MOD_BUTTON4) result = Fcons (Qbutton4, result);
|
|
1626 if (mod & XEMACS_MOD_BUTTON5) result = Fcons (Qbutton5, result);
|
|
1627 RETURN_UNGCPRO (Fnreverse (result));
|
428
|
1628 }
|
|
1629
|
|
1630 static int
|
|
1631 event_x_y_pixel_internal (Lisp_Object event, int *x, int *y, int relative)
|
|
1632 {
|
|
1633 struct window *w;
|
|
1634 struct frame *f;
|
|
1635
|
|
1636 if (XEVENT (event)->event_type == pointer_motion_event)
|
|
1637 {
|
|
1638 *x = XEVENT (event)->event.motion.x;
|
|
1639 *y = XEVENT (event)->event.motion.y;
|
|
1640 }
|
|
1641 else if (XEVENT (event)->event_type == button_press_event ||
|
|
1642 XEVENT (event)->event_type == button_release_event)
|
|
1643 {
|
|
1644 *x = XEVENT (event)->event.button.x;
|
|
1645 *y = XEVENT (event)->event.button.y;
|
|
1646 }
|
|
1647 else if (XEVENT (event)->event_type == misc_user_event)
|
|
1648 {
|
|
1649 *x = XEVENT (event)->event.misc.x;
|
|
1650 *y = XEVENT (event)->event.misc.y;
|
|
1651 }
|
|
1652 else
|
|
1653 return 0;
|
|
1654
|
|
1655 f = XFRAME (EVENT_CHANNEL (XEVENT (event)));
|
|
1656
|
|
1657 if (relative)
|
|
1658 {
|
|
1659 w = find_window_by_pixel_pos (*x, *y, f->root_window);
|
|
1660
|
|
1661 if (!w)
|
442
|
1662 return 1; /* #### What should really happen here? */
|
428
|
1663
|
|
1664 *x -= w->pixel_left;
|
|
1665 *y -= w->pixel_top;
|
|
1666 }
|
|
1667 else
|
|
1668 {
|
|
1669 *y -= FRAME_REAL_TOP_TOOLBAR_HEIGHT (f) -
|
|
1670 FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f);
|
|
1671 *x -= FRAME_REAL_LEFT_TOOLBAR_WIDTH (f) -
|
|
1672 FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f);
|
|
1673 }
|
|
1674
|
|
1675 return 1;
|
|
1676 }
|
|
1677
|
|
1678 DEFUN ("event-window-x-pixel", Fevent_window_x_pixel, 1, 1, 0, /*
|
|
1679 Return the X position in pixels of mouse event EVENT.
|
|
1680 The value returned is relative to the window the event occurred in.
|
|
1681 This will signal an error if the event is not a mouse event.
|
|
1682 See also `mouse-event-p' and `event-x-pixel'.
|
|
1683 */
|
|
1684 (event))
|
|
1685 {
|
|
1686 int x, y;
|
|
1687
|
|
1688 CHECK_LIVE_EVENT (event);
|
|
1689
|
|
1690 if (!event_x_y_pixel_internal (event, &x, &y, 1))
|
|
1691 return wrong_type_argument (Qmouse_event_p, event);
|
|
1692 else
|
|
1693 return make_int (x);
|
|
1694 }
|
|
1695
|
|
1696 DEFUN ("event-window-y-pixel", Fevent_window_y_pixel, 1, 1, 0, /*
|
|
1697 Return the Y position in pixels of mouse event EVENT.
|
|
1698 The value returned is relative to the window the event occurred in.
|
|
1699 This will signal an error if the event is not a mouse event.
|
|
1700 See also `mouse-event-p' and `event-y-pixel'.
|
|
1701 */
|
|
1702 (event))
|
|
1703 {
|
|
1704 int x, y;
|
|
1705
|
|
1706 CHECK_LIVE_EVENT (event);
|
|
1707
|
|
1708 if (!event_x_y_pixel_internal (event, &x, &y, 1))
|
|
1709 return wrong_type_argument (Qmouse_event_p, event);
|
|
1710 else
|
|
1711 return make_int (y);
|
|
1712 }
|
|
1713
|
|
1714 DEFUN ("event-x-pixel", Fevent_x_pixel, 1, 1, 0, /*
|
|
1715 Return the X position in pixels of mouse event EVENT.
|
|
1716 The value returned is relative to the frame the event occurred in.
|
|
1717 This will signal an error if the event is not a mouse event.
|
|
1718 See also `mouse-event-p' and `event-window-x-pixel'.
|
|
1719 */
|
|
1720 (event))
|
|
1721 {
|
|
1722 int x, y;
|
|
1723
|
|
1724 CHECK_LIVE_EVENT (event);
|
|
1725
|
|
1726 if (!event_x_y_pixel_internal (event, &x, &y, 0))
|
|
1727 return wrong_type_argument (Qmouse_event_p, event);
|
|
1728 else
|
|
1729 return make_int (x);
|
|
1730 }
|
|
1731
|
|
1732 DEFUN ("event-y-pixel", Fevent_y_pixel, 1, 1, 0, /*
|
|
1733 Return the Y position in pixels of mouse event EVENT.
|
|
1734 The value returned is relative to the frame the event occurred in.
|
|
1735 This will signal an error if the event is not a mouse event.
|
|
1736 See also `mouse-event-p' `event-window-y-pixel'.
|
|
1737 */
|
|
1738 (event))
|
|
1739 {
|
|
1740 int x, y;
|
|
1741
|
|
1742 CHECK_LIVE_EVENT (event);
|
|
1743
|
|
1744 if (!event_x_y_pixel_internal (event, &x, &y, 0))
|
|
1745 return wrong_type_argument (Qmouse_event_p, event);
|
|
1746 else
|
|
1747 return make_int (y);
|
|
1748 }
|
|
1749
|
|
1750 /* Given an event, return a value:
|
|
1751
|
|
1752 OVER_TOOLBAR: over one of the 4 frame toolbars
|
|
1753 OVER_MODELINE: over a modeline
|
|
1754 OVER_BORDER: over an internal border
|
|
1755 OVER_NOTHING: over the text area, but not over text
|
|
1756 OVER_OUTSIDE: outside of the frame border
|
|
1757 OVER_TEXT: over text in the text area
|
|
1758 OVER_V_DIVIDER: over windows vertical divider
|
|
1759
|
|
1760 and return:
|
|
1761
|
|
1762 The X char position in CHAR_X, if not a null pointer.
|
|
1763 The Y char position in CHAR_Y, if not a null pointer.
|
|
1764 (These last two values are relative to the window the event is over.)
|
|
1765 The window it's over in W, if not a null pointer.
|
|
1766 The buffer position it's over in BUFP, if not a null pointer.
|
|
1767 The closest buffer position in CLOSEST, if not a null pointer.
|
|
1768
|
|
1769 OBJ_X, OBJ_Y, OBJ1, and OBJ2 are as in pixel_to_glyph_translation().
|
|
1770 */
|
|
1771
|
|
1772 static int
|
|
1773 event_pixel_translation (Lisp_Object event, int *char_x, int *char_y,
|
|
1774 int *obj_x, int *obj_y,
|
665
|
1775 struct window **w, Charbpos *bufp, Charbpos *closest,
|
428
|
1776 Charcount *modeline_closest,
|
|
1777 Lisp_Object *obj1, Lisp_Object *obj2)
|
|
1778 {
|
|
1779 int pix_x = 0;
|
|
1780 int pix_y = 0;
|
|
1781 int result;
|
|
1782 Lisp_Object frame;
|
|
1783
|
|
1784 int ret_x, ret_y, ret_obj_x, ret_obj_y;
|
|
1785 struct window *ret_w;
|
665
|
1786 Charbpos ret_bufp, ret_closest;
|
428
|
1787 Charcount ret_modeline_closest;
|
|
1788 Lisp_Object ret_obj1, ret_obj2;
|
|
1789
|
|
1790 CHECK_LIVE_EVENT (event);
|
|
1791 frame = XEVENT (event)->channel;
|
|
1792 switch (XEVENT (event)->event_type)
|
|
1793 {
|
|
1794 case pointer_motion_event :
|
|
1795 pix_x = XEVENT (event)->event.motion.x;
|
|
1796 pix_y = XEVENT (event)->event.motion.y;
|
|
1797 break;
|
|
1798 case button_press_event :
|
|
1799 case button_release_event :
|
|
1800 pix_x = XEVENT (event)->event.button.x;
|
|
1801 pix_y = XEVENT (event)->event.button.y;
|
|
1802 break;
|
|
1803 case misc_user_event :
|
|
1804 pix_x = XEVENT (event)->event.misc.x;
|
|
1805 pix_y = XEVENT (event)->event.misc.y;
|
|
1806 break;
|
|
1807 default:
|
|
1808 dead_wrong_type_argument (Qmouse_event_p, event);
|
|
1809 }
|
|
1810
|
|
1811 result = pixel_to_glyph_translation (XFRAME (frame), pix_x, pix_y,
|
|
1812 &ret_x, &ret_y, &ret_obj_x, &ret_obj_y,
|
|
1813 &ret_w, &ret_bufp, &ret_closest,
|
|
1814 &ret_modeline_closest,
|
|
1815 &ret_obj1, &ret_obj2);
|
|
1816
|
|
1817 if (result == OVER_NOTHING || result == OVER_OUTSIDE)
|
|
1818 ret_bufp = 0;
|
|
1819 else if (ret_w && NILP (ret_w->buffer))
|
|
1820 /* Why does this happen? (Does it still happen?)
|
|
1821 I guess the window has gotten reused as a non-leaf... */
|
|
1822 ret_w = 0;
|
|
1823
|
|
1824 /* #### pixel_to_glyph_translation() sometimes returns garbage...
|
|
1825 The word has type Lisp_Type_Record (presumably meaning `extent') but the
|
|
1826 pointer points to random memory, often filled with 0, sometimes not.
|
|
1827 */
|
|
1828 /* #### Chuck, do we still need this crap? */
|
|
1829 if (!NILP (ret_obj1) && !(GLYPHP (ret_obj1)
|
|
1830 #ifdef HAVE_TOOLBARS
|
|
1831 || TOOLBAR_BUTTONP (ret_obj1)
|
|
1832 #endif
|
|
1833 ))
|
|
1834 abort ();
|
|
1835 if (!NILP (ret_obj2) && !(EXTENTP (ret_obj2) || CONSP (ret_obj2)))
|
|
1836 abort ();
|
|
1837
|
|
1838 if (char_x)
|
|
1839 *char_x = ret_x;
|
|
1840 if (char_y)
|
|
1841 *char_y = ret_y;
|
|
1842 if (obj_x)
|
|
1843 *obj_x = ret_obj_x;
|
|
1844 if (obj_y)
|
|
1845 *obj_y = ret_obj_y;
|
|
1846 if (w)
|
|
1847 *w = ret_w;
|
|
1848 if (bufp)
|
|
1849 *bufp = ret_bufp;
|
|
1850 if (closest)
|
|
1851 *closest = ret_closest;
|
|
1852 if (modeline_closest)
|
|
1853 *modeline_closest = ret_modeline_closest;
|
|
1854 if (obj1)
|
|
1855 *obj1 = ret_obj1;
|
|
1856 if (obj2)
|
|
1857 *obj2 = ret_obj2;
|
|
1858
|
|
1859 return result;
|
|
1860 }
|
|
1861
|
|
1862 DEFUN ("event-over-text-area-p", Fevent_over_text_area_p, 1, 1, 0, /*
|
|
1863 Return t if the mouse event EVENT occurred over the text area of a window.
|
|
1864 The modeline is not considered to be part of the text area.
|
|
1865 */
|
|
1866 (event))
|
|
1867 {
|
|
1868 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1869
|
|
1870 return result == OVER_TEXT || result == OVER_NOTHING ? Qt : Qnil;
|
|
1871 }
|
|
1872
|
|
1873 DEFUN ("event-over-modeline-p", Fevent_over_modeline_p, 1, 1, 0, /*
|
|
1874 Return t if the mouse event EVENT occurred over the modeline of a window.
|
|
1875 */
|
|
1876 (event))
|
|
1877 {
|
|
1878 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1879
|
|
1880 return result == OVER_MODELINE ? Qt : Qnil;
|
|
1881 }
|
|
1882
|
|
1883 DEFUN ("event-over-border-p", Fevent_over_border_p, 1, 1, 0, /*
|
|
1884 Return t if the mouse event EVENT occurred over an internal border.
|
|
1885 */
|
|
1886 (event))
|
|
1887 {
|
|
1888 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1889
|
|
1890 return result == OVER_BORDER ? Qt : Qnil;
|
|
1891 }
|
|
1892
|
|
1893 DEFUN ("event-over-toolbar-p", Fevent_over_toolbar_p, 1, 1, 0, /*
|
|
1894 Return t if the mouse event EVENT occurred over a toolbar.
|
|
1895 */
|
|
1896 (event))
|
|
1897 {
|
|
1898 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1899
|
|
1900 return result == OVER_TOOLBAR ? Qt : Qnil;
|
|
1901 }
|
|
1902
|
|
1903 DEFUN ("event-over-vertical-divider-p", Fevent_over_vertical_divider_p, 1, 1, 0, /*
|
|
1904 Return t if the mouse event EVENT occurred over a window divider.
|
|
1905 */
|
|
1906 (event))
|
|
1907 {
|
|
1908 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
1909
|
|
1910 return result == OVER_V_DIVIDER ? Qt : Qnil;
|
|
1911 }
|
|
1912
|
|
1913 struct console *
|
|
1914 event_console_or_selected (Lisp_Object event)
|
|
1915 {
|
|
1916 Lisp_Object channel = EVENT_CHANNEL (XEVENT (event));
|
|
1917 Lisp_Object console = CDFW_CONSOLE (channel);
|
|
1918
|
|
1919 if (NILP (console))
|
|
1920 console = Vselected_console;
|
|
1921
|
|
1922 return XCONSOLE (console);
|
|
1923 }
|
|
1924
|
|
1925 DEFUN ("event-channel", Fevent_channel, 1, 1, 0, /*
|
|
1926 Return the channel that the event EVENT occurred on.
|
|
1927 This will be a frame, device, console, or nil for some types
|
|
1928 of events (e.g. eval events).
|
|
1929 */
|
|
1930 (event))
|
|
1931 {
|
|
1932 CHECK_LIVE_EVENT (event);
|
|
1933 return EVENT_CHANNEL (XEVENT (event));
|
|
1934 }
|
|
1935
|
|
1936 DEFUN ("event-window", Fevent_window, 1, 1, 0, /*
|
|
1937 Return the window over which mouse event EVENT occurred.
|
|
1938 This may be nil if the event occurred in the border or over a toolbar.
|
|
1939 The modeline is considered to be within the window it describes.
|
|
1940 */
|
|
1941 (event))
|
|
1942 {
|
|
1943 struct window *w;
|
|
1944
|
|
1945 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, 0, 0);
|
|
1946
|
|
1947 if (!w)
|
|
1948 return Qnil;
|
|
1949 else
|
|
1950 {
|
|
1951 Lisp_Object window;
|
|
1952
|
|
1953 XSETWINDOW (window, w);
|
|
1954 return window;
|
|
1955 }
|
|
1956 }
|
|
1957
|
|
1958 DEFUN ("event-point", Fevent_point, 1, 1, 0, /*
|
|
1959 Return the character position of the mouse event EVENT.
|
|
1960 If the event did not occur over a window, or did not occur over text,
|
|
1961 then this returns nil. Otherwise, it returns a position in the buffer
|
|
1962 visible in the event's window.
|
|
1963 */
|
|
1964 (event))
|
|
1965 {
|
665
|
1966 Charbpos bufp;
|
428
|
1967 struct window *w;
|
|
1968
|
|
1969 event_pixel_translation (event, 0, 0, 0, 0, &w, &bufp, 0, 0, 0, 0);
|
|
1970
|
|
1971 return w && bufp ? make_int (bufp) : Qnil;
|
|
1972 }
|
|
1973
|
|
1974 DEFUN ("event-closest-point", Fevent_closest_point, 1, 1, 0, /*
|
|
1975 Return the character position closest to the mouse event EVENT.
|
|
1976 If the event did not occur over a window or over text, return the
|
|
1977 closest point to the location of the event. If the Y pixel position
|
|
1978 overlaps a window and the X pixel position is to the left of that
|
|
1979 window, the closest point is the beginning of the line containing the
|
|
1980 Y position. If the Y pixel position overlaps a window and the X pixel
|
|
1981 position is to the right of that window, the closest point is the end
|
|
1982 of the line containing the Y position. If the Y pixel position is
|
|
1983 above a window, return 0. If it is below the last character in a window,
|
|
1984 return the value of (window-end).
|
|
1985 */
|
|
1986 (event))
|
|
1987 {
|
665
|
1988 Charbpos bufp;
|
428
|
1989
|
|
1990 event_pixel_translation (event, 0, 0, 0, 0, 0, 0, &bufp, 0, 0, 0);
|
|
1991
|
|
1992 return bufp ? make_int (bufp) : Qnil;
|
|
1993 }
|
|
1994
|
|
1995 DEFUN ("event-x", Fevent_x, 1, 1, 0, /*
|
|
1996 Return the X position of the mouse event EVENT in characters.
|
|
1997 This is relative to the window the event occurred over.
|
|
1998 */
|
|
1999 (event))
|
|
2000 {
|
|
2001 int char_x;
|
|
2002
|
|
2003 event_pixel_translation (event, &char_x, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
2004
|
|
2005 return make_int (char_x);
|
|
2006 }
|
|
2007
|
|
2008 DEFUN ("event-y", Fevent_y, 1, 1, 0, /*
|
|
2009 Return the Y position of the mouse event EVENT in characters.
|
|
2010 This is relative to the window the event occurred over.
|
|
2011 */
|
|
2012 (event))
|
|
2013 {
|
|
2014 int char_y;
|
|
2015
|
|
2016 event_pixel_translation (event, 0, &char_y, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
2017
|
|
2018 return make_int (char_y);
|
|
2019 }
|
|
2020
|
|
2021 DEFUN ("event-modeline-position", Fevent_modeline_position, 1, 1, 0, /*
|
|
2022 Return the character position in the modeline that EVENT occurred over.
|
|
2023 EVENT should be a mouse event. If EVENT did not occur over a modeline,
|
|
2024 nil is returned. You can determine the actual character that the
|
|
2025 event occurred over by looking in `generated-modeline-string' at the
|
|
2026 returned character position. Note that `generated-modeline-string'
|
|
2027 is buffer-local, and you must use EVENT's buffer when retrieving
|
|
2028 `generated-modeline-string' in order to get accurate results.
|
|
2029 */
|
|
2030 (event))
|
|
2031 {
|
|
2032 Charcount mbufp;
|
|
2033 int where;
|
|
2034
|
|
2035 where = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, &mbufp, 0, 0);
|
|
2036
|
|
2037 return (mbufp < 0 || where != OVER_MODELINE) ? Qnil : make_int (mbufp);
|
|
2038 }
|
|
2039
|
|
2040 DEFUN ("event-glyph", Fevent_glyph, 1, 1, 0, /*
|
|
2041 Return the glyph that the mouse event EVENT occurred over, or nil.
|
|
2042 */
|
|
2043 (event))
|
|
2044 {
|
|
2045 Lisp_Object glyph;
|
|
2046 struct window *w;
|
|
2047
|
|
2048 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, &glyph, 0);
|
|
2049
|
|
2050 return w && GLYPHP (glyph) ? glyph : Qnil;
|
|
2051 }
|
|
2052
|
|
2053 DEFUN ("event-glyph-extent", Fevent_glyph_extent, 1, 1, 0, /*
|
|
2054 Return the extent of the glyph that the mouse event EVENT occurred over.
|
|
2055 If the event did not occur over a glyph, nil is returned.
|
|
2056 */
|
|
2057 (event))
|
|
2058 {
|
|
2059 Lisp_Object extent;
|
|
2060 struct window *w;
|
|
2061
|
|
2062 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, 0, &extent);
|
|
2063
|
|
2064 return w && EXTENTP (extent) ? extent : Qnil;
|
|
2065 }
|
|
2066
|
|
2067 DEFUN ("event-glyph-x-pixel", Fevent_glyph_x_pixel, 1, 1, 0, /*
|
|
2068 Return the X pixel position of EVENT relative to the glyph it occurred over.
|
|
2069 EVENT should be a mouse event. If the event did not occur over a glyph,
|
|
2070 nil is returned.
|
|
2071 */
|
|
2072 (event))
|
|
2073 {
|
|
2074 Lisp_Object extent;
|
|
2075 struct window *w;
|
|
2076 int obj_x;
|
|
2077
|
|
2078 event_pixel_translation (event, 0, 0, &obj_x, 0, &w, 0, 0, 0, 0, &extent);
|
|
2079
|
|
2080 return w && EXTENTP (extent) ? make_int (obj_x) : Qnil;
|
|
2081 }
|
|
2082
|
|
2083 DEFUN ("event-glyph-y-pixel", Fevent_glyph_y_pixel, 1, 1, 0, /*
|
|
2084 Return the Y pixel position of EVENT relative to the glyph it occurred over.
|
|
2085 EVENT should be a mouse event. If the event did not occur over a glyph,
|
|
2086 nil is returned.
|
|
2087 */
|
|
2088 (event))
|
|
2089 {
|
|
2090 Lisp_Object extent;
|
|
2091 struct window *w;
|
|
2092 int obj_y;
|
|
2093
|
|
2094 event_pixel_translation (event, 0, 0, 0, &obj_y, &w, 0, 0, 0, 0, &extent);
|
|
2095
|
|
2096 return w && EXTENTP (extent) ? make_int (obj_y) : Qnil;
|
|
2097 }
|
|
2098
|
|
2099 DEFUN ("event-toolbar-button", Fevent_toolbar_button, 1, 1, 0, /*
|
|
2100 Return the toolbar button that the mouse event EVENT occurred over.
|
|
2101 If the event did not occur over a toolbar button, nil is returned.
|
|
2102 */
|
|
2103 (event))
|
|
2104 {
|
|
2105 #ifdef HAVE_TOOLBARS
|
|
2106 Lisp_Object button;
|
|
2107
|
|
2108 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, &button, 0);
|
|
2109
|
|
2110 return result == OVER_TOOLBAR && TOOLBAR_BUTTONP (button) ? button : Qnil;
|
|
2111 #else
|
|
2112 return Qnil;
|
|
2113 #endif
|
|
2114 }
|
|
2115
|
|
2116 DEFUN ("event-process", Fevent_process, 1, 1, 0, /*
|
444
|
2117 Return the process of the process-output event EVENT.
|
428
|
2118 */
|
|
2119 (event))
|
|
2120 {
|
|
2121 CHECK_EVENT_TYPE (event, process_event, Qprocess_event_p);
|
|
2122 return XEVENT (event)->event.process.process;
|
|
2123 }
|
|
2124
|
|
2125 DEFUN ("event-function", Fevent_function, 1, 1, 0, /*
|
|
2126 Return the callback function of EVENT.
|
|
2127 EVENT should be a timeout, misc-user, or eval event.
|
|
2128 */
|
|
2129 (event))
|
|
2130 {
|
|
2131 again:
|
|
2132 CHECK_LIVE_EVENT (event);
|
|
2133 switch (XEVENT (event)->event_type)
|
|
2134 {
|
|
2135 case timeout_event:
|
|
2136 return XEVENT (event)->event.timeout.function;
|
|
2137 case misc_user_event:
|
|
2138 return XEVENT (event)->event.misc.function;
|
|
2139 case eval_event:
|
|
2140 return XEVENT (event)->event.eval.function;
|
|
2141 default:
|
|
2142 event = wrong_type_argument (intern ("timeout-or-eval-event-p"), event);
|
|
2143 goto again;
|
|
2144 }
|
|
2145 }
|
|
2146
|
|
2147 DEFUN ("event-object", Fevent_object, 1, 1, 0, /*
|
|
2148 Return the callback function argument of EVENT.
|
|
2149 EVENT should be a timeout, misc-user, or eval event.
|
|
2150 */
|
|
2151 (event))
|
|
2152 {
|
|
2153 again:
|
|
2154 CHECK_LIVE_EVENT (event);
|
|
2155 switch (XEVENT (event)->event_type)
|
|
2156 {
|
|
2157 case timeout_event:
|
|
2158 return XEVENT (event)->event.timeout.object;
|
|
2159 case misc_user_event:
|
|
2160 return XEVENT (event)->event.misc.object;
|
|
2161 case eval_event:
|
|
2162 return XEVENT (event)->event.eval.object;
|
|
2163 default:
|
|
2164 event = wrong_type_argument (intern ("timeout-or-eval-event-p"), event);
|
|
2165 goto again;
|
|
2166 }
|
|
2167 }
|
|
2168
|
|
2169 DEFUN ("event-properties", Fevent_properties, 1, 1, 0, /*
|
|
2170 Return a list of all of the properties of EVENT.
|
|
2171 This is in the form of a property list (alternating keyword/value pairs).
|
|
2172 */
|
|
2173 (event))
|
|
2174 {
|
|
2175 Lisp_Object props = Qnil;
|
440
|
2176 Lisp_Event *e;
|
428
|
2177 struct gcpro gcpro1;
|
|
2178
|
|
2179 CHECK_LIVE_EVENT (event);
|
|
2180 e = XEVENT (event);
|
|
2181 GCPRO1 (props);
|
|
2182
|
|
2183 props = cons3 (Qtimestamp, Fevent_timestamp (event), props);
|
|
2184
|
|
2185 switch (e->event_type)
|
|
2186 {
|
|
2187 default: abort ();
|
|
2188
|
|
2189 case process_event:
|
|
2190 props = cons3 (Qprocess, e->event.process.process, props);
|
|
2191 break;
|
|
2192
|
|
2193 case timeout_event:
|
|
2194 props = cons3 (Qobject, Fevent_object (event), props);
|
|
2195 props = cons3 (Qfunction, Fevent_function (event), props);
|
|
2196 props = cons3 (Qid, make_int (e->event.timeout.id_number), props);
|
|
2197 break;
|
|
2198
|
|
2199 case key_press_event:
|
|
2200 props = cons3 (Qmodifiers, Fevent_modifiers (event), props);
|
|
2201 props = cons3 (Qkey, Fevent_key (event), props);
|
|
2202 break;
|
|
2203
|
|
2204 case button_press_event:
|
|
2205 case button_release_event:
|
|
2206 props = cons3 (Qy, Fevent_y_pixel (event), props);
|
|
2207 props = cons3 (Qx, Fevent_x_pixel (event), props);
|
|
2208 props = cons3 (Qmodifiers, Fevent_modifiers (event), props);
|
|
2209 props = cons3 (Qbutton, Fevent_button (event), props);
|
|
2210 break;
|
|
2211
|
|
2212 case pointer_motion_event:
|
|
2213 props = cons3 (Qmodifiers, Fevent_modifiers (event), props);
|
|
2214 props = cons3 (Qy, Fevent_y_pixel (event), props);
|
|
2215 props = cons3 (Qx, Fevent_x_pixel (event), props);
|
|
2216 break;
|
|
2217
|
|
2218 case misc_user_event:
|
|
2219 props = cons3 (Qobject, Fevent_object (event), props);
|
|
2220 props = cons3 (Qfunction, Fevent_function (event), props);
|
|
2221 props = cons3 (Qy, Fevent_y_pixel (event), props);
|
|
2222 props = cons3 (Qx, Fevent_x_pixel (event), props);
|
|
2223 props = cons3 (Qmodifiers, Fevent_modifiers (event), props);
|
|
2224 props = cons3 (Qbutton, Fevent_button (event), props);
|
|
2225 break;
|
|
2226
|
|
2227 case eval_event:
|
|
2228 props = cons3 (Qobject, Fevent_object (event), props);
|
|
2229 props = cons3 (Qfunction, Fevent_function (event), props);
|
|
2230 break;
|
|
2231
|
|
2232 case magic_eval_event:
|
|
2233 case magic_event:
|
|
2234 break;
|
|
2235
|
|
2236 case empty_event:
|
|
2237 RETURN_UNGCPRO (Qnil);
|
|
2238 break;
|
|
2239 }
|
|
2240
|
|
2241 props = cons3 (Qchannel, Fevent_channel (event), props);
|
|
2242 UNGCPRO;
|
|
2243
|
|
2244 return props;
|
|
2245 }
|
|
2246
|
|
2247
|
|
2248 /************************************************************************/
|
|
2249 /* initialization */
|
|
2250 /************************************************************************/
|
|
2251
|
|
2252 void
|
|
2253 syms_of_events (void)
|
|
2254 {
|
442
|
2255 INIT_LRECORD_IMPLEMENTATION (event);
|
|
2256
|
428
|
2257 DEFSUBR (Fcharacter_to_event);
|
|
2258 DEFSUBR (Fevent_to_character);
|
|
2259
|
|
2260 DEFSUBR (Fmake_event);
|
|
2261 DEFSUBR (Fdeallocate_event);
|
|
2262 DEFSUBR (Fcopy_event);
|
|
2263 DEFSUBR (Feventp);
|
|
2264 DEFSUBR (Fevent_live_p);
|
|
2265 DEFSUBR (Fevent_type);
|
|
2266 DEFSUBR (Fevent_properties);
|
|
2267
|
|
2268 DEFSUBR (Fevent_timestamp);
|
442
|
2269 DEFSUBR (Fevent_timestamp_lessp);
|
428
|
2270 DEFSUBR (Fevent_key);
|
|
2271 DEFSUBR (Fevent_button);
|
|
2272 DEFSUBR (Fevent_modifier_bits);
|
|
2273 DEFSUBR (Fevent_modifiers);
|
|
2274 DEFSUBR (Fevent_x_pixel);
|
|
2275 DEFSUBR (Fevent_y_pixel);
|
|
2276 DEFSUBR (Fevent_window_x_pixel);
|
|
2277 DEFSUBR (Fevent_window_y_pixel);
|
|
2278 DEFSUBR (Fevent_over_text_area_p);
|
|
2279 DEFSUBR (Fevent_over_modeline_p);
|
|
2280 DEFSUBR (Fevent_over_border_p);
|
|
2281 DEFSUBR (Fevent_over_toolbar_p);
|
|
2282 DEFSUBR (Fevent_over_vertical_divider_p);
|
|
2283 DEFSUBR (Fevent_channel);
|
|
2284 DEFSUBR (Fevent_window);
|
|
2285 DEFSUBR (Fevent_point);
|
|
2286 DEFSUBR (Fevent_closest_point);
|
|
2287 DEFSUBR (Fevent_x);
|
|
2288 DEFSUBR (Fevent_y);
|
|
2289 DEFSUBR (Fevent_modeline_position);
|
|
2290 DEFSUBR (Fevent_glyph);
|
|
2291 DEFSUBR (Fevent_glyph_extent);
|
|
2292 DEFSUBR (Fevent_glyph_x_pixel);
|
|
2293 DEFSUBR (Fevent_glyph_y_pixel);
|
|
2294 DEFSUBR (Fevent_toolbar_button);
|
|
2295 DEFSUBR (Fevent_process);
|
|
2296 DEFSUBR (Fevent_function);
|
|
2297 DEFSUBR (Fevent_object);
|
|
2298
|
563
|
2299 DEFSYMBOL (Qeventp);
|
|
2300 DEFSYMBOL (Qevent_live_p);
|
|
2301 DEFSYMBOL (Qkey_press_event_p);
|
|
2302 DEFSYMBOL (Qbutton_event_p);
|
|
2303 DEFSYMBOL (Qmouse_event_p);
|
|
2304 DEFSYMBOL (Qprocess_event_p);
|
|
2305 DEFSYMBOL (Qkey_press);
|
|
2306 DEFSYMBOL (Qbutton_press);
|
|
2307 DEFSYMBOL (Qbutton_release);
|
|
2308 DEFSYMBOL (Qmisc_user);
|
|
2309 DEFSYMBOL (Qascii_character);
|
428
|
2310
|
|
2311 defsymbol (&QKbackspace, "backspace");
|
|
2312 defsymbol (&QKtab, "tab");
|
|
2313 defsymbol (&QKlinefeed, "linefeed");
|
|
2314 defsymbol (&QKreturn, "return");
|
|
2315 defsymbol (&QKescape, "escape");
|
|
2316 defsymbol (&QKspace, "space");
|
|
2317 defsymbol (&QKdelete, "delete");
|
|
2318 }
|
|
2319
|
|
2320
|
|
2321 void
|
|
2322 reinit_vars_of_events (void)
|
|
2323 {
|
|
2324 Vevent_resource = Qnil;
|
|
2325 }
|
|
2326
|
|
2327 void
|
|
2328 vars_of_events (void)
|
|
2329 {
|
|
2330 reinit_vars_of_events ();
|
|
2331
|
|
2332 DEFVAR_LISP ("character-set-property", &Vcharacter_set_property /*
|
|
2333 A symbol used to look up the 8-bit character of a keysym.
|
|
2334 To convert a keysym symbol to an 8-bit code, as when that key is
|
|
2335 bound to self-insert-command, we will look up the property that this
|
|
2336 variable names on the property list of the keysym-symbol. The window-
|
|
2337 system-specific code will set up appropriate properties and set this
|
|
2338 variable.
|
|
2339 */ );
|
|
2340 Vcharacter_set_property = Qnil;
|
|
2341 }
|