"Fossies" - the Fresh Open Source Software Archive

Member "xorg-server-1.20.5/Xi/chgdctl.c" (30 May 2019, 8243 Bytes) of package /linux/misc/xorg-server-1.20.5.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "chgdctl.c" see the Fossies "Dox" file reference documentation.

    1 /************************************************************
    2 
    3 Copyright 1989, 1998  The Open Group
    4 
    5 Permission to use, copy, modify, distribute, and sell this software and its
    6 documentation for any purpose is hereby granted without fee, provided that
    7 the above copyright notice appear in all copies and that both that
    8 copyright notice and this permission notice appear in supporting
    9 documentation.
   10 
   11 The above copyright notice and this permission notice shall be included in
   12 all copies or substantial portions of the Software.
   13 
   14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
   16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
   17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
   18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
   19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
   20 
   21 Except as contained in this notice, the name of The Open Group shall not be
   22 used in advertising or otherwise to promote the sale, use or other dealings
   23 in this Software without prior written authorization from The Open Group.
   24 
   25 Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
   26 
   27             All Rights Reserved
   28 
   29 Permission to use, copy, modify, and distribute this software and its
   30 documentation for any purpose and without fee is hereby granted,
   31 provided that the above copyright notice appear in all copies and that
   32 both that copyright notice and this permission notice appear in
   33 supporting documentation, and that the name of Hewlett-Packard not be
   34 used in advertising or publicity pertaining to distribution of the
   35 software without specific, written prior permission.
   36 
   37 HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
   38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
   39 HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
   40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
   41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
   42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
   43 SOFTWARE.
   44 
   45 ********************************************************/
   46 
   47 /********************************************************************
   48  *
   49  *  Change Device control attributes for an extension device.
   50  *
   51  */
   52 
   53 #ifdef HAVE_DIX_CONFIG_H
   54 #include <dix-config.h>
   55 #endif
   56 
   57 #include "inputstr.h"           /* DeviceIntPtr      */
   58 #include <X11/extensions/XI.h>
   59 #include <X11/extensions/XIproto.h>     /* control constants */
   60 #include "XIstubs.h"
   61 
   62 #include "exglobals.h"
   63 #include "exevents.h"
   64 
   65 #include "chgdctl.h"
   66 
   67 /***********************************************************************
   68  *
   69  * This procedure changes the control attributes for an extension device,
   70  * for clients on machines with a different byte ordering than the server.
   71  *
   72  */
   73 
   74 int _X_COLD
   75 SProcXChangeDeviceControl(ClientPtr client)
   76 {
   77     xDeviceCtl *ctl;
   78 
   79     REQUEST(xChangeDeviceControlReq);
   80     swaps(&stuff->length);
   81     REQUEST_AT_LEAST_EXTRA_SIZE(xChangeDeviceControlReq, sizeof(xDeviceCtl));
   82     swaps(&stuff->control);
   83     ctl = (xDeviceCtl *) &stuff[1];
   84     swaps(&ctl->control);
   85     swaps(&ctl->length);
   86     switch (stuff->control) {
   87     case DEVICE_ABS_CALIB:
   88     case DEVICE_ABS_AREA:
   89     case DEVICE_CORE:
   90     case DEVICE_ENABLE:
   91     case DEVICE_RESOLUTION:
   92         /* hmm. beer. *drool* */
   93         break;
   94 
   95     }
   96     return (ProcXChangeDeviceControl(client));
   97 }
   98 
   99 /***********************************************************************
  100  *
  101  * Change the control attributes.
  102  *
  103  */
  104 
  105 int
  106 ProcXChangeDeviceControl(ClientPtr client)
  107 {
  108     unsigned len;
  109     int i, status, ret = BadValue;
  110     DeviceIntPtr dev;
  111     xDeviceResolutionCtl *r;
  112     xChangeDeviceControlReply rep;
  113     AxisInfoPtr a;
  114     CARD32 *resolution;
  115     xDeviceEnableCtl *e;
  116 
  117     REQUEST(xChangeDeviceControlReq);
  118     REQUEST_AT_LEAST_EXTRA_SIZE(xChangeDeviceControlReq, sizeof(xDeviceCtl));
  119 
  120     len = stuff->length - bytes_to_int32(sizeof(xChangeDeviceControlReq));
  121     ret = dixLookupDevice(&dev, stuff->deviceid, client, DixManageAccess);
  122     if (ret != Success)
  123         goto out;
  124 
  125     /* XTest devices are special, none of the below apply to them anyway */
  126     if (IsXTestDevice(dev, NULL)) {
  127         ret = BadMatch;
  128         goto out;
  129     }
  130 
  131     rep = (xChangeDeviceControlReply) {
  132         .repType = X_Reply,
  133         .RepType = X_ChangeDeviceControl,
  134         .sequenceNumber = client->sequence,
  135         .length = 0,
  136         .status = Success,
  137     };
  138 
  139     switch (stuff->control) {
  140     case DEVICE_RESOLUTION:
  141         r = (xDeviceResolutionCtl *) &stuff[1];
  142         if ((len < bytes_to_int32(sizeof(xDeviceResolutionCtl))) ||
  143             (len !=
  144              bytes_to_int32(sizeof(xDeviceResolutionCtl)) + r->num_valuators)) {
  145             ret = BadLength;
  146             goto out;
  147         }
  148         if (!dev->valuator) {
  149             ret = BadMatch;
  150             goto out;
  151         }
  152         if ((dev->deviceGrab.grab) && !SameClient(dev->deviceGrab.grab, client)) {
  153             rep.status = AlreadyGrabbed;
  154             ret = Success;
  155             goto out;
  156         }
  157         resolution = (CARD32 *) (r + 1);
  158         if (r->first_valuator + r->num_valuators > dev->valuator->numAxes) {
  159             ret = BadValue;
  160             goto out;
  161         }
  162         status = ChangeDeviceControl(client, dev, (xDeviceCtl *) r);
  163         if (status == Success) {
  164             a = &dev->valuator->axes[r->first_valuator];
  165             for (i = 0; i < r->num_valuators; i++)
  166                 if (*(resolution + i) < (a + i)->min_resolution ||
  167                     *(resolution + i) > (a + i)->max_resolution)
  168                     return BadValue;
  169             for (i = 0; i < r->num_valuators; i++)
  170                 (a++)->resolution = *resolution++;
  171 
  172             ret = Success;
  173         }
  174         else if (status == DeviceBusy) {
  175             rep.status = DeviceBusy;
  176             ret = Success;
  177         }
  178         else {
  179             ret = BadMatch;
  180         }
  181         break;
  182     case DEVICE_ABS_CALIB:
  183     case DEVICE_ABS_AREA:
  184         /* Calibration is now done through properties, and never had any effect
  185          * on anything (in the open-source world). Thus, be honest. */
  186         ret = BadMatch;
  187         break;
  188     case DEVICE_CORE:
  189         /* Sorry, no device core switching no more. If you want a device to
  190          * send core events, attach it to a master device */
  191         ret = BadMatch;
  192         break;
  193     case DEVICE_ENABLE:
  194         e = (xDeviceEnableCtl *) &stuff[1];
  195         if ((len != bytes_to_int32(sizeof(xDeviceEnableCtl)))) {
  196             ret = BadLength;
  197             goto out;
  198         }
  199 
  200         if (IsXTestDevice(dev, NULL))
  201             status = !Success;
  202         else
  203             status = ChangeDeviceControl(client, dev, (xDeviceCtl *) e);
  204 
  205         if (status == Success) {
  206             if (e->enable)
  207                 EnableDevice(dev, TRUE);
  208             else
  209                 DisableDevice(dev, TRUE);
  210             ret = Success;
  211         }
  212         else if (status == DeviceBusy) {
  213             rep.status = DeviceBusy;
  214             ret = Success;
  215         }
  216         else {
  217             ret = BadMatch;
  218         }
  219 
  220         break;
  221     default:
  222         ret = BadValue;
  223     }
  224 
  225  out:
  226     if (ret == Success) {
  227         devicePresenceNotify dpn = {
  228             .type = DevicePresenceNotify,
  229             .time = currentTime.milliseconds,
  230             .devchange = DeviceControlChanged,
  231             .deviceid = dev->id,
  232             .control = stuff->control
  233         };
  234         SendEventToAllWindows(dev, DevicePresenceNotifyMask,
  235                               (xEvent *) &dpn, 1);
  236 
  237         WriteReplyToClient(client, sizeof(xChangeDeviceControlReply), &rep);
  238     }
  239 
  240     return ret;
  241 }
  242 
  243 /***********************************************************************
  244  *
  245  * This procedure writes the reply for the xChangeDeviceControl function,
  246  * if the client and server have a different byte ordering.
  247  *
  248  */
  249 
  250 void _X_COLD
  251 SRepXChangeDeviceControl(ClientPtr client, int size,
  252                          xChangeDeviceControlReply * rep)
  253 {
  254     swaps(&rep->sequenceNumber);
  255     swapl(&rep->length);
  256     WriteToClient(client, size, rep);
  257 }