comparison src/events.c @ 189:489f57a838ef r20-3b21

Import from CVS: tag r20-3b21
author cvs
date Mon, 13 Aug 2007 09:57:07 +0200
parents 3d6bfa290dbd
children a2f645c6b9f8
comparison
equal deleted inserted replaced
188:e29a8e7498d9 189:489f57a838ef
351 351
352 return 0; /* unreached */ 352 return 0; /* unreached */
353 } 353 }
354 354
355 355
356 /* #### This should accept a type and props (as returned by 356 DEFUN ("make-event", Fmake_event, 0, 2, 0, /*
357 event-properties) to allow creation of any type of event. 357 Create a new event of type TYPE, with properties stored in PLIST.
358 This is useful, for example, in Lisp code that might want 358 TYPE is a symbol, either `empty', `key-press', `button-press',
359 to determine if, for a given button-down event, what the 359 `button-release', or `motion'. If TYPE is left out, it defaults to
360 binding for the corresponding button-up event is. */ 360 `empty'.
361 361 PLIST is a list of properties, as returned by `event-properties'. Not
362 DEFUN ("make-event", Fmake_event, 0, 0, 0, /* 362 all properties are allowed for all kinds of events, and some are
363 Create a new empty event. 363 required.
364
364 WARNING, the event object returned may be a reused one; see the function 365 WARNING, the event object returned may be a reused one; see the function
365 `deallocate-event'. 366 `deallocate-event'.
366 */ 367 */
367 ()) 368 (type, plist))
368 { 369 {
369 Lisp_Object event; 370 Lisp_Object event, prop, val;
371 struct Lisp_Event *e;
372
373 if (NILP (type))
374 type = Qempty;
370 375
371 if (!NILP (Vevent_resource)) 376 if (!NILP (Vevent_resource))
372 { 377 {
373 event = Vevent_resource; 378 event = Vevent_resource;
374 Vevent_resource = XEVENT_NEXT (event); 379 Vevent_resource = XEVENT_NEXT (event);
375 } 380 }
376 else 381 else
377 { 382 {
378 event = allocate_event (); 383 event = allocate_event ();
379 } 384 }
380 zero_event (XEVENT (event)); 385 e = XEVENT (event);
386 zero_event (e);
387
388 if (EQ (type, Qkey_press))
389 e->event_type = key_press_event;
390 else if (EQ (type, Qbutton_press))
391 e->event_type = button_press_event;
392 else if (EQ (type, Qbutton_release))
393 e->event_type = button_release_event;
394 else if (EQ (type, Qmotion))
395 e->event_type = pointer_motion_event;
396 else if (EQ (type, Qempty))
397 e->event_type = empty_event;
398 else
399 /* not allowed: Qmisc_user, Qprocess, Qtimeout, Qmagic, Qmagic_eval */
400 signal_simple_error ("Invalid event type", type);
401
402 /* Process the plist. */
403 while (!NILP (plist))
404 {
405 prop = Fcar (plist);
406 plist = Fcdr (plist);
407 val = Fcar (plist);
408 plist = Fcdr (plist);
409 if (EQ (prop, Qchannel))
410 {
411 if (!DEVICEP (val) && !CONSOLEP (val) && !FRAMEP (val)
412 && !NILP (val))
413 signal_simple_error ("Invalid event channel", val);
414 EVENT_CHANNEL (e) = val;
415 }
416 else if (EQ (prop, Qkey))
417 {
418 if (e->event_type != key_press_event)
419 wrong_type_argument (Qkey_press_event_p, event);
420 if (!SYMBOLP (val) && !CHARP (val))
421 signal_simple_error ("Invalid event key", val);
422 e->event.key.keysym = val;
423 }
424 else if (EQ (prop, Qbutton))
425 {
426 CHECK_NATNUM (val);
427 check_int_range (XINT(val), 1, 3);
428 if (e->event_type != button_press_event
429 && e->event_type != button_release_event)
430 signal_simple_error ("Invalid event type for `button' property",
431 type);
432 e->event.button.button = XINT (val);
433 }
434 else if (EQ (prop, Qmodifiers))
435 {
436 Lisp_Object tail, sym;
437 int modifiers = 0;
438
439 if (e->event_type != key_press_event
440 && e->event_type != button_press_event
441 && e->event_type != button_release_event
442 && e->event_type != pointer_motion_event)
443 signal_simple_error ("Invalid event type for modifiers", type);
444
445 for (tail = val; !NILP (tail); tail = Fcdr (tail))
446 {
447 sym = Fcar (tail);
448 if (EQ (sym, Qcontrol)) modifiers |= MOD_CONTROL;
449 else if (EQ (sym, Qmeta)) modifiers |= MOD_META;
450 else if (EQ (sym, Qsuper)) modifiers |= MOD_SUPER;
451 else if (EQ (sym, Qhyper)) modifiers |= MOD_HYPER;
452 else if (EQ (sym, Qalt)) modifiers |= MOD_ALT;
453 else if (EQ (sym, Qsymbol)) modifiers |= MOD_ALT;
454 else if (EQ (sym, Qshift)) modifiers |= MOD_SHIFT;
455 else
456 signal_simple_error ("Invalid key modifier", Fcar (tail));
457 }
458 if (e->event_type == key_press_event)
459 e->event.key.modifiers = modifiers;
460 else if (e->event_type == button_press_event
461 || e->event_type == button_release_event)
462 e->event.button.modifiers = modifiers;
463 else /* pointer_motion_event */
464 e->event.motion.modifiers = modifiers;
465 }
466 else if (EQ (prop, Qx))
467 {
468 CHECK_NATNUM (val);
469 if (e->event_type == pointer_motion_event)
470 e->event.motion.x = XINT (val);
471 else if (e->event_type == button_press_event
472 || e->event_type == button_release_event)
473 e->event.button.x = XINT (val);
474 }
475 else if (EQ (prop, Qy))
476 {
477 CHECK_NATNUM (val);
478 if (e->event_type == pointer_motion_event)
479 e->event.motion.y = XINT (val);
480 else if (e->event_type == button_press_event
481 || e->event_type == button_release_event)
482 e->event.button.y = XINT (val);
483 }
484 else if (EQ (prop, Qtimestamp))
485 {
486 CHECK_NATNUM (val);
487 e->timestamp = XINT (val);
488 }
489 else
490 signal_simple_error ("Invalid property", prop);
491 } /* while */
492
493 /* Now, let's validate what we got. */
494 switch (e->event_type)
495 {
496 case key_press_event:
497 if (!(SYMBOLP (e->event.key.keysym) || CHARP (e->event.key.keysym)))
498 error ("Undefined key for keypress event");
499 break;
500 case button_press_event:
501 case button_release_event:
502 if (!e->event.button.button)
503 error ("Undefined button for button-press or button-release event");
504 if (NILP (EVENT_CHANNEL (e)))
505 error ("Undefined channel for button-press or button-release event");
506 break;
507 default:
508 break;
509 }
381 return event; 510 return event;
382 } 511 }
383 512
384 DEFUN ("deallocate-event", Fdeallocate_event, 1, 1, 0, /* 513 DEFUN ("deallocate-event", Fdeallocate_event, 1, 1, 0, /*
385 Allow the given event structure to be reused. 514 Allow the given event structure to be reused.
442 */ 571 */
443 (event1, event2)) 572 (event1, event2))
444 { 573 {
445 CHECK_LIVE_EVENT (event1); 574 CHECK_LIVE_EVENT (event1);
446 if (NILP (event2)) 575 if (NILP (event2))
447 event2 = Fmake_event (); 576 event2 = Fmake_event (Qnil, Qnil);
448 else CHECK_LIVE_EVENT (event2); 577 else CHECK_LIVE_EVENT (event2);
449 if (EQ (event1, event2)) 578 if (EQ (event1, event2))
450 return signal_simple_continuable_error_2 579 return signal_simple_continuable_error_2
451 ("copy-event called with `eq' events", event1, event2); 580 ("copy-event called with `eq' events", event1, event2);
452 581
826 */ 955 */
827 (ch, event, console, use_console_meta_flag)) 956 (ch, event, console, use_console_meta_flag))
828 { 957 {
829 struct console *con = decode_console (console); 958 struct console *con = decode_console (console);
830 if (NILP (event)) 959 if (NILP (event))
831 event = Fmake_event (); 960 event = Fmake_event (Qnil, Qnil);
832 else 961 else
833 CHECK_LIVE_EVENT (event); 962 CHECK_LIVE_EVENT (event);
834 if (CONSP (ch) || SYMBOLP (ch)) 963 if (CONSP (ch) || SYMBOLP (ch))
835 key_desc_list_to_event (ch, event, 1); 964 key_desc_list_to_event (ch, event, 1);
836 else 965 else
870 int i; 999 int i;
871 Lisp_Object head = Qnil, tail = Qnil; 1000 Lisp_Object head = Qnil, tail = Qnil;
872 1001
873 for (i = 0; i < len; i++) 1002 for (i = 0; i < len; i++)
874 { 1003 {
875 Lisp_Object event = Fmake_event (); 1004 Lisp_Object event = Fmake_event (Qnil, Qnil);
876 nth_of_key_sequence_as_event (seq, i, event); 1005 nth_of_key_sequence_as_event (seq, i, event);
877 enqueue_event (event, &head, &tail); 1006 enqueue_event (event, &head, &tail);
878 } 1007 }
879 1008
880 return head; 1009 return head;