Mercurial > emacs
comparison src/xterm.c @ 30748:13c7c5e6cc36
Include coding.h.
(XTread_socket): Work around a bug of XmbLookupString. If the
input is from XIM, decode it according to the current locale. In
that case, generate multibyte_char_keystroke events.
author | Kenichi Handa <handa@m17n.org> |
---|---|
date | Fri, 11 Aug 2000 00:49:39 +0000 |
parents | e25bfc3f618c |
children | bc4608ec8691 |
comparison
equal
deleted
inserted
replaced
30747:6c7afd50ec6a | 30748:13c7c5e6cc36 |
---|---|
66 #include <sys/stat.h> | 66 #include <sys/stat.h> |
67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */ | 67 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */ |
68 /* #include <sys/param.h> */ | 68 /* #include <sys/param.h> */ |
69 | 69 |
70 #include "charset.h" | 70 #include "charset.h" |
71 #include "coding.h" | |
71 #include "ccl.h" | 72 #include "ccl.h" |
72 #include "frame.h" | 73 #include "frame.h" |
73 #include "dispextern.h" | 74 #include "dispextern.h" |
74 #include "fontset.h" | 75 #include "fontset.h" |
75 #include "termhooks.h" | 76 #include "termhooks.h" |
9024 int nbytes = 0; | 9025 int nbytes = 0; |
9025 XEvent event; | 9026 XEvent event; |
9026 struct frame *f; | 9027 struct frame *f; |
9027 int event_found = 0; | 9028 int event_found = 0; |
9028 struct x_display_info *dpyinfo; | 9029 struct x_display_info *dpyinfo; |
9030 struct coding_system coding; | |
9029 | 9031 |
9030 if (interrupt_input_blocked) | 9032 if (interrupt_input_blocked) |
9031 { | 9033 { |
9032 interrupt_input_pending = 1; | 9034 interrupt_input_pending = 1; |
9033 return -1; | 9035 return -1; |
9042 if (numchars <= 0) | 9044 if (numchars <= 0) |
9043 abort (); /* Don't think this happens. */ | 9045 abort (); /* Don't think this happens. */ |
9044 | 9046 |
9045 ++handling_signal; | 9047 ++handling_signal; |
9046 | 9048 |
9049 /* The input should be decoded if it is from XIM. Currently the | |
9050 locale of XIM is the same as that of the system. So, we can use | |
9051 Vlocale_coding_system which is initialized properly at Emacs | |
9052 startup time. */ | |
9053 setup_coding_system (Vlocale_coding_system, &coding); | |
9054 coding.src_multibyte = 0; | |
9055 coding.dst_multibyte = 1; | |
9056 /* The input is converted to events, thus we can't handle | |
9057 composition. Anyway, there's no XIM that gives us composition | |
9058 information. */ | |
9059 coding.composing = COMPOSITION_DISABLED; | |
9060 | |
9047 /* Find the display we are supposed to read input for. | 9061 /* Find the display we are supposed to read input for. |
9048 It's the one communicating on descriptor SD. */ | 9062 It's the one communicating on descriptor SD. */ |
9049 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) | 9063 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) |
9050 { | 9064 { |
9051 #if 0 /* This ought to be unnecessary; let's verify it. */ | 9065 #if 0 /* This ought to be unnecessary; let's verify it. */ |
9498 #endif /* USE_MOTIF */ | 9512 #endif /* USE_MOTIF */ |
9499 | 9513 |
9500 if (f != 0) | 9514 if (f != 0) |
9501 { | 9515 { |
9502 KeySym keysym, orig_keysym; | 9516 KeySym keysym, orig_keysym; |
9503 /* al%imercury@uunet.uu.net says that making this 81 instead of | 9517 /* al%imercury@uunet.uu.net says that making this 81 |
9504 80 fixed a bug whereby meta chars made his Emacs hang. */ | 9518 instead of 80 fixed a bug whereby meta chars made |
9505 unsigned char copy_buffer[81]; | 9519 his Emacs hang. |
9520 | |
9521 It seems that some version of XmbLookupString has | |
9522 a bug of not returning XBufferOverflow in | |
9523 status_return even if the input is too long to | |
9524 fit in 81 bytes. So, we must prepare sufficient | |
9525 bytes for copy_buffer. 513 bytes (256 chars for | |
9526 two-byte character set) seems to be a faily good | |
9527 approximation. -- 2000.8.10 handa@etl.go.jp */ | |
9528 unsigned char copy_buffer[513]; | |
9529 unsigned char *copy_bufptr = copy_buffer; | |
9530 int copy_bufsiz = sizeof (copy_buffer); | |
9506 int modifiers; | 9531 int modifiers; |
9507 | 9532 |
9508 event.xkey.state | 9533 event.xkey.state |
9509 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f), | 9534 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f), |
9510 extra_keyboard_modifiers); | 9535 extra_keyboard_modifiers); |
9529 bzero (&compose_status, sizeof (compose_status)); | 9554 bzero (&compose_status, sizeof (compose_status)); |
9530 | 9555 |
9531 #ifdef HAVE_X_I18N | 9556 #ifdef HAVE_X_I18N |
9532 if (FRAME_XIC (f)) | 9557 if (FRAME_XIC (f)) |
9533 { | 9558 { |
9534 unsigned char *copy_bufptr = copy_buffer; | |
9535 int copy_bufsiz = sizeof (copy_buffer); | |
9536 Status status_return; | 9559 Status status_return; |
9537 | 9560 |
9538 nbytes = XmbLookupString (FRAME_XIC (f), | 9561 nbytes = XmbLookupString (FRAME_XIC (f), |
9539 &event.xkey, copy_bufptr, | 9562 &event.xkey, copy_bufptr, |
9540 copy_bufsiz, &keysym, | 9563 copy_bufsiz, &keysym, |
9559 else if (status_return != XLookupKeySym | 9582 else if (status_return != XLookupKeySym |
9560 && status_return != XLookupBoth) | 9583 && status_return != XLookupBoth) |
9561 abort (); | 9584 abort (); |
9562 } | 9585 } |
9563 else | 9586 else |
9564 nbytes = XLookupString (&event.xkey, copy_buffer, | 9587 nbytes = XLookupString (&event.xkey, copy_bufptr, |
9565 80, &keysym, &compose_status); | 9588 copy_bufsiz, &keysym, |
9589 &compose_status); | |
9566 #else | 9590 #else |
9567 nbytes = XLookupString (&event.xkey, copy_buffer, | 9591 nbytes = XLookupString (&event.xkey, copy_bufptr, |
9568 80, &keysym, &compose_status); | 9592 copy_bufsiz, &keysym, |
9593 &compose_status); | |
9569 #endif | 9594 #endif |
9570 | 9595 |
9571 orig_keysym = keysym; | 9596 orig_keysym = keysym; |
9572 | 9597 |
9573 if (numchars > 1) | 9598 if (numchars > 1) |
9658 numchars--; | 9683 numchars--; |
9659 } | 9684 } |
9660 else if (numchars > nbytes) | 9685 else if (numchars > nbytes) |
9661 { | 9686 { |
9662 register int i; | 9687 register int i; |
9688 register int c; | |
9689 unsigned char *p, *pend; | |
9690 int nchars, len; | |
9663 | 9691 |
9664 for (i = 0; i < nbytes; i++) | 9692 for (i = 0; i < nbytes; i++) |
9665 { | 9693 { |
9666 if (temp_index == sizeof temp_buffer / sizeof (short)) | 9694 if (temp_index == (sizeof temp_buffer |
9695 / sizeof (short))) | |
9667 temp_index = 0; | 9696 temp_index = 0; |
9668 temp_buffer[temp_index++] = copy_buffer[i]; | 9697 temp_buffer[temp_index++] = copy_bufptr[i]; |
9669 bufp->kind = ascii_keystroke; | 9698 } |
9670 bufp->code = copy_buffer[i]; | 9699 |
9700 if (/* If the event is not from XIM, */ | |
9701 event.xkey.keycode != 0 | |
9702 /* or the current locale doesn't request | |
9703 decoding of the intup data, ... */ | |
9704 || coding.type == coding_type_raw_text | |
9705 || coding.type == coding_type_no_conversion) | |
9706 { | |
9707 /* ... we can use the input data as is. */ | |
9708 nchars = nbytes; | |
9709 } | |
9710 else | |
9711 { | |
9712 /* We have to decode the input data. */ | |
9713 int require; | |
9714 unsigned char *p; | |
9715 | |
9716 require = decoding_buffer_size (&coding, nbytes); | |
9717 p = (unsigned char *) alloca (require); | |
9718 coding.mode |= CODING_MODE_LAST_BLOCK; | |
9719 decode_coding (&coding, copy_bufptr, p, | |
9720 nbytes, require); | |
9721 nbytes = coding.produced; | |
9722 nchars = coding.produced_char; | |
9723 copy_bufptr = p; | |
9724 } | |
9725 | |
9726 /* Convert the input data to a sequence of | |
9727 character events. */ | |
9728 for (i = 0; i < nbytes; i += len) | |
9729 { | |
9730 c = STRING_CHAR_AND_LENGTH (copy_bufptr + i, | |
9731 nbytes - i, len); | |
9732 bufp->kind = (SINGLE_BYTE_CHAR_P (c) | |
9733 ? ascii_keystroke | |
9734 : multibyte_char_keystroke); | |
9735 bufp->code = c; | |
9671 XSETFRAME (bufp->frame_or_window, f); | 9736 XSETFRAME (bufp->frame_or_window, f); |
9672 bufp->arg = Qnil; | 9737 bufp->arg = Qnil; |
9673 bufp->modifiers | 9738 bufp->modifiers |
9674 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), | 9739 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f), |
9675 modifiers); | 9740 modifiers); |
9676 bufp->timestamp = event.xkey.time; | 9741 bufp->timestamp = event.xkey.time; |
9677 bufp++; | 9742 bufp++; |
9678 } | 9743 } |
9679 | 9744 |
9680 count += nbytes; | 9745 count += nchars; |
9681 numchars -= nbytes; | 9746 numchars -= nchars; |
9682 | 9747 |
9683 if (keysym == NoSymbol) | 9748 if (keysym == NoSymbol) |
9684 break; | 9749 break; |
9685 } | 9750 } |
9686 else | 9751 else |