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