Decode keyboard input as latin-1 whenever appropriate

* src/keyboard.c (kbd_buffer_get_event_1): Use `coding'
property if present.

* src/termhooks.h (enum event_kind): Document meaning of
`coding' property on text strings.

* src/xterm.c (handle_one_xevent): Set coding property on text
to latin-1 if it was obtained with XLookupString.
This commit is contained in:
Po Lu 2022-02-16 10:53:00 +08:00
parent 0a9c8855b0
commit f1d535da1e
3 changed files with 34 additions and 2 deletions

View file

@ -3838,7 +3838,12 @@ clear_event (struct input_event *event)
static Lisp_Object
kbd_buffer_get_event_1 (Lisp_Object arg)
{
return code_convert_string (arg, Vlocale_coding_system,
Lisp_Object coding_system = Fget_text_property (make_fixnum (0),
Qcoding, arg);
return code_convert_string (arg, (!NILP (coding_system)
? coding_system
: Vlocale_coding_system),
Qnil, 0, false, 0);
}
@ -12477,6 +12482,9 @@ See also `pre-command-hook'. */);
DEFSYM (Qtouchscreen_end, "touchscreen-end");
DEFSYM (Qtouchscreen_update, "touchscreen-update");
DEFSYM (Qpinch, "pinch");
DEFSYM (Qcoding, "coding");
Fset (Qecho_area_clear_hook, Qnil);
DEFVAR_LISP ("lucid-menu-bar-dirty-flag", Vlucid_menu_bar_dirty_flag,

View file

@ -90,7 +90,17 @@ enum event_kind
decoded and the decoded
string's characters will be
used as .code
individually. */
individually.
The string can have a
property `coding', which
should be a symbol
describing a coding system
to use to decode the string.
If it is nil, then the
locale coding system will
be used. */
NON_ASCII_KEYSTROKE_EVENT, /* .code is a number identifying the
function key. A code N represents
a key whose name is

View file

@ -9132,6 +9132,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
static XComposeStatus compose_status;
XEvent configureEvent;
XEvent next_event;
Lisp_Object coding;
*finish = X_EVENT_NORMAL;
@ -9784,6 +9785,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
case KeyPress:
x_display_set_last_user_time (dpyinfo, event->xkey.time);
ignore_next_mouse_click_timeout = 0;
coding = Qlatin_1;
#if defined (USE_X_TOOLKIT) || defined (USE_GTK)
/* Dispatch KeyPress events when in menu. */
@ -9884,6 +9886,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
&xkey, (char *) copy_bufptr,
copy_bufsiz, &keysym,
&status_return);
coding = Qnil;
if (status_return == XBufferOverflow)
{
copy_bufsiz = nbytes + 1;
@ -10053,6 +10056,9 @@ handle_one_xevent (struct x_display_info *dpyinfo,
inev.ie.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
inev.ie.arg = make_unibyte_string ((char *) copy_bufptr, nbytes);
Fput_text_property (make_fixnum (0), make_fixnum (nbytes),
Qcoding, coding, inev.ie.arg);
if (keysym == NoSymbol)
break;
}
@ -11444,6 +11450,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
ptrdiff_t i;
struct xi_device_t *device;
coding = Qlatin_1;
device = xi_device_from_id (dpyinfo, xev->deviceid);
if (!device || !device->master_p)
@ -11571,6 +11579,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
&xkey, (char *) copy_bufptr,
copy_bufsiz, &keysym,
&status_return);
coding = Qnil;
if (status_return == XBufferOverflow)
{
@ -11617,6 +11626,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
if (overflow)
nbytes = 0;
}
coding = Qnil;
}
else
#endif
@ -11748,6 +11759,9 @@ handle_one_xevent (struct x_display_info *dpyinfo,
inev.ie.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
inev.ie.arg = make_unibyte_string (copy_bufptr, nbytes);
Fput_text_property (make_fixnum (0), make_fixnum (nbytes),
Qcoding, coding, inev.ie.arg);
goto xi_done_keysym;
}