XGMotion.c revision 21e67964
1c43cc173Smrg/* $Xorg: XGMotion.c,v 1.4 2001/02/09 02:03:50 xorgcvs Exp $ */ 2c43cc173Smrg 3c43cc173Smrg/************************************************************ 4c43cc173Smrg 5c43cc173SmrgCopyright 1989, 1998 The Open Group 6c43cc173Smrg 7c43cc173SmrgPermission to use, copy, modify, distribute, and sell this software and its 8c43cc173Smrgdocumentation for any purpose is hereby granted without fee, provided that 9c43cc173Smrgthe above copyright notice appear in all copies and that both that 10c43cc173Smrgcopyright notice and this permission notice appear in supporting 11c43cc173Smrgdocumentation. 12c43cc173Smrg 13c43cc173SmrgThe above copyright notice and this permission notice shall be included in 14c43cc173Smrgall copies or substantial portions of the Software. 15c43cc173Smrg 16c43cc173SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17c43cc173SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18c43cc173SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19c43cc173SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20c43cc173SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21c43cc173SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22c43cc173Smrg 23c43cc173SmrgExcept as contained in this notice, the name of The Open Group shall not be 24c43cc173Smrgused in advertising or otherwise to promote the sale, use or other dealings 25c43cc173Smrgin this Software without prior written authorization from The Open Group. 26c43cc173Smrg 27c43cc173SmrgCopyright 1989 by Hewlett-Packard Company, Palo Alto, California. 28c43cc173Smrg 29c43cc173Smrg All Rights Reserved 30c43cc173Smrg 31c43cc173SmrgPermission to use, copy, modify, and distribute this software and its 32c43cc173Smrgdocumentation for any purpose and without fee is hereby granted, 33c43cc173Smrgprovided that the above copyright notice appear in all copies and that 34c43cc173Smrgboth that copyright notice and this permission notice appear in 35c43cc173Smrgsupporting documentation, and that the name of Hewlett-Packard not be 36c43cc173Smrgused in advertising or publicity pertaining to distribution of the 37c43cc173Smrgsoftware without specific, written prior permission. 38c43cc173Smrg 39c43cc173SmrgHEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 40c43cc173SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 41c43cc173SmrgHEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 42c43cc173SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 43c43cc173SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 44c43cc173SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 45c43cc173SmrgSOFTWARE. 46c43cc173Smrg 47c43cc173Smrg********************************************************/ 48c43cc173Smrg/* $XFree86: xc/lib/Xi/XGMotion.c,v 3.3 2001/12/14 19:55:12 dawes Exp $ */ 49c43cc173Smrg 50c43cc173Smrg/*********************************************************************** 51c43cc173Smrg * 52c43cc173Smrg * XGetDeviceMotionEvents - Get the motion history of an input device. 53c43cc173Smrg * 54c43cc173Smrg */ 55c43cc173Smrg 56c43cc173Smrg#include <X11/extensions/XI.h> 57c43cc173Smrg#include <X11/extensions/XIproto.h> 58c43cc173Smrg#include <X11/Xlibint.h> 59c43cc173Smrg#include <X11/extensions/XInput.h> 60c43cc173Smrg#include <X11/extensions/extutil.h> 61c43cc173Smrg#include "XIint.h" 62c43cc173Smrg 63c43cc173SmrgXDeviceTimeCoord 64c43cc173Smrg * XGetDeviceMotionEvents(dpy, dev, start, stop, nEvents, mode, axis_count) 65c43cc173Smrg register Display * 66c43cc173Smrg dpy; 67c43cc173Smrg XDevice * 68c43cc173Smrg dev; 69c43cc173Smrg 70c43cc173SmrgTime start; 71c43cc173SmrgTime stop; 72c43cc173Smrg int * 73c43cc173Smrg nEvents; 74c43cc173Smrg int * 75c43cc173Smrg mode; 76c43cc173Smrg int * 77c43cc173Smrg axis_count; 78c43cc173Smrg{ 79c43cc173Smrg xGetDeviceMotionEventsReq *req; 80c43cc173Smrg xGetDeviceMotionEventsReply rep; 81c43cc173Smrg XDeviceTimeCoord *tc; 82c43cc173Smrg int *data, *bufp, *readp, *savp; 83c43cc173Smrg long size, size2; 84c43cc173Smrg int i, j; 85c43cc173Smrg XExtDisplayInfo *info = XInput_find_display(dpy); 86c43cc173Smrg 87c43cc173Smrg LockDisplay(dpy); 88c43cc173Smrg if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1) 89c43cc173Smrg return ((XDeviceTimeCoord *) NoSuchExtension); 90c43cc173Smrg 91c43cc173Smrg GetReq(GetDeviceMotionEvents, req); 92c43cc173Smrg req->reqType = info->codes->major_opcode; 93c43cc173Smrg req->ReqType = X_GetDeviceMotionEvents; 94c43cc173Smrg req->start = start; 95c43cc173Smrg req->stop = stop; 96c43cc173Smrg req->deviceid = dev->device_id; 97c43cc173Smrg 98c43cc173Smrg if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) { 99c43cc173Smrg UnlockDisplay(dpy); 100c43cc173Smrg SyncHandle(); 101c43cc173Smrg *nEvents = 0; 102c43cc173Smrg return (NULL); 103c43cc173Smrg } 104c43cc173Smrg 105c43cc173Smrg *mode = rep.mode; 106c43cc173Smrg *axis_count = rep.axes; 107c43cc173Smrg *nEvents = rep.nEvents; 108c43cc173Smrg if (!rep.nEvents) { 109c43cc173Smrg UnlockDisplay(dpy); 110c43cc173Smrg SyncHandle(); 111c43cc173Smrg return (NULL); 112c43cc173Smrg } 113c43cc173Smrg size = rep.length << 2; 114c43cc173Smrg size2 = rep.nEvents * (sizeof(XDeviceTimeCoord) + (rep.axes * sizeof(int))); 115c43cc173Smrg savp = readp = (int *)Xmalloc(size); 116c43cc173Smrg bufp = (int *)Xmalloc(size2); 117c43cc173Smrg if (!bufp || !savp) { 11821e67964Smrg Xfree(bufp); 11921e67964Smrg Xfree(savp); 120c43cc173Smrg *nEvents = 0; 121c43cc173Smrg _XEatData(dpy, (unsigned long)size); 122c43cc173Smrg UnlockDisplay(dpy); 123c43cc173Smrg SyncHandle(); 124c43cc173Smrg return (NULL); 125c43cc173Smrg } 126c43cc173Smrg _XRead(dpy, (char *)readp, size); 127c43cc173Smrg 128c43cc173Smrg tc = (XDeviceTimeCoord *) bufp; 129c43cc173Smrg data = (int *)(tc + rep.nEvents); 130c43cc173Smrg for (i = 0; i < *nEvents; i++, tc++) { 131c43cc173Smrg tc->time = *readp++; 132c43cc173Smrg tc->data = data; 133c43cc173Smrg for (j = 0; j < *axis_count; j++) 134c43cc173Smrg *data++ = *readp++; 135c43cc173Smrg } 136c43cc173Smrg XFree((char *)savp); 137c43cc173Smrg UnlockDisplay(dpy); 138c43cc173Smrg SyncHandle(); 139c43cc173Smrg return ((XDeviceTimeCoord *) bufp); 140c43cc173Smrg} 141c43cc173Smrg 142c43cc173Smrgvoid 143c43cc173SmrgXFreeDeviceMotionEvents(events) 144c43cc173Smrg XDeviceTimeCoord *events; 145c43cc173Smrg{ 146c43cc173Smrg XFree((char *)events); 147c43cc173Smrg} 148