From f1d535da1ed2e7a70c6cf28fdcdca31d3f86a3f5 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Wed, 16 Feb 2022 10:53:00 +0800 Subject: [PATCH] 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. --- src/keyboard.c | 10 +++++++++- src/termhooks.h | 12 +++++++++++- src/xterm.c | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/keyboard.c b/src/keyboard.c index 800632aa25d..0747ab48205 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -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, diff --git a/src/termhooks.h b/src/termhooks.h index 4276d8ac2f2..0a9ab61afab 100644 --- a/src/termhooks.h +++ b/src/termhooks.h @@ -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 diff --git a/src/xterm.c b/src/xterm.c index 568351d2e3d..bd8d5f892f3 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -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; } -- 2.39.5