1 /************************************************************
3 Copyright 2008 Peter Hutterer
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of the author shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from the author.
27 /***********************************************************************
28 * XGetDeviceProperties - get an input device's properties.
35 #include <X11/Xlibint.h>
36 #include <X11/extensions/XI.h>
37 #include <X11/extensions/XIproto.h>
38 #include <X11/extensions/XInput.h>
39 #include <X11/extensions/extutil.h>
43 XGetDeviceProperty(Display* dpy, XDevice* dev,
44 Atom property, long offset, long length, Bool delete,
45 Atom req_type, Atom *actual_type, int *actual_format,
46 unsigned long *nitems, unsigned long *bytes_after,
49 xGetDevicePropertyReq *req;
50 xGetDevicePropertyReply rep;
53 XExtDisplayInfo *info = XInput_find_display(dpy);
56 if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
59 GetReq(GetDeviceProperty, req);
60 req->reqType = info->codes->major_opcode;
61 req->ReqType = X_GetDeviceProperty;
62 req->deviceid = dev->device_id;
63 req->property = property;
65 req->longOffset = offset;
66 req->longLength = length;
69 if (!_XReply (dpy, (xReply *) &rep, 0, xFalse))
76 *prop = (unsigned char *) NULL;
78 if (rep.propertyType != None) {
80 * One extra byte is malloced than is needed to contain the property
81 * data, but this last byte is null terminated and convenient for
82 * returning string properties, so the client doesn't then have to
83 * recopy the string to make it null terminated.
88 rbytes = rep.nItems + 1;
90 (*prop = (unsigned char *) Xmalloc ((unsigned)rbytes)))
91 _XReadPad (dpy, (char *) *prop, nbytes);
95 nbytes = rep.nItems << 1;
96 rbytes = rep.nItems * sizeof (short) + 1;
98 (*prop = (unsigned char *) Xmalloc ((unsigned)rbytes)))
99 _XRead16Pad (dpy, (short *) *prop, nbytes);
103 nbytes = rep.nItems << 2;
104 rbytes = rep.nItems * sizeof (long) + 1;
106 (*prop = (unsigned char *) Xmalloc ((unsigned)rbytes)))
107 _XRead32 (dpy, (long *) *prop, nbytes);
112 * This part of the code should never be reached. If it is,
113 * the server sent back a property with an invalid format.
115 nbytes = rep.length << 2;
116 _XEatData(dpy, (unsigned long) nbytes);
119 return(BadImplementation);
122 _XEatData(dpy, (unsigned long) nbytes);
127 (*prop)[rbytes - 1] = '\0';
130 *actual_type = rep.propertyType;
131 *actual_format = rep.format;
132 *nitems = rep.nItems;
133 *bytes_after = rep.bytesAfter;