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