emacs-diffs
[Top][All Lists]
Advanced

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

master c914572a46 1/3: Improve XInput2 version checking


From: Po Lu
Subject: master c914572a46 1/3: Improve XInput2 version checking
Date: Tue, 22 Feb 2022 05:48:14 -0500 (EST)

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

    Improve XInput2 version checking
    
    * configure.ac: Check for various important structures from all
    versions of libXi.
    
    * src/xfns.c (setup_xi_event_mask):
    * src/xwidget.c (x_draw_xwidget_glyph_string):
    * src/xterm.c (x_init_master_valuators, handle_one_xevent)
    (x_term_init): Replace XI version checks based on protocol
    headers with new constants.
    
    * src/xterm.h (HAVE_XINPUT2_1, HAVE_XINPUT2_2, HAVE_XINPUT2_3)
    (HAVE_XINPUT2_4): New definitions.
---
 configure.ac  | 14 +++++++-------
 src/xfns.c    |  4 ++--
 src/xterm.c   | 35 +++++++++++++++++++----------------
 src/xterm.h   | 19 +++++++++++++++++++
 src/xwidget.c |  2 +-
 5 files changed, 48 insertions(+), 26 deletions(-)

diff --git a/configure.ac b/configure.ac
index 945e2ff8d4..00711cccd5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4478,13 +4478,13 @@ if test "${HAVE_X11}" = "yes" && test "${with_xinput2}" 
!= "no"; then
        AC_MSG_WARN([You are building Emacs with GTK+ 2 and the X Input 
Extension version 2.
 This might lead to problems if your version of GTK+ is not built with support 
for XInput 2.])
      fi
-     # Detect both faulty installations of libXi where gesture event
-     # types are defined but gesture event structures are not, and
-     # also where gesture event structures are empty.
-     AC_CHECK_MEMBERS([XIGesturePinchEvent.delta_unaccel_y],
-       [AC_DEFINE(HAVE_USABLE_XI_GESTURE_PINCH_EVENT, 1,
-         [Define to 1 if XInput headers define gesture structures 
correctly.])],
-       [], [[#include <X11/extensions/XInput2.h>]])
+
+     # Now check for some members (which used in conjunction with
+     # protocol definitions) can be used to determine the version of
+     # XInput supported.
+     AC_CHECK_MEMBERS([XIScrollClassInfo.type, XITouchClassInfo.type,
+       XIBarrierReleasePointerInfo.deviceid, XIGestureClassInfo.type],
+       [], [], [#include <X11/extensions/XInput2.h>])
    fi
 fi
 AC_SUBST(XINPUT_CFLAGS)
diff --git a/src/xfns.c b/src/xfns.c
index b0e7af9d8f..9afadd16e9 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -3565,13 +3565,13 @@ setup_xi_event_mask (struct frame *f)
   XISetMask (m, XI_PropertyEvent);
   XISetMask (m, XI_HierarchyChanged);
   XISetMask (m, XI_DeviceChanged);
-#ifdef XI_TouchBegin
+#ifdef HAVE_XINPUT2_2
   if (FRAME_DISPLAY_INFO (f)->xi2_version >= 2)
     {
       XISetMask (m, XI_TouchBegin);
       XISetMask (m, XI_TouchUpdate);
       XISetMask (m, XI_TouchEnd);
-#ifdef XI_GesturePinchBegin
+#ifdef HAVE_XINPUT2_4
       if (FRAME_DISPLAY_INFO (f)->xi2_version >= 4)
        {
          XISetMask (m, XI_GesturePinchBegin);
diff --git a/src/xterm.c b/src/xterm.c
index dce0bf306a..23721352f3 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -629,7 +629,7 @@ x_init_master_valuators (struct x_display_info *dpyinfo)
            {
              switch (device->classes[c]->type)
                {
-#ifdef XIScrollClass /* XInput 2.1 */
+#ifdef HAVE_XINPUT2_1
                case XIScrollClass:
                  {
                    XIScrollClassInfo *info =
@@ -648,7 +648,7 @@ x_init_master_valuators (struct x_display_info *dpyinfo)
                    break;
                  }
 #endif
-#ifdef XITouchClass /* XInput 2.2 */
+#ifdef HAVE_XINPUT2_2
                case XITouchClass:
                  {
                    XITouchClassInfo *info;
@@ -739,7 +739,7 @@ xi_device_from_id (struct x_display_info *dpyinfo, int 
deviceid)
   return NULL;
 }
 
-#ifdef XI_TouchBegin
+#ifdef HAVE_XINPUT2_2
 
 static void
 xi_link_touch_point (struct xi_device_t *device,
@@ -11046,7 +11046,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              if (!device)
                goto XI_OTHER;
 
-#ifdef XI_TouchBegin
+#ifdef HAVE_XINPUT2_2
              if (xev->flags & XIPointerEmulated)
                goto XI_OTHER;
 #endif
@@ -11929,7 +11929,10 @@ handle_one_xevent (struct x_display_info *dpyinfo,
            {
              struct xi_device_t *device;
              struct xi_touch_point_t *tem, *last;
-             int c, i;
+             int c;
+#ifdef HAVE_XINPUT2_1
+             int i;
+#endif
 
              device = xi_device_from_id (dpyinfo, device_changed->deviceid);
 
@@ -11959,7 +11962,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                {
                  switch (device_changed->classes[c]->type)
                    {
-#ifdef XIScrollClass
+#ifdef HAVE_XINPUT2_1
                    case XIScrollClass:
                      {
                        XIScrollClassInfo *info;
@@ -11979,7 +11982,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                      }
 #endif
 
-#ifdef XITouchClass
+#ifdef HAVE_XINPUT2_2
                    case XITouchClass:
                      {
                        XITouchClassInfo *info;
@@ -11993,7 +11996,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                    }
                }
 
-#ifdef XIScrollClass
+#ifdef HAVE_XINPUT2_1
              for (c = 0; c < device_changed->num_classes; ++c)
                {
                  if (device_changed->classes[c]->type == XIValuatorClass)
@@ -12043,7 +12046,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
              goto XI_OTHER;
            }
 
-#ifdef XI_TouchBegin
+#ifdef HAVE_XINPUT2_2
          case XI_TouchBegin:
            {
              struct xi_device_t *device;
@@ -12205,13 +12208,13 @@ handle_one_xevent (struct x_display_info *dpyinfo,
            }
 
 #endif
-#ifdef XI_GesturePinchBegin
+
+#ifdef HAVE_XINPUT2_4
          case XI_GesturePinchBegin:
          case XI_GesturePinchUpdate:
            {
              x_display_set_last_user_time (dpyinfo, xi_event->time);
 
-#ifdef HAVE_USABLE_XI_GESTURE_PINCH_EVENT
              XIGesturePinchEvent *pev = (XIGesturePinchEvent *) xi_event;
              struct xi_device_t *device = xi_device_from_id (dpyinfo, 
pev->deviceid);
 
@@ -12243,7 +12246,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                                       make_float (pev->scale),
                                       make_float (pev->delta_angle));
                }
-#endif
+
              /* Once again GTK seems to crash when confronted by
                 events it doesn't understand.  */
              *finish = X_EVENT_DROP;
@@ -16261,13 +16264,13 @@ x_term_init (Lisp_Object display_name, char 
*xrm_option, char *resource_name)
   dpyinfo->supports_xi2 = false;
   int rc;
   int major = 2;
-#ifdef XI_GesturePinchBegin /* XInput 2.4 */
+#ifdef HAVE_XINPUT2_4
   int minor = 4;
-#elif XI_BarrierHit /* XInput 2.3 */
+#elif defined HAVE_XINPUT2_3 /* XInput 2.3 */
   int minor = 3;
-#elif defined XI_TouchBegin /* XInput 2.2 */
+#elif defined HAVE_XINPUT2_2 /* XInput 2.2 */
   int minor = 2;
-#elif defined XIScrollClass /* XInput 2.1 */
+#elif defined HAVE_XINPUT2_1 /* XInput 2.1 */
   int minor = 1;
 #else /* Some old version of XI2 we're not interested in. */
   int minor = 0;
diff --git a/src/xterm.h b/src/xterm.h
index 14457b32cc..e2256ce2df 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -42,6 +42,10 @@ along with GNU Emacs.  If not, see 
<https://www.gnu.org/licenses/>.  */
 #include <X11/Xmu/Editres.h>
 #endif
 
+#ifdef HAVE_XINPUT2
+#include <X11/extensions/XInput2.h>
+#endif
+
 typedef Widget xt_or_gtk_widget;
 #endif
 
@@ -1465,6 +1469,21 @@ struct xi_device_t *xi_device_from_id (struct 
x_display_info *, int);
    (nr).width = (rwidth),                              \
    (nr).height = (rheight))
 
+#ifdef HAVE_XINPUT2
+#if HAVE_XISCROLLCLASSINFO_TYPE && defined XIScrollClass
+#define HAVE_XINPUT2_1
+#endif
+#if HAVE_XITOUCHCLASSINFO_TYPE && defined XITouchClass
+#define HAVE_XINPUT2_2
+#endif
+#if HAVE_XIBARRIERRELEASEPOINTERINFO_DEVICEID && defined 
XIBarrierPointerReleased
+#define HAVE_XINPUT2_3
+#endif
+#if HAVE_XIGESTURECLASSINFO_TYPE && defined XIGestureClass
+#define HAVE_XINPUT2_4
+#endif
+#endif
+
 INLINE_HEADER_END
 
 #endif /* XTERM_H */
diff --git a/src/xwidget.c b/src/xwidget.c
index 9fbf6678ae..e812b13f23 100644
--- a/src/xwidget.c
+++ b/src/xwidget.c
@@ -2853,7 +2853,7 @@ x_draw_xwidget_glyph_string (struct glyph_string *s)
          XISetMask (m, XI_ButtonRelease);
          XISetMask (m, XI_Enter);
          XISetMask (m, XI_Leave);
-#ifdef XI_GesturePinchBegin
+#ifdef HAVE_XINPUT2_4
          if (FRAME_DISPLAY_INFO (s->f)->xi2_version >= 4)
            {
              XISetMask (m, XI_GesturePinchBegin);



reply via email to

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