From: Po Lu Date: Wed, 23 Feb 2022 00:56:06 +0000 (+0800) Subject: Fix X errors caused by GTK using newer versions of XI2 than Emacs X-Git-Tag: emacs-29.0.90~2151 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=1f00710ecfac12de12f4a2046b9b66802b8ffac6;p=emacs.git 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. --- 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;