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