aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2000-08-11 00:49:39 +0000
committerKenichi Handa2000-08-11 00:49:39 +0000
commit379b5ac0b0c953be1f0092210af2c5f4ebe6e35f (patch)
treeb79fda3c9ac5d1c7bed56f77cf31453d4f7bd2ce /src
parent91c3f500ad844c1b97ca2a4ff88337f938809bda (diff)
downloademacs-379b5ac0b0c953be1f0092210af2c5f4ebe6e35f.tar.gz
emacs-379b5ac0b0c953be1f0092210af2c5f4ebe6e35f.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/xterm.c95
1 files changed, 80 insertions, 15 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 9cec2679444..8ed946c8492 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -68,6 +68,7 @@ Boston, MA 02111-1307, USA. */
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"
@@ -9026,6 +9027,7 @@ XTread_socket (sd, bufp, numchars, expected)
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 {
@@ -9044,6 +9046,18 @@ XTread_socket (sd, bufp, numchars, expected)
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)
@@ -9500,9 +9514,20 @@ XTread_socket (sd, bufp, numchars, expected)
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
@@ -9531,8 +9556,6 @@ XTread_socket (sd, bufp, numchars, expected)
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),
@@ -9561,11 +9584,13 @@ XTread_socket (sd, bufp, numchars, expected)
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;
@@ -9660,14 +9685,54 @@ XTread_socket (sd, bufp, numchars, expected)
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
@@ -9677,8 +9742,8 @@ XTread_socket (sd, bufp, numchars, expected)
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;