summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-02-23 08:56:06 +0800
committerPo Lu <luangruo@yahoo.com>2022-02-23 08:56:06 +0800
commit1f00710ecfac12de12f4a2046b9b66802b8ffac6 (patch)
tree49ba5903aefdc330f7f47a0ddfd9d71a98c247a6
parentc20e96d186618e7f644188a7f71d5dcb6fa4eaf1 (diff)
downloademacs-1f00710ecfac12de12f4a2046b9b66802b8ffac6.tar.gz
Fix X errors caused by GTK using newer versions of XI2 than Emacs
* 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.
-rw-r--r--src/xterm.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 23721352f3c..fffa40840ab 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -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;