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