]> git.eshelyaron.com Git - emacs.git/commitdiff
Attribute filtered events to the right source device
authorPo Lu <luangruo@yahoo.com>
Sun, 10 Apr 2022 11:33:51 +0000 (19:33 +0800)
committerPo Lu <luangruo@yahoo.com>
Sun, 10 Apr 2022 11:34:31 +0000 (19:34 +0800)
* src/xterm.c (handle_one_xevent): Attribute core events sent by
input methods like I-Bus to the extension device that caused
them to be sent.
* src/xterm.h (struct x_display_info): New fields
`pending_keystroke_time' and `pending_keystroke_source'.

src/xterm.c
src/xterm.h

index 9de46aba10300ce8e1402bc8c5c6744b7ffa5514..88122416e27b198290e5049ba5628426cabbb1f9 100644 (file)
@@ -14490,6 +14490,15 @@ handle_one_xevent (struct x_display_info *dpyinfo,
             `event' itself.  */
          XKeyEvent xkey = event->xkey;
          int i;
+#ifdef HAVE_XINPUT2
+         Time pending_keystroke_time;
+         struct xi_device_t *source;
+
+         pending_keystroke_time = dpyinfo->pending_keystroke_time;
+
+         if (event->xkey.time >= pending_keystroke_time)
+           dpyinfo->pending_keystroke_time = 0;
+#endif
 
 #ifdef USE_GTK
           /* Don't pass keys to GTK.  A Tab will shift focus to the
@@ -14612,6 +14621,18 @@ handle_one_xevent (struct x_display_info *dpyinfo,
            {
              inev.ie.kind = ASCII_KEYSTROKE_EVENT;
              inev.ie.code = keysym;
+
+#ifdef HAVE_XINPUT2
+             if (event->xkey.time == pending_keystroke_time)
+               {
+                 source = xi_device_from_id (dpyinfo,
+                                             dpyinfo->pending_keystroke_source);
+
+                 if (source)
+                   inev.ie.device = source->name;
+               }
+#endif
+
              goto done_keysym;
            }
 
@@ -14623,6 +14644,18 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              else
                inev.ie.kind = MULTIBYTE_CHAR_KEYSTROKE_EVENT;
              inev.ie.code = keysym & 0xFFFFFF;
+
+#ifdef HAVE_XINPUT2
+             if (event->xkey.time == pending_keystroke_time)
+               {
+                 source = xi_device_from_id (dpyinfo,
+                                             dpyinfo->pending_keystroke_source);
+
+                 if (source)
+                   inev.ie.device = source->name;
+               }
+#endif
+
              goto done_keysym;
            }
 
@@ -14637,6 +14670,18 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                               ? ASCII_KEYSTROKE_EVENT
                               : MULTIBYTE_CHAR_KEYSTROKE_EVENT);
              inev.ie.code = XFIXNAT (c);
+
+#ifdef HAVE_XINPUT2
+             if (event->xkey.time == pending_keystroke_time)
+               {
+                 source = xi_device_from_id (dpyinfo,
+                                             dpyinfo->pending_keystroke_source);
+
+                 if (source)
+                   inev.ie.device = source->name;
+               }
+#endif
+
              goto done_keysym;
            }
 
@@ -14741,6 +14786,18 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                 key.  */
              inev.ie.kind = NON_ASCII_KEYSTROKE_EVENT;
              inev.ie.code = keysym;
+
+#ifdef HAVE_XINPUT2
+             if (event->xkey.time == pending_keystroke_time)
+               {
+                 source = xi_device_from_id (dpyinfo,
+                                             dpyinfo->pending_keystroke_source);
+
+                 if (source)
+                   inev.ie.device = source->name;
+               }
+#endif
+
              goto done_keysym;
            }
 
@@ -14759,6 +14816,17 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 
                Fput_text_property (make_fixnum (0), make_fixnum (nbytes),
                                    Qcoding, coding, inev.ie.arg);
+
+#ifdef HAVE_XINPUT2
+               if (event->xkey.time == pending_keystroke_time)
+                 {
+                   source = xi_device_from_id (dpyinfo,
+                                               dpyinfo->pending_keystroke_source);
+
+                   if (source)
+                     inev.ie.device = source->name;
+                 }
+#endif
              }
 
            if (keysym == NoSymbol)
@@ -17312,6 +17380,12 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 #else
              if (x_filter_event (dpyinfo, (XEvent *) &xkey))
                {
+                 /* Try to attribute core key events from the input
+                    method to the input extension event that caused
+                    them.  */
+                 dpyinfo->pending_keystroke_time = xev->time;
+                 dpyinfo->pending_keystroke_source = xev->sourceid;
+
                  *finish = X_EVENT_DROP;
                  goto XI_OTHER;
                }
index c12fd6c3fe12e47b52cc6515c733e8b20ef742c9..85b773cf0bba6d1c75dd2a0507221d9d59199e4b 100644 (file)
@@ -615,6 +615,9 @@ struct x_display_info
 
   int num_devices;
   struct xi_device_t *devices;
+
+  Time pending_keystroke_time;
+  int pending_keystroke_source;
 #endif
 
 #ifdef HAVE_XKB