[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 14562b45bd: Avoid consing extra string when processing GTK native
From: |
Po Lu |
Subject: |
master 14562b45bd: Avoid consing extra string when processing GTK native input |
Date: |
Sat, 19 Feb 2022 08:02:42 -0500 (EST) |
branch: master
commit 14562b45bd81334064b19ed91f02e11cd46aaf56
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
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.
---
src/gtkutil.c | 16 +++++++++++++---
src/keyboard.c | 3 +++
src/termhooks.h | 4 +++-
3 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/src/gtkutil.c b/src/gtkutil.c
index 27aa28b890..158c29272f 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -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;
diff --git a/src/keyboard.c b/src/keyboard.c
index 0747ab4820..2aff0f1011 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -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),
diff --git a/src/termhooks.h b/src/termhooks.h
index 0a9ab61afa..b7696fed4f 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -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
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 14562b45bd: Avoid consing extra string when processing GTK native input,
Po Lu <=