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