OSDN Git Service

[Fix] For macro triggers, special keys or XIM inputs are pushed into term queue rever...
authoriks <iks@users.sourceforge.jp>
Sun, 8 Nov 2020 11:27:12 +0000 (20:27 +0900)
committerdeskull <deskull@users.sourceforge.jp>
Fri, 13 Nov 2020 23:27:52 +0000 (08:27 +0900)
src/main-x11.c

index 0a97dd6..c427ed7 100644 (file)
@@ -1041,6 +1041,39 @@ struct x11_selection_type
 static x11_selection_type s_ptr[1];
 
 /*
+ * Convert to EUC-JP
+ */
+#ifdef USE_XIM
+static void convert_to_euc(char *buf)
+{
+       size_t inlen = strlen(buf);
+       size_t outlen = inlen + 1;
+       char tmp[outlen];
+
+       iconv_t iconvd = iconv_open("EUC-JP", "UTF-8");
+       char *inbuf = buf;
+       char *outbuf = tmp;
+       iconv(iconvd, &inbuf, &inlen, &outbuf, &outlen);
+       iconv_close(iconvd);
+
+       int i, l = strlen(tmp);
+       for (i = 0; i < l; i++)
+               buf[i] = tmp[i];
+       buf[l] = '\0';
+}
+#endif
+
+/*
+ * Push multiple keys reversal
+ */
+static void term_string_push(char *buf)
+{
+       int i, l = strlen(buf);
+       for (i = l; i >= 0; i--)
+               term_key_push(buf[i]);
+}
+
+/*
  * Process a keypress event
  *
  * Also appears in "main-xaw.c".
@@ -1079,9 +1112,9 @@ static void react_keypress(XKeyEvent *xev)
        buf[n] = '\0';
 
 #ifdef USE_XIM
-       if(!valid_keysym){
-               for (i = 0; buf[i]; i++) term_key_push(buf[i]);
-
+       if(!valid_keysym) { /* XIMからの入力時のみ FALSE になる */
+               convert_to_euc(buf);
+               term_string_push(buf);
                return;
        }
 #endif
@@ -1095,8 +1128,7 @@ static void react_keypress(XKeyEvent *xev)
        mx = (ev->state & Mod2Mask) ? TRUE : FALSE;
        if (n && !mo && !mx && !IsSpecialKey(ks))
        {
-               for (i = 0; buf[i]; i++) term_key_push(buf[i]);
-
+               term_string_push(buf);
                return;
        }
 
@@ -1147,7 +1179,7 @@ static void react_keypress(XKeyEvent *xev)
                        ev->keycode, 13);
        }
 
-       for (i = 0; msg[i]; i++) term_key_push(msg[i]);
+       term_string_push(msg);
 
        if (n && (macro_find_exact(msg) < 0))
        {
@@ -2217,7 +2249,7 @@ static errr term_data_init(term_data *td, int i)
        char buf[80];
 
        concptr str;
-
+text
        int val;
 
        XClassHint *ch;