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