From 8cf0497d29dcb22e3a8f222405aa26b93dd1ba19 Mon Sep 17 00:00:00 2001 From: Antti Korpi Date: Sun, 22 Mar 2020 22:22:33 +0100 Subject: Query for specific XInput2 version This is necessary to guarantee the same API in case future versions of XInput decide to break backward compatibility in their defaults. Quoting `man 3 xiqueryversion`: > Clients are required to use XIQueryVersion instead of > XGetExtensionVersion if they use XI2 calls. The server may treat a > client differently depending on the supported version announced by the > client. --- xkbcat.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/xkbcat.c b/xkbcat.c index d5b87e4..1d3bbee 100644 --- a/xkbcat.c +++ b/xkbcat.c @@ -41,12 +41,22 @@ int main(int argc, char * argv[]) { } // Test for XInput 2 extension - int xiOpcode; - int queryEvent, queryError; + int xiOpcode, queryEvent, queryError; if (! XQueryExtension(disp, "XInputExtension", &xiOpcode, &queryEvent, &queryError)) { - // XXX Test version >=2 - fprintf(stderr, "X Input extension not available\n"); return 1; + fprintf(stderr, "X Input extension not available\n"); + exit(2); + } + { // Request XInput 2.0, guarding against changes in future versions + int major = 2, minor = 0; + int queryResult = XIQueryVersion(disp, &major, &minor); + if (queryResult == BadRequest) { + fprintf(stderr, "Need XI 2.0 support (got %d.%d)\n", major, minor); + exit(3); + } else if (queryResult != Success) { + fprintf(stderr, "Internal error\n"); + exit(4); + } } // Register events -- cgit v1.3-2-g0d8e