diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2008-07-09 16:53:46 +0930 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2008-07-09 17:51:27 +0930 |
commit | 7d5bb99ffce3200f82420c5a5ebac3b445aac633 (patch) | |
tree | 25ff38d672e6167be7cc1e52f3b644485bff2eb3 | |
parent | 908ac35ebb25e2f55945825e6256d1848e17cc38 (diff) |
Add support for input device properties requests.
-rw-r--r-- | include/X11/extensions/XInput.h | 67 | ||||
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/XChDProp.c | 106 | ||||
-rw-r--r-- | src/XConfDProp.c | 76 | ||||
-rw-r--r-- | src/XDelDProp.c | 64 | ||||
-rw-r--r-- | src/XGetDProp.c | 141 | ||||
-rw-r--r-- | src/XListDProp.c | 84 | ||||
-rw-r--r-- | src/XQryDProp.c | 97 |
8 files changed, 641 insertions, 0 deletions
diff --git a/include/X11/extensions/XInput.h b/include/X11/extensions/XInput.h index e30762b..93c9041 100644 --- a/include/X11/extensions/XInput.h +++ b/include/X11/extensions/XInput.h @@ -1449,6 +1449,73 @@ extern Status XExtendedGrabDevice( XGenericEventMask* /* generic_events */ ); +typedef struct { + Bool pending; + Bool range; + Bool immutable; + Bool fromClient; + int num_values; + long *values; +} XIPropertyInfo; + +extern Atom* XListDeviceProperties( + Display* /* dpy */, + XDevice* /* dev */, + int* /* nprops_return */ +); + +extern void XChangeDeviceProperty( + Display* /* dpy */, + XDevice* /* dev */, + Atom /* property */, + Atom /* type */, + int /* format */, + int /* mode */, + _Xconst unsigned char * /*data */, + int /* nelements */ +); + +extern XIPropertyInfo* XQueryDeviceProperty( + Display* /* dpy */, + XDevice* /* dev */, + Atom /* property */ +); + +extern void +XConfigureDeviceProperty( + Display* /* dpy */, + XDevice* /* dev */, + Atom /* property */, + Bool /* pending */, + Bool /* range */, + int /* num_values */, + long* /* values */ +); + +extern void +XDeleteDeviceProperty( + Display* /* dpy */, + XDevice* /* dev */, + Atom /* property */ +); + +extern Status +XGetDeviceProperty( + Display* /* dpy*/, + XDevice* /* dev*/, + Atom /* property*/, + long /* offset*/, + long /* length*/, + Bool /* delete*/, + Bool /* pending*/, + Atom /* req_type*/, + Atom* /* actual_type*/, + int* /* actual_format*/, + unsigned long* /* nitems*/, + unsigned long* /* bytes_after*/, + unsigned char** /* prop*/ +); + _XFUNCPROTOEND #endif /* _XINPUT_H_ */ diff --git a/src/Makefile.am b/src/Makefile.am index b81546f..0a9fb19 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -6,6 +6,7 @@ libXi_la_SOURCES = \ XAllowDv.c \ XChAccRl.c \ XChDevHier.c \ + XChDProp.c \ XChgDCtl.c \ XChgFCtl.c \ XChgKbd.c \ @@ -14,7 +15,9 @@ libXi_la_SOURCES = \ XChgProp.c \ XClrAcc.c \ XCloseDev.c \ + XConfDProp.c \ XDefDevCur.c \ + XDelDProp.c \ XDenyDev.c \ XDevBell.c \ XExtGrabDev.c \ @@ -22,6 +25,7 @@ libXi_la_SOURCES = \ XGetBMap.c \ XGetCPtr.c \ XGetDCtl.c \ + XGetDProp.c \ XGetFCtl.c \ XGetKMap.c \ XGetMMap.c \ @@ -34,9 +38,11 @@ libXi_la_SOURCES = \ XGtFocus.c \ XGtSelect.c \ XListDev.c \ + XListDProp.c \ XOpenDev.c \ XPermDev.c \ XQryAccRl.c \ + XQryDProp.c \ XQueryDv.c \ XQueryDvPtr.c \ XSelect.c \ diff --git a/src/XChDProp.c b/src/XChDProp.c new file mode 100644 index 0000000..c863cdb --- /dev/null +++ b/src/XChDProp.c @@ -0,0 +1,106 @@ +/************************************************************ + +Copyright 2008 Peter Hutterer + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the author shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the author. + +*/ + +/*********************************************************************** + * XChangeDeviceProperties - change an input device's properties. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <X11/Xlibint.h> +#include <X11/extensions/XI.h> +#include <X11/extensions/XIproto.h> +#include <X11/extensions/XInput.h> +#include <X11/extensions/extutil.h> +#include "XIint.h" + +void +XChangeDeviceProperty(Display* dpy, XDevice* dev, + Atom property, Atom type, + int format, int mode, + _Xconst unsigned char *data, int nelements) +{ + xChangeDevicePropertyReq *req; + int len; + + XExtDisplayInfo *info = XInput_find_display(dpy); + + LockDisplay(dpy); + if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) + return; + + GetReq(ChangeDeviceProperty, req); + req->reqType = info->codes->major_opcode; + req->ReqType = X_ChangeDeviceProperty; + req->deviceid = dev->device_id; + req->property = property; + req->type = type; + req->mode = mode; + if (nelements < 0) { + req->nUnits = 0; + req->format = 0; /* ask for garbage, get garbage */ + } else { + req->nUnits = nelements; + req->format = format; + } + + switch (req->format) { + case 8: + len = ((long)nelements + 3) >> 2; + if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { + SetReqLen(req, len, len); + Data (dpy, (char *)data, nelements); + } /* else force BadLength */ + break; + + case 16: + len = ((long)nelements + 1) >> 1; + if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { + SetReqLen(req, len, len); + len = (long)nelements << 1; + Data16 (dpy, (short *) data, len); + } /* else force BadLength */ + break; + + case 32: + len = nelements; + if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { + SetReqLen(req, len, len); + len = (long)nelements << 2; + Data32 (dpy, (long *) data, len); + } /* else force BadLength */ + break; + + default: + /* BadValue will be generated */ ; + } + + UnlockDisplay(dpy); + SyncHandle(); +} + diff --git a/src/XConfDProp.c b/src/XConfDProp.c new file mode 100644 index 0000000..00e1a4b --- /dev/null +++ b/src/XConfDProp.c @@ -0,0 +1,76 @@ +/************************************************************ + +Copyright 2008 Peter Hutterer + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the author shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the author. + +*/ + +/*********************************************************************** + * XConfigureDeviceProperties - delete an input device's properties. + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <X11/Xlibint.h> +#include <X11/extensions/XI.h> +#include <X11/extensions/XIproto.h> +#include <X11/extensions/XInput.h> +#include <X11/extensions/extutil.h> +#include "XIint.h" + +void +XConfigureDeviceProperty(Display* dpy, XDevice* dev, Atom property, + Bool pending, Bool range, + int num_values, long* values) +{ + xConfigureDevicePropertyReq *req; + int len; + + XExtDisplayInfo *info = XInput_find_display(dpy); + + LockDisplay(dpy); + if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) + return; + + GetReq(ConfigureDeviceProperty, req); + req->reqType = info->codes->major_opcode; + req->ReqType = X_ConfigureDeviceProperty; + req->deviceid = dev->device_id; + req->property = property; + req->range = range; + req->pending = pending; + + len = num_values; + if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { + SetReqLen(req, len, len); + len = (long)num_values << 2; + Data32 (dpy, values, len); + } /* else force BadLength */ + + UnlockDisplay(dpy); + SyncHandle(); + return; +} + diff --git a/src/XDelDProp.c b/src/XDelDProp.c new file mode 100644 index 0000000..d6594c4 --- /dev/null +++ b/src/XDelDProp.c @@ -0,0 +1,64 @@ +/************************************************************ + +Copyright 2008 Peter Hutterer + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the author shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the author. + +*/ + +/*********************************************************************** + * XDeleteDeviceProperties - delete an input device's properties. + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <X11/Xlibint.h> +#include <X11/extensions/XI.h> +#include <X11/extensions/XIproto.h> +#include <X11/extensions/XInput.h> +#include <X11/extensions/extutil.h> +#include "XIint.h" + +void +XDeleteDeviceProperty(Display* dpy, XDevice* dev, Atom property) +{ + xDeleteDevicePropertyReq *req; + + XExtDisplayInfo *info = XInput_find_display(dpy); + + LockDisplay(dpy); + if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) + return; + + GetReq(DeleteDeviceProperty, req); + req->reqType = info->codes->major_opcode; + req->ReqType = X_DeleteDeviceProperty; + req->deviceid = dev->device_id; + req->property = property; + + UnlockDisplay(dpy); + SyncHandle(); + return; +} + diff --git a/src/XGetDProp.c b/src/XGetDProp.c new file mode 100644 index 0000000..909e9d2 --- /dev/null +++ b/src/XGetDProp.c @@ -0,0 +1,141 @@ +/************************************************************ + +Copyright 2008 Peter Hutterer + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the author shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the author. + +*/ + +/*********************************************************************** + * XGetDeviceProperties - get an input device's properties. + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <X11/Xlibint.h> +#include <X11/extensions/XI.h> +#include <X11/extensions/XIproto.h> +#include <X11/extensions/XInput.h> +#include <X11/extensions/extutil.h> +#include "XIint.h" + +int +XGetDeviceProperty(Display* dpy, XDevice* dev, + Atom property, long offset, long length, Bool delete, + Bool pending, Atom req_type, + Atom *actual_type, int *actual_format, + unsigned long *nitems, unsigned long *bytes_after, + unsigned char **prop) +{ + xGetDevicePropertyReq *req; + xGetDevicePropertyReply rep; + long nbytes, rbytes; + + XExtDisplayInfo *info = XInput_find_display(dpy); + + LockDisplay(dpy); + if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) + return 1; + + GetReq(GetDeviceProperty, req); + req->reqType = info->codes->major_opcode; + req->ReqType = X_GetDeviceProperty; + req->deviceid = dev->device_id; + req->property = property; + req->type = req_type; + req->longOffset = offset; + req->longLength = length; + req->delete = delete; + req->pending = pending; + + if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) + { + UnlockDisplay (dpy); + SyncHandle (); + return 1; + } + + *prop = (unsigned char *) NULL; + + if (rep.propertyType != None) { + /* + * One extra byte is malloced than is needed to contain the property + * data, but this last byte is null terminated and convenient for + * returning string properties, so the client doesn't then have to + * recopy the string to make it null terminated. + */ + switch (rep.format) { + case 8: + nbytes = rep.nItems; + rbytes = rep.nItems + 1; + if (rbytes > 0 && + (*prop = (unsigned char *) Xmalloc ((unsigned)rbytes))) + _XReadPad (dpy, (char *) *prop, nbytes); + break; + + case 16: + nbytes = rep.nItems << 1; + rbytes = rep.nItems * sizeof (short) + 1; + if (rbytes > 0 && + (*prop = (unsigned char *) Xmalloc ((unsigned)rbytes))) + _XRead16Pad (dpy, (short *) *prop, nbytes); + break; + + case 32: + nbytes = rep.nItems << 2; + rbytes = rep.nItems * sizeof (long) + 1; + if (rbytes > 0 && + (*prop = (unsigned char *) Xmalloc ((unsigned)rbytes))) + _XRead32 (dpy, (long *) *prop, nbytes); + break; + + default: + /* + * This part of the code should never be reached. If it is, + * the server sent back a property with an invalid format. + */ + nbytes = rep.length << 2; + _XEatData(dpy, (unsigned long) nbytes); + UnlockDisplay(dpy); + SyncHandle(); + return(BadImplementation); + } + if (! *prop) { + _XEatData(dpy, (unsigned long) nbytes); + UnlockDisplay(dpy); + SyncHandle(); + return(BadAlloc); + } + (*prop)[rbytes - 1] = '\0'; + } + + *actual_type = rep.propertyType; + *actual_format = rep.format; + *nitems = rep.nItems; + *bytes_after = rep.bytesAfter; + UnlockDisplay (dpy); + SyncHandle (); + + return Success; +} + diff --git a/src/XListDProp.c b/src/XListDProp.c new file mode 100644 index 0000000..aee2737 --- /dev/null +++ b/src/XListDProp.c @@ -0,0 +1,84 @@ +/************************************************************ + +Copyright 2008 Peter Hutterer + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the author shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the author. + +*/ + +/*********************************************************************** + * XListDeviceProperties - List an input device's properties. + */ + + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <X11/Xlibint.h> +#include <X11/extensions/XI.h> +#include <X11/extensions/XIproto.h> +#include <X11/extensions/XInput.h> +#include <X11/extensions/extutil.h> +#include "XIint.h" + +Atom* +XListDeviceProperties(Display* dpy, XDevice* dev, int *nprops_return) +{ + xListDevicePropertiesReq *req; + xListDevicePropertiesReply rep; + XExtDisplayInfo *info = XInput_find_display(dpy); + Atom *props = NULL; + + LockDisplay(dpy); + if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) + return (NoSuchExtension); + + GetReq(ListDeviceProperties, req); + req->reqType = info->codes->major_opcode; + req->ReqType = X_ListDeviceProperties; + req->deviceid = dev->device_id; + + if (!_XReply(dpy, (xReply*)&rep, 0, xFalse)) { + *nprops_return = 0; + goto cleanup; + } + + *nprops_return = rep.nAtoms; + + if (rep.nAtoms) { + props = (Atom*)Xmalloc(rep.nAtoms * sizeof(Atom)); + if (!props) + { + _XEatData(dpy, rep.nAtoms << 2); + *nprops_return = 0; + goto cleanup; + } + + _XRead32(dpy, props, rep.nAtoms << 2); + } + +cleanup: + UnlockDisplay(dpy); + SyncHandle(); + return props; +} + diff --git a/src/XQryDProp.c b/src/XQryDProp.c new file mode 100644 index 0000000..0ac7227 --- /dev/null +++ b/src/XQryDProp.c @@ -0,0 +1,97 @@ +/************************************************************ + +Copyright 2008 Peter Hutterer + +Permission to use, copy, modify, distribute, and sell this software and its +documentation for any purpose is hereby granted without fee, provided that +the above copyright notice appear in all copies and that both that +copyright notice and this permission notice appear in supporting +documentation. + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +Except as contained in this notice, the name of the author shall not be +used in advertising or otherwise to promote the sale, use or other dealings +in this Software without prior written authorization from the author. + +*/ + +/*********************************************************************** + * XQueryDeviceProperties - query an input device's properties. + * + */ + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +#include <X11/Xlibint.h> +#include <X11/extensions/XI.h> +#include <X11/extensions/XIproto.h> +#include <X11/extensions/XInput.h> +#include <X11/extensions/extutil.h> +#include "XIint.h" + +XIPropertyInfo* +XQueryDeviceProperty(Display* dpy, XDevice* dev, Atom property) +{ + xQueryDevicePropertyReq *req; + xQueryDevicePropertyReply rep; + int len; + int rbytes, nbytes; + XIPropertyInfo *prop_info; + + XExtDisplayInfo *info = XInput_find_display(dpy); + + LockDisplay(dpy); + if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) + return NULL; + + GetReq(QueryDeviceProperty, req); + req->reqType = info->codes->major_opcode; + req->ReqType = X_QueryDeviceProperty; + req->deviceid = dev->device_id; + req->property = property; + + if (!_XReply(dpy, (xReply*)&rep, 0, xFalse)) { + UnlockDisplay(dpy); + SyncHandle(); + return NULL; + } + + rbytes = sizeof (XIPropertyInfo) + rep.length * sizeof (long); + nbytes = rep.length << 2; + + prop_info = (XIPropertyInfo*) Xmalloc (rbytes); + if (prop_info == NULL) { + _XEatData (dpy, nbytes); + UnlockDisplay (dpy); + SyncHandle (); + return NULL; + } + + prop_info->pending = rep.pending; + prop_info->range = rep.range; + prop_info->immutable = rep.immutable; + prop_info->fromClient = rep.fromClient; + prop_info->num_values = rep.length; + if (rep.length != 0) { + prop_info->values = (long *) (prop_info + 1); + _XRead32 (dpy, prop_info->values, nbytes); + } else { + prop_info->values = NULL; + } + + UnlockDisplay(dpy); + SyncHandle(); + return prop_info; +} + |