comparison src/xterm.c @ 44626:404f74d6dc4a

(Qlatin_1, Qutf_8): New vars. (syms_of_xterm): Initialize them. (XTread_socket): Eliminate incorrect optimization that tried to avoid decoding the output of X*LookupString. Always use latin-1 to decode the output of XLookupString. Try Xutf8LookupString if XmbLookupString failed.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Tue, 16 Apr 2002 15:07:46 +0000
parents cf3b9d517c45
children 8826cd76618a
comparison
equal deleted inserted replaced
44625:cd1ab4027e5a 44626:404f74d6dc4a
392 392
393 Lisp_Object Vx_alt_keysym, Vx_hyper_keysym, Vx_meta_keysym, Vx_super_keysym; 393 Lisp_Object Vx_alt_keysym, Vx_hyper_keysym, Vx_meta_keysym, Vx_super_keysym;
394 static Lisp_Object Qalt, Qhyper, Qmeta, Qsuper, Qmodifier_value; 394 static Lisp_Object Qalt, Qhyper, Qmeta, Qsuper, Qmodifier_value;
395 395
396 static Lisp_Object Qvendor_specific_keysyms; 396 static Lisp_Object Qvendor_specific_keysyms;
397 static Lisp_Object Qlatin_1, Qutf_8;
397 398
398 extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *)); 399 extern XrmDatabase x_load_resources P_ ((Display *, char *, char *, char *));
399 extern Lisp_Object x_icon_type P_ ((struct frame *)); 400 extern Lisp_Object x_icon_type P_ ((struct frame *));
400 401
401 402
9933 if (numchars <= 0) 9934 if (numchars <= 0)
9934 abort (); /* Don't think this happens. */ 9935 abort (); /* Don't think this happens. */
9935 9936
9936 ++handling_signal; 9937 ++handling_signal;
9937 9938
9938 /* The input should be decoded if it is from XIM. Currently the
9939 locale of XIM is the same as that of the system. So, we can use
9940 Vlocale_coding_system which is initialized properly at Emacs
9941 startup time. */
9942 setup_coding_system (Vlocale_coding_system, &coding);
9943 coding.src_multibyte = 0;
9944 coding.dst_multibyte = 1;
9945 /* The input is converted to events, thus we can't handle
9946 composition. Anyway, there's no XIM that gives us composition
9947 information. */
9948 coding.composing = COMPOSITION_DISABLED;
9949
9950 /* Find the display we are supposed to read input for. 9939 /* Find the display we are supposed to read input for.
9951 It's the one communicating on descriptor SD. */ 9940 It's the one communicating on descriptor SD. */
9952 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next) 9941 for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
9953 { 9942 {
9954 #if 0 /* This ought to be unnecessary; let's verify it. */ 9943 #if 0 /* This ought to be unnecessary; let's verify it. */
10455 approximation. -- 2000.8.10 handa@etl.go.jp */ 10444 approximation. -- 2000.8.10 handa@etl.go.jp */
10456 unsigned char copy_buffer[513]; 10445 unsigned char copy_buffer[513];
10457 unsigned char *copy_bufptr = copy_buffer; 10446 unsigned char *copy_bufptr = copy_buffer;
10458 int copy_bufsiz = sizeof (copy_buffer); 10447 int copy_bufsiz = sizeof (copy_buffer);
10459 int modifiers; 10448 int modifiers;
10449 Lisp_Object coding_system = Qlatin_1;
10460 10450
10461 event.xkey.state 10451 event.xkey.state
10462 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f), 10452 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f),
10463 extra_keyboard_modifiers); 10453 extra_keyboard_modifiers);
10464 modifiers = event.xkey.state; 10454 modifiers = event.xkey.state;
10484 #ifdef HAVE_X_I18N 10474 #ifdef HAVE_X_I18N
10485 if (FRAME_XIC (f)) 10475 if (FRAME_XIC (f))
10486 { 10476 {
10487 Status status_return; 10477 Status status_return;
10488 10478
10479 coding_system = Vlocale_coding_system;
10489 nbytes = XmbLookupString (FRAME_XIC (f), 10480 nbytes = XmbLookupString (FRAME_XIC (f),
10490 &event.xkey, copy_bufptr, 10481 &event.xkey, copy_bufptr,
10491 copy_bufsiz, &keysym, 10482 copy_bufsiz, &keysym,
10492 &status_return); 10483 &status_return);
10493 if (status_return == XBufferOverflow) 10484 if (status_return == XBufferOverflow)
10497 nbytes = XmbLookupString (FRAME_XIC (f), 10488 nbytes = XmbLookupString (FRAME_XIC (f),
10498 &event.xkey, copy_bufptr, 10489 &event.xkey, copy_bufptr,
10499 copy_bufsiz, &keysym, 10490 copy_bufsiz, &keysym,
10500 &status_return); 10491 &status_return);
10501 } 10492 }
10493 #ifdef X_HAVE_UTF8_STRING
10494 else if (status_return == XLookupKeySym)
10495 { /* Try again but with utf-8. */
10496 coding_system = Qutf_8;
10497 nbytes = Xutf8LookupString (FRAME_XIC (f),
10498 &event.xkey, copy_bufptr,
10499 copy_bufsiz, &keysym,
10500 &status_return);
10501 if (status_return == XBufferOverflow)
10502 {
10503 copy_bufsiz = nbytes + 1;
10504 copy_bufptr = (char *) alloca (copy_bufsiz);
10505 nbytes = Xutf8LookupString (FRAME_XIC (f),
10506 &event.xkey,
10507 copy_bufptr,
10508 copy_bufsiz, &keysym,
10509 &status_return);
10510 }
10511 }
10512 #endif
10502 10513
10503 if (status_return == XLookupNone) 10514 if (status_return == XLookupNone)
10504 break; 10515 break;
10505 else if (status_return == XLookupChars) 10516 else if (status_return == XLookupChars)
10506 { 10517 {
10623 { 10634 {
10624 register int i; 10635 register int i;
10625 register int c; 10636 register int c;
10626 int nchars, len; 10637 int nchars, len;
10627 10638
10639 /* The input should be decoded with `coding_system'
10640 which depends on which X*LookupString function
10641 we used just above and the locale. */
10642 setup_coding_system (coding_system, &coding);
10643 coding.src_multibyte = 0;
10644 coding.dst_multibyte = 1;
10645 /* The input is converted to events, thus we can't
10646 handle composition. Anyway, there's no XIM that
10647 gives us composition information. */
10648 coding.composing = COMPOSITION_DISABLED;
10649
10628 for (i = 0; i < nbytes; i++) 10650 for (i = 0; i < nbytes; i++)
10629 { 10651 {
10630 if (temp_index == (sizeof temp_buffer 10652 if (temp_index == (sizeof temp_buffer
10631 / sizeof (short))) 10653 / sizeof (short)))
10632 temp_index = 0; 10654 temp_index = 0;
10633 temp_buffer[temp_index++] = copy_bufptr[i]; 10655 temp_buffer[temp_index++] = copy_bufptr[i];
10634 } 10656 }
10635 10657
10636 if (/* If the event is not from XIM, */ 10658 {
10637 event.xkey.keycode != 0 10659 /* Decode the input data. */
10638 /* or the current locale doesn't request 10660 int require;
10639 decoding of the intup data, ... */ 10661 unsigned char *p;
10640 || coding.type == coding_type_raw_text 10662
10641 || coding.type == coding_type_no_conversion) 10663 require = decoding_buffer_size (&coding, nbytes);
10642 { 10664 p = (unsigned char *) alloca (require);
10643 /* ... we can use the input data as is. */ 10665 coding.mode |= CODING_MODE_LAST_BLOCK;
10644 nchars = nbytes; 10666 decode_coding (&coding, copy_bufptr, p,
10645 } 10667 nbytes, require);
10646 else 10668 nbytes = coding.produced;
10647 { 10669 nchars = coding.produced_char;
10648 /* We have to decode the input data. */ 10670 copy_bufptr = p;
10649 int require; 10671 }
10650 unsigned char *p;
10651
10652 require = decoding_buffer_size (&coding, nbytes);
10653 p = (unsigned char *) alloca (require);
10654 coding.mode |= CODING_MODE_LAST_BLOCK;
10655 decode_coding (&coding, copy_bufptr, p,
10656 nbytes, require);
10657 nbytes = coding.produced;
10658 nchars = coding.produced_char;
10659 copy_bufptr = p;
10660 }
10661 10672
10662 /* Convert the input data to a sequence of 10673 /* Convert the input data to a sequence of
10663 character events. */ 10674 character events. */
10664 for (i = 0; i < nbytes; i += len) 10675 for (i = 0; i < nbytes; i += len)
10665 { 10676 {
15078 last_mouse_scroll_bar = Qnil; 15089 last_mouse_scroll_bar = Qnil;
15079 15090
15080 staticpro (&Qvendor_specific_keysyms); 15091 staticpro (&Qvendor_specific_keysyms);
15081 Qvendor_specific_keysyms = intern ("vendor-specific-keysyms"); 15092 Qvendor_specific_keysyms = intern ("vendor-specific-keysyms");
15082 15093
15094 staticpro (&Qutf_8);
15095 Qutf_8 = intern ("utf-8");
15096 staticpro (&Qlatin_1);
15097 Qlatin_1 = intern ("latin-1");
15098
15083 staticpro (&last_mouse_press_frame); 15099 staticpro (&last_mouse_press_frame);
15084 last_mouse_press_frame = Qnil; 15100 last_mouse_press_frame = Qnil;
15085 15101
15086 help_echo = Qnil; 15102 help_echo = Qnil;
15087 staticpro (&help_echo); 15103 staticpro (&help_echo);