XIQueryVersion.c revision c27c18e8
1/* 2 * Copyright © 2009 Red Hat, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice (including the next 12 * paragraph) shall be included in all copies or substantial portions of the 13 * Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 * DEALINGS IN THE SOFTWARE. 22 * 23 */ 24 25#include <stdint.h> 26#include <X11/Xlibint.h> 27#include <X11/extensions/XI2proto.h> 28#include <X11/extensions/XInput2.h> 29#include <X11/extensions/extutil.h> 30#include "XIint.h" 31 32Status 33XIQueryVersion(Display *dpy, int *major_inout, int *minor_inout) 34{ 35 int rc = Success; 36 37 XExtDisplayInfo *info = XInput_find_display(dpy); 38 39 LockDisplay(dpy); 40 rc = _xiQueryVersion(dpy, major_inout, minor_inout, info); 41 42 UnlockDisplay(dpy); 43 SyncHandle(); 44 return rc; 45} 46 47_X_HIDDEN Status 48_xiQueryVersion(Display * dpy, int *major, int *minor, XExtDisplayInfo *info) 49{ 50 xXIQueryVersionReq *req; 51 xXIQueryVersionReply rep; 52 53 /* This could mean either a malloc problem, or supported 54 version < XInput_2_0 */ 55 if (_XiCheckExtInit(dpy, XInput_2_0, info) == -1) 56 { 57 XExtensionVersion *ext; 58 XExtDisplayInfo *info = XInput_find_display(dpy); 59 60 if (!info || !info->data) { 61 *major = 0; 62 *minor = 0; 63 UnlockDisplay(dpy); 64 return BadRequest; 65 } 66 67 ext = ((XInputData*)info->data)->vers; 68 69 *major = ext->major_version; 70 *minor = ext->minor_version; 71 return BadRequest; 72 } 73 74 GetReq(XIQueryVersion, req); 75 req->reqType = info->codes->major_opcode; 76 req->ReqType = X_XIQueryVersion; 77 req->major_version = *major; 78 req->minor_version = *minor; 79 80 if (!_XReply(dpy, (xReply*)&rep, 0, xTrue)) { 81 return BadImplementation; 82 } 83 *major = rep.major_version; 84 *minor = rep.minor_version; 85 return Success; 86} 87