emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master e91848344e: Pass through caret position from native GTK input met


From: Po Lu
Subject: master e91848344e: Pass through caret position from native GTK input methods
Date: Sun, 9 Jan 2022 07:44:57 -0500 (EST)

branch: master
commit e91848344e096e23ad00a8a4e58299a33ed82e1c
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>

    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.
---
 src/gtkutil.c | 13 +++++++++++--
 src/xfns.c    |  6 ++++--
 2 files changed, 15 insertions(+), 4 deletions(-)

diff --git a/src/gtkutil.c b/src/gtkutil.c
index 5ed871a822..c47386dae0 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -6089,6 +6089,13 @@ xg_im_context_preedit_changed (GtkIMContext *imc, 
gpointer user_data)
   EVENT_INIT (inev);
   inev.kind = PREEDIT_TEXT_EVENT;
   inev.arg = build_string_from_utf8 (str);
+
+  Fput_text_property (make_fixnum (min (SCHARS (inev.arg),
+                                       max (0, cursor))),
+                     make_fixnum (min (SCHARS (inev.arg),
+                                       max (0, cursor) + 1)),
+                     Qcursor, Qt, inev.arg);
+
   kbd_buffer_store_event (&inev);
 
   g_free (str);
@@ -6146,6 +6153,9 @@ xg_widget_key_press_event_cb (GtkWidget *widget, GdkEvent 
*event,
   inev.ie.modifiers
     |= x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f), xstate);
 
+  if (event->key.is_modifier)
+    goto done;
+
   /* First deal with keysyms which have defined
      translations to characters.  */
   if (keysym >= 32 && keysym < 128)
@@ -6217,8 +6227,7 @@ xg_widget_key_press_event_cb (GtkWidget *widget, GdkEvent 
*event,
        || IsKeypadKey (keysym) /* 0xff80 <= x < 0xffbe */
        || IsFunctionKey (keysym)       /* 0xffbe <= x < 0xffe1 */
        /* Any "vendor-specific" key is ok.  */
-       || (keysym & (1 << 28)))
-      && !(event->key.is_modifier))
+       || (keysym & (1 << 28))))
     {
       inev.ie.kind = NON_ASCII_KEYSTROKE_EVENT;
       inev.ie.code = keysym;
diff --git a/src/xfns.c b/src/xfns.c
index 293a1b586a..7540816416 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -2973,7 +2973,8 @@ xic_preedit_caret_callback (XIC xic, XPointer client_data,
          ie.arg = make_string_from_utf8 (output->preedit_chars,
                                          output->preedit_size);
 
-         Fput_text_property (make_fixnum (max (0, output->preedit_caret)),
+         Fput_text_property (make_fixnum (min (SCHARS (ie.arg),
+                                               max (0, 
output->preedit_caret))),
                              make_fixnum (max (SCHARS (ie.arg),
                                                max (0, output->preedit_caret) 
+ 1)),
                              Qcursor, Qt, ie.arg);
@@ -3195,7 +3196,8 @@ xic_preedit_draw_callback (XIC xic, XPointer client_data,
       ie.arg = make_string_from_utf8 (output->preedit_chars,
                                      output->preedit_size);
 
-      Fput_text_property (make_fixnum (max (0, output->preedit_caret)),
+      Fput_text_property (make_fixnum (min (SCHARS (ie.arg),
+                                           max (0, output->preedit_caret))),
                          make_fixnum (min (SCHARS (ie.arg),
                                            max (0, output->preedit_caret) + 
1)),
                          Qcursor, Qt, ie.arg);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]