Mercurial > vim
comparison src/gui_gtk_x11.c @ 20595:3609e842f822 v8.2.0851
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Commit: https://github.com/vim/vim/commit/f4ae6b245a54f11dd967d06b80f30e5abf55fb82
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat May 30 19:52:46 2020 +0200
patch 8.2.0851: can't distinguish <M-a> from accented "a" in the GUI
Problem: Can't distinguish <M-a> from accented "a" in the GUI.
Solution: Use another way to make mapping <C-bslash> work. (closes https://github.com/vim/vim/issues/6163)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 30 May 2020 20:00:03 +0200 |
parents | 682513df5af1 |
children | 9f5f64cc9720 |
comparison
equal
deleted
inserted
replaced
20594:033006d6a9c6 | 20595:3609e842f822 |
---|---|
1016 /* | 1016 /* |
1017 * Translate a GDK key value to UTF-8 independently of the current locale. | 1017 * Translate a GDK key value to UTF-8 independently of the current locale. |
1018 * The output is written to string, which must have room for at least 6 bytes | 1018 * The output is written to string, which must have room for at least 6 bytes |
1019 * plus the NUL terminator. Returns the length in bytes. | 1019 * plus the NUL terminator. Returns the length in bytes. |
1020 * | 1020 * |
1021 * This function is used in the GTK+ 2 GUI only. The GTK+ 1 code makes use | 1021 * event->string is evil; see here why: |
1022 * of GdkEventKey::string instead. But event->string is evil; see here why: | |
1023 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey | 1022 * http://developer.gnome.org/doc/API/2.0/gdk/gdk-Event-Structures.html#GdkEventKey |
1024 */ | 1023 */ |
1025 static int | 1024 static int |
1026 keyval_to_string(unsigned int keyval, unsigned int *state, char_u *string) | 1025 keyval_to_string(unsigned int keyval, char_u *string) |
1027 { | 1026 { |
1028 int len; | 1027 int len; |
1029 guint32 uc; | 1028 guint32 uc; |
1030 | 1029 |
1031 uc = gdk_keyval_to_unicode(keyval); | 1030 uc = gdk_keyval_to_unicode(keyval); |
1032 if (uc != 0) | 1031 if (uc != 0) |
1033 { | 1032 { |
1034 // Check for CTRL-char | 1033 // Translate a normal key to UTF-8. This doesn't work for dead |
1035 if ((*state & GDK_CONTROL_MASK) && uc >= 0x20 && uc < 0x80) | 1034 // keys of course, you _have_ to use an input method for that. |
1036 { | 1035 len = utf_char2bytes((int)uc, string); |
1037 // These mappings look arbitrary at the first glance, but in fact | |
1038 // resemble quite exactly the behaviour of the GTK+ 1.2 GUI on my | |
1039 // machine. The only difference is BS vs. DEL for CTRL-8 (makes | |
1040 // more sense and is consistent with usual terminal behaviour). | |
1041 if (uc >= '@') | |
1042 string[0] = uc & 0x1F; | |
1043 else if (uc == '2') | |
1044 string[0] = NUL; | |
1045 else if (uc >= '3' && uc <= '7') | |
1046 string[0] = uc ^ 0x28; | |
1047 else if (uc == '8') | |
1048 string[0] = BS; | |
1049 else if (uc == '?') | |
1050 string[0] = DEL; | |
1051 else | |
1052 string[0] = uc; | |
1053 len = 1; | |
1054 | |
1055 if (string[0] != uc) | |
1056 // The modifier was used, remove it. | |
1057 *state = *state & ~GDK_CONTROL_MASK; | |
1058 } | |
1059 else | |
1060 { | |
1061 // Translate a normal key to UTF-8. This doesn't work for dead | |
1062 // keys of course, you _have_ to use an input method for that. | |
1063 len = utf_char2bytes((int)uc, string); | |
1064 } | |
1065 } | 1036 } |
1066 else | 1037 else |
1067 { | 1038 { |
1068 // Translate keys which are represented by ASCII control codes in Vim. | 1039 // Translate keys which are represented by ASCII control codes in Vim. |
1069 // There are only a few of those; most control keys are translated to | 1040 // There are only a few of those; most control keys are translated to |
1171 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) | 1142 if (key_sym == SunXK_F36 || key_sym == SunXK_F37) |
1172 len = 0; | 1143 len = 0; |
1173 else | 1144 else |
1174 #endif | 1145 #endif |
1175 { | 1146 { |
1176 len = keyval_to_string(key_sym, &state, string2); | 1147 len = keyval_to_string(key_sym, string2); |
1177 | 1148 |
1178 // Careful: convert_input() doesn't handle the NUL character. | 1149 // Careful: convert_input() doesn't handle the NUL character. |
1179 // No need to convert pure ASCII anyway, thus the len > 1 check. | 1150 // No need to convert pure ASCII anyway, thus the len > 1 check. |
1180 if (len > 1 && input_conv.vc_type != CONV_NONE) | 1151 if (len > 1 && input_conv.vc_type != CONV_NONE) |
1181 len = convert_input(string2, len, sizeof(string2)); | 1152 len = convert_input(string2, len, sizeof(string2)); |
1259 string[2] = K_THIRD(key); | 1230 string[2] = K_THIRD(key); |
1260 len = 3; | 1231 len = 3; |
1261 } | 1232 } |
1262 else | 1233 else |
1263 { | 1234 { |
1235 // <C-H> and <C-h> mean the same thing, always use "H" | |
1236 if ((modifiers & MOD_MASK_CTRL) && ASCII_ISALPHA(key)) | |
1237 key = TOUPPER_ASC(key); | |
1264 string[0] = key; | 1238 string[0] = key; |
1265 len = 1; | 1239 len = 1; |
1266 } | 1240 } |
1267 | 1241 |
1268 if (modifiers != 0) | 1242 if (modifiers != 0) |