comparison src/event-Xt.c @ 179:9ad43877534d r20-3b16

Import from CVS: tag r20-3b16
author cvs
date Mon, 13 Aug 2007 09:52:19 +0200
parents 2d532a89d707
children e121b013d1f0
comparison
equal deleted inserted replaced
178:e703507b8a00 179:9ad43877534d
610 /************************************************************************/ 610 /************************************************************************/
611 /* X to Emacs event conversion */ 611 /* X to Emacs event conversion */
612 /************************************************************************/ 612 /************************************************************************/
613 613
614 static Lisp_Object 614 static Lisp_Object
615 x_to_emacs_keysym (XKeyPressedEvent *event, int simple_p) 615 x_keysym_to_emacs_keysym (KeySym keysym, int simple_p)
616 /* simple_p means don't try too hard (ASCII only) */
617 { 616 {
618 char *name; 617 char *name;
619 KeySym keysym = 0;
620 /* Apparently it's necessary to specify a dummy here (rather than
621 passing in 0) to avoid crashes on German IRIX */
622 char dummy[256];
623
624 #ifdef HAVE_XIM
625 int len;
626 char buffer[64];
627 char *bufptr = buffer;
628 int bufsiz = sizeof (buffer);
629 Status status;
630 #endif
631
632 #ifdef HAVE_XIM
633 #ifdef XIM_MOTIF
634 #define LOOKUPSTRING \
635 len = XmImMbLookupString (XtWindowToWidget (event->display, event->window), \
636 event, bufptr, bufsiz, &keysym, &status);
637 #else /* XIM_XLIB */
638 #define LOOKUPSTRING \
639 len = XmbLookupString \
640 (FRAME_X_XIC (x_any_window_to_frame \
641 (get_device_from_display (event->display), event->window)), \
642 event, bufptr, bufsiz, &keysym, &status);
643 #endif /* XIM_XLIB */
644 LOOKUPSTRING;
645 check_status: /* Come-From XBufferOverflow */
646
647 #ifdef DEBUG_XEMACS
648 if (x_debug_events > 0)
649 {
650 stderr_out (" status=");
651 #define print_status_when(S) if (status == S) stderr_out (#S)
652 print_status_when (XLookupKeySym);
653 print_status_when (XLookupBoth);
654 print_status_when (XLookupChars);
655 print_status_when (XLookupNone);
656 print_status_when (XBufferOverflow);
657
658 if (status == XLookupKeySym || status == XLookupBoth)
659 stderr_out (" keysym=%s", XKeysymToString (keysym));
660 if (status == XLookupChars || status == XLookupBoth)
661 {
662 if (len != 1)
663 {
664 int j;
665 stderr_out (" chars=\"");
666 for (j=0; j<len; j++)
667 stderr_out ("%c", bufptr[j]);
668 stderr_out ("\"");
669 }
670 else if (bufptr[0] <= 32 || bufptr[0] >= 127)
671 stderr_out (" char=0x%x", bufptr[0]);
672 else
673 stderr_out (" char=%c", bufptr[0]);
674 }
675 stderr_out ("\n");
676 }
677 #endif /* DEBUG_XEMACS */
678
679 switch (status)
680 {
681 case XLookupKeySym:
682 case XLookupBoth: break;
683
684 case XLookupChars:
685 {
686 /* Generate multiple emacs events */
687 struct device *d = get_device_from_display (event->display);
688 Emchar ch;
689 Lisp_Object instream =
690 make_fixed_buffer_input_stream ((unsigned char *) bufptr, len);
691
692 /* ### Use Fget_coding_system (Vcomposed_input_coding_system) */
693 instream =
694 make_decoding_input_stream
695 (XLSTREAM (instream), Fget_coding_system (Qautomatic_conversion));
696
697 while ((ch = Lstream_get_emchar (XLSTREAM (instream))) != EOF)
698 {
699 Lisp_Object emacs_event = Fmake_event ();
700 XEVENT (emacs_event)->channel = DEVICE_CONSOLE (d);
701 XEVENT (emacs_event)->event_type = key_press_event;
702 XEVENT (emacs_event)->timestamp = event->time;
703 XEVENT (emacs_event)->event.key.modifiers = 0;
704 XEVENT (emacs_event)->event.key.keysym = make_char (ch);
705 enqueue_Xt_dispatch_event (emacs_event);
706 }
707 Lstream_close (XLSTREAM (instream));
708 return Qnil;
709 }
710 case XLookupNone: return Qnil;
711 case XBufferOverflow:
712 bufptr = alloca (len+1);
713 bufsiz = len+1;
714 LOOKUPSTRING;
715 goto check_status;
716 }
717 #else /* ! HAVE_XIM */
718 XLookupString (event, dummy, 200, &keysym, 0);
719 #endif /* HAVE_XIM */
720
721 if (keysym >= XK_exclam && keysym <= XK_asciitilde) 618 if (keysym >= XK_exclam && keysym <= XK_asciitilde)
722 /* We must assume that the X keysym numbers for the ASCII graphic 619 /* We must assume that the X keysym numbers for the ASCII graphic
723 characters are the same as their ASCII codes. */ 620 characters are the same as their ASCII codes. */
724 return make_char (keysym); 621 return make_char (keysym);
725 622
769 *s2 = 0; 666 *s2 = 0;
770 return KEYSYM (buf); 667 return KEYSYM (buf);
771 } 668 }
772 return KEYSYM (name); 669 return KEYSYM (name);
773 } 670 }
671 }
672
673 static Lisp_Object
674 x_to_emacs_keysym (XKeyPressedEvent *event, int simple_p)
675 /* simple_p means don't try too hard (ASCII only) */
676 {
677 KeySym keysym = 0;
678
679 #ifdef HAVE_XIM
680 int len;
681 char buffer[64];
682 char *bufptr = buffer;
683 int bufsiz = sizeof (buffer);
684 Status status;
685 #ifdef XIM_XLIB
686 XIC xic = FRAME_X_XIC (x_any_window_to_frame
687 (get_device_from_display (event->display),
688 event->window));
689 #endif /* XIM_XLIB */
690 #endif /* HAVE_XIM */
691
692 if (
693 #ifndef HAVE_XIM
694 1
695 #elif defined (XIM_MOTIF)
696 0
697 #else /* XIM_XLIB */
698 !xic
699 #endif
700 )
701 {
702 /* Apparently it's necessary to specify a dummy here (rather
703 than passing in 0) to avoid crashes on German IRIX */
704 char dummy[256];
705 XLookupString (event, dummy, 200, &keysym, 0);
706 return x_keysym_to_emacs_keysym (keysym, simple_p);
707 }
708
709 #ifdef HAVE_XIM
710 Lookup_String: /* Come-From XBufferOverflow */
711 #ifdef XIM_MOTIF
712 len = XmImMbLookupString (XtWindowToWidget (event->display, event->window),
713 event, bufptr, bufsiz, &keysym, &status);
714 #else /* XIM_XLIB */
715 len = XmbLookupString (xic, event, bufptr, bufsiz, &keysym, &status);
716 #endif /* XIM_XLIB */
717
718 #ifdef DEBUG_XEMACS
719 if (x_debug_events > 0)
720 {
721 stderr_out (" status=");
722 #define print_status_when(S) if (status == S) stderr_out (#S)
723 print_status_when (XLookupKeySym);
724 print_status_when (XLookupBoth);
725 print_status_when (XLookupChars);
726 print_status_when (XLookupNone);
727 print_status_when (XBufferOverflow);
728
729 if (status == XLookupKeySym || status == XLookupBoth)
730 stderr_out (" keysym=%s", XKeysymToString (keysym));
731 if (status == XLookupChars || status == XLookupBoth)
732 {
733 if (len != 1)
734 {
735 int j;
736 stderr_out (" chars=\"");
737 for (j=0; j<len; j++)
738 stderr_out ("%c", bufptr[j]);
739 stderr_out ("\"");
740 }
741 else if (bufptr[0] <= 32 || bufptr[0] >= 127)
742 stderr_out (" char=0x%x", bufptr[0]);
743 else
744 stderr_out (" char=%c", bufptr[0]);
745 }
746 stderr_out ("\n");
747 }
748 #endif /* DEBUG_XEMACS */
749
750 switch (status)
751 {
752 case XLookupKeySym:
753 case XLookupBoth:
754 return x_keysym_to_emacs_keysym (keysym, simple_p);
755
756 case XLookupChars:
757 {
758 /* Generate multiple emacs events */
759 struct device *d = get_device_from_display (event->display);
760 Emchar ch;
761 Lisp_Object instream =
762 make_fixed_buffer_input_stream ((unsigned char *) bufptr, len);
763
764 /* ### Use Fget_coding_system (Vcomposed_input_coding_system) */
765 instream =
766 make_decoding_input_stream (XLSTREAM (instream),
767 Fget_coding_system (Qautomatic_conversion));
768
769 while ((ch = Lstream_get_emchar (XLSTREAM (instream))) != EOF)
770 {
771 Lisp_Object emacs_event = Fmake_event ();
772 XEVENT (emacs_event)->channel = DEVICE_CONSOLE (d);
773 XEVENT (emacs_event)->event_type = key_press_event;
774 XEVENT (emacs_event)->timestamp = event->time;
775 XEVENT (emacs_event)->event.key.modifiers = 0;
776 XEVENT (emacs_event)->event.key.keysym = make_char (ch);
777 enqueue_Xt_dispatch_event (emacs_event);
778 }
779 Lstream_close (XLSTREAM (instream));
780 return Qnil;
781 }
782 case XLookupNone: return Qnil;
783 case XBufferOverflow:
784 bufptr = alloca (len+1);
785 bufsiz = len+1;
786 goto Lookup_String;
787 }
788 #endif /* HAVE_XIM */
774 } 789 }
775 790
776 static void 791 static void
777 set_last_server_timestamp (struct device *d, XEvent *x_event) 792 set_last_server_timestamp (struct device *d, XEvent *x_event)
778 { 793 {