]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix keyboard event device attribution on GTK+ 2
authorPo Lu <luangruo@yahoo.com>
Tue, 12 Apr 2022 13:29:02 +0000 (21:29 +0800)
committerPo Lu <luangruo@yahoo.com>
Tue, 12 Apr 2022 13:30:25 +0000 (21:30 +0800)
* src/xfns.c (setup_xi_event_mask): Select for raw keypress
events on GTK 2.
* src/xterm.c (handle_one_xevent): Set pending keystroke time
when a raw event is received.
* src/xterm.h (struct x_display_info): New flag
`pending_keystroke_time_special_p'.

src/xfns.c
src/xterm.c
src/xterm.h

index 5cf3eb41996377558f737230d32fb4c729751bce..2f90534c48498e662179df697cfe66ae54d89773 100644 (file)
@@ -3688,6 +3688,15 @@ setup_xi_event_mask (struct frame *f)
   XISelectEvents (FRAME_X_DISPLAY (f),
                  FRAME_X_WINDOW (f),
                  &mask, 1);
+
+#if defined USE_GTK && !defined HAVE_GTK3
+  memset (m, 0, l);
+  XISetMask (m, XI_RawKeyPress);
+
+  XISelectEvents (FRAME_X_DISPLAY (f),
+                 FRAME_DISPLAY_INFO (f)->root_window,
+                 &mask, 1);
+#endif
   unblock_input ();
 }
 #endif
index e922ab8fbb276add8fa2908f8a8d8aa95a285864..2999480659b9d9fba4daf06fd569f7254678a769 100644 (file)
@@ -14516,7 +14516,16 @@ handle_one_xevent (struct x_display_info *dpyinfo,
          pending_keystroke_time = dpyinfo->pending_keystroke_time;
 
          if (event->xkey.time >= pending_keystroke_time)
-           dpyinfo->pending_keystroke_time = 0;
+           {
+#if defined USE_GTK && !defined HAVE_GTK3
+             if (!dpyinfo->pending_keystroke_time_special_p)
+#endif
+               dpyinfo->pending_keystroke_time = 0;
+#if defined USE_GTK && !defined HAVE_GTK3
+             else
+               dpyinfo->pending_keystroke_time_special_p = false;
+#endif
+           }
 #endif
 
 #ifdef USE_GTK
@@ -17781,6 +17790,21 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              goto XI_OTHER;
            }
 
+#if defined USE_GTK && !defined HAVE_GTK3
+         case XI_RawKeyPress:
+           {
+             XIRawEvent *raw_event = (XIRawEvent *) xi_event;
+
+             /* This is the only way to attribute core keyboard
+                events generated on GTK+ 2.x to the extension device
+                that generated them.  */
+             dpyinfo->pending_keystroke_time = raw_event->time;
+             dpyinfo->pending_keystroke_source = raw_event->sourceid;
+             dpyinfo->pending_keystroke_time_special_p = true;
+             goto XI_OTHER;
+           }
+#endif
+
          case XI_KeyRelease:
 #if defined HAVE_X_I18N || defined USE_GTK
            {
index 85b773cf0bba6d1c75dd2a0507221d9d59199e4b..69313166db9cac93977636d085cdfd5664920dff 100644 (file)
@@ -618,6 +618,14 @@ struct x_display_info
 
   Time pending_keystroke_time;
   int pending_keystroke_source;
+
+#if defined USE_GTK && !defined HAVE_GTK3
+  /* This means the two variables above shouldn't be reset the first
+     time a KeyPress event arrives, since they were set from a raw key
+     press event that was sent before the first (real, not sent by an
+     input method) core key event.  */
+  bool pending_keystroke_time_special_p;
+#endif
 #endif
 
 #ifdef HAVE_XKB