comparison src/events.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents e11d67e05968
children bbff43aa5eb7
comparison
equal deleted inserted replaced
379:76b7d63099ad 380:8626e4521993
108 struct Lisp_Event *event = XEVENT (obj); 108 struct Lisp_Event *event = XEVENT (obj);
109 109
110 switch (event->event_type) 110 switch (event->event_type)
111 { 111 {
112 case key_press_event: 112 case key_press_event:
113 ((markobj) (event->event.key.keysym)); 113 markobj (event->event.key.keysym);
114 break; 114 break;
115 case process_event: 115 case process_event:
116 ((markobj) (event->event.process.process)); 116 markobj (event->event.process.process);
117 break; 117 break;
118 case timeout_event: 118 case timeout_event:
119 ((markobj) (event->event.timeout.function)); 119 markobj (event->event.timeout.function);
120 ((markobj) (event->event.timeout.object)); 120 markobj (event->event.timeout.object);
121 break; 121 break;
122 case eval_event: 122 case eval_event:
123 case misc_user_event: 123 case misc_user_event:
124 ((markobj) (event->event.eval.function)); 124 markobj (event->event.eval.function);
125 ((markobj) (event->event.eval.object)); 125 markobj (event->event.eval.object);
126 break; 126 break;
127 case magic_eval_event: 127 case magic_eval_event:
128 ((markobj) (event->event.magic_eval.object)); 128 markobj (event->event.magic_eval.object);
129 break; 129 break;
130 case button_press_event: 130 case button_press_event:
131 case button_release_event: 131 case button_release_event:
132 case pointer_motion_event: 132 case pointer_motion_event:
133 case magic_event: 133 case magic_event:
135 case dead_event: 135 case dead_event:
136 break; 136 break;
137 default: 137 default:
138 abort (); 138 abort ();
139 } 139 }
140 ((markobj) (event->channel)); 140 markobj (event->channel);
141 return event->next; 141 return event->next;
142 } 142 }
143 143
144 static void 144 static void
145 print_event_1 (CONST char *str, Lisp_Object obj, Lisp_Object printcharfun) 145 print_event_1 (CONST char *str, Lisp_Object obj, Lisp_Object printcharfun)
152 152
153 static void 153 static void
154 print_event (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) 154 print_event (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
155 { 155 {
156 if (print_readably) 156 if (print_readably)
157 error ("printing unreadable object #<event>"); 157 error ("Printing unreadable object #<event>");
158 158
159 switch (XEVENT (obj)->event_type) 159 switch (XEVENT (obj)->event_type)
160 { 160 {
161 case key_press_event: 161 case key_press_event:
162 print_event_1 ("#<keypress-event ", obj, printcharfun); 162 print_event_1 ("#<keypress-event ", obj, printcharfun);
217 } 217 }
218 write_c_string (">", printcharfun); 218 write_c_string (">", printcharfun);
219 } 219 }
220 220
221 static int 221 static int
222 event_equal (Lisp_Object o1, Lisp_Object o2, int depth) 222 event_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
223 { 223 {
224 struct Lisp_Event *e1 = XEVENT (o1); 224 struct Lisp_Event *e1 = XEVENT (obj1);
225 struct Lisp_Event *e2 = XEVENT (o2); 225 struct Lisp_Event *e2 = XEVENT (obj2);
226 226
227 if (e1->event_type != e2->event_type) return 0; 227 if (e1->event_type != e2->event_type) return 0;
228 if (!EQ (e1->channel, e2->channel)) return 0; 228 if (!EQ (e1->channel, e2->channel)) return 0;
229 /* if (e1->timestamp != e2->timestamp) return 0; */ 229 /* if (e1->timestamp != e2->timestamp) return 0; */
230 switch (e1->event_type) 230 switch (e1->event_type)
231 { 231 {
232 default: abort ();
233
232 case process_event: 234 case process_event:
233 return EQ (e1->event.process.process, e2->event.process.process); 235 return EQ (e1->event.process.process, e2->event.process.process);
234 236
235 case timeout_event: 237 case timeout_event:
236 return (internal_equal (e1->event.timeout.function, 238 return (internal_equal (e1->event.timeout.function,
282 return (e1->event.magic.underlying_x_event.xany.serial == 284 return (e1->event.magic.underlying_x_event.xany.serial ==
283 e2->event.magic.underlying_x_event.xany.serial); 285 e2->event.magic.underlying_x_event.xany.serial);
284 #endif 286 #endif
285 #ifdef HAVE_TTY 287 #ifdef HAVE_TTY
286 if (CONSOLE_TTY_P (con)) 288 if (CONSOLE_TTY_P (con))
287 return (e1->event.magic.underlying_tty_event == 289 return (e1->event.magic.underlying_tty_event ==
288 e2->event.magic.underlying_tty_event); 290 e2->event.magic.underlying_tty_event);
289 #endif 291 #endif
290 #ifdef HAVE_MS_WINDOWS 292 #ifdef HAVE_MS_WINDOWS
291 if (CONSOLE_MSWINDOWS_P (con)) 293 if (CONSOLE_MSWINDOWS_P (con))
292 return (!memcmp(&e1->event.magic.underlying_mswindows_event, 294 return (!memcmp(&e1->event.magic.underlying_mswindows_event,
293 &e2->event.magic.underlying_mswindows_event, 295 &e2->event.magic.underlying_mswindows_event,
294 sizeof(union magic_data))); 296 sizeof(union magic_data)));
295 #endif 297 #endif
296 return 1; /* not reached */ 298 return 1; /* not reached */
297 } 299 }
298 300
299 case empty_event: /* Empty and deallocated events are equal. */ 301 case empty_event: /* Empty and deallocated events are equal. */
300 case dead_event: 302 case dead_event:
301 return 1; 303 return 1;
302
303 default:
304 abort ();
305 return 0; /* not reached; warning suppression */
306 } 304 }
307 } 305 }
308 306
309 static unsigned long 307 static unsigned long
310 event_hash (Lisp_Object obj, int depth) 308 event_hash (Lisp_Object obj, int depth)
510 } 508 }
511 EVENT_CHANNEL (e) = value; 509 EVENT_CHANNEL (e) = value;
512 } 510 }
513 else if (EQ (keyword, Qkey)) 511 else if (EQ (keyword, Qkey))
514 { 512 {
515 if (e->event_type != key_press_event) 513 switch (e->event_type)
516 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); 514 {
517 if (!SYMBOLP (value) && !CHARP (value)) 515 case key_press_event:
518 signal_simple_error ("Invalid event key", value); 516 if (!SYMBOLP (value) && !CHARP (value))
519 e->event.key.keysym = value; 517 signal_simple_error ("Invalid event key", value);
518 e->event.key.keysym = value;
519 break;
520 default:
521 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
522 break;
523 }
520 } 524 }
521 else if (EQ (keyword, Qbutton)) 525 else if (EQ (keyword, Qbutton))
522 { 526 {
523 if (e->event_type != button_press_event
524 && e->event_type != button_release_event
525 && e->event_type != misc_user_event)
526 {
527 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
528 }
529 CHECK_NATNUM (value); 527 CHECK_NATNUM (value);
530 check_int_range (XINT (value), 0, 7); 528 check_int_range (XINT (value), 0, 7);
531 if (e->event_type == misc_user_event) 529
532 e->event.misc.button = XINT (value); 530 switch (e->event_type)
533 else 531 {
534 e->event.button.button = XINT (value); 532 case button_press_event:
533 case button_release_event:
534 e->event.button.button = XINT (value);
535 break;
536 case misc_user_event:
537 e->event.misc.button = XINT (value);
538 break;
539 default:
540 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
541 break;
542 }
535 } 543 }
536 else if (EQ (keyword, Qmodifiers)) 544 else if (EQ (keyword, Qmodifiers))
537 { 545 {
538 Lisp_Object modtail;
539 int modifiers = 0; 546 int modifiers = 0;
540 547 Lisp_Object sym;
541 if (e->event_type != key_press_event 548
542 && e->event_type != button_press_event 549 EXTERNAL_LIST_LOOP_2 (sym, value)
543 && e->event_type != button_release_event
544 && e->event_type != pointer_motion_event
545 && e->event_type != misc_user_event)
546 { 550 {
547 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); 551 if (EQ (sym, Qcontrol)) modifiers |= MOD_CONTROL;
548 }
549
550 EXTERNAL_LIST_LOOP (modtail, value)
551 {
552 Lisp_Object sym = XCAR (modtail);
553 if (EQ (sym, Qcontrol)) modifiers |= MOD_CONTROL;
554 else if (EQ (sym, Qmeta)) modifiers |= MOD_META; 552 else if (EQ (sym, Qmeta)) modifiers |= MOD_META;
555 else if (EQ (sym, Qsuper)) modifiers |= MOD_SUPER; 553 else if (EQ (sym, Qsuper)) modifiers |= MOD_SUPER;
556 else if (EQ (sym, Qhyper)) modifiers |= MOD_HYPER; 554 else if (EQ (sym, Qhyper)) modifiers |= MOD_HYPER;
557 else if (EQ (sym, Qalt)) modifiers |= MOD_ALT; 555 else if (EQ (sym, Qalt)) modifiers |= MOD_ALT;
558 else if (EQ (sym, Qsymbol)) modifiers |= MOD_ALT; 556 else if (EQ (sym, Qsymbol)) modifiers |= MOD_ALT;
559 else if (EQ (sym, Qshift)) modifiers |= MOD_SHIFT; 557 else if (EQ (sym, Qshift)) modifiers |= MOD_SHIFT;
560 else 558 else
561 signal_simple_error ("Invalid key modifier", sym); 559 signal_simple_error ("Invalid key modifier", sym);
562 } 560 }
563 if (e->event_type == key_press_event) 561
564 e->event.key.modifiers = modifiers; 562 switch (e->event_type)
565 else if (e->event_type == button_press_event 563 {
566 || e->event_type == button_release_event) 564 case key_press_event:
567 e->event.button.modifiers = modifiers; 565 e->event.key.modifiers = modifiers;
568 else if (e->event_type == pointer_motion_event) 566 break;
569 e->event.motion.modifiers = modifiers; 567 case button_press_event:
570 else /* misc_user_event */ 568 case button_release_event:
571 e->event.misc.modifiers = modifiers; 569 e->event.button.modifiers = modifiers;
570 break;
571 case pointer_motion_event:
572 e->event.motion.modifiers = modifiers;
573 break;
574 case misc_user_event:
575 e->event.misc.modifiers = modifiers;
576 break;
577 default:
578 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
579 break;
580 }
572 } 581 }
573 else if (EQ (keyword, Qx)) 582 else if (EQ (keyword, Qx))
574 { 583 {
575 if (e->event_type != pointer_motion_event 584 switch (e->event_type)
576 && e->event_type != button_press_event
577 && e->event_type != button_release_event
578 && e->event_type != misc_user_event)
579 { 585 {
586 case pointer_motion_event:
587 case button_press_event:
588 case button_release_event:
589 case misc_user_event:
590 /* Allow negative values, so we can specify toolbar
591 positions. */
592 CHECK_INT (value);
593 coord_x = XINT (value);
594 break;
595 default:
580 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); 596 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
597 break;
581 } 598 }
582 /* Allow negative values, so we can specify toolbar
583 positions. */
584 CHECK_INT (value);
585 coord_x = XINT (value);
586 } 599 }
587 else if (EQ (keyword, Qy)) 600 else if (EQ (keyword, Qy))
588 { 601 {
589 if (e->event_type != pointer_motion_event 602 switch (e->event_type)
590 && e->event_type != button_press_event
591 && e->event_type != button_release_event
592 && e->event_type != misc_user_event)
593 { 603 {
604 case pointer_motion_event:
605 case button_press_event:
606 case button_release_event:
607 case misc_user_event:
608 /* Allow negative values; see above. */
609 CHECK_INT (value);
610 coord_y = XINT (value);
611 break;
612 default:
594 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); 613 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
614 break;
595 } 615 }
596 /* Allow negative values; see above. */
597 CHECK_INT (value);
598 coord_y = XINT (value);
599 } 616 }
600 else if (EQ (keyword, Qtimestamp)) 617 else if (EQ (keyword, Qtimestamp))
601 { 618 {
602 CHECK_NATNUM (value); 619 CHECK_NATNUM (value);
603 e->timestamp = XINT (value); 620 e->timestamp = XINT (value);
604 } 621 }
605 else if (EQ (keyword, Qfunction)) 622 else if (EQ (keyword, Qfunction))
606 { 623 {
607 if (e->event_type != misc_user_event) 624 switch (e->event_type)
608 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); 625 {
609 e->event.eval.function = value; 626 case misc_user_event:
627 e->event.eval.function = value;
628 break;
629 default:
630 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
631 break;
632 }
610 } 633 }
611 else if (EQ (keyword, Qobject)) 634 else if (EQ (keyword, Qobject))
612 { 635 {
613 if (e->event_type != misc_user_event) 636 switch (e->event_type)
614 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword); 637 {
615 e->event.eval.object = value; 638 case misc_user_event:
639 e->event.eval.object = value;
640 break;
641 default:
642 WRONG_EVENT_TYPE_FOR_PROPERTY (type, keyword);
643 break;
644 }
616 } 645 }
617 else 646 else
618 signal_simple_error_2 ("Invalid property", keyword, value); 647 signal_simple_error_2 ("Invalid property", keyword, value);
619 } 648 }
620 649
627 EVENT_CHANNEL (e) = Fselected_frame (Qnil); 656 EVENT_CHANNEL (e) = Fselected_frame (Qnil);
628 } 657 }
629 658
630 /* Fevent_properties, Fevent_x_pixel, etc. work with pixels relative 659 /* Fevent_properties, Fevent_x_pixel, etc. work with pixels relative
631 to the frame, so we must adjust accordingly. */ 660 to the frame, so we must adjust accordingly. */
632 if (e->event_type == pointer_motion_event 661 if (FRAMEP (EVENT_CHANNEL (e)))
633 || e->event_type == button_press_event 662 {
634 || e->event_type == button_release_event 663 coord_x += FRAME_REAL_LEFT_TOOLBAR_WIDTH (XFRAME (EVENT_CHANNEL (e)));
635 || e->event_type == misc_user_event) 664 coord_y += FRAME_REAL_TOP_TOOLBAR_HEIGHT (XFRAME (EVENT_CHANNEL (e)));
636 { 665
637 struct frame *f = XFRAME (EVENT_CHANNEL (e)); 666 switch (e->event_type)
638
639 coord_x += FRAME_REAL_LEFT_TOOLBAR_WIDTH (f);
640 coord_y += FRAME_REAL_TOP_TOOLBAR_HEIGHT (f);
641
642 if (e->event_type == pointer_motion_event)
643 { 667 {
668 case pointer_motion_event:
644 e->event.motion.x = coord_x; 669 e->event.motion.x = coord_x;
645 e->event.motion.y = coord_y; 670 e->event.motion.y = coord_y;
646 } 671 break;
647 else if (e->event_type == button_press_event 672 case button_press_event:
648 || e->event_type == button_release_event) 673 case button_release_event:
649 {
650 e->event.button.x = coord_x; 674 e->event.button.x = coord_x;
651 e->event.button.y = coord_y; 675 e->event.button.y = coord_y;
652 } 676 break;
653 else if (e->event_type == misc_user_event) 677 case misc_user_event:
654 {
655 e->event.misc.x = coord_x; 678 e->event.misc.x = coord_x;
656 e->event.misc.y = coord_y; 679 e->event.misc.y = coord_y;
680 break;
681 default:
682 abort();
657 } 683 }
658 } 684 }
659 685
660 /* Finally, do some more validation. */ 686 /* Finally, do some more validation. */
661 switch (e->event_type) 687 switch (e->event_type)
662 { 688 {
663 case key_press_event: 689 case key_press_event:
664 if (UNBOUNDP (e->event.key.keysym) 690 if (UNBOUNDP (e->event.key.keysym))
665 || !(SYMBOLP (e->event.key.keysym) || CHARP (e->event.key.keysym))) 691 error ("A key must be specified to make a keypress event");
666 error ("Undefined key for keypress event");
667 break; 692 break;
668 case button_press_event: 693 case button_press_event:
694 if (!e->event.button.button)
695 error ("A button must be specified to make a button-press event");
696 break;
669 case button_release_event: 697 case button_release_event:
670 if (!e->event.button.button) 698 if (!e->event.button.button)
671 error ("Undefined button for %s event", 699 error ("A button must be specified to make a button-release event");
672 e->event_type == button_press_event
673 ? "buton-press" : "button-release");
674 break; 700 break;
675 case misc_user_event: 701 case misc_user_event:
676 if (NILP (e->event.misc.function)) 702 if (NILP (e->event.misc.function))
677 error ("Undefined function for misc-user event"); 703 error ("A function must be specified to make a misc-user event");
678 break; 704 break;
679 default: 705 default:
680 break; 706 break;
681 } 707 }
682 708
987 #endif /* defined(HAVE_TTY) && !defined(__CYGWIN32__) */ 1013 #endif /* defined(HAVE_TTY) && !defined(__CYGWIN32__) */
988 break; 1014 break;
989 } 1015 }
990 if (c >= 'A' && c <= 'Z') c -= 'A'-'a'; 1016 if (c >= 'A' && c <= 'Z') c -= 'A'-'a';
991 } 1017 }
992 #if defined(HAVE_TTY) 1018 #if defined(HAVE_TTY)
993 else if (do_backspace_mapping && 1019 else if (do_backspace_mapping &&
994 CHARP (con->tty_erase_char) && c == XCHAR (con->tty_erase_char)) 1020 CHARP (con->tty_erase_char) && c == XCHAR (con->tty_erase_char))
995 k = QKbackspace; 1021 k = QKbackspace;
996 #endif /* defined(HAVE_TTY) && !defined(__CYGWIN32__) */ 1022 #endif /* defined(HAVE_TTY) && !defined(__CYGWIN32__) */
997 else if (c == 127) 1023 else if (c == 127)
1251 case empty_event: strcpy (buf, "empty"); return; 1277 case empty_event: strcpy (buf, "empty"); return;
1252 case dead_event: strcpy (buf, "DEAD-EVENT"); return; 1278 case dead_event: strcpy (buf, "DEAD-EVENT"); return;
1253 default: 1279 default:
1254 abort (); 1280 abort ();
1255 } 1281 }
1256 #define modprint1(x) { strcpy (buf, (x)); buf += sizeof (x)-1; } 1282 #define modprint1(x) do { strcpy (buf, (x)); buf += sizeof (x)-1; } while (0)
1257 #define modprint(x,y) { if (brief) modprint1 (y) else modprint1 (x) } 1283 #define modprint(x,y) do { if (brief) modprint1 (y); else modprint1 (x); } while (0)
1258 if (mod & MOD_CONTROL) modprint ("control-", "C-"); 1284 if (mod & MOD_CONTROL) modprint ("control-", "C-");
1259 if (mod & MOD_META) modprint ("meta-", "M-"); 1285 if (mod & MOD_META) modprint ("meta-", "M-");
1260 if (mod & MOD_SUPER) modprint ("super-", "S-"); 1286 if (mod & MOD_SUPER) modprint ("super-", "S-");
1261 if (mod & MOD_HYPER) modprint ("hyper-", "H-"); 1287 if (mod & MOD_HYPER) modprint ("hyper-", "H-");
1262 if (mod & MOD_ALT) modprint ("alt-", "A-"); 1288 if (mod & MOD_ALT) modprint ("alt-", "A-");
2075 2101
2076 props = cons3 (Qtimestamp, Fevent_timestamp (event), props); 2102 props = cons3 (Qtimestamp, Fevent_timestamp (event), props);
2077 2103
2078 switch (e->event_type) 2104 switch (e->event_type)
2079 { 2105 {
2106 default: abort ();
2107
2080 case process_event: 2108 case process_event:
2081 props = cons3 (Qprocess, e->event.process.process, props); 2109 props = cons3 (Qprocess, e->event.process.process, props);
2082 break; 2110 break;
2083 2111
2084 case timeout_event: 2112 case timeout_event:
2125 break; 2153 break;
2126 2154
2127 case empty_event: 2155 case empty_event:
2128 RETURN_UNGCPRO (Qnil); 2156 RETURN_UNGCPRO (Qnil);
2129 break; 2157 break;
2130
2131 default:
2132 abort ();
2133 break; /* not reached; warning suppression */
2134 } 2158 }
2135 2159
2136 props = cons3 (Qchannel, Fevent_channel (event), props); 2160 props = cons3 (Qchannel, Fevent_channel (event), props);
2137 UNGCPRO; 2161 UNGCPRO;
2138 2162