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