diff options
| author | Po Lu | 2022-01-09 20:43:17 +0800 |
|---|---|---|
| committer | Po Lu | 2022-01-09 20:43:17 +0800 |
| commit | e91848344e096e23ad00a8a4e58299a33ed82e1c (patch) | |
| tree | e0b2a1066abf0328103a168984ec1a89831525b5 /src | |
| parent | 59ede5cce8e58eabc479ecca88c0ce67bc4bb928 (diff) | |
| download | emacs-e91848344e096e23ad00a8a4e58299a33ed82e1c.tar.gz emacs-e91848344e096e23ad00a8a4e58299a33ed82e1c.zip | |
Pass through caret position from native GTK input methods
* src/gtkutil.c (xg_im_context_preedit_changed): Set caret
position appropriately.
* src/xfns.c (xg_widget_key_press_event_cb): Ignore modifier
keys.
(xic_preedit_caret_callback, xic_preedit_draw_callback):
Constrain caret position to the string length as well.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gtkutil.c | 13 | ||||
| -rw-r--r-- | src/xfns.c | 6 |
2 files changed, 15 insertions, 4 deletions
diff --git a/src/gtkutil.c b/src/gtkutil.c index 5ed871a8226..c47386dae00 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c | |||
| @@ -6089,6 +6089,13 @@ xg_im_context_preedit_changed (GtkIMContext *imc, gpointer user_data) | |||
| 6089 | EVENT_INIT (inev); | 6089 | EVENT_INIT (inev); |
| 6090 | inev.kind = PREEDIT_TEXT_EVENT; | 6090 | inev.kind = PREEDIT_TEXT_EVENT; |
| 6091 | inev.arg = build_string_from_utf8 (str); | 6091 | inev.arg = build_string_from_utf8 (str); |
| 6092 | |||
| 6093 | Fput_text_property (make_fixnum (min (SCHARS (inev.arg), | ||
| 6094 | max (0, cursor))), | ||
| 6095 | make_fixnum (min (SCHARS (inev.arg), | ||
| 6096 | max (0, cursor) + 1)), | ||
| 6097 | Qcursor, Qt, inev.arg); | ||
| 6098 | |||
| 6092 | kbd_buffer_store_event (&inev); | 6099 | kbd_buffer_store_event (&inev); |
| 6093 | 6100 | ||
| 6094 | g_free (str); | 6101 | g_free (str); |
| @@ -6146,6 +6153,9 @@ xg_widget_key_press_event_cb (GtkWidget *widget, GdkEvent *event, | |||
| 6146 | inev.ie.modifiers | 6153 | inev.ie.modifiers |
| 6147 | |= x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f), xstate); | 6154 | |= x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f), xstate); |
| 6148 | 6155 | ||
| 6156 | if (event->key.is_modifier) | ||
| 6157 | goto done; | ||
| 6158 | |||
| 6149 | /* First deal with keysyms which have defined | 6159 | /* First deal with keysyms which have defined |
| 6150 | translations to characters. */ | 6160 | translations to characters. */ |
| 6151 | if (keysym >= 32 && keysym < 128) | 6161 | if (keysym >= 32 && keysym < 128) |
| @@ -6217,8 +6227,7 @@ xg_widget_key_press_event_cb (GtkWidget *widget, GdkEvent *event, | |||
| 6217 | || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */ | 6227 | || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */ |
| 6218 | || IsFunctionKey (keysym) /* 0xffbe <= x < 0xffe1 */ | 6228 | || IsFunctionKey (keysym) /* 0xffbe <= x < 0xffe1 */ |
| 6219 | /* Any "vendor-specific" key is ok. */ | 6229 | /* Any "vendor-specific" key is ok. */ |
| 6220 | || (keysym & (1 << 28))) | 6230 | || (keysym & (1 << 28)))) |
| 6221 | && !(event->key.is_modifier)) | ||
| 6222 | { | 6231 | { |
| 6223 | inev.ie.kind = NON_ASCII_KEYSTROKE_EVENT; | 6232 | inev.ie.kind = NON_ASCII_KEYSTROKE_EVENT; |
| 6224 | inev.ie.code = keysym; | 6233 | inev.ie.code = keysym; |
diff --git a/src/xfns.c b/src/xfns.c index 293a1b586a4..7540816416d 100644 --- a/src/xfns.c +++ b/src/xfns.c | |||
| @@ -2973,7 +2973,8 @@ xic_preedit_caret_callback (XIC xic, XPointer client_data, | |||
| 2973 | ie.arg = make_string_from_utf8 (output->preedit_chars, | 2973 | ie.arg = make_string_from_utf8 (output->preedit_chars, |
| 2974 | output->preedit_size); | 2974 | output->preedit_size); |
| 2975 | 2975 | ||
| 2976 | Fput_text_property (make_fixnum (max (0, output->preedit_caret)), | 2976 | Fput_text_property (make_fixnum (min (SCHARS (ie.arg), |
| 2977 | max (0, output->preedit_caret))), | ||
| 2977 | make_fixnum (max (SCHARS (ie.arg), | 2978 | make_fixnum (max (SCHARS (ie.arg), |
| 2978 | max (0, output->preedit_caret) + 1)), | 2979 | max (0, output->preedit_caret) + 1)), |
| 2979 | Qcursor, Qt, ie.arg); | 2980 | Qcursor, Qt, ie.arg); |
| @@ -3195,7 +3196,8 @@ xic_preedit_draw_callback (XIC xic, XPointer client_data, | |||
| 3195 | ie.arg = make_string_from_utf8 (output->preedit_chars, | 3196 | ie.arg = make_string_from_utf8 (output->preedit_chars, |
| 3196 | output->preedit_size); | 3197 | output->preedit_size); |
| 3197 | 3198 | ||
| 3198 | Fput_text_property (make_fixnum (max (0, output->preedit_caret)), | 3199 | Fput_text_property (make_fixnum (min (SCHARS (ie.arg), |
| 3200 | max (0, output->preedit_caret))), | ||
| 3199 | make_fixnum (min (SCHARS (ie.arg), | 3201 | make_fixnum (min (SCHARS (ie.arg), |
| 3200 | max (0, output->preedit_caret) + 1)), | 3202 | max (0, output->preedit_caret) + 1)), |
| 3201 | Qcursor, Qt, ie.arg); | 3203 | Qcursor, Qt, ie.arg); |