home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / server / xinput / xopendev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-18  |  5.1 KB  |  178 lines

  1. /* $XConsortium: xopendev.c,v 1.11 90/05/18 15:24:17 rws Exp $ */
  2.  
  3. /************************************************************
  4. Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, California, and the 
  5. Massachusetts Institute of Technology, Cambridge, Massachusetts.
  6.  
  7.             All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its
  10. documentation for any purpose and without fee is hereby granted,
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in
  13. supporting documentation, and that the names of Hewlett-Packard or MIT not be
  14. used in advertising or publicity pertaining to distribution of the
  15. software without specific, written prior permission.
  16.  
  17. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  19. HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  20. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  22. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  23. SOFTWARE.
  24.  
  25. ********************************************************/
  26.  
  27. /***********************************************************************
  28.  *
  29.  * Request to open an extension input device.
  30.  *
  31.  */
  32.  
  33. #define     NEED_EVENTS
  34. #define     NEED_REPLIES
  35. #include "X.h"                /* for inputstr.h    */
  36. #include "Xproto.h"            /* Request macro     */
  37. #include "XI.h"
  38. #include "XIproto.h"
  39. #include "inputstr.h"            /* DeviceIntPtr         */
  40. #include "windowstr.h"            /* window structure  */
  41.  
  42. extern    int         IReqCode;
  43. extern    int         BadDevice;
  44. extern    CARD8        event_base [];
  45. extern    InputInfo    inputInfo;
  46. extern    void        (* ReplySwapVector[256]) ();
  47. DeviceIntPtr        LookupDeviceIntRec();
  48.  
  49. /***********************************************************************
  50.  *
  51.  * This procedure swaps the request if the server and client have different
  52.  * byte orderings.
  53.  *
  54.  */
  55.  
  56. int
  57. SProcXOpenDevice(client)
  58.     register ClientPtr client;
  59.     {
  60.     register char n;
  61.  
  62.     REQUEST(xOpenDeviceReq);
  63.     swaps(&stuff->length, n);
  64.     return(ProcXOpenDevice(client));
  65.     }
  66.  
  67. /***********************************************************************
  68.  *
  69.  * This procedure causes the server to open an input device.
  70.  *
  71.  */
  72.  
  73. int
  74. ProcXOpenDevice(client)
  75.     register ClientPtr client;
  76.     {
  77.     xInputClassInfo evbase [numInputClasses];
  78.     Bool enableit = FALSE;
  79.     int j=0;
  80.     int status = Success;
  81.     xOpenDeviceReply    rep;
  82.     DeviceIntPtr dev;
  83.     void OpenInputDevice();
  84.  
  85.     REQUEST(xOpenDeviceReq);
  86.     REQUEST_SIZE_MATCH(xOpenDeviceReq);
  87.  
  88.     if (stuff->deviceid == inputInfo.pointer->id || 
  89.     stuff->deviceid == inputInfo.keyboard->id)
  90.     {
  91.     SendErrorToClient(client, IReqCode, X_OpenDevice, 0, BadDevice);
  92.         return Success;
  93.     }
  94.  
  95.     if ((dev = LookupDeviceIntRec(stuff->deviceid)) == NULL) /* not open */
  96.     {
  97.         for (dev=inputInfo.off_devices; dev; dev=dev->next)
  98.         if (dev->id == stuff->deviceid)
  99.         break;
  100.     if (dev == NULL)
  101.         {
  102.         SendErrorToClient(client, IReqCode, X_OpenDevice, 0, BadDevice);
  103.         return Success;
  104.         }
  105.     enableit = TRUE;
  106.     }
  107.  
  108.     OpenInputDevice (dev, client, &status);
  109.     if (status != Success)
  110.     {
  111.     SendErrorToClient(client, IReqCode, X_OpenDevice, 0, status);
  112.     return Success;
  113.     }
  114.     if (enableit && dev->inited && dev->startup)
  115.     (void)EnableDevice(dev);
  116.  
  117.     rep.repType = X_Reply;
  118.     rep.RepType = X_OpenDevice;
  119.     rep.sequenceNumber = client->sequence;
  120.     if (dev->key != NULL)
  121.     {
  122.     evbase[j].class = KeyClass;
  123.     evbase[j++].event_type_base = event_base[KeyClass];
  124.     }
  125.     if (dev->button != NULL)
  126.     {
  127.     evbase[j].class = ButtonClass;
  128.     evbase[j++].event_type_base = event_base[ButtonClass];
  129.     }
  130.     if (dev->valuator != NULL)
  131.     {
  132.     evbase[j].class = ValuatorClass;
  133.     evbase[j++].event_type_base = event_base[ValuatorClass];
  134.     }
  135.     if (dev->kbdfeed != NULL || dev->ptrfeed != NULL || dev->leds != NULL ||
  136.     dev->intfeed != NULL || dev->bell != NULL || dev->stringfeed != NULL)
  137.     {
  138.     evbase[j].class = FeedbackClass;
  139.     evbase[j++].event_type_base = event_base[FeedbackClass];
  140.     }
  141.     if (dev->focus != NULL)
  142.     {
  143.     evbase[j].class = FocusClass;
  144.     evbase[j++].event_type_base = event_base[FocusClass];
  145.     }
  146.     if (dev->proximity != NULL)
  147.     {
  148.     evbase[j].class = ProximityClass;
  149.     evbase[j++].event_type_base = event_base[ProximityClass];
  150.     }
  151.     evbase[j].class = OtherClass;
  152.     evbase[j++].event_type_base = event_base[OtherClass];
  153.     rep.length = (j * sizeof (xInputClassInfo) + 3) >> 2;
  154.     rep.num_classes = j;
  155.     WriteReplyToClient (client, sizeof (xOpenDeviceReply), &rep);
  156.     WriteToClient(client, j * sizeof (xInputClassInfo), evbase);
  157.     return (Success);
  158.     }
  159.  
  160. /***********************************************************************
  161.  *
  162.  * This procedure writes the reply for the XOpenDevice function,
  163.  * if the client and server have a different byte ordering.
  164.  *
  165.  */
  166.  
  167. SRepXOpenDevice (client, size, rep)
  168.     ClientPtr    client;
  169.     int        size;
  170.     xOpenDeviceReply    *rep;
  171.     {
  172.     register char n;
  173.  
  174.     swaps(&rep->sequenceNumber, n);
  175.     swapl(&rep->length, n);
  176.     WriteToClient(client, size, rep);
  177.     }
  178.