121e67964Smrg/************************************************************ 221e67964Smrg 321e67964SmrgCopyright 2008 Peter Hutterer 421e67964Smrg 521e67964SmrgPermission to use, copy, modify, distribute, and sell this software and its 621e67964Smrgdocumentation for any purpose is hereby granted without fee, provided that 721e67964Smrgthe above copyright notice appear in all copies and that both that 821e67964Smrgcopyright notice and this permission notice appear in supporting 921e67964Smrgdocumentation. 1021e67964Smrg 1121e67964SmrgThe above copyright notice and this permission notice shall be included in 1221e67964Smrgall copies or substantial portions of the Software. 1321e67964Smrg 1421e67964SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1521e67964SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1621e67964SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1721e67964SmrgAUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1821e67964SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1921e67964SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2021e67964Smrg 2121e67964SmrgExcept as contained in this notice, the name of the author shall not be 2221e67964Smrgused in advertising or otherwise to promote the sale, use or other dealings 2321e67964Smrgin this Software without prior written authorization from the author. 2421e67964Smrg 2521e67964Smrg*/ 2621e67964Smrg 2721e67964Smrg/*********************************************************************** 2821e67964Smrg * XChangeDeviceProperties - change an input device's properties. 2921e67964Smrg */ 3021e67964Smrg 3121e67964Smrg#ifdef HAVE_CONFIG_H 3221e67964Smrg#include <config.h> 3321e67964Smrg#endif 3421e67964Smrg 3521e67964Smrg#include <X11/Xlibint.h> 3621e67964Smrg#include <X11/extensions/XI.h> 3721e67964Smrg#include <X11/extensions/XIproto.h> 3821e67964Smrg#include <X11/extensions/XInput.h> 3921e67964Smrg#include <X11/extensions/extutil.h> 4021e67964Smrg#include "XIint.h" 4121e67964Smrg 4221e67964Smrgvoid 4321e67964SmrgXChangeDeviceProperty(Display* dpy, XDevice* dev, 4421e67964Smrg Atom property, Atom type, 4521e67964Smrg int format, int mode, 4621e67964Smrg _Xconst unsigned char *data, int nelements) 4721e67964Smrg{ 4821e67964Smrg xChangeDevicePropertyReq *req; 4921e67964Smrg int len; 5021e67964Smrg 5121e67964Smrg XExtDisplayInfo *info = XInput_find_display(dpy); 5221e67964Smrg 5321e67964Smrg LockDisplay(dpy); 5421e67964Smrg if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) 5521e67964Smrg return; 5621e67964Smrg 5721e67964Smrg GetReq(ChangeDeviceProperty, req); 5821e67964Smrg req->reqType = info->codes->major_opcode; 5921e67964Smrg req->ReqType = X_ChangeDeviceProperty; 6021e67964Smrg req->deviceid = dev->device_id; 6121e67964Smrg req->property = property; 6221e67964Smrg req->type = type; 6321e67964Smrg req->mode = mode; 6421e67964Smrg if (nelements < 0) { 6521e67964Smrg req->nUnits = 0; 6621e67964Smrg req->format = 0; /* ask for garbage, get garbage */ 6721e67964Smrg } else { 6821e67964Smrg req->nUnits = nelements; 6921e67964Smrg req->format = format; 7021e67964Smrg } 7121e67964Smrg 7221e67964Smrg switch (req->format) { 7321e67964Smrg case 8: 7421e67964Smrg len = ((long)nelements + 3) >> 2; 7521e67964Smrg if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { 7621e67964Smrg SetReqLen(req, len, len); 7744584a44Smrg Data (dpy, (_Xconst char *)data, nelements); 7821e67964Smrg } /* else force BadLength */ 7921e67964Smrg break; 8021e67964Smrg 8121e67964Smrg case 16: 8221e67964Smrg len = ((long)nelements + 1) >> 1; 8321e67964Smrg if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { 8421e67964Smrg SetReqLen(req, len, len); 8521e67964Smrg len = (long)nelements << 1; 8644584a44Smrg Data16 (dpy, (_Xconst short *) data, len); 8721e67964Smrg } /* else force BadLength */ 8821e67964Smrg break; 8921e67964Smrg 9021e67964Smrg case 32: 9121e67964Smrg len = nelements; 9221e67964Smrg if (dpy->bigreq_size || req->length + len <= (unsigned) 65535) { 9321e67964Smrg SetReqLen(req, len, len); 9421e67964Smrg len = (long)nelements << 2; 9544584a44Smrg Data32 (dpy, (_Xconst long *) data, len); 9621e67964Smrg } /* else force BadLength */ 9721e67964Smrg break; 9821e67964Smrg 9921e67964Smrg default: 10021e67964Smrg /* BadValue will be generated */ ; 10121e67964Smrg } 10221e67964Smrg 10321e67964Smrg UnlockDisplay(dpy); 10421e67964Smrg SyncHandle(); 10521e67964Smrg} 10621e67964Smrg 107