]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid consing extra string when processing GTK native input
authorPo Lu <luangruo@yahoo.com>
Sat, 19 Feb 2022 12:59:12 +0000 (20:59 +0800)
committerPo Lu <luangruo@yahoo.com>
Sat, 19 Feb 2022 13:02:30 +0000 (21:02 +0800)
* 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.

src/gtkutil.c
src/keyboard.c
src/termhooks.h

index 27aa28b89026b4928920a6269743dae10a17c723..158c29272f5264c56c60ed57a1c175c0608213f4 100644 (file)
@@ -6097,11 +6097,21 @@ xg_im_context_commit (GtkIMContext *imc, gchar *str,
   struct input_event ie;
 
   EVENT_INIT (ie);
+  /* This used to use g_utf8_to_ucs4_fast, which led to bad results
+     when STR wasn't actually a UTF-8 string, which some input method
+     modules commit.  */
+
   ie.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
-  ie.arg = build_unibyte_string (str);
+  ie.arg = decode_string_utf_8 (Qnil, str, strlen (str),
+                               Qnil, false, Qnil, Qnil);
+
+  /* STR is invalid and not really encoded in UTF-8.  */
+  if (NILP (ie.arg))
+    ie.arg = build_unibyte_string (str);
 
-  Fput_text_property (make_fixnum (0), make_fixnum (strlen (str)),
-                     Qcoding, Qutf_8_unix, ie.arg);
+  Fput_text_property (make_fixnum (0),
+                     make_fixnum (SCHARS (ie.arg)),
+                     Qcoding, Qt, ie.arg);
 
   XSETFRAME (ie.frame_or_window, f);
   ie.modifiers = 0;
index 0747ab482050bc776b747566a2b360157f3f543c..2aff0f1011d0f71a6edbd08ad77c4b3d6dd77e04 100644 (file)
@@ -3841,6 +3841,9 @@ kbd_buffer_get_event_1 (Lisp_Object arg)
   Lisp_Object coding_system = Fget_text_property (make_fixnum (0),
                                                  Qcoding, arg);
 
+  if (EQ (coding_system, Qt))
+    return arg;
+
   return code_convert_string (arg, (!NILP (coding_system)
                                    ? coding_system
                                    : Vlocale_coding_system),
index 0a9ab61afab8179335081b96be4a5115155da074..b7696fed4f8eba9c5aeb930a7e310e61c655db14 100644 (file)
@@ -100,7 +100,9 @@ enum event_kind
 
                                           If it is nil, then the
                                           locale coding system will
-                                          be used.  */
+                                          be used.  If it is t, then
+                                          no decoding will take
+                                          place.  */
   NON_ASCII_KEYSTROKE_EVENT,   /* .code is a number identifying the
                                   function key.  A code N represents
                                   a key whose name is