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;
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),
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