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