getdctl.c revision 05b261ec
105b261ecSmrg/************************************************************ 205b261ecSmrg 305b261ecSmrgCopyright 1989, 1998 The Open Group 405b261ecSmrg 505b261ecSmrgPermission to use, copy, modify, distribute, and sell this software and its 605b261ecSmrgdocumentation for any purpose is hereby granted without fee, provided that 705b261ecSmrgthe above copyright notice appear in all copies and that both that 805b261ecSmrgcopyright notice and this permission notice appear in supporting 905b261ecSmrgdocumentation. 1005b261ecSmrg 1105b261ecSmrgThe above copyright notice and this permission notice shall be included in 1205b261ecSmrgall copies or substantial portions of the Software. 1305b261ecSmrg 1405b261ecSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1505b261ecSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1605b261ecSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 1705b261ecSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 1805b261ecSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 1905b261ecSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2005b261ecSmrg 2105b261ecSmrgExcept as contained in this notice, the name of The Open Group shall not be 2205b261ecSmrgused in advertising or otherwise to promote the sale, use or other dealings 2305b261ecSmrgin this Software without prior written authorization from The Open Group. 2405b261ecSmrg 2505b261ecSmrgCopyright 1989 by Hewlett-Packard Company, Palo Alto, California. 2605b261ecSmrg 2705b261ecSmrg All Rights Reserved 2805b261ecSmrg 2905b261ecSmrgPermission to use, copy, modify, and distribute this software and its 3005b261ecSmrgdocumentation for any purpose and without fee is hereby granted, 3105b261ecSmrgprovided that the above copyright notice appear in all copies and that 3205b261ecSmrgboth that copyright notice and this permission notice appear in 3305b261ecSmrgsupporting documentation, and that the name of Hewlett-Packard not be 3405b261ecSmrgused in advertising or publicity pertaining to distribution of the 3505b261ecSmrgsoftware without specific, written prior permission. 3605b261ecSmrg 3705b261ecSmrgHEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 3805b261ecSmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 3905b261ecSmrgHEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 4005b261ecSmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 4105b261ecSmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 4205b261ecSmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 4305b261ecSmrgSOFTWARE. 4405b261ecSmrg 4505b261ecSmrg********************************************************/ 4605b261ecSmrg 4705b261ecSmrg/******************************************************************** 4805b261ecSmrg * 4905b261ecSmrg * Get Device control attributes for an extension device. 5005b261ecSmrg * 5105b261ecSmrg */ 5205b261ecSmrg 5305b261ecSmrg#define NEED_EVENTS /* for inputstr.h */ 5405b261ecSmrg#define NEED_REPLIES 5505b261ecSmrg#ifdef HAVE_DIX_CONFIG_H 5605b261ecSmrg#include <dix-config.h> 5705b261ecSmrg#endif 5805b261ecSmrg 5905b261ecSmrg#include <X11/X.h> /* for inputstr.h */ 6005b261ecSmrg#include <X11/Xproto.h> /* Request macro */ 6105b261ecSmrg#include "inputstr.h" /* DeviceIntPtr */ 6205b261ecSmrg#include <X11/extensions/XI.h> 6305b261ecSmrg#include <X11/extensions/XIproto.h> 6405b261ecSmrg#include "extnsionst.h" 6505b261ecSmrg#include "extinit.h" /* LookupDeviceIntRec */ 6605b261ecSmrg#include "exglobals.h" 6705b261ecSmrg 6805b261ecSmrg#include "getdctl.h" 6905b261ecSmrg 7005b261ecSmrg/*********************************************************************** 7105b261ecSmrg * 7205b261ecSmrg * This procedure gets the control attributes for an extension device, 7305b261ecSmrg * for clients on machines with a different byte ordering than the server. 7405b261ecSmrg * 7505b261ecSmrg */ 7605b261ecSmrg 7705b261ecSmrgint 7805b261ecSmrgSProcXGetDeviceControl(ClientPtr client) 7905b261ecSmrg{ 8005b261ecSmrg char n; 8105b261ecSmrg 8205b261ecSmrg REQUEST(xGetDeviceControlReq); 8305b261ecSmrg swaps(&stuff->length, n); 8405b261ecSmrg REQUEST_SIZE_MATCH(xGetDeviceControlReq); 8505b261ecSmrg swaps(&stuff->control, n); 8605b261ecSmrg return (ProcXGetDeviceControl(client)); 8705b261ecSmrg} 8805b261ecSmrg 8905b261ecSmrg/*********************************************************************** 9005b261ecSmrg * 9105b261ecSmrg * This procedure copies DeviceResolution data, swapping if necessary. 9205b261ecSmrg * 9305b261ecSmrg */ 9405b261ecSmrg 9505b261ecSmrgstatic void 9605b261ecSmrgCopySwapDeviceResolution(ClientPtr client, ValuatorClassPtr v, char *buf, 9705b261ecSmrg int length) 9805b261ecSmrg{ 9905b261ecSmrg char n; 10005b261ecSmrg AxisInfoPtr a; 10105b261ecSmrg xDeviceResolutionState *r; 10205b261ecSmrg int i, *iptr; 10305b261ecSmrg 10405b261ecSmrg r = (xDeviceResolutionState *) buf; 10505b261ecSmrg r->control = DEVICE_RESOLUTION; 10605b261ecSmrg r->length = length; 10705b261ecSmrg r->num_valuators = v->numAxes; 10805b261ecSmrg buf += sizeof(xDeviceResolutionState); 10905b261ecSmrg iptr = (int *)buf; 11005b261ecSmrg for (i = 0, a = v->axes; i < v->numAxes; i++, a++) 11105b261ecSmrg *iptr++ = a->resolution; 11205b261ecSmrg for (i = 0, a = v->axes; i < v->numAxes; i++, a++) 11305b261ecSmrg *iptr++ = a->min_resolution; 11405b261ecSmrg for (i = 0, a = v->axes; i < v->numAxes; i++, a++) 11505b261ecSmrg *iptr++ = a->max_resolution; 11605b261ecSmrg if (client->swapped) { 11705b261ecSmrg swaps(&r->control, n); 11805b261ecSmrg swaps(&r->length, n); 11905b261ecSmrg swapl(&r->num_valuators, n); 12005b261ecSmrg iptr = (int *)buf; 12105b261ecSmrg for (i = 0; i < (3 * v->numAxes); i++, iptr++) { 12205b261ecSmrg swapl(iptr, n); 12305b261ecSmrg } 12405b261ecSmrg } 12505b261ecSmrg} 12605b261ecSmrg 12705b261ecSmrgstatic void CopySwapDeviceAbsCalib (ClientPtr client, AbsoluteClassPtr dts, 12805b261ecSmrg char *buf) 12905b261ecSmrg{ 13005b261ecSmrg char n; 13105b261ecSmrg xDeviceAbsCalibState *calib = (xDeviceAbsCalibState *) buf; 13205b261ecSmrg 13305b261ecSmrg calib->control = DEVICE_ABS_CALIB; 13405b261ecSmrg calib->length = sizeof(calib); 13505b261ecSmrg calib->min_x = dts->min_x; 13605b261ecSmrg calib->max_x = dts->max_x; 13705b261ecSmrg calib->min_y = dts->min_y; 13805b261ecSmrg calib->max_y = dts->max_y; 13905b261ecSmrg calib->flip_x = dts->flip_x; 14005b261ecSmrg calib->flip_y = dts->flip_y; 14105b261ecSmrg calib->rotation = dts->rotation; 14205b261ecSmrg calib->button_threshold = dts->button_threshold; 14305b261ecSmrg 14405b261ecSmrg if (client->swapped) { 14505b261ecSmrg swaps(&calib->control, n); 14605b261ecSmrg swaps(&calib->length, n); 14705b261ecSmrg swapl(&calib->min_x, n); 14805b261ecSmrg swapl(&calib->max_x, n); 14905b261ecSmrg swapl(&calib->min_y, n); 15005b261ecSmrg swapl(&calib->max_y, n); 15105b261ecSmrg swapl(&calib->flip_x, n); 15205b261ecSmrg swapl(&calib->flip_y, n); 15305b261ecSmrg swapl(&calib->rotation, n); 15405b261ecSmrg swapl(&calib->button_threshold, n); 15505b261ecSmrg } 15605b261ecSmrg} 15705b261ecSmrg 15805b261ecSmrgstatic void CopySwapDeviceAbsArea (ClientPtr client, AbsoluteClassPtr dts, 15905b261ecSmrg char *buf) 16005b261ecSmrg{ 16105b261ecSmrg char n; 16205b261ecSmrg xDeviceAbsAreaState *area = (xDeviceAbsAreaState *) buf; 16305b261ecSmrg 16405b261ecSmrg area->control = DEVICE_ABS_AREA; 16505b261ecSmrg area->length = sizeof(area); 16605b261ecSmrg area->offset_x = dts->offset_x; 16705b261ecSmrg area->offset_y = dts->offset_y; 16805b261ecSmrg area->width = dts->width; 16905b261ecSmrg area->height = dts->height; 17005b261ecSmrg area->screen = dts->screen; 17105b261ecSmrg area->following = dts->following; 17205b261ecSmrg 17305b261ecSmrg if (client->swapped) { 17405b261ecSmrg swaps(&area->control, n); 17505b261ecSmrg swaps(&area->length, n); 17605b261ecSmrg swapl(&area->offset_x, n); 17705b261ecSmrg swapl(&area->offset_y, n); 17805b261ecSmrg swapl(&area->width, n); 17905b261ecSmrg swapl(&area->height, n); 18005b261ecSmrg swapl(&area->screen, n); 18105b261ecSmrg swapl(&area->following, n); 18205b261ecSmrg } 18305b261ecSmrg} 18405b261ecSmrg 18505b261ecSmrgstatic void CopySwapDeviceCore (ClientPtr client, DeviceIntPtr dev, char *buf) 18605b261ecSmrg{ 18705b261ecSmrg char n; 18805b261ecSmrg xDeviceCoreState *c = (xDeviceCoreState *) buf; 18905b261ecSmrg 19005b261ecSmrg c->control = DEVICE_CORE; 19105b261ecSmrg c->length = sizeof(c); 19205b261ecSmrg c->status = dev->coreEvents; 19305b261ecSmrg c->iscore = (dev == inputInfo.keyboard || dev == inputInfo.pointer); 19405b261ecSmrg 19505b261ecSmrg if (client->swapped) { 19605b261ecSmrg swaps(&c->control, n); 19705b261ecSmrg swaps(&c->length, n); 19805b261ecSmrg swaps(&c->status, n); 19905b261ecSmrg } 20005b261ecSmrg} 20105b261ecSmrg 20205b261ecSmrgstatic void CopySwapDeviceEnable (ClientPtr client, DeviceIntPtr dev, char *buf) 20305b261ecSmrg{ 20405b261ecSmrg char n; 20505b261ecSmrg xDeviceEnableState *e = (xDeviceEnableState *) buf; 20605b261ecSmrg 20705b261ecSmrg e->control = DEVICE_ENABLE; 20805b261ecSmrg e->length = sizeof(e); 20905b261ecSmrg e->enable = dev->enabled; 21005b261ecSmrg 21105b261ecSmrg if (client->swapped) { 21205b261ecSmrg swaps(&e->control, n); 21305b261ecSmrg swaps(&e->length, n); 21405b261ecSmrg swaps(&e->enable, n); 21505b261ecSmrg } 21605b261ecSmrg} 21705b261ecSmrg 21805b261ecSmrg/*********************************************************************** 21905b261ecSmrg * 22005b261ecSmrg * This procedure writes the reply for the xGetDeviceControl function, 22105b261ecSmrg * if the client and server have a different byte ordering. 22205b261ecSmrg * 22305b261ecSmrg */ 22405b261ecSmrg 22505b261ecSmrgvoid 22605b261ecSmrgSRepXGetDeviceControl(ClientPtr client, int size, xGetDeviceControlReply * rep) 22705b261ecSmrg{ 22805b261ecSmrg char n; 22905b261ecSmrg 23005b261ecSmrg swaps(&rep->sequenceNumber, n); 23105b261ecSmrg swapl(&rep->length, n); 23205b261ecSmrg WriteToClient(client, size, (char *)rep); 23305b261ecSmrg} 23405b261ecSmrg 23505b261ecSmrg/*********************************************************************** 23605b261ecSmrg * 23705b261ecSmrg * Get the state of the specified device control. 23805b261ecSmrg * 23905b261ecSmrg */ 24005b261ecSmrg 24105b261ecSmrgint 24205b261ecSmrgProcXGetDeviceControl(ClientPtr client) 24305b261ecSmrg{ 24405b261ecSmrg int total_length = 0; 24505b261ecSmrg char *buf, *savbuf; 24605b261ecSmrg DeviceIntPtr dev; 24705b261ecSmrg xGetDeviceControlReply rep; 24805b261ecSmrg 24905b261ecSmrg REQUEST(xGetDeviceControlReq); 25005b261ecSmrg REQUEST_SIZE_MATCH(xGetDeviceControlReq); 25105b261ecSmrg 25205b261ecSmrg dev = LookupDeviceIntRec(stuff->deviceid); 25305b261ecSmrg if (dev == NULL) { 25405b261ecSmrg SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadDevice); 25505b261ecSmrg return Success; 25605b261ecSmrg } 25705b261ecSmrg 25805b261ecSmrg rep.repType = X_Reply; 25905b261ecSmrg rep.RepType = X_GetDeviceControl; 26005b261ecSmrg rep.length = 0; 26105b261ecSmrg rep.sequenceNumber = client->sequence; 26205b261ecSmrg 26305b261ecSmrg switch (stuff->control) { 26405b261ecSmrg case DEVICE_RESOLUTION: 26505b261ecSmrg if (!dev->valuator) { 26605b261ecSmrg SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, 26705b261ecSmrg BadMatch); 26805b261ecSmrg return Success; 26905b261ecSmrg } 27005b261ecSmrg total_length = sizeof(xDeviceResolutionState) + 27105b261ecSmrg (3 * sizeof(int) * dev->valuator->numAxes); 27205b261ecSmrg break; 27305b261ecSmrg case DEVICE_ABS_CALIB: 27405b261ecSmrg if (!dev->absolute) { 27505b261ecSmrg SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, 27605b261ecSmrg BadMatch); 27705b261ecSmrg return Success; 27805b261ecSmrg } 27905b261ecSmrg 28005b261ecSmrg total_length = sizeof(xDeviceAbsCalibCtl); 28105b261ecSmrg break; 28205b261ecSmrg case DEVICE_ABS_AREA: 28305b261ecSmrg if (!dev->absolute) { 28405b261ecSmrg SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, 28505b261ecSmrg BadMatch); 28605b261ecSmrg return Success; 28705b261ecSmrg } 28805b261ecSmrg 28905b261ecSmrg total_length = sizeof(xDeviceAbsAreaCtl); 29005b261ecSmrg break; 29105b261ecSmrg case DEVICE_CORE: 29205b261ecSmrg total_length = sizeof(xDeviceCoreCtl); 29305b261ecSmrg break; 29405b261ecSmrg case DEVICE_ENABLE: 29505b261ecSmrg total_length = sizeof(xDeviceEnableCtl); 29605b261ecSmrg break; 29705b261ecSmrg default: 29805b261ecSmrg SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadValue); 29905b261ecSmrg return Success; 30005b261ecSmrg } 30105b261ecSmrg 30205b261ecSmrg buf = (char *)xalloc(total_length); 30305b261ecSmrg if (!buf) { 30405b261ecSmrg SendErrorToClient(client, IReqCode, X_GetDeviceControl, 0, BadAlloc); 30505b261ecSmrg return Success; 30605b261ecSmrg } 30705b261ecSmrg savbuf = buf; 30805b261ecSmrg 30905b261ecSmrg switch (stuff->control) { 31005b261ecSmrg case DEVICE_RESOLUTION: 31105b261ecSmrg CopySwapDeviceResolution(client, dev->valuator, buf, total_length); 31205b261ecSmrg break; 31305b261ecSmrg case DEVICE_ABS_CALIB: 31405b261ecSmrg CopySwapDeviceAbsCalib(client, dev->absolute, buf); 31505b261ecSmrg break; 31605b261ecSmrg case DEVICE_ABS_AREA: 31705b261ecSmrg CopySwapDeviceAbsArea(client, dev->absolute, buf); 31805b261ecSmrg break; 31905b261ecSmrg case DEVICE_CORE: 32005b261ecSmrg CopySwapDeviceCore(client, dev, buf); 32105b261ecSmrg break; 32205b261ecSmrg case DEVICE_ENABLE: 32305b261ecSmrg CopySwapDeviceEnable(client, dev, buf); 32405b261ecSmrg break; 32505b261ecSmrg default: 32605b261ecSmrg break; 32705b261ecSmrg } 32805b261ecSmrg 32905b261ecSmrg rep.length = (total_length + 3) >> 2; 33005b261ecSmrg WriteReplyToClient(client, sizeof(xGetDeviceControlReply), &rep); 33105b261ecSmrg WriteToClient(client, total_length, savbuf); 33205b261ecSmrg xfree(savbuf); 33305b261ecSmrg return Success; 33405b261ecSmrg} 335