]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix X errors caused by GTK using newer versions of XI2 than Emacs
authorPo Lu <luangruo@yahoo.com>
Wed, 23 Feb 2022 00:56:06 +0000 (08:56 +0800)
committerPo Lu <luangruo@yahoo.com>
Wed, 23 Feb 2022 00:56:06 +0000 (08:56 +0800)
* src/xterm.c (x_term_init): Handle errors from XIQueryVersion
caused by Emacs requesting versions of XI2 older than 2.2 and
what GTK requested.

src/xterm.c

index 23721352f3cdf9800759a3a3bd5a8f75ea6e88d4..fffa40840ab05c29bb03fc4d150549ee22ebe1c9 100644 (file)
@@ -16264,6 +16264,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
   dpyinfo->supports_xi2 = false;
   int rc;
   int major = 2;
+  int xi_first_event, xi_first_error;
+
 #ifdef HAVE_XINPUT2_4
   int minor = 4;
 #elif defined HAVE_XINPUT2_3 /* XInput 2.3 */
@@ -16275,12 +16277,39 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
 #else /* Some old version of XI2 we're not interested in. */
   int minor = 0;
 #endif
-  int fer, fee;
 
   if (XQueryExtension (dpyinfo->display, "XInputExtension",
-                      &dpyinfo->xi2_opcode, &fer, &fee))
+                      &dpyinfo->xi2_opcode, &xi_first_event,
+                      &xi_first_error))
     {
+#ifdef HAVE_GTK3
+    query:
+      /* Catch errors caused by GTK requesting a different version of
+        XInput 2 than what Emacs was built with.  */
+      x_catch_errors (dpyinfo->display);
+#endif
+
       rc = XIQueryVersion (dpyinfo->display, &major, &minor);
+
+#ifdef HAVE_GTK3
+      if (x_had_errors_p (dpyinfo->display))
+       {
+         /* Some unreasonable value that will probably not be
+            exceeded in the future.  */
+         if (minor > 100)
+           rc = BadRequest;
+         else
+           {
+             /* Increase the minor version until we find one the X server
+                agrees with.  */
+             minor++;
+             goto query;
+           }
+       }
+
+      x_uncatch_errors ();
+#endif
+
       if (rc == Success)
        {
          dpyinfo->supports_xi2 = true;