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