XChgDCtl.c revision c43cc173
1c43cc173Smrg/* $Xorg: XChgDCtl.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/XChgDCtl.c,v 3.3 2001/12/14 19:55:03 dawes Exp $ */ 49c43cc173Smrg 50c43cc173Smrg/*********************************************************************** 51c43cc173Smrg * 52c43cc173Smrg * XChangeDeviceControl - Change the control attributes of an extension 53c43cc173Smrg * input device. 54c43cc173Smrg * 55c43cc173Smrg */ 56c43cc173Smrg 57c43cc173Smrg#include <X11/extensions/XI.h> 58c43cc173Smrg#include <X11/extensions/XIproto.h> 59c43cc173Smrg#include <X11/Xlibint.h> 60c43cc173Smrg#include <X11/extensions/XInput.h> 61c43cc173Smrg#include <X11/extensions/extutil.h> 62c43cc173Smrg#include "XIint.h" 63c43cc173Smrg 64c43cc173Smrgint 65c43cc173SmrgXChangeDeviceControl(dpy, dev, control, d) 66c43cc173Smrg register Display *dpy; 67c43cc173Smrg XDevice *dev; 68c43cc173Smrg int control; 69c43cc173Smrg XDeviceControl *d; 70c43cc173Smrg{ 71c43cc173Smrg int length; 72c43cc173Smrg xChangeDeviceControlReq *req; 73c43cc173Smrg xChangeDeviceControlReply rep; 74c43cc173Smrg XExtDisplayInfo *info = XInput_find_display(dpy); 75c43cc173Smrg 76c43cc173Smrg LockDisplay(dpy); 77c43cc173Smrg if (_XiCheckExtInit(dpy, XInput_Add_XChangeDeviceControl, info) == -1) 78c43cc173Smrg return (NoSuchExtension); 79c43cc173Smrg 80c43cc173Smrg GetReq(ChangeDeviceControl, req); 81c43cc173Smrg req->reqType = info->codes->major_opcode; 82c43cc173Smrg req->ReqType = X_ChangeDeviceControl; 83c43cc173Smrg req->deviceid = dev->device_id; 84c43cc173Smrg req->control = control; 85c43cc173Smrg 86c43cc173Smrg switch (control) { 87c43cc173Smrg case DEVICE_RESOLUTION: 88c43cc173Smrg { 89c43cc173Smrg XDeviceResolutionControl *R; 90c43cc173Smrg xDeviceResolutionCtl r; 91c43cc173Smrg 92c43cc173Smrg R = (XDeviceResolutionControl *) d; 93c43cc173Smrg r.control = DEVICE_RESOLUTION; 94c43cc173Smrg r.length = sizeof(xDeviceResolutionCtl) + 95c43cc173Smrg R->num_valuators * sizeof(int); 96c43cc173Smrg r.first_valuator = R->first_valuator; 97c43cc173Smrg r.num_valuators = R->num_valuators; 98c43cc173Smrg req->length += ((unsigned)(r.length + 3) >> 2); 99c43cc173Smrg length = sizeof(xDeviceResolutionCtl); 100c43cc173Smrg Data(dpy, (char *)&r, length); 101c43cc173Smrg length = r.num_valuators * sizeof(int); 102c43cc173Smrg Data(dpy, (char *)R->resolutions, length); 103c43cc173Smrg if (!_XReply(dpy, (xReply *) & rep, 0, xTrue)) { 104c43cc173Smrg UnlockDisplay(dpy); 105c43cc173Smrg SyncHandle(); 106c43cc173Smrg return (NoSuchExtension); 107c43cc173Smrg } else { 108c43cc173Smrg UnlockDisplay(dpy); 109c43cc173Smrg SyncHandle(); 110c43cc173Smrg return (rep.status); 111c43cc173Smrg } 112c43cc173Smrg } 113c43cc173Smrg case DEVICE_ABS_CALIB: 114c43cc173Smrg { 115c43cc173Smrg XDeviceAbsCalibControl *C = (XDeviceAbsCalibControl *) d; 116c43cc173Smrg xDeviceAbsCalibCtl c; 117c43cc173Smrg 118c43cc173Smrg c.control = DEVICE_ABS_CALIB; 119c43cc173Smrg c.length = sizeof(c); 120c43cc173Smrg c.min_x = C->min_x; 121c43cc173Smrg c.max_x = C->max_x; 122c43cc173Smrg c.min_y = C->min_y; 123c43cc173Smrg c.max_y = C->max_y; 124c43cc173Smrg c.flip_x = C->flip_x; 125c43cc173Smrg c.flip_y = C->flip_y; 126c43cc173Smrg c.rotation = C->rotation; 127c43cc173Smrg c.button_threshold = C->button_threshold; 128c43cc173Smrg 129c43cc173Smrg req->length += (sizeof(c) + 3) >> 2; 130c43cc173Smrg Data(dpy, (char *) &c, sizeof(c)); 131c43cc173Smrg 132c43cc173Smrg if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) { 133c43cc173Smrg UnlockDisplay(dpy); 134c43cc173Smrg SyncHandle(); 135c43cc173Smrg return NoSuchExtension; 136c43cc173Smrg } 137c43cc173Smrg else { 138c43cc173Smrg UnlockDisplay(dpy); 139c43cc173Smrg SyncHandle(); 140c43cc173Smrg return rep.status; 141c43cc173Smrg } 142c43cc173Smrg } 143c43cc173Smrg case DEVICE_ABS_AREA: 144c43cc173Smrg { 145c43cc173Smrg XDeviceAbsAreaControl *A = (XDeviceAbsAreaControl *) d; 146c43cc173Smrg xDeviceAbsAreaCtl a; 147c43cc173Smrg 148c43cc173Smrg a.control = DEVICE_ABS_AREA; 149c43cc173Smrg a.length = sizeof(a); 150c43cc173Smrg a.offset_x = A->offset_x; 151c43cc173Smrg a.offset_y = A->offset_y; 152c43cc173Smrg a.width = A->width; 153c43cc173Smrg a.height = A->height; 154c43cc173Smrg a.screen = A->screen; 155c43cc173Smrg a.following = A->following; 156c43cc173Smrg 157c43cc173Smrg req->length += (sizeof(a) + 3) >> 2; 158c43cc173Smrg Data(dpy, (char *) &a, sizeof(a)); 159c43cc173Smrg 160c43cc173Smrg if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) { 161c43cc173Smrg UnlockDisplay(dpy); 162c43cc173Smrg SyncHandle(); 163c43cc173Smrg return NoSuchExtension; 164c43cc173Smrg } 165c43cc173Smrg else { 166c43cc173Smrg UnlockDisplay(dpy); 167c43cc173Smrg SyncHandle(); 168c43cc173Smrg return rep.status; 169c43cc173Smrg } 170c43cc173Smrg } 171c43cc173Smrg case DEVICE_CORE: 172c43cc173Smrg { 173c43cc173Smrg XDeviceCoreControl *C = (XDeviceCoreControl *) d; 174c43cc173Smrg xDeviceCoreCtl c; 175c43cc173Smrg 176c43cc173Smrg c.control = DEVICE_CORE; 177c43cc173Smrg c.length = sizeof(c); 178c43cc173Smrg c.status = C->status; 179c43cc173Smrg 180c43cc173Smrg req->length += (sizeof(c) + 3) >> 2; 181c43cc173Smrg Data (dpy, (char *) &c, sizeof(c)); 182c43cc173Smrg 183c43cc173Smrg if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) { 184c43cc173Smrg UnlockDisplay(dpy); 185c43cc173Smrg SyncHandle(); 186c43cc173Smrg return NoSuchExtension; 187c43cc173Smrg } 188c43cc173Smrg else { 189c43cc173Smrg UnlockDisplay(dpy); 190c43cc173Smrg SyncHandle(); 191c43cc173Smrg return rep.status; 192c43cc173Smrg } 193c43cc173Smrg } 194c43cc173Smrg case DEVICE_ENABLE: 195c43cc173Smrg { 196c43cc173Smrg XDeviceEnableControl *E = (XDeviceEnableControl *) d; 197c43cc173Smrg xDeviceEnableCtl e; 198c43cc173Smrg 199c43cc173Smrg e.control = DEVICE_ENABLE; 200c43cc173Smrg e.length = sizeof(e); 201c43cc173Smrg e.enable = E->enable; 202c43cc173Smrg 203c43cc173Smrg req->length += (sizeof(e) + 3) >> 2; 204c43cc173Smrg Data (dpy, (char *) &e, sizeof(e)); 205c43cc173Smrg 206c43cc173Smrg if (!_XReply(dpy, (xReply *) &rep, 0, xTrue)) { 207c43cc173Smrg UnlockDisplay(dpy); 208c43cc173Smrg SyncHandle(); 209c43cc173Smrg return NoSuchExtension; 210c43cc173Smrg } 211c43cc173Smrg else { 212c43cc173Smrg UnlockDisplay(dpy); 213c43cc173Smrg SyncHandle(); 214c43cc173Smrg return rep.status; 215c43cc173Smrg } 216c43cc173Smrg } 217c43cc173Smrg default: 218c43cc173Smrg { 219c43cc173Smrg xDeviceCtl u; 220c43cc173Smrg 221c43cc173Smrg u.control = d->control; 222c43cc173Smrg u.length = d->length - sizeof(int); 223c43cc173Smrg length = ((unsigned)(u.length + 3) >> 2); 224c43cc173Smrg req->length += length; 225c43cc173Smrg length <<= 2; 226c43cc173Smrg Data(dpy, (char *)&u, length); 227c43cc173Smrg } 228c43cc173Smrg } 229c43cc173Smrg 230c43cc173Smrg UnlockDisplay(dpy); 231c43cc173Smrg SyncHandle(); 232c43cc173Smrg return (Success); 233c43cc173Smrg} 234