emacs-diffs
[Top][All Lists]
Advanced

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

master ac566bcdee3: Don't deliver touch or pinch events from master or s


From: Po Lu
Subject: master ac566bcdee3: Don't deliver touch or pinch events from master or slave devices
Date: Mon, 17 Jul 2023 08:43:30 -0400 (EDT)

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

    Don't deliver touch or pinch events from master or slave devices
    
    * src/xfns.c (setup_xi_event_mask): Select for gesture events on
    only master devices if safe.
    * src/xterm.c (handle_one_xevent): Deliver touchscreen events
    only from direct slave devices, and gesture events only from
    master pointers.
---
 src/xfns.c  | 42 ++++++++++++++++++++++++++++++++----------
 src/xterm.c | 30 ++++++++++++++++++++++++++----
 2 files changed, 58 insertions(+), 14 deletions(-)

diff --git a/src/xfns.c b/src/xfns.c
index 5c9f58e3a96..fd4807fd5f5 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -4036,7 +4036,7 @@ setup_xi_event_mask (struct frame *f)
   selected->mask = ((unsigned char *) selected) + sizeof *selected;
   selected->mask_len = l;
   selected->deviceid = XIAllMasterDevices;
-#endif
+#endif /* !HAVE_XINPUT2_1 */
 
   mask.mask = m = alloca (l);
   memset (m, 0, l);
@@ -4056,7 +4056,19 @@ setup_xi_event_mask (struct frame *f)
   XISetMask (m, XI_FocusOut);
   XISetMask (m, XI_KeyPress);
   XISetMask (m, XI_KeyRelease);
-#endif
+#endif /* !USE_GTK */
+#if defined HAVE_XINPUT2_4
+  if (FRAME_DISPLAY_INFO (f)->xi2_version >= 4)
+    {
+      /* Select for gesture events.  Since this configuration doesn't
+        use GTK 3, Emacs is the only code that can change the XI
+        event mask, and can safely select for gesture events on
+        master pointers only.  */
+      XISetMask (m, XI_GesturePinchBegin);
+      XISetMask (m, XI_GesturePinchUpdate);
+      XISetMask (m, XI_GesturePinchEnd);
+    }
+#endif /* HAVE_XINPUT2_4 */
   XISelectEvents (FRAME_X_DISPLAY (f),
                  FRAME_X_WINDOW (f),
                  &mask, 1);
@@ -4065,7 +4077,7 @@ setup_xi_event_mask (struct frame *f)
      to get the event mask from the X server.  */
 #ifndef HAVE_XINPUT2_1
   memcpy (selected->mask, m, l);
-#endif
+#endif /* !HAVE_XINPUT2_1 */
 
   memset (m, 0, l);
 #endif /* !HAVE_GTK3 */
@@ -4080,35 +4092,45 @@ setup_xi_event_mask (struct frame *f)
                  FRAME_OUTER_WINDOW (f),
                  &mask, 1);
   memset (m, 0, l);
-#endif
+#endif /* USE_X_TOOLKIT */
 
 #ifdef HAVE_XINPUT2_2
   if (FRAME_DISPLAY_INFO (f)->xi2_version >= 2)
     {
+      /* Select for touch events from all devices.
+
+         Emacs will only process touch events originating
+         from slave devices, as master pointers may also
+         represent dependent touch devices.  */
       mask.deviceid = XIAllDevices;
 
       XISetMask (m, XI_TouchBegin);
       XISetMask (m, XI_TouchUpdate);
       XISetMask (m, XI_TouchEnd);
-#ifdef HAVE_XINPUT2_4
+
+#if defined HAVE_XINPUT2_4 && defined USE_GTK3
       if (FRAME_DISPLAY_INFO (f)->xi2_version >= 4)
        {
+         /* Now select for gesture events from all pointer devices.
+            Emacs will only handle gesture events from the master
+            pointer, but cannot afford to overwrite the event mask
+            set by GDK.  */
+
          XISetMask (m, XI_GesturePinchBegin);
          XISetMask (m, XI_GesturePinchUpdate);
          XISetMask (m, XI_GesturePinchEnd);
        }
-#endif
+#endif /* HAVE_XINPUT2_4 && USE_GTK3 */
 
-      XISelectEvents (FRAME_X_DISPLAY (f),
-                     FRAME_X_WINDOW (f),
+      XISelectEvents (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
                      &mask, 1);
     }
-#endif
+#endif /* HAVE_XINPUT2_2 */
 
 #ifndef HAVE_XINPUT2_1
   FRAME_X_OUTPUT (f)->xi_masks = selected;
   FRAME_X_OUTPUT (f)->num_xi_masks = 1;
-#endif
+#endif /* HAVE_XINPUT2_1 */
 
   unblock_input ();
 }
diff --git a/src/xterm.c b/src/xterm.c
index 9ecead03b08..5cc2dfdae1d 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -24259,7 +24259,13 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              x_display_set_last_user_time (dpyinfo, xev->time,
                                            xev->send_event, true);
 
-             if (!device)
+             /* Don't process touch sequences from this device if
+                it's a master pointer.  Touch sequences aren't
+                canceled by the X server if a slave device is
+                detached, and master pointers may also represent
+                dependent touch devices.  */
+
+             if (!device || device->use == XIMasterPointer)
                goto XI_OTHER;
 
              if (xi_find_touch_point (device, xev->detail))
@@ -24427,12 +24433,22 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              x_display_set_last_user_time (dpyinfo, xev->time,
                                            xev->send_event, true);
 
+             /* Don't process touch sequences from this device if
+                it's a master pointer.  Touch sequences aren't
+                canceled by the X server if a slave device is
+                detached, and master pointers may also represent
+                dependent touch devices.  */
+
              if (!device)
                goto XI_OTHER;
 
              touchpoint = xi_find_touch_point (device, xev->detail);
 
-             if (!touchpoint)
+             if (!touchpoint
+                 /* Don't send this event if nothing has changed
+                    either.  */
+                 || (touchpoint->x == (int) xev->event_x
+                     && touchpoint->y == (int) xev->event_y))
                goto XI_OTHER;
 
              touchpoint->x = xev->event_x;
@@ -24475,7 +24491,13 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              x_display_set_last_user_time (dpyinfo, xev->time,
                                            xev->send_event, true);
 
-             if (!device)
+             /* Don't process touch sequences from this device if
+                it's a master pointer.  Touch sequences aren't
+                canceled by the X server if a slave device is
+                detached, and master pointers may also represent
+                dependent touch devices.  */
+
+             if (!device || device->use == XIMasterPointer)
                goto XI_OTHER;
 
              unlinked_p = xi_unlink_touch_point (xev->detail, device);
@@ -24543,7 +24565,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              x_display_set_last_user_time (dpyinfo, pev->time,
                                            pev->send_event, true);
 
-             if (!device)
+             if (!device || device->use != XIMasterPointer)
                goto XI_OTHER;
 
 #ifdef HAVE_XWIDGETS



reply via email to

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