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