aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPo Lu2022-02-19 20:59:12 +0800
committerPo Lu2022-02-19 21:02:30 +0800
commit14562b45bd81334064b19ed91f02e11cd46aaf56 (patch)
tree5fe7e1b23e386fdcf3bd03e99de0764613630020 /src
parentf273a504be670d714fe46a067e5edba548443701 (diff)
downloademacs-14562b45bd81334064b19ed91f02e11cd46aaf56.tar.gz
emacs-14562b45bd81334064b19ed91f02e11cd46aaf56.zip
Avoid consing extra string when processing GTK native input
* src/gtkutil.c (xg_im_context_commit): Use `decode_string_utf8' to decode input text. * src/keyboard.c (kbd_buffer_get_event_1): If coding system is Qt, simply return the string without decoding it. * src/termhooks.h (enum event_kind): Document meaning of Qt as coding system in a multibyte keystroke event's string argument.
Diffstat (limited to 'src')
-rw-r--r--src/gtkutil.c16
-rw-r--r--src/keyboard.c3
-rw-r--r--src/termhooks.h4
3 files changed, 19 insertions, 4 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 27aa28b8902..158c29272f5 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -6097,11 +6097,21 @@ xg_im_context_commit (GtkIMContext *imc, gchar *str,
6097 struct input_event ie; 6097 struct input_event ie;
6098 6098
6099 EVENT_INIT (ie); 6099 EVENT_INIT (ie);
6100 /* This used to use g_utf8_to_ucs4_fast, which led to bad results
6101 when STR wasn't actually a UTF-8 string, which some input method
6102 modules commit. */
6103
6100 ie.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT; 6104 ie.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
6101 ie.arg = build_unibyte_string (str); 6105 ie.arg = decode_string_utf_8 (Qnil, str, strlen (str),
6106 Qnil, false, Qnil, Qnil);
6107
6108 /* STR is invalid and not really encoded in UTF-8. */
6109 if (NILP (ie.arg))
6110 ie.arg = build_unibyte_string (str);
6102 6111
6103 Fput_text_property (make_fixnum (0), make_fixnum (strlen (str)), 6112 Fput_text_property (make_fixnum (0),
6104 Qcoding, Qutf_8_unix, ie.arg); 6113 make_fixnum (SCHARS (ie.arg)),
6114 Qcoding, Qt, ie.arg);
6105 6115
6106 XSETFRAME (ie.frame_or_window, f); 6116 XSETFRAME (ie.frame_or_window, f);
6107 ie.modifiers = 0; 6117 ie.modifiers = 0;
diff --git a/src/keyboard.c b/src/keyboard.c
index 0747ab48205..2aff0f1011d 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3841,6 +3841,9 @@ kbd_buffer_get_event_1 (Lisp_Object arg)
3841 Lisp_Object coding_system = Fget_text_property (make_fixnum (0), 3841 Lisp_Object coding_system = Fget_text_property (make_fixnum (0),
3842 Qcoding, arg); 3842 Qcoding, arg);
3843 3843
3844 if (EQ (coding_system, Qt))
3845 return arg;
3846
3844 return code_convert_string (arg, (!NILP (coding_system) 3847 return code_convert_string (arg, (!NILP (coding_system)
3845 ? coding_system 3848 ? coding_system
3846 : Vlocale_coding_system), 3849 : Vlocale_coding_system),
diff --git a/src/termhooks.h b/src/termhooks.h
index 0a9ab61afab..b7696fed4f8 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -100,7 +100,9 @@ enum event_kind
100 100
101 If it is nil, then the 101 If it is nil, then the
102 locale coding system will 102 locale coding system will
103 be used. */ 103 be used. If it is t, then
104 no decoding will take
105 place. */
104 NON_ASCII_KEYSTROKE_EVENT, /* .code is a number identifying the 106 NON_ASCII_KEYSTROKE_EVENT, /* .code is a number identifying the
105 function key. A code N represents 107 function key. A code N represents
106 a key whose name is 108 a key whose name is