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