Mercurial > hg > xemacs-beta
annotate src/events.c @ 5125:b5df3737028a ben-lisp-object
merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Feb 2010 01:58:04 -0600 |
parents | 623d57b7fbe8 e813cf16c015 |
children | 2a462149bd6a |
rev | line source |
---|---|
428 | 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. | |
3063 | 4 Copyright (C) 2001, 2002, 2005 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: Not in FSF. */ | |
24 | |
25 /* This file has been Mule-ized. */ | |
26 | |
27 #include <config.h> | |
28 #include "lisp.h" | |
29 #include "buffer.h" | |
30 #include "console.h" | |
31 #include "device.h" | |
788 | 32 #include "extents.h" |
428 | 33 #include "events.h" |
872 | 34 #include "frame-impl.h" |
428 | 35 #include "glyphs.h" |
36 #include "keymap.h" /* for key_desc_list_to_event() */ | |
788 | 37 #include "lstream.h" |
428 | 38 #include "redisplay.h" |
800 | 39 #include "toolbar.h" |
428 | 40 #include "window.h" |
41 | |
872 | 42 #include "console-tty-impl.h" /* for stuff in character_to_event */ |
800 | 43 |
2340 | 44 #ifdef HAVE_TTY |
45 #define USED_IF_TTY(decl) decl | |
46 #else | |
47 #define USED_IF_TTY(decl) UNUSED (decl) | |
48 #endif | |
49 | |
50 #ifdef HAVE_TOOLBARS | |
51 #define USED_IF_TOOLBARS(decl) decl | |
52 #else | |
53 #define USED_IF_TOOLBARS(decl) UNUSED (decl) | |
54 #endif | |
55 | |
428 | 56 /* Where old events go when they are explicitly deallocated. |
57 The event chain here is cut loose before GC, so these will be freed | |
58 eventually. | |
59 */ | |
60 static Lisp_Object Vevent_resource; | |
61 | |
62 Lisp_Object Qeventp; | |
63 Lisp_Object Qevent_live_p; | |
64 Lisp_Object Qkey_press_event_p; | |
65 Lisp_Object Qbutton_event_p; | |
66 Lisp_Object Qmouse_event_p; | |
67 Lisp_Object Qprocess_event_p; | |
68 | |
69 Lisp_Object Qkey_press, Qbutton_press, Qbutton_release, Qmisc_user; | |
2828 | 70 Lisp_Object Qcharacter_of_keysym, Qascii_character; |
428 | 71 |
771 | 72 |
73 /************************************************************************/ | |
74 /* definition of event object */ | |
75 /************************************************************************/ | |
428 | 76 |
77 /* #### Ad-hoc hack. Should be part of define_lrecord_implementation */ | |
78 void | |
79 clear_event_resource (void) | |
80 { | |
81 Vevent_resource = Qnil; | |
82 } | |
83 | |
934 | 84 /* Make sure we lose quickly if we try to use this event */ |
85 static void | |
86 deinitialize_event (Lisp_Object ev) | |
87 { | |
88 Lisp_Event *event = XEVENT (ev); | |
3063 | 89 int i; |
90 /* Preserve the old UID for this event, for tracking it */ | |
91 unsigned int old_uid = event->lheader.uid; | |
934 | 92 |
1204 | 93 for (i = 0; i < (int) (sizeof (Lisp_Event) / sizeof (int)); i++) |
94 ((int *) event) [i] = 0xdeadbeef; /* -559038737 base 10 */ | |
95 set_lheader_implementation (&event->lheader, &lrecord_event); | |
3063 | 96 event->lheader.uid = old_uid; |
934 | 97 set_event_type (event, dead_event); |
98 SET_EVENT_CHANNEL (event, Qnil); | |
428 | 99 XSET_EVENT_NEXT (ev, Qnil); |
100 } | |
101 | |
102 /* Set everything to zero or nil so that it's predictable. */ | |
103 void | |
440 | 104 zero_event (Lisp_Event *e) |
428 | 105 { |
3063 | 106 /* Preserve the old UID for this event, for tracking it */ |
107 unsigned int old_uid = e->lheader.uid; | |
108 | |
428 | 109 xzero (*e); |
442 | 110 set_lheader_implementation (&e->lheader, &lrecord_event); |
3063 | 111 e->lheader.uid = old_uid; |
1204 | 112 set_event_type (e, empty_event); |
113 SET_EVENT_CHANNEL (e, Qnil); | |
114 SET_EVENT_NEXT (e, Qnil); | |
428 | 115 } |
116 | |
1204 | 117 static const struct memory_description key_data_description_1 [] = { |
118 { XD_LISP_OBJECT, offsetof (struct Lisp_Key_Data, keysym) }, | |
119 { XD_END } | |
120 }; | |
121 | |
122 static const struct sized_memory_description key_data_description = { | |
123 sizeof (Lisp_Key_Data), key_data_description_1 | |
124 }; | |
125 | |
126 static const struct memory_description button_data_description_1 [] = { | |
127 { XD_END } | |
128 }; | |
129 | |
130 static const struct sized_memory_description button_data_description = { | |
131 sizeof (Lisp_Button_Data), button_data_description_1 | |
132 }; | |
133 | |
134 static const struct memory_description motion_data_description_1 [] = { | |
135 { XD_END } | |
136 }; | |
137 | |
138 static const struct sized_memory_description motion_data_description = { | |
139 sizeof (Lisp_Motion_Data), motion_data_description_1 | |
140 }; | |
141 | |
142 static const struct memory_description process_data_description_1 [] = { | |
143 { XD_LISP_OBJECT, offsetof (struct Lisp_Process_Data, process) }, | |
144 { XD_END } | |
145 }; | |
146 | |
147 static const struct sized_memory_description process_data_description = { | |
148 sizeof (Lisp_Process_Data), process_data_description_1 | |
149 }; | |
150 | |
151 static const struct memory_description timeout_data_description_1 [] = { | |
152 { XD_LISP_OBJECT, offsetof (struct Lisp_Timeout_Data, function) }, | |
153 { XD_LISP_OBJECT, offsetof (struct Lisp_Timeout_Data, object) }, | |
154 { XD_END } | |
155 }; | |
156 | |
157 static const struct sized_memory_description timeout_data_description = { | |
158 sizeof (Lisp_Timeout_Data), timeout_data_description_1 | |
159 }; | |
160 | |
161 static const struct memory_description eval_data_description_1 [] = { | |
162 { XD_LISP_OBJECT, offsetof (struct Lisp_Eval_Data, function) }, | |
163 { XD_LISP_OBJECT, offsetof (struct Lisp_Eval_Data, object) }, | |
164 { XD_END } | |
165 }; | |
166 | |
167 static const struct sized_memory_description eval_data_description = { | |
168 sizeof (Lisp_Eval_Data), eval_data_description_1 | |
169 }; | |
170 | |
171 static const struct memory_description misc_user_data_description_1 [] = { | |
172 { XD_LISP_OBJECT, offsetof (struct Lisp_Misc_User_Data, function) }, | |
173 { XD_LISP_OBJECT, offsetof (struct Lisp_Misc_User_Data, object) }, | |
174 { XD_END } | |
175 }; | |
176 | |
177 static const struct sized_memory_description misc_user_data_description = { | |
178 sizeof (Lisp_Misc_User_Data), misc_user_data_description_1 | |
179 }; | |
180 | |
181 static const struct memory_description magic_eval_data_description_1 [] = { | |
182 { XD_LISP_OBJECT, offsetof (struct Lisp_Magic_Eval_Data, object) }, | |
183 { XD_END } | |
184 }; | |
185 | |
186 static const struct sized_memory_description magic_eval_data_description = { | |
187 sizeof (Lisp_Magic_Eval_Data), magic_eval_data_description_1 | |
188 }; | |
189 | |
190 static const struct memory_description magic_data_description_1 [] = { | |
191 { XD_END } | |
192 }; | |
193 | |
194 static const struct sized_memory_description magic_data_description = { | |
195 sizeof (Lisp_Magic_Data), magic_data_description_1 | |
196 }; | |
197 | |
198 static const struct memory_description event_data_description_1 [] = { | |
2551 | 199 { XD_BLOCK_ARRAY, key_press_event, 1, { &key_data_description } }, |
200 { XD_BLOCK_ARRAY, button_press_event, 1, { &button_data_description } }, | |
201 { XD_BLOCK_ARRAY, button_release_event, 1, { &button_data_description } }, | |
202 { XD_BLOCK_ARRAY, pointer_motion_event, 1, { &motion_data_description } }, | |
203 { XD_BLOCK_ARRAY, process_event, 1, { &process_data_description } }, | |
204 { XD_BLOCK_ARRAY, timeout_event, 1, { &timeout_data_description } }, | |
205 { XD_BLOCK_ARRAY, magic_event, 1, { &magic_data_description } }, | |
206 { XD_BLOCK_ARRAY, magic_eval_event, 1, { &magic_eval_data_description } }, | |
207 { XD_BLOCK_ARRAY, eval_event, 1, { &eval_data_description } }, | |
208 { XD_BLOCK_ARRAY, misc_user_event, 1, { &misc_user_data_description } }, | |
1204 | 209 { XD_END } |
210 }; | |
211 | |
212 static const struct sized_memory_description event_data_description = { | |
213 0, event_data_description_1 | |
214 }; | |
215 | |
216 static const struct memory_description event_description [] = { | |
217 { XD_INT, offsetof (struct Lisp_Event, event_type) }, | |
218 { XD_LISP_OBJECT, offsetof (struct Lisp_Event, next) }, | |
219 { XD_LISP_OBJECT, offsetof (struct Lisp_Event, channel) }, | |
220 { XD_UNION, offsetof (struct Lisp_Event, event), | |
2551 | 221 XD_INDIRECT (0, 0), { &event_data_description } }, |
1204 | 222 { XD_END } |
223 }; | |
224 | |
225 #ifdef EVENT_DATA_AS_OBJECTS | |
226 | |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
227 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("key-data", key_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
228 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
229 key_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
230 Lisp_Key_Data); |
1204 | 231 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
232 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("button-data", button_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
233 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
234 button_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
235 Lisp_Button_Data); |
1204 | 236 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
237 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("motion-data", motion_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
238 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
239 motion_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
240 Lisp_Motion_Data); |
1204 | 241 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
242 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("process-data", process_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
243 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
244 process_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
245 Lisp_Process_Data); |
1204 | 246 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
247 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("timeout-data", timeout_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
248 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
249 timeout_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
250 Lisp_Timeout_Data); |
1204 | 251 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
252 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("eval-data", eval_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
253 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
254 eval_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
255 Lisp_Eval_Data); |
1204 | 256 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
257 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("misc-user-data", misc_user_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
258 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
259 misc_user_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
260 Lisp_Misc_User_Data); |
1204 | 261 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
262 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("magic-eval-data", magic_eval_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
263 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
264 magic_eval_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
265 Lisp_Magic_Eval_Data); |
1204 | 266 |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
267 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("magic-data", magic_data, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
268 0, internal_object_printer, 0, 0, 0, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
269 magic_data_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
270 Lisp_Magic_Data); |
1204 | 271 |
272 #endif /* EVENT_DATA_AS_OBJECTS */ | |
273 | |
428 | 274 static Lisp_Object |
275 mark_event (Lisp_Object obj) | |
276 { | |
440 | 277 Lisp_Event *event = XEVENT (obj); |
428 | 278 |
279 switch (event->event_type) | |
280 { | |
281 case key_press_event: | |
1204 | 282 mark_object (EVENT_KEY_KEYSYM (event)); |
428 | 283 break; |
284 case process_event: | |
1204 | 285 mark_object (EVENT_PROCESS_PROCESS (event)); |
428 | 286 break; |
287 case timeout_event: | |
1204 | 288 mark_object (EVENT_TIMEOUT_FUNCTION (event)); |
289 mark_object (EVENT_TIMEOUT_OBJECT (event)); | |
428 | 290 break; |
291 case eval_event: | |
292 case misc_user_event: | |
1204 | 293 mark_object (EVENT_EVAL_FUNCTION (event)); |
294 mark_object (EVENT_EVAL_OBJECT (event)); | |
428 | 295 break; |
296 case magic_eval_event: | |
1204 | 297 mark_object (EVENT_MAGIC_EVAL_OBJECT (event)); |
428 | 298 break; |
299 case button_press_event: | |
300 case button_release_event: | |
301 case pointer_motion_event: | |
302 case magic_event: | |
303 case empty_event: | |
304 case dead_event: | |
305 break; | |
306 default: | |
2500 | 307 ABORT (); |
428 | 308 } |
309 mark_object (event->channel); | |
310 return event->next; | |
311 } | |
312 | |
313 static void | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4780
diff
changeset
|
314 print_event_1 (const Ascbyte *str, Lisp_Object obj, Lisp_Object printcharfun) |
428 | 315 { |
793 | 316 DECLARE_EISTRING_MALLOC (ei); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4780
diff
changeset
|
317 write_ascstring (printcharfun, str); |
1204 | 318 format_event_object (ei, obj, 0); |
826 | 319 write_eistring (printcharfun, ei); |
793 | 320 eifree (ei); |
428 | 321 } |
322 | |
323 static void | |
2286 | 324 print_event (Lisp_Object obj, Lisp_Object printcharfun, |
325 int UNUSED (escapeflag)) | |
428 | 326 { |
327 if (print_readably) | |
563 | 328 printing_unreadable_object ("#<event>"); |
428 | 329 |
330 switch (XEVENT (obj)->event_type) | |
331 { | |
332 case key_press_event: | |
333 print_event_1 ("#<keypress-event ", obj, printcharfun); | |
334 break; | |
335 case button_press_event: | |
336 print_event_1 ("#<buttondown-event ", obj, printcharfun); | |
337 break; | |
338 case button_release_event: | |
339 print_event_1 ("#<buttonup-event ", obj, printcharfun); | |
340 break; | |
341 case magic_event: | |
342 case magic_eval_event: | |
343 print_event_1 ("#<magic-event ", obj, printcharfun); | |
344 break; | |
345 case pointer_motion_event: | |
346 { | |
347 Lisp_Object Vx, Vy; | |
348 Vx = Fevent_x_pixel (obj); | |
349 assert (INTP (Vx)); | |
350 Vy = Fevent_y_pixel (obj); | |
351 assert (INTP (Vy)); | |
793 | 352 write_fmt_string (printcharfun, "#<motion-event %ld, %ld", |
353 (long) XINT (Vx), (long) XINT (Vy)); | |
428 | 354 break; |
355 } | |
356 case process_event: | |
1204 | 357 write_fmt_string_lisp (printcharfun, "#<process-event %S", 1, |
358 XEVENT_PROCESS_PROCESS (obj)); | |
428 | 359 break; |
360 case timeout_event: | |
1204 | 361 write_fmt_string_lisp (printcharfun, "#<timeout-event %S", 1, |
362 XEVENT_TIMEOUT_OBJECT (obj)); | |
428 | 363 break; |
364 case empty_event: | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4780
diff
changeset
|
365 write_ascstring (printcharfun, "#<empty-event"); |
428 | 366 break; |
367 case misc_user_event: | |
1204 | 368 write_fmt_string_lisp (printcharfun, "#<misc-user-event (%S", 1, |
369 XEVENT_MISC_USER_FUNCTION (obj)); | |
370 write_fmt_string_lisp (printcharfun, " %S)", 1, | |
371 XEVENT_MISC_USER_OBJECT (obj)); | |
428 | 372 break; |
373 case eval_event: | |
1204 | 374 write_fmt_string_lisp (printcharfun, "#<eval-event (%S", 1, |
375 XEVENT_EVAL_FUNCTION (obj)); | |
376 write_fmt_string_lisp (printcharfun, " %S)", 1, | |
377 XEVENT_EVAL_OBJECT (obj)); | |
428 | 378 break; |
379 case dead_event: | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4780
diff
changeset
|
380 write_ascstring (printcharfun, "#<DEALLOCATED-EVENT"); |
428 | 381 break; |
382 default: | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4780
diff
changeset
|
383 write_ascstring (printcharfun, "#<UNKNOWN-EVENT-TYPE"); |
428 | 384 break; |
385 } | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4780
diff
changeset
|
386 write_ascstring (printcharfun, ">"); |
428 | 387 } |
388 | |
389 static int | |
4906
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4780
diff
changeset
|
390 event_equal (Lisp_Object obj1, Lisp_Object obj2, int UNUSED (depth), |
6ef8256a020a
implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents:
4780
diff
changeset
|
391 int UNUSED (foldcase)) |
428 | 392 { |
440 | 393 Lisp_Event *e1 = XEVENT (obj1); |
394 Lisp_Event *e2 = XEVENT (obj2); | |
428 | 395 |
396 if (e1->event_type != e2->event_type) return 0; | |
397 if (!EQ (e1->channel, e2->channel)) return 0; | |
398 /* if (e1->timestamp != e2->timestamp) return 0; */ | |
399 switch (e1->event_type) | |
400 { | |
2500 | 401 default: ABORT (); |
428 | 402 |
403 case process_event: | |
1204 | 404 return EQ (EVENT_PROCESS_PROCESS (e1), EVENT_PROCESS_PROCESS (e2)); |
428 | 405 |
406 case timeout_event: | |
1204 | 407 return (internal_equal (EVENT_TIMEOUT_FUNCTION (e1), |
408 EVENT_TIMEOUT_FUNCTION (e2), 0) && | |
409 internal_equal (EVENT_TIMEOUT_OBJECT (e1), | |
410 EVENT_TIMEOUT_OBJECT (e2), 0)); | |
428 | 411 |
412 case key_press_event: | |
1204 | 413 return (EQ (EVENT_KEY_KEYSYM (e1), EVENT_KEY_KEYSYM (e2)) && |
414 (EVENT_KEY_MODIFIERS (e1) == EVENT_KEY_MODIFIERS (e2))); | |
428 | 415 |
416 case button_press_event: | |
417 case button_release_event: | |
1204 | 418 return (EVENT_BUTTON_BUTTON (e1) == EVENT_BUTTON_BUTTON (e2) && |
419 EVENT_BUTTON_MODIFIERS (e1) == EVENT_BUTTON_MODIFIERS (e2)); | |
428 | 420 |
421 case pointer_motion_event: | |
1204 | 422 return (EVENT_MOTION_X (e1) == EVENT_MOTION_X (e2) && |
423 EVENT_MOTION_Y (e1) == EVENT_MOTION_Y (e2)); | |
428 | 424 |
425 case misc_user_event: | |
1204 | 426 return (internal_equal (EVENT_EVAL_FUNCTION (e1), |
427 EVENT_EVAL_FUNCTION (e2), 0) && | |
428 internal_equal (EVENT_EVAL_OBJECT (e1), | |
429 EVENT_EVAL_OBJECT (e2), 0) && | |
430 /* #### is this really needed for equality | |
428 | 431 or is x and y also important? */ |
1204 | 432 EVENT_MISC_USER_BUTTON (e1) == EVENT_MISC_USER_BUTTON (e2) && |
433 EVENT_MISC_USER_MODIFIERS (e1) == EVENT_MISC_USER_MODIFIERS (e2)); | |
428 | 434 |
435 case eval_event: | |
1204 | 436 return (internal_equal (EVENT_EVAL_FUNCTION (e1), |
437 EVENT_EVAL_FUNCTION (e2), 0) && | |
438 internal_equal (EVENT_EVAL_OBJECT (e1), | |
439 EVENT_EVAL_OBJECT (e2), 0)); | |
428 | 440 |
441 case magic_eval_event: | |
1204 | 442 return (EVENT_MAGIC_EVAL_INTERNAL_FUNCTION (e1) == |
443 EVENT_MAGIC_EVAL_INTERNAL_FUNCTION (e2) && | |
444 internal_equal (EVENT_MAGIC_EVAL_OBJECT (e1), | |
445 EVENT_MAGIC_EVAL_OBJECT (e2), 0)); | |
428 | 446 |
447 case magic_event: | |
788 | 448 return event_stream_compare_magic_event (e1, e2); |
428 | 449 |
450 case empty_event: /* Empty and deallocated events are equal. */ | |
451 case dead_event: | |
452 return 1; | |
453 } | |
454 } | |
455 | |
665 | 456 static Hashcode |
428 | 457 event_hash (Lisp_Object obj, int depth) |
458 { | |
440 | 459 Lisp_Event *e = XEVENT (obj); |
665 | 460 Hashcode hash; |
428 | 461 |
462 hash = HASH2 (e->event_type, LISP_HASH (e->channel)); | |
463 switch (e->event_type) | |
464 { | |
465 case process_event: | |
1204 | 466 return HASH2 (hash, LISP_HASH (EVENT_PROCESS_PROCESS (e))); |
428 | 467 |
468 case timeout_event: | |
1204 | 469 return HASH3 (hash, |
470 internal_hash (EVENT_TIMEOUT_FUNCTION (e), depth + 1), | |
471 internal_hash (EVENT_TIMEOUT_OBJECT (e), depth + 1)); | |
428 | 472 |
473 case key_press_event: | |
1204 | 474 return HASH3 (hash, LISP_HASH (EVENT_KEY_KEYSYM (e)), |
475 EVENT_KEY_MODIFIERS (e)); | |
428 | 476 |
477 case button_press_event: | |
478 case button_release_event: | |
1204 | 479 return HASH3 (hash, EVENT_BUTTON_BUTTON (e), EVENT_BUTTON_MODIFIERS (e)); |
428 | 480 |
481 case pointer_motion_event: | |
1204 | 482 return HASH3 (hash, EVENT_MOTION_X (e), EVENT_MOTION_Y (e)); |
428 | 483 |
484 case misc_user_event: | |
1204 | 485 return HASH5 (hash, |
486 internal_hash (EVENT_MISC_USER_FUNCTION (e), depth + 1), | |
487 internal_hash (EVENT_MISC_USER_OBJECT (e), depth + 1), | |
488 EVENT_MISC_USER_BUTTON (e), EVENT_MISC_USER_MODIFIERS (e)); | |
428 | 489 |
490 case eval_event: | |
1204 | 491 return HASH3 (hash, internal_hash (EVENT_EVAL_FUNCTION (e), depth + 1), |
492 internal_hash (EVENT_EVAL_OBJECT (e), depth + 1)); | |
428 | 493 |
494 case magic_eval_event: | |
495 return HASH3 (hash, | |
1204 | 496 (Hashcode) EVENT_MAGIC_EVAL_INTERNAL_FUNCTION (e), |
497 internal_hash (EVENT_MAGIC_EVAL_OBJECT (e), depth + 1)); | |
428 | 498 |
499 case magic_event: | |
788 | 500 return HASH2 (hash, event_stream_hash_magic_event (e)); |
428 | 501 |
502 case empty_event: | |
503 case dead_event: | |
504 return hash; | |
505 | |
506 default: | |
2500 | 507 ABORT (); |
428 | 508 } |
509 | |
510 return 0; /* unreached */ | |
511 } | |
934 | 512 |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
513 DEFINE_NODUMP_FROB_BLOCK_LISP_OBJECT ("event", event, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
514 mark_event, print_event, 0, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
515 event_equal, event_hash, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
516 event_description, |
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
517 Lisp_Event); |
428 | 518 |
519 DEFUN ("make-event", Fmake_event, 0, 2, 0, /* | |
520 Return a new event of type TYPE, with properties described by PLIST. | |
521 | |
522 TYPE is a symbol, either `empty', `key-press', `button-press', | |
523 `button-release', `misc-user' or `motion'. If TYPE is nil, it | |
524 defaults to `empty'. | |
525 | |
526 PLIST is a property list, the properties being compatible to those | |
527 returned by `event-properties'. The following properties are | |
528 allowed: | |
529 | |
530 channel -- The event channel, a frame or a console. For | |
531 button-press, button-release, misc-user and motion events, | |
532 this must be a frame. For key-press events, it must be | |
533 a console. If channel is unspecified, it will be set to | |
534 the selected frame or selected console, as appropriate. | |
535 key -- The event key, a symbol or character. Allowed only for | |
536 keypress events. | |
537 button -- The event button, integer 1, 2 or 3. Allowed for | |
538 button-press, button-release and misc-user events. | |
539 modifiers -- The event modifiers, a list of modifier symbols. Allowed | |
540 for key-press, button-press, button-release, motion and | |
541 misc-user events. | |
542 function -- Function. Allowed for misc-user events only. | |
543 object -- An object, function's parameter. Allowed for misc-user | |
544 events only. | |
545 x -- The event X coordinate, an integer. This is relative | |
546 to the left of CHANNEL's root window. Allowed for | |
547 motion, button-press, button-release and misc-user events. | |
548 y -- The event Y coordinate, an integer. This is relative | |
549 to the top of CHANNEL's root window. Allowed for | |
550 motion, button-press, button-release and misc-user events. | |
551 timestamp -- The event timestamp, a non-negative integer. Allowed for | |
552 all types of events. If unspecified, it will be set to 0 | |
553 by default. | |
554 | |
555 For event type `empty', PLIST must be nil. | |
556 `button-release', or `motion'. If TYPE is left out, it defaults to | |
557 `empty'. | |
558 PLIST is a list of properties, as returned by `event-properties'. Not | |
559 all properties are allowed for all kinds of events, and some are | |
560 required. | |
561 | |
562 WARNING: the event object returned may be a reused one; see the function | |
563 `deallocate-event'. | |
564 */ | |
565 (type, plist)) | |
566 { | |
567 Lisp_Object event = Qnil; | |
440 | 568 Lisp_Event *e; |
428 | 569 EMACS_INT coord_x = 0, coord_y = 0; |
570 struct gcpro gcpro1; | |
571 | |
572 GCPRO1 (event); | |
573 | |
574 if (NILP (type)) | |
575 type = Qempty; | |
576 | |
577 if (!NILP (Vevent_resource)) | |
578 { | |
579 event = Vevent_resource; | |
580 Vevent_resource = XEVENT_NEXT (event); | |
581 } | |
582 else | |
583 { | |
584 event = allocate_event (); | |
585 } | |
586 e = XEVENT (event); | |
587 zero_event (e); | |
588 | |
589 if (EQ (type, Qempty)) | |
590 { | |
591 /* For empty event, we return immediately, without processing | |
592 PLIST. In fact, processing PLIST would be wrong, because the | |
593 sanitizing process would fill in the properties | |
594 (e.g. CHANNEL), which we don't want in empty events. */ | |
934 | 595 set_event_type (e, empty_event); |
428 | 596 if (!NILP (plist)) |
563 | 597 invalid_operation ("Cannot set properties of empty event", plist); |
428 | 598 UNGCPRO; |
599 return event; | |
600 } | |
601 else if (EQ (type, Qkey_press)) | |
602 { | |
934 | 603 set_event_type (e, key_press_event); |
1204 | 604 SET_EVENT_KEY_KEYSYM (e, Qunbound); |
428 | 605 } |
606 else if (EQ (type, Qbutton_press)) | |
934 | 607 set_event_type (e, button_press_event); |
428 | 608 else if (EQ (type, Qbutton_release)) |
934 | 609 set_event_type (e, button_release_event); |
428 | 610 else if (EQ (type, Qmotion)) |
934 | 611 set_event_type (e, pointer_motion_event); |
428 | 612 else if (EQ (type, Qmisc_user)) |
613 { | |
934 | 614 set_event_type (e, misc_user_event); |
1204 | 615 SET_EVENT_MISC_USER_FUNCTION (e, Qnil); |
616 SET_EVENT_MISC_USER_OBJECT (e, Qnil); | |
428 | 617 } |
618 else | |
619 { | |
620 /* Not allowed: Qprocess, Qtimeout, Qmagic, Qeval, Qmagic_eval. */ | |
563 | 621 invalid_constant ("Invalid event type", type); |
428 | 622 } |
623 | |
624 EVENT_CHANNEL (e) = Qnil; | |
625 | |
626 plist = Fcopy_sequence (plist); | |
627 Fcanonicalize_plist (plist, Qnil); | |
628 | |
442 | 629 #define WRONG_EVENT_TYPE_FOR_PROPERTY(event_type, prop) \ |
563 | 630 invalid_argument_2 ("Invalid property for event type", prop, event_type) |
428 | 631 |
442 | 632 { |
633 EXTERNAL_PROPERTY_LIST_LOOP_3 (keyword, value, plist) | |
634 { | |
635 if (EQ (keyword, Qchannel)) | |
636 { | |
1204 | 637 if (EVENT_TYPE (e) == key_press_event) |
442 | 638 { |
639 if (!CONSOLEP (value)) | |
640 value = wrong_type_argument (Qconsolep, value); | |
641 } | |
642 else | |
643 { | |
644 if (!FRAMEP (value)) | |
645 value = wrong_type_argument (Qframep, value); | |
646 } | |
647 EVENT_CHANNEL (e) = value; | |
648 } | |
649 else if (EQ (keyword, Qkey)) | |
650 { | |
1204 | 651 switch (EVENT_TYPE (e)) |
442 | 652 { |
653 case key_press_event: | |
654 if (!SYMBOLP (value) && !CHARP (value)) | |
563 | 655 invalid_argument ("Invalid event key", value); |
1204 | 656 SET_EVENT_KEY_KEYSYM (e, value); |
442 | 657 break; |
658 default: | |
659 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); | |
660 break; | |
661 } | |
662 } | |
663 else if (EQ (keyword, Qbutton)) | |
664 { | |
665 CHECK_NATNUM (value); | |
666 check_int_range (XINT (value), 0, 7); | |
428 | 667 |
1204 | 668 switch (EVENT_TYPE (e)) |
442 | 669 { |
670 case button_press_event: | |
671 case button_release_event: | |
1204 | 672 SET_EVENT_BUTTON_BUTTON (e, XINT (value)); |
442 | 673 break; |
674 case misc_user_event: | |
1204 | 675 SET_EVENT_MISC_USER_BUTTON (e, XINT (value)); |
442 | 676 break; |
677 default: | |
678 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); | |
679 break; | |
680 } | |
681 } | |
682 else if (EQ (keyword, Qmodifiers)) | |
683 { | |
684 int modifiers = 0; | |
428 | 685 |
442 | 686 EXTERNAL_LIST_LOOP_2 (sym, value) |
687 { | |
688 if (EQ (sym, Qcontrol)) modifiers |= XEMACS_MOD_CONTROL; | |
689 else if (EQ (sym, Qmeta)) modifiers |= XEMACS_MOD_META; | |
690 else if (EQ (sym, Qsuper)) modifiers |= XEMACS_MOD_SUPER; | |
691 else if (EQ (sym, Qhyper)) modifiers |= XEMACS_MOD_HYPER; | |
692 else if (EQ (sym, Qalt)) modifiers |= XEMACS_MOD_ALT; | |
693 else if (EQ (sym, Qsymbol)) modifiers |= XEMACS_MOD_ALT; | |
694 else if (EQ (sym, Qshift)) modifiers |= XEMACS_MOD_SHIFT; | |
695 else if (EQ (sym, Qbutton1)) modifiers |= XEMACS_MOD_BUTTON1; | |
696 else if (EQ (sym, Qbutton2)) modifiers |= XEMACS_MOD_BUTTON2; | |
697 else if (EQ (sym, Qbutton3)) modifiers |= XEMACS_MOD_BUTTON3; | |
698 else if (EQ (sym, Qbutton4)) modifiers |= XEMACS_MOD_BUTTON4; | |
699 else if (EQ (sym, Qbutton5)) modifiers |= XEMACS_MOD_BUTTON5; | |
700 else | |
563 | 701 invalid_constant ("Invalid key modifier", sym); |
442 | 702 } |
428 | 703 |
1204 | 704 switch (EVENT_TYPE (e)) |
442 | 705 { |
706 case key_press_event: | |
1204 | 707 SET_EVENT_KEY_MODIFIERS (e, modifiers); |
442 | 708 break; |
709 case button_press_event: | |
710 case button_release_event: | |
1204 | 711 SET_EVENT_BUTTON_MODIFIERS (e, modifiers); |
442 | 712 break; |
713 case pointer_motion_event: | |
1204 | 714 SET_EVENT_MOTION_MODIFIERS (e, modifiers); |
442 | 715 break; |
716 case misc_user_event: | |
1204 | 717 SET_EVENT_MISC_USER_MODIFIERS (e, modifiers); |
442 | 718 break; |
719 default: | |
720 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); | |
721 break; | |
722 } | |
723 } | |
724 else if (EQ (keyword, Qx)) | |
725 { | |
1204 | 726 switch (EVENT_TYPE (e)) |
442 | 727 { |
728 case pointer_motion_event: | |
729 case button_press_event: | |
730 case button_release_event: | |
731 case misc_user_event: | |
732 /* Allow negative values, so we can specify toolbar | |
733 positions. */ | |
734 CHECK_INT (value); | |
735 coord_x = XINT (value); | |
736 break; | |
737 default: | |
738 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); | |
739 break; | |
740 } | |
741 } | |
742 else if (EQ (keyword, Qy)) | |
743 { | |
1204 | 744 switch (EVENT_TYPE (e)) |
442 | 745 { |
746 case pointer_motion_event: | |
747 case button_press_event: | |
748 case button_release_event: | |
749 case misc_user_event: | |
750 /* Allow negative values; see above. */ | |
751 CHECK_INT (value); | |
752 coord_y = XINT (value); | |
753 break; | |
754 default: | |
755 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); | |
756 break; | |
757 } | |
758 } | |
759 else if (EQ (keyword, Qtimestamp)) | |
760 { | |
761 CHECK_NATNUM (value); | |
934 | 762 SET_EVENT_TIMESTAMP (e, XINT (value)); |
442 | 763 } |
764 else if (EQ (keyword, Qfunction)) | |
765 { | |
1204 | 766 switch (EVENT_TYPE (e)) |
442 | 767 { |
768 case misc_user_event: | |
1204 | 769 SET_EVENT_MISC_USER_FUNCTION (e, value); |
442 | 770 break; |
771 default: | |
772 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); | |
773 break; | |
774 } | |
775 } | |
776 else if (EQ (keyword, Qobject)) | |
777 { | |
1204 | 778 switch (EVENT_TYPE (e)) |
442 | 779 { |
780 case misc_user_event: | |
1204 | 781 SET_EVENT_MISC_USER_OBJECT (e, value); |
442 | 782 break; |
783 default: | |
784 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); | |
785 break; | |
786 } | |
787 } | |
788 else | |
563 | 789 invalid_constant_2 ("Invalid property", keyword, value); |
442 | 790 } |
791 } | |
428 | 792 |
793 /* Insert the channel, if missing. */ | |
794 if (NILP (EVENT_CHANNEL (e))) | |
795 { | |
934 | 796 if (EVENT_TYPE (e) == key_press_event) |
428 | 797 EVENT_CHANNEL (e) = Vselected_console; |
798 else | |
799 EVENT_CHANNEL (e) = Fselected_frame (Qnil); | |
800 } | |
801 | |
802 /* Fevent_properties, Fevent_x_pixel, etc. work with pixels relative | |
803 to the frame, so we must adjust accordingly. */ | |
804 if (FRAMEP (EVENT_CHANNEL (e))) | |
805 { | |
806 coord_x += FRAME_REAL_LEFT_TOOLBAR_WIDTH (XFRAME (EVENT_CHANNEL (e))); | |
807 coord_y += FRAME_REAL_TOP_TOOLBAR_HEIGHT (XFRAME (EVENT_CHANNEL (e))); | |
808 | |
809 switch (e->event_type) | |
810 { | |
811 case pointer_motion_event: | |
1204 | 812 SET_EVENT_MOTION_X (e, coord_x); |
813 SET_EVENT_MOTION_Y (e, coord_y); | |
428 | 814 break; |
815 case button_press_event: | |
816 case button_release_event: | |
1204 | 817 SET_EVENT_BUTTON_X (e, coord_x); |
818 SET_EVENT_BUTTON_Y (e, coord_y); | |
428 | 819 break; |
820 case misc_user_event: | |
1204 | 821 SET_EVENT_MISC_USER_X (e, coord_x); |
822 SET_EVENT_MISC_USER_Y (e, coord_y); | |
428 | 823 break; |
824 default: | |
2500 | 825 ABORT (); |
428 | 826 } |
827 } | |
828 | |
829 /* Finally, do some more validation. */ | |
1204 | 830 switch (EVENT_TYPE (e)) |
428 | 831 { |
832 case key_press_event: | |
1204 | 833 if (UNBOUNDP (EVENT_KEY_KEYSYM (e))) |
563 | 834 sferror ("A key must be specified to make a keypress event", |
442 | 835 plist); |
428 | 836 break; |
837 case button_press_event: | |
1204 | 838 if (!EVENT_BUTTON_BUTTON (e)) |
563 | 839 sferror |
442 | 840 ("A button must be specified to make a button-press event", |
841 plist); | |
428 | 842 break; |
843 case button_release_event: | |
1204 | 844 if (!EVENT_BUTTON_BUTTON (e)) |
563 | 845 sferror |
442 | 846 ("A button must be specified to make a button-release event", |
847 plist); | |
428 | 848 break; |
849 case misc_user_event: | |
1204 | 850 if (NILP (EVENT_MISC_USER_FUNCTION (e))) |
563 | 851 sferror ("A function must be specified to make a misc-user event", |
442 | 852 plist); |
428 | 853 break; |
854 default: | |
855 break; | |
856 } | |
857 | |
858 UNGCPRO; | |
859 return event; | |
860 } | |
861 | |
862 DEFUN ("deallocate-event", Fdeallocate_event, 1, 1, 0, /* | |
863 Allow the given event structure to be reused. | |
864 You MUST NOT use this event object after calling this function with it. | |
865 You will lose. It is not necessary to call this function, as event | |
866 objects are garbage-collected like all other objects; however, it may | |
867 be more efficient to explicitly deallocate events when you are sure | |
868 that it is safe to do so. | |
869 */ | |
870 (event)) | |
871 { | |
872 CHECK_EVENT (event); | |
873 | |
874 if (XEVENT_TYPE (event) == dead_event) | |
563 | 875 invalid_argument ("this event is already deallocated!", Qunbound); |
428 | 876 |
877 assert (XEVENT_TYPE (event) <= last_event_type); | |
878 | |
879 #if 0 | |
880 { | |
881 int i, len; | |
882 | |
883 if (EQ (event, Vlast_command_event) || | |
884 EQ (event, Vlast_input_event) || | |
885 EQ (event, Vunread_command_event)) | |
2500 | 886 ABORT (); |
428 | 887 |
888 len = XVECTOR_LENGTH (Vthis_command_keys); | |
889 for (i = 0; i < len; i++) | |
890 if (EQ (event, XVECTOR_DATA (Vthis_command_keys) [i])) | |
2500 | 891 ABORT (); |
428 | 892 if (!NILP (Vrecent_keys_ring)) |
893 { | |
894 int recent_ring_len = XVECTOR_LENGTH (Vrecent_keys_ring); | |
895 for (i = 0; i < recent_ring_len; i++) | |
896 if (EQ (event, XVECTOR_DATA (Vrecent_keys_ring) [i])) | |
2500 | 897 ABORT (); |
428 | 898 } |
899 } | |
900 #endif /* 0 */ | |
901 | |
902 assert (!EQ (event, Vevent_resource)); | |
903 deinitialize_event (event); | |
904 #ifndef ALLOC_NO_POOLS | |
905 XSET_EVENT_NEXT (event, Vevent_resource); | |
906 Vevent_resource = event; | |
907 #endif | |
908 return Qnil; | |
909 } | |
910 | |
911 DEFUN ("copy-event", Fcopy_event, 1, 2, 0, /* | |
444 | 912 Make a copy of the event object EVENT1. |
913 If a second event argument EVENT2 is given, EVENT1 is copied into | |
914 EVENT2 and EVENT2 is returned. If EVENT2 is not supplied (or is nil) | |
915 then a new event will be made as with `make-event'. See also the | |
916 function `deallocate-event'. | |
428 | 917 */ |
918 (event1, event2)) | |
919 { | |
920 CHECK_LIVE_EVENT (event1); | |
921 if (NILP (event2)) | |
922 event2 = Fmake_event (Qnil, Qnil); | |
430 | 923 else |
924 { | |
925 CHECK_LIVE_EVENT (event2); | |
926 if (EQ (event1, event2)) | |
563 | 927 return signal_continuable_error_2 |
928 (Qinvalid_argument, | |
929 "copy-event called with `eq' events", event1, event2); | |
430 | 930 } |
428 | 931 |
932 assert (XEVENT_TYPE (event1) <= last_event_type); | |
933 assert (XEVENT_TYPE (event2) <= last_event_type); | |
934 | |
934 | 935 XSET_EVENT_TYPE (event2, XEVENT_TYPE (event1)); |
936 XSET_EVENT_CHANNEL (event2, XEVENT_CHANNEL (event1)); | |
937 XSET_EVENT_TIMESTAMP (event2, XEVENT_TIMESTAMP (event1)); | |
1204 | 938 |
939 #ifdef EVENT_DATA_AS_OBJECTS | |
940 copy_lisp_object (XEVENT_DATA (event2), XEVENT_DATA (event1)); | |
941 #else | |
942 XEVENT (event2)->event = XEVENT (event1)->event; | |
943 #endif | |
934 | 944 return event2; |
428 | 945 } |
946 | |
947 | |
771 | 948 /************************************************************************/ |
949 /* event chain functions */ | |
950 /************************************************************************/ | |
428 | 951 |
952 /* Given a chain of events (or possibly nil), deallocate them all. */ | |
953 | |
954 void | |
955 deallocate_event_chain (Lisp_Object event_chain) | |
956 { | |
957 while (!NILP (event_chain)) | |
958 { | |
959 Lisp_Object next = XEVENT_NEXT (event_chain); | |
960 Fdeallocate_event (event_chain); | |
961 event_chain = next; | |
962 } | |
963 } | |
964 | |
965 /* Return the last event in a chain. | |
966 NOTE: You cannot pass nil as a value here! The routine will | |
967 abort if you do. */ | |
968 | |
969 Lisp_Object | |
970 event_chain_tail (Lisp_Object event_chain) | |
971 { | |
972 while (1) | |
973 { | |
974 Lisp_Object next = XEVENT_NEXT (event_chain); | |
975 if (NILP (next)) | |
976 return event_chain; | |
977 event_chain = next; | |
978 } | |
979 } | |
980 | |
981 /* Enqueue a single event onto the end of a chain of events. | |
982 HEAD points to the first event in the chain, TAIL to the last event. | |
983 If the chain is empty, both values should be nil. */ | |
984 | |
985 void | |
986 enqueue_event (Lisp_Object event, Lisp_Object *head, Lisp_Object *tail) | |
987 { | |
988 assert (NILP (XEVENT_NEXT (event))); | |
989 assert (!EQ (*tail, event)); | |
990 | |
991 if (!NILP (*tail)) | |
992 XSET_EVENT_NEXT (*tail, event); | |
993 else | |
994 *head = event; | |
995 *tail = event; | |
996 | |
997 assert (!EQ (event, XEVENT_NEXT (event))); | |
998 } | |
999 | |
1000 /* Remove an event off the head of a chain of events and return it. | |
1001 HEAD points to the first event in the chain, TAIL to the last event. */ | |
1002 | |
1003 Lisp_Object | |
1004 dequeue_event (Lisp_Object *head, Lisp_Object *tail) | |
1005 { | |
1006 Lisp_Object event; | |
1007 | |
1008 event = *head; | |
1009 *head = XEVENT_NEXT (event); | |
1010 XSET_EVENT_NEXT (event, Qnil); | |
1011 if (NILP (*head)) | |
1012 *tail = Qnil; | |
1013 return event; | |
1014 } | |
1015 | |
1016 /* Enqueue a chain of events (or possibly nil) onto the end of another | |
1017 chain of events. HEAD points to the first event in the chain being | |
1018 queued onto, TAIL to the last event. If the chain is empty, both values | |
1019 should be nil. */ | |
1020 | |
1021 void | |
1022 enqueue_event_chain (Lisp_Object event_chain, Lisp_Object *head, | |
1023 Lisp_Object *tail) | |
1024 { | |
1025 if (NILP (event_chain)) | |
1026 return; | |
1027 | |
1028 if (NILP (*head)) | |
1029 { | |
1030 *head = event_chain; | |
1031 *tail = event_chain; | |
1032 } | |
1033 else | |
1034 { | |
1035 XSET_EVENT_NEXT (*tail, event_chain); | |
1036 *tail = event_chain_tail (event_chain); | |
1037 } | |
1038 } | |
1039 | |
1204 | 1040 /* Map a function over each event in the chain. If the function returns |
1041 non-zero, remove the event just processed. Return the total number of | |
1042 items removed. | |
1043 | |
1044 NOTE: | |
1045 | |
1046 If you want a simple mapping over an event chain, with no intention to | |
1047 add or remove items, just use EVENT_CHAIN_LOOP(). | |
1048 */ | |
1049 | |
1050 int | |
1051 map_event_chain_remove (int (*fn) (Lisp_Object ev, void *user_data), | |
1052 Lisp_Object *head, Lisp_Object *tail, | |
1053 void *user_data, int flags) | |
1054 { | |
1055 Lisp_Object event; | |
1056 Lisp_Object previous_event = Qnil; | |
1057 int count = 0; | |
1058 | |
1059 EVENT_CHAIN_LOOP (event, *head) | |
1060 { | |
1061 if (fn (event, user_data)) | |
1062 { | |
1063 if (NILP (previous_event)) | |
1064 dequeue_event (head, tail); | |
1065 else | |
1066 { | |
1067 XSET_EVENT_NEXT (previous_event, XEVENT_NEXT (event)); | |
1068 if (EQ (*tail, event)) | |
1069 *tail = previous_event; | |
1070 } | |
1071 | |
1072 if (flags & MECR_DEALLOCATE_EVENT) | |
1073 Fdeallocate_event (event); | |
1074 count++; | |
1075 } | |
1076 else | |
1077 previous_event = event; | |
1078 } | |
1079 return count; | |
1080 } | |
1081 | |
428 | 1082 /* Return the number of events (possibly 0) on an event chain. */ |
1083 | |
1084 int | |
1085 event_chain_count (Lisp_Object event_chain) | |
1086 { | |
1087 Lisp_Object event; | |
1088 int n = 0; | |
1089 | |
1090 EVENT_CHAIN_LOOP (event, event_chain) | |
1091 n++; | |
1092 | |
1093 return n; | |
1094 } | |
1095 | |
1096 /* Find the event before EVENT in an event chain. This aborts | |
1097 if the event is not in the chain. */ | |
1098 | |
1099 Lisp_Object | |
1100 event_chain_find_previous (Lisp_Object event_chain, Lisp_Object event) | |
1101 { | |
1102 Lisp_Object previous = Qnil; | |
1103 | |
1104 while (!NILP (event_chain)) | |
1105 { | |
1106 if (EQ (event_chain, event)) | |
1107 return previous; | |
1108 previous = event_chain; | |
1109 event_chain = XEVENT_NEXT (event_chain); | |
1110 } | |
1111 | |
2500 | 1112 ABORT (); |
428 | 1113 return Qnil; |
1114 } | |
1115 | |
1116 Lisp_Object | |
1117 event_chain_nth (Lisp_Object event_chain, int n) | |
1118 { | |
1119 Lisp_Object event; | |
1120 EVENT_CHAIN_LOOP (event, event_chain) | |
1121 { | |
1122 if (!n) | |
1123 return event; | |
1124 n--; | |
1125 } | |
1126 return Qnil; | |
1127 } | |
1128 | |
771 | 1129 /* Return a freshly allocated copy of all events in the given chain. */ |
1130 | |
428 | 1131 Lisp_Object |
1132 copy_event_chain (Lisp_Object event_chain) | |
1133 { | |
1134 Lisp_Object new_chain = Qnil; | |
1135 Lisp_Object new_chain_tail = Qnil; | |
1136 Lisp_Object event; | |
1137 | |
1138 EVENT_CHAIN_LOOP (event, event_chain) | |
1139 { | |
1140 Lisp_Object copy = Fcopy_event (event, Qnil); | |
1141 enqueue_event (copy, &new_chain, &new_chain_tail); | |
1142 } | |
1143 | |
1144 return new_chain; | |
1145 } | |
1146 | |
771 | 1147 /* Given a pointer (maybe nil) into an old chain (also maybe nil, if |
1148 pointer is nil) and a new chain which is a copy of the old, return | |
1149 the corresponding new pointer. */ | |
1150 Lisp_Object | |
1151 transfer_event_chain_pointer (Lisp_Object pointer, Lisp_Object old_chain, | |
1152 Lisp_Object new_chain) | |
1153 { | |
1154 if (NILP (pointer)) | |
1155 return Qnil; | |
1156 assert (!NILP (old_chain)); | |
800 | 1157 #ifdef ERROR_CHECK_STRUCTURES |
771 | 1158 /* make sure we're actually in the chain */ |
1159 event_chain_find_previous (old_chain, pointer); | |
1160 assert (event_chain_count (old_chain) == event_chain_count (new_chain)); | |
800 | 1161 #endif /* ERROR_CHECK_STRUCTURES */ |
771 | 1162 return event_chain_nth (new_chain, |
1163 event_chain_count (old_chain) - | |
1164 event_chain_count (pointer)); | |
1165 } | |
1166 | |
428 | 1167 |
771 | 1168 /************************************************************************/ |
1169 /* higher level functions */ | |
1170 /************************************************************************/ | |
428 | 1171 |
1172 Lisp_Object QKbackspace, QKtab, QKlinefeed, QKreturn, QKescape, | |
1173 QKspace, QKdelete; | |
1174 | |
1175 int | |
1176 command_event_p (Lisp_Object event) | |
1177 { | |
1178 switch (XEVENT_TYPE (event)) | |
1179 { | |
1180 case key_press_event: | |
1181 case button_press_event: | |
1182 case button_release_event: | |
1183 case misc_user_event: | |
1184 return 1; | |
1185 default: | |
1186 return 0; | |
1187 } | |
1188 } | |
1189 | |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1190 /* META_BEHAVIOR can be one of the following values, defined in events.h: |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1191 |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1192 high_bit_is_meta |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1193 use_console_meta_flag |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1194 latin_1_maps_to_itself |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1195 |
1204 | 1196 DO_BACKSPACE_MAPPING means that if CON is a TTY, and C is a the TTY's |
1197 backspace character, the event will have keysym `backspace' instead of | |
1198 '(control h). It is clearly correct to do this conversion is the | |
1199 character was just read from a TTY, clearly incorrect inside of | |
1200 define-key, which must be able to handle all consoles. #### What about | |
1201 in other circumstances? #### Should the user have access to this flag? | |
1202 | |
1203 #### We need to go through and review all the flags in | |
1204 character_to_event() and event_to_character() and figure out exactly | |
1205 under what circumstances they should or should not be set, then go | |
1206 through and review all callers of character_to_event(), | |
1207 Fcharacter_to_event(), event_to_character(), and Fevent_to_character() | |
1208 and check that they are passing the correct flags in for their varied | |
1209 circumstances. | |
1210 | |
1211 #### Some of this garbage, and some of the flags, could go away if we | |
1212 implemented the suggestion, originally from event-Xt.c: | |
1213 | |
2828 | 1214 [[ The way that keysym correspondence to characters should work: |
1204 | 1215 - a Lisp_Event should contain a keysym AND a character slot. |
1216 - keybindings are tried with the keysym. If no binding can be found, | |
2828 | 1217 and there is a corresponding character, call self-insert-command. ]] |
1218 | |
1219 That's an X-specific way of thinking. All the other platforms--even | |
1220 the TTY, make sure you've done (set-input-mode t nil 1) and set your | |
1221 console coding system appropriately when checking--just use | |
1222 characters as emacs keysyms, and, together with defaulting to | |
1223 self-insert-command if an unbound key with a character correspondence | |
1224 is typed, that works fine for them. (Yes, this ignores GTK.) | |
1225 | |
1226 [[ [... snipping other suggestions which I've implemented.] | |
1227 Nuke the Qascii_character property. ]] | |
1204 | 1228 |
2828 | 1229 Well, we've renamed it anyway--it was badly named. |
1230 Qcharacter_of_keysym, here we go. It's really only with X11 that how | |
1231 to map between adiaeresis and (int-to-char #xE4), or ellipsis and | |
1232 whatever, becomes an issue, and IMO the property approach to this is | |
1233 fine. Aidan Kehoe, 2005-05-15. | |
1204 | 1234 |
2828 | 1235 [[ This would apparently solve a lot of different problems. ]] |
1236 | |
1237 I'd be interested to know what's left. Removing the allow-meta | |
1238 argument from event-to-character would be a Good Thing, IMO, but | |
1239 beyond that, I'm not sure what else there is to do wrt. key | |
1240 mappings. Of course, feedback from users of the Russian C-x facility | |
1241 is still needed. */ | |
428 | 1242 |
1243 void | |
867 | 1244 character_to_event (Ichar c, Lisp_Event *event, struct console *con, |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1245 character_to_event_meta_behavior meta_behavior, |
2340 | 1246 int USED_IF_TTY (do_backspace_mapping)) |
428 | 1247 { |
1248 Lisp_Object k = Qnil; | |
442 | 1249 int m = 0; |
934 | 1250 if (EVENT_TYPE (event) == dead_event) |
563 | 1251 invalid_argument ("character-to-event called with a deallocated event!", Qunbound); |
428 | 1252 |
1253 #ifndef MULE | |
1254 c &= 255; | |
1255 #endif | |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1256 if (meta_behavior != latin_1_maps_to_itself && c > 127 && c <= 255) |
428 | 1257 { |
1258 int meta_flag = 1; | |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1259 if (meta_behavior == use_console_meta_flag && CONSOLE_TTY_P (con)) |
428 | 1260 meta_flag = TTY_FLAGS (con).meta_key; |
1261 switch (meta_flag) | |
1262 { | |
1263 case 0: /* ignore top bit; it's parity */ | |
1264 c -= 128; | |
1265 break; | |
1266 case 1: /* top bit is meta */ | |
1267 c -= 128; | |
442 | 1268 m = XEMACS_MOD_META; |
428 | 1269 break; |
1270 default: /* this is a real character */ | |
1271 break; | |
1272 } | |
1273 } | |
442 | 1274 if (c < ' ') c += '@', m |= XEMACS_MOD_CONTROL; |
1275 if (m & XEMACS_MOD_CONTROL) | |
428 | 1276 { |
1277 switch (c) | |
1278 { | |
442 | 1279 case 'I': k = QKtab; m &= ~XEMACS_MOD_CONTROL; break; |
1280 case 'J': k = QKlinefeed; m &= ~XEMACS_MOD_CONTROL; break; | |
1281 case 'M': k = QKreturn; m &= ~XEMACS_MOD_CONTROL; break; | |
1282 case '[': k = QKescape; m &= ~XEMACS_MOD_CONTROL; break; | |
428 | 1283 default: |
1204 | 1284 #if defined (HAVE_TTY) |
428 | 1285 if (do_backspace_mapping && |
1286 CHARP (con->tty_erase_char) && | |
1287 c - '@' == XCHAR (con->tty_erase_char)) | |
1288 { | |
1289 k = QKbackspace; | |
442 | 1290 m &= ~XEMACS_MOD_CONTROL; |
428 | 1291 } |
1204 | 1292 #endif /* defined (HAVE_TTY) */ |
428 | 1293 break; |
1294 } | |
1295 if (c >= 'A' && c <= 'Z') c -= 'A'-'a'; | |
1296 } | |
1204 | 1297 #if defined (HAVE_TTY) |
428 | 1298 else if (do_backspace_mapping && |
1299 CHARP (con->tty_erase_char) && c == XCHAR (con->tty_erase_char)) | |
1300 k = QKbackspace; | |
1204 | 1301 #endif /* defined (HAVE_TTY) */ |
428 | 1302 else if (c == 127) |
1303 k = QKdelete; | |
1304 else if (c == ' ') | |
1305 k = QKspace; | |
1306 | |
934 | 1307 set_event_type (event, key_press_event); |
1308 SET_EVENT_TIMESTAMP_ZERO (event); /* #### */ | |
1309 SET_EVENT_CHANNEL (event, wrap_console (con)); | |
1204 | 1310 SET_EVENT_KEY_KEYSYM (event, (!NILP (k) ? k : make_char (c))); |
1311 SET_EVENT_KEY_MODIFIERS (event, m); | |
428 | 1312 } |
1313 | |
867 | 1314 Ichar |
1204 | 1315 event_to_character (Lisp_Object event, |
428 | 1316 int allow_extra_modifiers, |
2828 | 1317 int allow_meta) |
428 | 1318 { |
867 | 1319 Ichar c = 0; |
428 | 1320 Lisp_Object code; |
1321 | |
1204 | 1322 if (XEVENT_TYPE (event) != key_press_event) |
428 | 1323 { |
1204 | 1324 assert (XEVENT_TYPE (event) != dead_event); |
428 | 1325 return -1; |
1326 } | |
1327 if (!allow_extra_modifiers && | |
2828 | 1328 XEVENT_KEY_MODIFIERS (event) & |
1329 (XEMACS_MOD_SUPER|XEMACS_MOD_HYPER|XEMACS_MOD_ALT)) | |
428 | 1330 return -1; |
1204 | 1331 if (CHAR_OR_CHAR_INTP (XEVENT_KEY_KEYSYM (event))) |
1332 c = XCHAR_OR_CHAR_INT (XEVENT_KEY_KEYSYM (event)); | |
1333 else if (!SYMBOLP (XEVENT_KEY_KEYSYM (event))) | |
2500 | 1334 ABORT (); |
1204 | 1335 else if (CHAR_OR_CHAR_INTP (code = Fget (XEVENT_KEY_KEYSYM (event), |
2828 | 1336 Qcharacter_of_keysym, Qnil))) |
428 | 1337 c = XCHAR_OR_CHAR_INT (code); |
1338 else | |
2828 | 1339 { |
1340 Lisp_Object thekeysym = XEVENT_KEY_KEYSYM (event); | |
1341 | |
1342 if (CHAR_OR_CHAR_INTP (code = Fget (thekeysym, Qascii_character, Qnil))) | |
1343 { | |
1344 c = XCHAR_OR_CHAR_INT (code); | |
1345 warn_when_safe(Qkey_mapping, Qwarning, | |
1346 "Obsolete key binding technique.\n" | |
428 | 1347 |
2828 | 1348 "Some code you're using bound %s to `self-insert-command' and messed around\n" |
1349 "with its `ascii-character' property. Doing this is deprecated, and the code\n" | |
1350 "should be updated to use the `set-character-of-keysym' interface.\n" | |
1351 "If you're the one updating the code, first check if there's still a need\n" | |
1352 "for it; we support many more X11 keysyms out of the box now than we did\n" | |
1353 "in the past. ", XSTRING_DATA(XSYMBOL_NAME(thekeysym))); | |
1354 /* Only show the warning once for each keysym. */ | |
1355 Fput(thekeysym, Qcharacter_of_keysym, code); | |
1356 } | |
1357 else | |
1358 { | |
1359 return -1; | |
1360 } | |
1361 } | |
1204 | 1362 if (XEVENT_KEY_MODIFIERS (event) & XEMACS_MOD_CONTROL) |
428 | 1363 { |
1364 if (c >= 'a' && c <= 'z') | |
1365 c -= ('a' - 'A'); | |
1366 else | |
1367 /* reject Control-Shift- keys */ | |
1368 if (c >= 'A' && c <= 'Z' && !allow_extra_modifiers) | |
1369 return -1; | |
1370 | |
1371 if (c >= '@' && c <= '_') | |
1372 c -= '@'; | |
1373 else if (c == ' ') /* C-space and C-@ are the same. */ | |
1374 c = 0; | |
1375 else | |
1376 /* reject keys that can't take Control- modifiers */ | |
1377 if (! allow_extra_modifiers) return -1; | |
1378 } | |
1379 | |
1204 | 1380 if (XEVENT_KEY_MODIFIERS (event) & XEMACS_MOD_META) |
428 | 1381 { |
1382 if (! allow_meta) return -1; | |
1204 | 1383 if (c >= 128) return -1; /* don't allow M-oslash (overlap) */ |
428 | 1384 c |= 0200; |
1385 } | |
1386 return c; | |
1387 } | |
1388 | |
2862 | 1389 DEFUN ("event-to-character", Fevent_to_character, 1, 4, 0, /* |
2828 | 1390 Return the closest character approximation to the given event object. |
428 | 1391 If the event isn't a keypress, this returns nil. |
1392 If the ALLOW-EXTRA-MODIFIERS argument is non-nil, then this is lenient in | |
1393 its translation; it will ignore modifier keys other than control and meta, | |
1394 and will ignore the shift modifier on those characters which have no | |
1395 shifted ASCII equivalent (Control-Shift-A for example, will be mapped to | |
1396 the same ASCII code as Control-A). | |
1397 If the ALLOW-META argument is non-nil, then the Meta modifier will be | |
1398 represented by turning on the high bit of the byte returned; otherwise, nil | |
1399 will be returned for events containing the Meta modifier. | |
1204 | 1400 Note that ALLOW-META may cause ambiguity between meta characters and |
1401 Latin-1 characters. | |
2862 | 1402 ALLOW-NON-ASCII is unused, and retained for compatibility. |
428 | 1403 */ |
2862 | 1404 (event, allow_extra_modifiers, allow_meta, UNUSED(allow_non_ascii))) |
428 | 1405 { |
867 | 1406 Ichar c; |
428 | 1407 CHECK_LIVE_EVENT (event); |
1204 | 1408 c = event_to_character (event, |
428 | 1409 !NILP (allow_extra_modifiers), |
2828 | 1410 !NILP (allow_meta)); |
428 | 1411 return c < 0 ? Qnil : make_char (c); |
1412 } | |
1413 | |
1414 DEFUN ("character-to-event", Fcharacter_to_event, 1, 4, 0, /* | |
444 | 1415 Convert KEY-DESCRIPTION into an event structure, replete with bucky bits. |
428 | 1416 |
444 | 1417 KEY-DESCRIPTION is the first argument, and the event to fill in is the |
1418 second. This function contains knowledge about what various kinds of | |
1419 arguments ``mean'' -- for example, the number 9 is converted to the | |
1420 character ``Tab'', not the distinct character ``Control-I''. | |
428 | 1421 |
3025 | 1422 KEY-DESCRIPTION can be an integer, a character, a symbol such as `clear', |
444 | 1423 or a list such as '(control backspace). |
1424 | |
1425 If the optional second argument EVENT is an event, it is modified and | |
1426 returned; otherwise, a new event object is created and returned. | |
428 | 1427 |
1428 Optional third arg CONSOLE is the console to store in the event, and | |
1429 defaults to the selected console. | |
1430 | |
444 | 1431 If KEY-DESCRIPTION is an integer or character, the high bit may be |
1204 | 1432 interpreted as the meta key. (This is done for backward compatibility in |
1433 lots of places -- specifically, because lots of Lisp code uses specs like | |
1434 ?\M-d and "\M-d" in key code, expecting this to work; yet these are in | |
1435 reality converted directly to 8-bit characters by the Lisp reader.) If | |
1436 USE-CONSOLE-META-FLAG is nil or CONSOLE is not a TTY, this will always be | |
1437 the case. If USE-CONSOLE-META-FLAG is non-nil and CONSOLE is a TTY, the | |
1438 `meta' flag for CONSOLE affects whether the high bit is interpreted as a | |
1439 meta key. (See `set-input-mode'.) Don't set this flag to non-nil unless | |
1440 you know what you're doing (more specifically, only if the character came | |
1441 directly from a TTY, not from the user). If you don't want this silly meta | |
1442 interpretation done, you should pass in a list containing the character. | |
428 | 1443 |
1444 Beware that character-to-event and event-to-character are not strictly | |
1445 inverse functions, since events contain much more information than the | |
444 | 1446 Lisp character object type can encode. |
428 | 1447 */ |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1448 (keystroke, event, console, use_console_meta_flag_)) |
428 | 1449 { |
1450 struct console *con = decode_console (console); | |
1451 if (NILP (event)) | |
1452 event = Fmake_event (Qnil, Qnil); | |
1453 else | |
1454 CHECK_LIVE_EVENT (event); | |
444 | 1455 if (CONSP (keystroke) || SYMBOLP (keystroke)) |
1456 key_desc_list_to_event (keystroke, event, 1); | |
428 | 1457 else |
1458 { | |
444 | 1459 CHECK_CHAR_COERCE_INT (keystroke); |
1460 character_to_event (XCHAR (keystroke), XEVENT (event), con, | |
4780
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1461 (NILP (use_console_meta_flag_) ? |
2fd201d73a92
Call character_to_event on characters received from XIM, event-Xt.c
Aidan Kehoe <kehoea@parhasard.net>
parents:
3092
diff
changeset
|
1462 high_bit_is_meta : use_console_meta_flag), 1); |
428 | 1463 } |
1464 return event; | |
1465 } | |
1466 | |
1467 void | |
1468 nth_of_key_sequence_as_event (Lisp_Object seq, int n, Lisp_Object event) | |
1469 { | |
1470 assert (STRINGP (seq) || VECTORP (seq)); | |
1471 assert (n < XINT (Flength (seq))); | |
1472 | |
1473 if (STRINGP (seq)) | |
1474 { | |
867 | 1475 Ichar ch = string_ichar (seq, n); |
428 | 1476 Fcharacter_to_event (make_char (ch), event, Qnil, Qnil); |
1477 } | |
1478 else | |
1479 { | |
1480 Lisp_Object keystroke = XVECTOR_DATA (seq)[n]; | |
1481 if (EVENTP (keystroke)) | |
1482 Fcopy_event (keystroke, event); | |
1483 else | |
1484 Fcharacter_to_event (keystroke, event, Qnil, Qnil); | |
1485 } | |
1486 } | |
1487 | |
1488 Lisp_Object | |
1489 key_sequence_to_event_chain (Lisp_Object seq) | |
1490 { | |
1491 int len = XINT (Flength (seq)); | |
1492 int i; | |
1493 Lisp_Object head = Qnil, tail = Qnil; | |
1494 | |
1495 for (i = 0; i < len; i++) | |
1496 { | |
1497 Lisp_Object event = Fmake_event (Qnil, Qnil); | |
1498 nth_of_key_sequence_as_event (seq, i, event); | |
1499 enqueue_event (event, &head, &tail); | |
1500 } | |
1501 | |
1502 return head; | |
1503 } | |
1504 | |
934 | 1505 |
793 | 1506 /* Concatenate a string description of EVENT onto the end of BUF. If |
1507 BRIEF, use short forms for keys, e.g. C- instead of control-. */ | |
1508 | |
934 | 1509 void |
1510 format_event_object (Eistring *buf, Lisp_Object event, int brief) | |
428 | 1511 { |
1512 int mouse_p = 0; | |
1513 int mod = 0; | |
1514 Lisp_Object key; | |
1515 | |
1204 | 1516 switch (XEVENT_TYPE (event)) |
428 | 1517 { |
1518 case key_press_event: | |
1519 { | |
1204 | 1520 mod = XEVENT_KEY_MODIFIERS (event); |
1521 key = XEVENT_KEY_KEYSYM (event); | |
428 | 1522 /* Hack. */ |
1523 if (! brief && CHARP (key) && | |
793 | 1524 mod & (XEMACS_MOD_CONTROL | XEMACS_MOD_META | XEMACS_MOD_SUPER | |
1525 XEMACS_MOD_HYPER)) | |
428 | 1526 { |
1527 int k = XCHAR (key); | |
1528 if (k >= 'a' && k <= 'z') | |
1529 key = make_char (k - ('a' - 'A')); | |
1530 else if (k >= 'A' && k <= 'Z') | |
442 | 1531 mod |= XEMACS_MOD_SHIFT; |
428 | 1532 } |
1533 break; | |
1534 } | |
1535 case button_release_event: | |
1536 mouse_p++; | |
1537 /* Fall through */ | |
1538 case button_press_event: | |
1539 { | |
1540 mouse_p++; | |
1204 | 1541 mod = XEVENT_BUTTON_MODIFIERS (event); |
1542 key = make_char (XEVENT_BUTTON_BUTTON (event) + '0'); | |
428 | 1543 break; |
1544 } | |
1545 case magic_event: | |
1546 { | |
788 | 1547 Lisp_Object stream; |
1548 struct gcpro gcpro1; | |
1549 GCPRO1 (stream); | |
428 | 1550 |
788 | 1551 stream = make_resizing_buffer_output_stream (); |
1204 | 1552 event_stream_format_magic_event (XEVENT (event), stream); |
788 | 1553 Lstream_flush (XLSTREAM (stream)); |
793 | 1554 eicat_raw (buf, resizing_buffer_stream_ptr (XLSTREAM (stream)), |
1555 Lstream_byte_count (XLSTREAM (stream))); | |
788 | 1556 Lstream_delete (XLSTREAM (stream)); |
1557 UNGCPRO; | |
428 | 1558 return; |
1559 } | |
2421 | 1560 case magic_eval_event: eicat_ascii (buf, "magic-eval"); return; |
1561 case pointer_motion_event: eicat_ascii (buf, "motion"); return; | |
1562 case misc_user_event: eicat_ascii (buf, "misc-user"); return; | |
1563 case eval_event: eicat_ascii (buf, "eval"); return; | |
1564 case process_event: eicat_ascii (buf, "process"); return; | |
1565 case timeout_event: eicat_ascii (buf, "timeout"); return; | |
1566 case empty_event: eicat_ascii (buf, "empty"); return; | |
1567 case dead_event: eicat_ascii (buf, "DEAD-EVENT"); return; | |
428 | 1568 default: |
2500 | 1569 ABORT (); |
442 | 1570 return; |
428 | 1571 } |
793 | 1572 #define modprint(x,y) \ |
2421 | 1573 do { if (brief) eicat_ascii (buf, (y)); else eicat_ascii (buf, (x)); } while (0) |
442 | 1574 if (mod & XEMACS_MOD_CONTROL) modprint ("control-", "C-"); |
1575 if (mod & XEMACS_MOD_META) modprint ("meta-", "M-"); | |
1576 if (mod & XEMACS_MOD_SUPER) modprint ("super-", "S-"); | |
1577 if (mod & XEMACS_MOD_HYPER) modprint ("hyper-", "H-"); | |
1578 if (mod & XEMACS_MOD_ALT) modprint ("alt-", "A-"); | |
1579 if (mod & XEMACS_MOD_SHIFT) modprint ("shift-", "Sh-"); | |
428 | 1580 if (mouse_p) |
1581 { | |
2421 | 1582 eicat_ascii (buf, "button"); |
428 | 1583 --mouse_p; |
1584 } | |
1585 | |
1586 #undef modprint | |
1587 | |
1588 if (CHARP (key)) | |
793 | 1589 eicat_ch (buf, XCHAR (key)); |
428 | 1590 else if (SYMBOLP (key)) |
1591 { | |
2367 | 1592 const Ascbyte *str = 0; |
428 | 1593 if (brief) |
1594 { | |
1595 if (EQ (key, QKlinefeed)) str = "LFD"; | |
1596 else if (EQ (key, QKtab)) str = "TAB"; | |
1597 else if (EQ (key, QKreturn)) str = "RET"; | |
1598 else if (EQ (key, QKescape)) str = "ESC"; | |
1599 else if (EQ (key, QKdelete)) str = "DEL"; | |
1600 else if (EQ (key, QKspace)) str = "SPC"; | |
1601 else if (EQ (key, QKbackspace)) str = "BS"; | |
1602 } | |
1603 if (str) | |
2421 | 1604 eicat_ascii (buf, str); |
428 | 1605 else |
793 | 1606 eicat_lstr (buf, XSYMBOL (key)->name); |
428 | 1607 } |
1608 else | |
2500 | 1609 ABORT (); |
428 | 1610 if (mouse_p) |
2421 | 1611 eicat_ascii (buf, "up"); |
428 | 1612 } |
1613 | |
1204 | 1614 void |
1615 upshift_event (Lisp_Object event) | |
1616 { | |
1617 Lisp_Object keysym = XEVENT_KEY_KEYSYM (event); | |
1618 Ichar c = 0; | |
1619 | |
1620 if (CHAR_OR_CHAR_INTP (keysym) | |
1621 && ((c = XCHAR_OR_CHAR_INT (keysym)), | |
1622 c >= 'a' && c <= 'z')) | |
1623 XSET_EVENT_KEY_KEYSYM (event, make_char (c + 'A' - 'a')); | |
1624 else | |
1625 if (!(XEVENT_KEY_MODIFIERS (event) & XEMACS_MOD_SHIFT)) | |
1626 XSET_EVENT_KEY_MODIFIERS | |
1627 (event, XEVENT_KEY_MODIFIERS (event) |= XEMACS_MOD_SHIFT); | |
1628 } | |
1629 | |
1630 void | |
1631 downshift_event (Lisp_Object event) | |
1632 { | |
1633 Lisp_Object keysym = XEVENT_KEY_KEYSYM (event); | |
1634 Ichar c = 0; | |
1635 | |
1636 if (XEVENT_KEY_MODIFIERS (event) & XEMACS_MOD_SHIFT) | |
1637 XSET_EVENT_KEY_MODIFIERS | |
1638 (event, XEVENT_KEY_MODIFIERS (event) & ~XEMACS_MOD_SHIFT); | |
1639 else if (CHAR_OR_CHAR_INTP (keysym) | |
1640 && ((c = XCHAR_OR_CHAR_INT (keysym)), | |
1641 c >= 'A' && c <= 'Z')) | |
1642 XSET_EVENT_KEY_KEYSYM (event, make_char (c + 'a' - 'A')); | |
1643 } | |
1644 | |
1645 int | |
1646 event_upshifted_p (Lisp_Object event) | |
1647 { | |
1648 Lisp_Object keysym = XEVENT_KEY_KEYSYM (event); | |
1649 Ichar c = 0; | |
1650 | |
1651 if ((XEVENT_KEY_MODIFIERS (event) & XEMACS_MOD_SHIFT) | |
1652 || (CHAR_OR_CHAR_INTP (keysym) | |
1653 && ((c = XCHAR_OR_CHAR_INT (keysym)), | |
1654 c >= 'A' && c <= 'Z'))) | |
1655 return 1; | |
1656 else | |
1657 return 0; | |
1658 } | |
934 | 1659 |
428 | 1660 DEFUN ("eventp", Feventp, 1, 1, 0, /* |
1661 True if OBJECT is an event object. | |
1662 */ | |
1663 (object)) | |
1664 { | |
1665 return EVENTP (object) ? Qt : Qnil; | |
1666 } | |
1667 | |
1668 DEFUN ("event-live-p", Fevent_live_p, 1, 1, 0, /* | |
1669 True if OBJECT is an event object that has not been deallocated. | |
1670 */ | |
1671 (object)) | |
1672 { | |
934 | 1673 return EVENTP (object) && XEVENT_TYPE (object) != dead_event ? |
1674 Qt : Qnil; | |
428 | 1675 } |
1676 | |
1677 #if 0 /* debugging functions */ | |
1678 | |
826 | 1679 DEFUN ("event-next", Fevent_next, 1, 1, 0, /* |
428 | 1680 Return the event object's `next' event, or nil if it has none. |
1681 The `next-event' field is changed by calling `set-next-event'. | |
1682 */ | |
1683 (event)) | |
1684 { | |
440 | 1685 Lisp_Event *e; |
428 | 1686 CHECK_LIVE_EVENT (event); |
1687 | |
1688 return XEVENT_NEXT (event); | |
1689 } | |
1690 | |
826 | 1691 DEFUN ("set-event-next", Fset_event_next, 2, 2, 0, /* |
428 | 1692 Set the `next event' of EVENT to NEXT-EVENT. |
1693 NEXT-EVENT must be an event object or nil. | |
1694 */ | |
1695 (event, next_event)) | |
1696 { | |
1697 Lisp_Object ev; | |
1698 | |
1699 CHECK_LIVE_EVENT (event); | |
1700 if (NILP (next_event)) | |
1701 { | |
1702 XSET_EVENT_NEXT (event, Qnil); | |
1703 return Qnil; | |
1704 } | |
1705 | |
1706 CHECK_LIVE_EVENT (next_event); | |
1707 | |
1708 EVENT_CHAIN_LOOP (ev, XEVENT_NEXT (event)) | |
1709 { | |
1710 QUIT; | |
1711 if (EQ (ev, event)) | |
563 | 1712 invalid_operation_2 ("Cyclic event-next", event, next_event); |
428 | 1713 } |
1714 XSET_EVENT_NEXT (event, next_event); | |
1715 return next_event; | |
1716 } | |
1717 | |
1718 #endif /* 0 */ | |
1719 | |
1720 DEFUN ("event-type", Fevent_type, 1, 1, 0, /* | |
1721 Return the type of EVENT. | |
1722 This will be a symbol; one of | |
1723 | |
1724 key-press A key was pressed. | |
1725 button-press A mouse button was pressed. | |
1726 button-release A mouse button was released. | |
1727 misc-user Some other user action happened; typically, this is | |
1728 a menu selection or scrollbar action. | |
1729 motion The mouse moved. | |
1730 process Input is available from a subprocess. | |
1731 timeout A timeout has expired. | |
1732 eval This causes a specified action to occur when dispatched. | |
1733 magic Some window-system-specific event has occurred. | |
1734 empty The event has been allocated but not assigned. | |
1735 | |
1736 */ | |
1737 (event)) | |
1738 { | |
1739 CHECK_LIVE_EVENT (event); | |
934 | 1740 switch (XEVENT_TYPE (event)) |
428 | 1741 { |
1742 case key_press_event: return Qkey_press; | |
1743 case button_press_event: return Qbutton_press; | |
1744 case button_release_event: return Qbutton_release; | |
1745 case misc_user_event: return Qmisc_user; | |
1746 case pointer_motion_event: return Qmotion; | |
1747 case process_event: return Qprocess; | |
1748 case timeout_event: return Qtimeout; | |
1749 case eval_event: return Qeval; | |
1750 case magic_event: | |
1751 case magic_eval_event: | |
1752 return Qmagic; | |
1753 | |
1754 case empty_event: | |
1755 return Qempty; | |
1756 | |
1757 default: | |
2500 | 1758 ABORT (); |
428 | 1759 return Qnil; |
1760 } | |
1761 } | |
1762 | |
1763 DEFUN ("event-timestamp", Fevent_timestamp, 1, 1, 0, /* | |
1764 Return the timestamp of the event object EVENT. | |
442 | 1765 Timestamps are measured in milliseconds since the start of the window system. |
1766 They are NOT related to any current time measurement. | |
1767 They should be compared with `event-timestamp<'. | |
1768 See also `current-event-timestamp'. | |
428 | 1769 */ |
1770 (event)) | |
1771 { | |
1772 CHECK_LIVE_EVENT (event); | |
1773 /* This junk is so that timestamps don't get to be negative, but contain | |
1774 as many bits as this particular emacs will allow. | |
1775 */ | |
2039 | 1776 return make_int (EMACS_INT_MAX & XEVENT_TIMESTAMP (event)); |
428 | 1777 } |
1778 | |
2039 | 1779 #define TIMESTAMP_HALFSPACE (1L << (INT_VALBITS - 2)) |
442 | 1780 |
1781 DEFUN ("event-timestamp<", Fevent_timestamp_lessp, 2, 2, 0, /* | |
1782 Return true if timestamp TIME1 is earlier than timestamp TIME2. | |
1783 This correctly handles timestamp wrap. | |
1784 See also `event-timestamp' and `current-event-timestamp'. | |
1785 */ | |
1786 (time1, time2)) | |
1787 { | |
1788 EMACS_INT t1, t2; | |
1789 | |
1790 CHECK_NATNUM (time1); | |
1791 CHECK_NATNUM (time2); | |
1792 t1 = XINT (time1); | |
1793 t2 = XINT (time2); | |
1794 | |
1795 if (t1 < t2) | |
1796 return t2 - t1 < TIMESTAMP_HALFSPACE ? Qt : Qnil; | |
1797 else | |
1798 return t1 - t2 < TIMESTAMP_HALFSPACE ? Qnil : Qt; | |
1799 } | |
1800 | |
934 | 1801 #define CHECK_EVENT_TYPE(e,t1,sym) do { \ |
1802 CHECK_LIVE_EVENT (e); \ | |
1803 if (XEVENT_TYPE (e) != (t1)) \ | |
1804 e = wrong_type_argument (sym,e); \ | |
1805 } while (0) | |
1806 | |
1807 #define CHECK_EVENT_TYPE2(e,t1,t2,sym) do { \ | |
1808 CHECK_LIVE_EVENT (e); \ | |
1809 { \ | |
1810 emacs_event_type CET_type = XEVENT_TYPE (e); \ | |
1811 if (CET_type != (t1) && \ | |
1812 CET_type != (t2)) \ | |
1813 e = wrong_type_argument (sym,e); \ | |
1814 } \ | |
1815 } while (0) | |
1816 | |
1817 #define CHECK_EVENT_TYPE3(e,t1,t2,t3,sym) do { \ | |
1818 CHECK_LIVE_EVENT (e); \ | |
1819 { \ | |
1820 emacs_event_type CET_type = XEVENT_TYPE (e); \ | |
1821 if (CET_type != (t1) && \ | |
1822 CET_type != (t2) && \ | |
1823 CET_type != (t3)) \ | |
1824 e = wrong_type_argument (sym,e); \ | |
1825 } \ | |
1826 } while (0) | |
428 | 1827 |
1828 DEFUN ("event-key", Fevent_key, 1, 1, 0, /* | |
1829 Return the Keysym of the key-press event EVENT. | |
1830 This will be a character if the event is associated with one, else a symbol. | |
1831 */ | |
1832 (event)) | |
1833 { | |
1834 CHECK_EVENT_TYPE (event, key_press_event, Qkey_press_event_p); | |
1204 | 1835 return XEVENT_KEY_KEYSYM (event); |
428 | 1836 } |
1837 | |
1838 DEFUN ("event-button", Fevent_button, 1, 1, 0, /* | |
444 | 1839 Return the button-number of the button-press or button-release event EVENT. |
428 | 1840 */ |
1841 (event)) | |
1842 { | |
1843 CHECK_EVENT_TYPE3 (event, button_press_event, button_release_event, | |
1844 misc_user_event, Qbutton_event_p); | |
1845 #ifdef HAVE_WINDOW_SYSTEM | |
1204 | 1846 if (XEVENT_TYPE (event) == misc_user_event) |
1847 return make_int (XEVENT_MISC_USER_BUTTON (event)); | |
934 | 1848 else |
1204 | 1849 return make_int (XEVENT_BUTTON_BUTTON (event)); |
428 | 1850 #else /* !HAVE_WINDOW_SYSTEM */ |
1851 return Qzero; | |
1852 #endif /* !HAVE_WINDOW_SYSTEM */ | |
1853 } | |
1854 | |
1855 DEFUN ("event-modifier-bits", Fevent_modifier_bits, 1, 1, 0, /* | |
442 | 1856 Return a number representing the modifier keys and buttons which were down |
428 | 1857 when the given mouse or keyboard event was produced. |
442 | 1858 See also the function `event-modifiers'. |
428 | 1859 */ |
1860 (event)) | |
1861 { | |
1862 again: | |
1863 CHECK_LIVE_EVENT (event); | |
934 | 1864 switch (XEVENT_TYPE (event)) |
1865 { | |
1866 case key_press_event: | |
1204 | 1867 return make_int (XEVENT_KEY_MODIFIERS (event)); |
934 | 1868 case button_press_event: |
1869 case button_release_event: | |
1204 | 1870 return make_int (XEVENT_BUTTON_MODIFIERS (event)); |
934 | 1871 case pointer_motion_event: |
1204 | 1872 return make_int (XEVENT_MOTION_MODIFIERS (event)); |
934 | 1873 case misc_user_event: |
1204 | 1874 return make_int (XEVENT_MISC_USER_MODIFIERS (event)); |
934 | 1875 default: |
1876 event = wrong_type_argument (intern ("key-or-mouse-event-p"), event); | |
1877 goto again; | |
1878 } | |
428 | 1879 } |
1880 | |
1881 DEFUN ("event-modifiers", Fevent_modifiers, 1, 1, 0, /* | |
442 | 1882 Return a list of symbols, the names of the modifier keys and buttons |
428 | 1883 which were down when the given mouse or keyboard event was produced. |
442 | 1884 See also the function `event-modifier-bits'. |
1885 | |
1886 The possible symbols in the list are | |
1887 | |
1888 `shift': The Shift key. Will not appear, in general, on key events | |
1889 where the keysym is an ASCII character, because using Shift | |
1890 on such a character converts it into another character rather | |
1891 than actually just adding a Shift modifier. | |
1892 | |
1893 `control': The Control key. | |
1894 | |
1895 `meta': The Meta key. On PC's and PC-style keyboards, this is generally | |
1896 labelled \"Alt\"; Meta is a holdover from early Lisp Machines and | |
1897 such, propagated through the X Window System. On Sun keyboards, | |
1898 this key is labelled with a diamond. | |
1899 | |
1900 `alt': The \"Alt\" key. Alt is in quotes because this does not refer | |
1901 to what it obviously should refer to, namely the Alt key on PC | |
1902 keyboards. Instead, it refers to the key labelled Alt on Sun | |
1903 keyboards, and to no key at all on PC keyboards. | |
1904 | |
1905 `super': The Super key. Most keyboards don't have any such key, but | |
1906 under X Windows using `xmodmap' you can assign any key (such as | |
1907 an underused right-shift, right-control, or right-alt key) to | |
1908 this key modifier. No support currently exists under MS Windows | |
1909 for generating these modifiers. | |
1910 | |
1911 `hyper': The Hyper key. Works just like the Super key. | |
1912 | |
1913 `button1': The mouse buttons. This means that the specified button was held | |
1914 `button2': down at the time the event occurred. NOTE: For button-press | |
1915 `button3': events, the button that was just pressed down does NOT appear in | |
1916 `button4': the modifiers. | |
1917 `button5': | |
1918 | |
1919 Button modifiers are currently ignored when defining and looking up key and | |
1920 mouse strokes in keymaps. This could be changed, which would allow a user to | |
1921 create button-chord actions, use a button as a key modifier and do other | |
1922 clever things. | |
428 | 1923 */ |
1924 (event)) | |
1925 { | |
1926 int mod = XINT (Fevent_modifier_bits (event)); | |
1927 Lisp_Object result = Qnil; | |
442 | 1928 struct gcpro gcpro1; |
1929 | |
1930 GCPRO1 (result); | |
1931 if (mod & XEMACS_MOD_SHIFT) result = Fcons (Qshift, result); | |
1932 if (mod & XEMACS_MOD_ALT) result = Fcons (Qalt, result); | |
1933 if (mod & XEMACS_MOD_HYPER) result = Fcons (Qhyper, result); | |
1934 if (mod & XEMACS_MOD_SUPER) result = Fcons (Qsuper, result); | |
1935 if (mod & XEMACS_MOD_META) result = Fcons (Qmeta, result); | |
1936 if (mod & XEMACS_MOD_CONTROL) result = Fcons (Qcontrol, result); | |
1937 if (mod & XEMACS_MOD_BUTTON1) result = Fcons (Qbutton1, result); | |
1938 if (mod & XEMACS_MOD_BUTTON2) result = Fcons (Qbutton2, result); | |
1939 if (mod & XEMACS_MOD_BUTTON3) result = Fcons (Qbutton3, result); | |
1940 if (mod & XEMACS_MOD_BUTTON4) result = Fcons (Qbutton4, result); | |
1941 if (mod & XEMACS_MOD_BUTTON5) result = Fcons (Qbutton5, result); | |
1942 RETURN_UNGCPRO (Fnreverse (result)); | |
428 | 1943 } |
1944 | |
1945 static int | |
1946 event_x_y_pixel_internal (Lisp_Object event, int *x, int *y, int relative) | |
1947 { | |
1948 struct window *w; | |
1949 struct frame *f; | |
1950 | |
934 | 1951 if (XEVENT_TYPE (event) == pointer_motion_event) |
1952 { | |
1204 | 1953 *x = XEVENT_MOTION_X (event); |
1954 *y = XEVENT_MOTION_Y (event); | |
934 | 1955 } |
1956 else if (XEVENT_TYPE (event) == button_press_event || | |
1957 XEVENT_TYPE (event) == button_release_event) | |
1958 { | |
1204 | 1959 *x = XEVENT_BUTTON_X (event); |
1960 *y = XEVENT_BUTTON_Y (event); | |
934 | 1961 } |
1962 else if (XEVENT_TYPE (event) == misc_user_event) | |
1963 { | |
1204 | 1964 *x = XEVENT_MISC_USER_X (event); |
1965 *y = XEVENT_MISC_USER_Y (event); | |
934 | 1966 } |
1967 else | |
1968 return 0; | |
428 | 1969 f = XFRAME (EVENT_CHANNEL (XEVENT (event))); |
1970 | |
1971 if (relative) | |
1972 { | |
1973 w = find_window_by_pixel_pos (*x, *y, f->root_window); | |
1974 | |
1975 if (!w) | |
442 | 1976 return 1; /* #### What should really happen here? */ |
428 | 1977 |
1978 *x -= w->pixel_left; | |
1979 *y -= w->pixel_top; | |
1980 } | |
1981 else | |
1982 { | |
1983 *y -= FRAME_REAL_TOP_TOOLBAR_HEIGHT (f) - | |
1984 FRAME_REAL_TOP_TOOLBAR_BORDER_WIDTH (f); | |
1985 *x -= FRAME_REAL_LEFT_TOOLBAR_WIDTH (f) - | |
1986 FRAME_REAL_LEFT_TOOLBAR_BORDER_WIDTH (f); | |
1987 } | |
1988 | |
1989 return 1; | |
1990 } | |
1991 | |
1992 DEFUN ("event-window-x-pixel", Fevent_window_x_pixel, 1, 1, 0, /* | |
1993 Return the X position in pixels of mouse event EVENT. | |
1994 The value returned is relative to the window the event occurred in. | |
1995 This will signal an error if the event is not a mouse event. | |
1996 See also `mouse-event-p' and `event-x-pixel'. | |
1997 */ | |
1998 (event)) | |
1999 { | |
2000 int x, y; | |
2001 | |
2002 CHECK_LIVE_EVENT (event); | |
2003 | |
2004 if (!event_x_y_pixel_internal (event, &x, &y, 1)) | |
2005 return wrong_type_argument (Qmouse_event_p, event); | |
2006 else | |
2007 return make_int (x); | |
2008 } | |
2009 | |
2010 DEFUN ("event-window-y-pixel", Fevent_window_y_pixel, 1, 1, 0, /* | |
2011 Return the Y position in pixels of mouse event EVENT. | |
2012 The value returned is relative to the window the event occurred in. | |
2013 This will signal an error if the event is not a mouse event. | |
2014 See also `mouse-event-p' and `event-y-pixel'. | |
2015 */ | |
2016 (event)) | |
2017 { | |
2018 int x, y; | |
2019 | |
2020 CHECK_LIVE_EVENT (event); | |
2021 | |
2022 if (!event_x_y_pixel_internal (event, &x, &y, 1)) | |
2023 return wrong_type_argument (Qmouse_event_p, event); | |
2024 else | |
2025 return make_int (y); | |
2026 } | |
2027 | |
2028 DEFUN ("event-x-pixel", Fevent_x_pixel, 1, 1, 0, /* | |
2029 Return the X position in pixels of mouse event EVENT. | |
2030 The value returned is relative to the frame the event occurred in. | |
2031 This will signal an error if the event is not a mouse event. | |
2032 See also `mouse-event-p' and `event-window-x-pixel'. | |
2033 */ | |
2034 (event)) | |
2035 { | |
2036 int x, y; | |
2037 | |
2038 CHECK_LIVE_EVENT (event); | |
2039 | |
2040 if (!event_x_y_pixel_internal (event, &x, &y, 0)) | |
2041 return wrong_type_argument (Qmouse_event_p, event); | |
2042 else | |
2043 return make_int (x); | |
2044 } | |
2045 | |
2046 DEFUN ("event-y-pixel", Fevent_y_pixel, 1, 1, 0, /* | |
2047 Return the Y position in pixels of mouse event EVENT. | |
2048 The value returned is relative to the frame the event occurred in. | |
2049 This will signal an error if the event is not a mouse event. | |
2050 See also `mouse-event-p' `event-window-y-pixel'. | |
2051 */ | |
2052 (event)) | |
2053 { | |
2054 int x, y; | |
2055 | |
2056 CHECK_LIVE_EVENT (event); | |
2057 | |
2058 if (!event_x_y_pixel_internal (event, &x, &y, 0)) | |
2059 return wrong_type_argument (Qmouse_event_p, event); | |
2060 else | |
2061 return make_int (y); | |
2062 } | |
2063 | |
2064 /* Given an event, return a value: | |
2065 | |
2066 OVER_TOOLBAR: over one of the 4 frame toolbars | |
2067 OVER_MODELINE: over a modeline | |
2068 OVER_BORDER: over an internal border | |
2069 OVER_NOTHING: over the text area, but not over text | |
2070 OVER_OUTSIDE: outside of the frame border | |
2071 OVER_TEXT: over text in the text area | |
2072 OVER_V_DIVIDER: over windows vertical divider | |
2073 | |
2074 and return: | |
2075 | |
2076 The X char position in CHAR_X, if not a null pointer. | |
2077 The Y char position in CHAR_Y, if not a null pointer. | |
2078 (These last two values are relative to the window the event is over.) | |
2079 The window it's over in W, if not a null pointer. | |
2080 The buffer position it's over in BUFP, if not a null pointer. | |
2081 The closest buffer position in CLOSEST, if not a null pointer. | |
2082 | |
2083 OBJ_X, OBJ_Y, OBJ1, and OBJ2 are as in pixel_to_glyph_translation(). | |
2084 */ | |
2085 | |
2086 static int | |
2087 event_pixel_translation (Lisp_Object event, int *char_x, int *char_y, | |
2088 int *obj_x, int *obj_y, | |
665 | 2089 struct window **w, Charbpos *bufp, Charbpos *closest, |
428 | 2090 Charcount *modeline_closest, |
2091 Lisp_Object *obj1, Lisp_Object *obj2) | |
2092 { | |
2093 int pix_x = 0; | |
2094 int pix_y = 0; | |
2095 int result; | |
2096 Lisp_Object frame; | |
2097 | |
2098 int ret_x, ret_y, ret_obj_x, ret_obj_y; | |
2099 struct window *ret_w; | |
665 | 2100 Charbpos ret_bufp, ret_closest; |
428 | 2101 Charcount ret_modeline_closest; |
2102 Lisp_Object ret_obj1, ret_obj2; | |
2103 | |
2104 CHECK_LIVE_EVENT (event); | |
934 | 2105 frame = XEVENT_CHANNEL (event); |
2106 switch (XEVENT_TYPE (event)) | |
2107 { | |
2108 case pointer_motion_event : | |
1204 | 2109 pix_x = XEVENT_MOTION_X (event); |
2110 pix_y = XEVENT_MOTION_Y (event); | |
934 | 2111 break; |
2112 case button_press_event : | |
2113 case button_release_event : | |
1204 | 2114 pix_x = XEVENT_BUTTON_X (event); |
2115 pix_y = XEVENT_BUTTON_Y (event); | |
934 | 2116 break; |
2117 case misc_user_event : | |
1204 | 2118 pix_x = XEVENT_MISC_USER_X (event); |
2119 pix_y = XEVENT_MISC_USER_Y (event); | |
934 | 2120 break; |
2121 default: | |
2122 dead_wrong_type_argument (Qmouse_event_p, event); | |
2123 } | |
428 | 2124 |
2125 result = pixel_to_glyph_translation (XFRAME (frame), pix_x, pix_y, | |
2126 &ret_x, &ret_y, &ret_obj_x, &ret_obj_y, | |
2127 &ret_w, &ret_bufp, &ret_closest, | |
2128 &ret_modeline_closest, | |
2129 &ret_obj1, &ret_obj2); | |
2130 | |
2131 if (result == OVER_NOTHING || result == OVER_OUTSIDE) | |
2132 ret_bufp = 0; | |
2133 else if (ret_w && NILP (ret_w->buffer)) | |
2134 /* Why does this happen? (Does it still happen?) | |
2135 I guess the window has gotten reused as a non-leaf... */ | |
2136 ret_w = 0; | |
2137 | |
2138 /* #### pixel_to_glyph_translation() sometimes returns garbage... | |
2139 The word has type Lisp_Type_Record (presumably meaning `extent') but the | |
2140 pointer points to random memory, often filled with 0, sometimes not. | |
2141 */ | |
2142 /* #### Chuck, do we still need this crap? */ | |
2143 if (!NILP (ret_obj1) && !(GLYPHP (ret_obj1) | |
2144 #ifdef HAVE_TOOLBARS | |
2145 || TOOLBAR_BUTTONP (ret_obj1) | |
2146 #endif | |
2147 )) | |
2500 | 2148 ABORT (); |
428 | 2149 if (!NILP (ret_obj2) && !(EXTENTP (ret_obj2) || CONSP (ret_obj2))) |
2500 | 2150 ABORT (); |
428 | 2151 |
2152 if (char_x) | |
2153 *char_x = ret_x; | |
2154 if (char_y) | |
2155 *char_y = ret_y; | |
2156 if (obj_x) | |
2157 *obj_x = ret_obj_x; | |
2158 if (obj_y) | |
2159 *obj_y = ret_obj_y; | |
2160 if (w) | |
2161 *w = ret_w; | |
2162 if (bufp) | |
2163 *bufp = ret_bufp; | |
2164 if (closest) | |
2165 *closest = ret_closest; | |
2166 if (modeline_closest) | |
2167 *modeline_closest = ret_modeline_closest; | |
2168 if (obj1) | |
2169 *obj1 = ret_obj1; | |
2170 if (obj2) | |
2171 *obj2 = ret_obj2; | |
2172 | |
2173 return result; | |
2174 } | |
2175 | |
2176 DEFUN ("event-over-text-area-p", Fevent_over_text_area_p, 1, 1, 0, /* | |
2177 Return t if the mouse event EVENT occurred over the text area of a window. | |
2178 The modeline is not considered to be part of the text area. | |
2179 */ | |
2180 (event)) | |
2181 { | |
2182 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | |
2183 | |
2184 return result == OVER_TEXT || result == OVER_NOTHING ? Qt : Qnil; | |
2185 } | |
2186 | |
2187 DEFUN ("event-over-modeline-p", Fevent_over_modeline_p, 1, 1, 0, /* | |
2188 Return t if the mouse event EVENT occurred over the modeline of a window. | |
2189 */ | |
2190 (event)) | |
2191 { | |
2192 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | |
2193 | |
2194 return result == OVER_MODELINE ? Qt : Qnil; | |
2195 } | |
2196 | |
2197 DEFUN ("event-over-border-p", Fevent_over_border_p, 1, 1, 0, /* | |
2198 Return t if the mouse event EVENT occurred over an internal border. | |
2199 */ | |
2200 (event)) | |
2201 { | |
2202 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | |
2203 | |
2204 return result == OVER_BORDER ? Qt : Qnil; | |
2205 } | |
2206 | |
2207 DEFUN ("event-over-toolbar-p", Fevent_over_toolbar_p, 1, 1, 0, /* | |
2208 Return t if the mouse event EVENT occurred over a toolbar. | |
2209 */ | |
2210 (event)) | |
2211 { | |
2212 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | |
2213 | |
2214 return result == OVER_TOOLBAR ? Qt : Qnil; | |
2215 } | |
2216 | |
2217 DEFUN ("event-over-vertical-divider-p", Fevent_over_vertical_divider_p, 1, 1, 0, /* | |
2218 Return t if the mouse event EVENT occurred over a window divider. | |
2219 */ | |
2220 (event)) | |
2221 { | |
2222 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); | |
2223 | |
2224 return result == OVER_V_DIVIDER ? Qt : Qnil; | |
2225 } | |
2226 | |
2227 struct console * | |
2228 event_console_or_selected (Lisp_Object event) | |
2229 { | |
2230 Lisp_Object channel = EVENT_CHANNEL (XEVENT (event)); | |
2231 Lisp_Object console = CDFW_CONSOLE (channel); | |
2232 | |
2233 if (NILP (console)) | |
2234 console = Vselected_console; | |
2235 | |
2236 return XCONSOLE (console); | |
2237 } | |
2238 | |
2239 DEFUN ("event-channel", Fevent_channel, 1, 1, 0, /* | |
2240 Return the channel that the event EVENT occurred on. | |
2241 This will be a frame, device, console, or nil for some types | |
2242 of events (e.g. eval events). | |
2243 */ | |
2244 (event)) | |
2245 { | |
2246 CHECK_LIVE_EVENT (event); | |
2247 return EVENT_CHANNEL (XEVENT (event)); | |
2248 } | |
2249 | |
2250 DEFUN ("event-window", Fevent_window, 1, 1, 0, /* | |
2251 Return the window over which mouse event EVENT occurred. | |
2252 This may be nil if the event occurred in the border or over a toolbar. | |
2253 The modeline is considered to be within the window it describes. | |
2254 */ | |
2255 (event)) | |
2256 { | |
2257 struct window *w; | |
2258 | |
2259 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, 0, 0); | |
2260 | |
2261 if (!w) | |
2262 return Qnil; | |
2263 else | |
2264 { | |
793 | 2265 return wrap_window (w); |
428 | 2266 } |
2267 } | |
2268 | |
2269 DEFUN ("event-point", Fevent_point, 1, 1, 0, /* | |
2270 Return the character position of the mouse event EVENT. | |
2271 If the event did not occur over a window, or did not occur over text, | |
2272 then this returns nil. Otherwise, it returns a position in the buffer | |
2273 visible in the event's window. | |
2274 */ | |
2275 (event)) | |
2276 { | |
665 | 2277 Charbpos bufp; |
428 | 2278 struct window *w; |
2279 | |
2280 event_pixel_translation (event, 0, 0, 0, 0, &w, &bufp, 0, 0, 0, 0); | |
2281 | |
2282 return w && bufp ? make_int (bufp) : Qnil; | |
2283 } | |
2284 | |
2285 DEFUN ("event-closest-point", Fevent_closest_point, 1, 1, 0, /* | |
2286 Return the character position closest to the mouse event EVENT. | |
2287 If the event did not occur over a window or over text, return the | |
2288 closest point to the location of the event. If the Y pixel position | |
2289 overlaps a window and the X pixel position is to the left of that | |
2290 window, the closest point is the beginning of the line containing the | |
2291 Y position. If the Y pixel position overlaps a window and the X pixel | |
2292 position is to the right of that window, the closest point is the end | |
2293 of the line containing the Y position. If the Y pixel position is | |
2294 above a window, return 0. If it is below the last character in a window, | |
2295 return the value of (window-end). | |
2296 */ | |
2297 (event)) | |
2298 { | |
665 | 2299 Charbpos bufp; |
428 | 2300 |
2301 event_pixel_translation (event, 0, 0, 0, 0, 0, 0, &bufp, 0, 0, 0); | |
2302 | |
2303 return bufp ? make_int (bufp) : Qnil; | |
2304 } | |
2305 | |
2306 DEFUN ("event-x", Fevent_x, 1, 1, 0, /* | |
2307 Return the X position of the mouse event EVENT in characters. | |
2308 This is relative to the window the event occurred over. | |
2309 */ | |
2310 (event)) | |
2311 { | |
2312 int char_x; | |
2313 | |
2314 event_pixel_translation (event, &char_x, 0, 0, 0, 0, 0, 0, 0, 0, 0); | |
2315 | |
2316 return make_int (char_x); | |
2317 } | |
2318 | |
2319 DEFUN ("event-y", Fevent_y, 1, 1, 0, /* | |
2320 Return the Y position of the mouse event EVENT in characters. | |
2321 This is relative to the window the event occurred over. | |
2322 */ | |
2323 (event)) | |
2324 { | |
2325 int char_y; | |
2326 | |
2327 event_pixel_translation (event, 0, &char_y, 0, 0, 0, 0, 0, 0, 0, 0); | |
2328 | |
2329 return make_int (char_y); | |
2330 } | |
2331 | |
2332 DEFUN ("event-modeline-position", Fevent_modeline_position, 1, 1, 0, /* | |
2333 Return the character position in the modeline that EVENT occurred over. | |
2334 EVENT should be a mouse event. If EVENT did not occur over a modeline, | |
2335 nil is returned. You can determine the actual character that the | |
2336 event occurred over by looking in `generated-modeline-string' at the | |
2337 returned character position. Note that `generated-modeline-string' | |
2338 is buffer-local, and you must use EVENT's buffer when retrieving | |
2339 `generated-modeline-string' in order to get accurate results. | |
2340 */ | |
2341 (event)) | |
2342 { | |
2343 Charcount mbufp; | |
2344 int where; | |
2345 | |
2346 where = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, &mbufp, 0, 0); | |
2347 | |
2348 return (mbufp < 0 || where != OVER_MODELINE) ? Qnil : make_int (mbufp); | |
2349 } | |
2350 | |
2351 DEFUN ("event-glyph", Fevent_glyph, 1, 1, 0, /* | |
2352 Return the glyph that the mouse event EVENT occurred over, or nil. | |
2353 */ | |
2354 (event)) | |
2355 { | |
2356 Lisp_Object glyph; | |
2357 struct window *w; | |
2358 | |
2359 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, &glyph, 0); | |
2360 | |
2361 return w && GLYPHP (glyph) ? glyph : Qnil; | |
2362 } | |
2363 | |
2364 DEFUN ("event-glyph-extent", Fevent_glyph_extent, 1, 1, 0, /* | |
2365 Return the extent of the glyph that the mouse event EVENT occurred over. | |
2366 If the event did not occur over a glyph, nil is returned. | |
2367 */ | |
2368 (event)) | |
2369 { | |
2370 Lisp_Object extent; | |
2371 struct window *w; | |
2372 | |
2373 event_pixel_translation (event, 0, 0, 0, 0, &w, 0, 0, 0, 0, &extent); | |
2374 | |
2375 return w && EXTENTP (extent) ? extent : Qnil; | |
2376 } | |
2377 | |
2378 DEFUN ("event-glyph-x-pixel", Fevent_glyph_x_pixel, 1, 1, 0, /* | |
2379 Return the X pixel position of EVENT relative to the glyph it occurred over. | |
2380 EVENT should be a mouse event. If the event did not occur over a glyph, | |
2381 nil is returned. | |
2382 */ | |
2383 (event)) | |
2384 { | |
2385 Lisp_Object extent; | |
2386 struct window *w; | |
2387 int obj_x; | |
2388 | |
2389 event_pixel_translation (event, 0, 0, &obj_x, 0, &w, 0, 0, 0, 0, &extent); | |
2390 | |
2391 return w && EXTENTP (extent) ? make_int (obj_x) : Qnil; | |
2392 } | |
2393 | |
2394 DEFUN ("event-glyph-y-pixel", Fevent_glyph_y_pixel, 1, 1, 0, /* | |
2395 Return the Y pixel position of EVENT relative to the glyph it occurred over. | |
2396 EVENT should be a mouse event. If the event did not occur over a glyph, | |
2397 nil is returned. | |
2398 */ | |
2399 (event)) | |
2400 { | |
2401 Lisp_Object extent; | |
2402 struct window *w; | |
2403 int obj_y; | |
2404 | |
2405 event_pixel_translation (event, 0, 0, 0, &obj_y, &w, 0, 0, 0, 0, &extent); | |
2406 | |
2407 return w && EXTENTP (extent) ? make_int (obj_y) : Qnil; | |
2408 } | |
2409 | |
2410 DEFUN ("event-toolbar-button", Fevent_toolbar_button, 1, 1, 0, /* | |
2411 Return the toolbar button that the mouse event EVENT occurred over. | |
2412 If the event did not occur over a toolbar button, nil is returned. | |
2413 */ | |
2340 | 2414 (USED_IF_TOOLBARS (event))) |
428 | 2415 { |
2416 #ifdef HAVE_TOOLBARS | |
2417 Lisp_Object button; | |
2418 | |
2419 int result = event_pixel_translation (event, 0, 0, 0, 0, 0, 0, 0, 0, &button, 0); | |
2420 | |
2421 return result == OVER_TOOLBAR && TOOLBAR_BUTTONP (button) ? button : Qnil; | |
2422 #else | |
2423 return Qnil; | |
2424 #endif | |
2425 } | |
2426 | |
2427 DEFUN ("event-process", Fevent_process, 1, 1, 0, /* | |
444 | 2428 Return the process of the process-output event EVENT. |
428 | 2429 */ |
2430 (event)) | |
2431 { | |
934 | 2432 CHECK_EVENT_TYPE (event, process_event, Qprocess_event_p); |
1204 | 2433 return XEVENT_PROCESS_PROCESS (event); |
428 | 2434 } |
2435 | |
2436 DEFUN ("event-function", Fevent_function, 1, 1, 0, /* | |
2437 Return the callback function of EVENT. | |
2438 EVENT should be a timeout, misc-user, or eval event. | |
2439 */ | |
2440 (event)) | |
2441 { | |
2442 again: | |
2443 CHECK_LIVE_EVENT (event); | |
934 | 2444 switch (XEVENT_TYPE (event)) |
2445 { | |
2446 case timeout_event: | |
1204 | 2447 return XEVENT_TIMEOUT_FUNCTION (event); |
934 | 2448 case misc_user_event: |
1204 | 2449 return XEVENT_MISC_USER_FUNCTION (event); |
934 | 2450 case eval_event: |
1204 | 2451 return XEVENT_EVAL_FUNCTION (event); |
934 | 2452 default: |
2453 event = wrong_type_argument (intern ("timeout-or-eval-event-p"), event); | |
2454 goto again; | |
2455 } | |
428 | 2456 } |
2457 | |
2458 DEFUN ("event-object", Fevent_object, 1, 1, 0, /* | |
2459 Return the callback function argument of EVENT. | |
2460 EVENT should be a timeout, misc-user, or eval event. | |
2461 */ | |
2462 (event)) | |
2463 { | |
2464 again: | |
2465 CHECK_LIVE_EVENT (event); | |
934 | 2466 switch (XEVENT_TYPE (event)) |
2467 { | |
2468 case timeout_event: | |
1204 | 2469 return XEVENT_TIMEOUT_OBJECT (event); |
934 | 2470 case misc_user_event: |
1204 | 2471 return XEVENT_MISC_USER_OBJECT (event); |
934 | 2472 case eval_event: |
1204 | 2473 return XEVENT_EVAL_OBJECT (event); |
934 | 2474 default: |
2475 event = wrong_type_argument (intern ("timeout-or-eval-event-p"), event); | |
2476 goto again; | |
2477 } | |
428 | 2478 } |
2479 | |
2480 DEFUN ("event-properties", Fevent_properties, 1, 1, 0, /* | |
2481 Return a list of all of the properties of EVENT. | |
2482 This is in the form of a property list (alternating keyword/value pairs). | |
2483 */ | |
2484 (event)) | |
2485 { | |
2486 Lisp_Object props = Qnil; | |
440 | 2487 Lisp_Event *e; |
428 | 2488 struct gcpro gcpro1; |
2489 | |
2490 CHECK_LIVE_EVENT (event); | |
2491 e = XEVENT (event); | |
2492 GCPRO1 (props); | |
2493 | |
2494 props = cons3 (Qtimestamp, Fevent_timestamp (event), props); | |
2495 | |
934 | 2496 switch (EVENT_TYPE (e)) |
428 | 2497 { |
2500 | 2498 default: ABORT (); |
428 | 2499 |
2500 case process_event: | |
1204 | 2501 props = cons3 (Qprocess, EVENT_PROCESS_PROCESS (e), props); |
428 | 2502 break; |
2503 | |
2504 case timeout_event: | |
2505 props = cons3 (Qobject, Fevent_object (event), props); | |
2506 props = cons3 (Qfunction, Fevent_function (event), props); | |
1204 | 2507 props = cons3 (Qid, make_int (EVENT_TIMEOUT_ID_NUMBER (e)), props); |
428 | 2508 break; |
2509 | |
2510 case key_press_event: | |
2511 props = cons3 (Qmodifiers, Fevent_modifiers (event), props); | |
2512 props = cons3 (Qkey, Fevent_key (event), props); | |
2513 break; | |
2514 | |
2515 case button_press_event: | |
2516 case button_release_event: | |
2517 props = cons3 (Qy, Fevent_y_pixel (event), props); | |
2518 props = cons3 (Qx, Fevent_x_pixel (event), props); | |
2519 props = cons3 (Qmodifiers, Fevent_modifiers (event), props); | |
2520 props = cons3 (Qbutton, Fevent_button (event), props); | |
2521 break; | |
2522 | |
2523 case pointer_motion_event: | |
2524 props = cons3 (Qmodifiers, Fevent_modifiers (event), props); | |
2525 props = cons3 (Qy, Fevent_y_pixel (event), props); | |
2526 props = cons3 (Qx, Fevent_x_pixel (event), props); | |
2527 break; | |
2528 | |
2529 case misc_user_event: | |
2530 props = cons3 (Qobject, Fevent_object (event), props); | |
2531 props = cons3 (Qfunction, Fevent_function (event), props); | |
2532 props = cons3 (Qy, Fevent_y_pixel (event), props); | |
2533 props = cons3 (Qx, Fevent_x_pixel (event), props); | |
2534 props = cons3 (Qmodifiers, Fevent_modifiers (event), props); | |
2535 props = cons3 (Qbutton, Fevent_button (event), props); | |
2536 break; | |
2537 | |
2538 case eval_event: | |
2539 props = cons3 (Qobject, Fevent_object (event), props); | |
2540 props = cons3 (Qfunction, Fevent_function (event), props); | |
2541 break; | |
2542 | |
2543 case magic_eval_event: | |
2544 case magic_event: | |
2545 break; | |
2546 | |
2547 case empty_event: | |
2548 RETURN_UNGCPRO (Qnil); | |
2549 break; | |
2550 } | |
2551 | |
2552 props = cons3 (Qchannel, Fevent_channel (event), props); | |
2553 UNGCPRO; | |
2554 | |
2555 return props; | |
2556 } | |
2557 | |
2558 | |
2559 /************************************************************************/ | |
2560 /* initialization */ | |
2561 /************************************************************************/ | |
2562 | |
2563 void | |
2564 syms_of_events (void) | |
2565 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2566 INIT_LISP_OBJECT (event); |
1204 | 2567 #ifdef EVENT_DATA_AS_OBJECTS |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2568 INIT_LISP_OBJECT (key_data); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2569 INIT_LISP_OBJECT (button_data); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2570 INIT_LISP_OBJECT (motion_data); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2571 INIT_LISP_OBJECT (process_data); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2572 INIT_LISP_OBJECT (timeout_data); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2573 INIT_LISP_OBJECT (eval_data); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2574 INIT_LISP_OBJECT (misc_user_data); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2575 INIT_LISP_OBJECT (magic_eval_data); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3063
diff
changeset
|
2576 INIT_LISP_OBJECT (magic_data); |
1204 | 2577 #endif /* EVENT_DATA_AS_OBJECTS */ |
442 | 2578 |
428 | 2579 DEFSUBR (Fcharacter_to_event); |
2580 DEFSUBR (Fevent_to_character); | |
2581 | |
2582 DEFSUBR (Fmake_event); | |
2583 DEFSUBR (Fdeallocate_event); | |
2584 DEFSUBR (Fcopy_event); | |
2585 DEFSUBR (Feventp); | |
2586 DEFSUBR (Fevent_live_p); | |
2587 DEFSUBR (Fevent_type); | |
2588 DEFSUBR (Fevent_properties); | |
2589 | |
2590 DEFSUBR (Fevent_timestamp); | |
442 | 2591 DEFSUBR (Fevent_timestamp_lessp); |
428 | 2592 DEFSUBR (Fevent_key); |
2593 DEFSUBR (Fevent_button); | |
2594 DEFSUBR (Fevent_modifier_bits); | |
2595 DEFSUBR (Fevent_modifiers); | |
2596 DEFSUBR (Fevent_x_pixel); | |
2597 DEFSUBR (Fevent_y_pixel); | |
2598 DEFSUBR (Fevent_window_x_pixel); | |
2599 DEFSUBR (Fevent_window_y_pixel); | |
2600 DEFSUBR (Fevent_over_text_area_p); | |
2601 DEFSUBR (Fevent_over_modeline_p); | |
2602 DEFSUBR (Fevent_over_border_p); | |
2603 DEFSUBR (Fevent_over_toolbar_p); | |
2604 DEFSUBR (Fevent_over_vertical_divider_p); | |
2605 DEFSUBR (Fevent_channel); | |
2606 DEFSUBR (Fevent_window); | |
2607 DEFSUBR (Fevent_point); | |
2608 DEFSUBR (Fevent_closest_point); | |
2609 DEFSUBR (Fevent_x); | |
2610 DEFSUBR (Fevent_y); | |
2611 DEFSUBR (Fevent_modeline_position); | |
2612 DEFSUBR (Fevent_glyph); | |
2613 DEFSUBR (Fevent_glyph_extent); | |
2614 DEFSUBR (Fevent_glyph_x_pixel); | |
2615 DEFSUBR (Fevent_glyph_y_pixel); | |
2616 DEFSUBR (Fevent_toolbar_button); | |
2617 DEFSUBR (Fevent_process); | |
2618 DEFSUBR (Fevent_function); | |
2619 DEFSUBR (Fevent_object); | |
2620 | |
563 | 2621 DEFSYMBOL (Qeventp); |
2622 DEFSYMBOL (Qevent_live_p); | |
2623 DEFSYMBOL (Qkey_press_event_p); | |
2624 DEFSYMBOL (Qbutton_event_p); | |
2625 DEFSYMBOL (Qmouse_event_p); | |
2626 DEFSYMBOL (Qprocess_event_p); | |
2627 DEFSYMBOL (Qkey_press); | |
2628 DEFSYMBOL (Qbutton_press); | |
2629 DEFSYMBOL (Qbutton_release); | |
2630 DEFSYMBOL (Qmisc_user); | |
2828 | 2631 DEFSYMBOL (Qcharacter_of_keysym); |
563 | 2632 DEFSYMBOL (Qascii_character); |
428 | 2633 |
2634 defsymbol (&QKbackspace, "backspace"); | |
2635 defsymbol (&QKtab, "tab"); | |
2636 defsymbol (&QKlinefeed, "linefeed"); | |
2637 defsymbol (&QKreturn, "return"); | |
2638 defsymbol (&QKescape, "escape"); | |
2639 defsymbol (&QKspace, "space"); | |
2640 defsymbol (&QKdelete, "delete"); | |
2641 } | |
2642 | |
2643 | |
2644 void | |
2645 reinit_vars_of_events (void) | |
2646 { | |
2647 Vevent_resource = Qnil; | |
3092 | 2648 #ifdef NEW_GC |
2649 staticpro (&Vevent_resource); | |
2650 #endif /* NEW_GC */ | |
428 | 2651 } |
2652 | |
2653 void | |
2654 vars_of_events (void) | |
2655 { | |
2656 } |