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