home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / extensions / server / xinput / xgetprop.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-24  |  5.1 KB  |  185 lines

  1. /* $Header: xgetprop.c,v 1.7 91/01/24 17:03:42 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.  * Function to return the dont-propagate-list for an extension 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 "inputstr.h"            /* DeviceIntPtr         */
  38. #include "windowstr.h"            /* window structs    */
  39. #include "XI.h"
  40. #include "XIproto.h"
  41.  
  42. extern    int         IReqCode;
  43. extern    void        (* ReplySwapVector[256]) ();
  44. extern            XExtEventInfo EventInfo[];
  45. DeviceIntPtr        LookupDeviceIntRec();
  46.  
  47. /***********************************************************************
  48.  *
  49.  * Handle a request from a client with a different byte order.
  50.  *
  51.  */
  52.  
  53. int
  54. SProcXGetDeviceDontPropagateList(client)
  55.     register ClientPtr client;
  56.     {
  57.     register char n;
  58.  
  59.     REQUEST(xGetDeviceDontPropagateListReq);
  60.     swaps(&stuff->length, n);
  61.     swapl(&stuff->window, n);
  62.     return(ProcXGetDeviceDontPropagateList(client));
  63.     }
  64.  
  65. /***********************************************************************
  66.  *
  67.  * This procedure lists the input devices available to the server.
  68.  *
  69.  */
  70.  
  71. ProcXGetDeviceDontPropagateList (client)
  72.     register ClientPtr client;
  73.     {
  74.     CARD16                count = 0;
  75.     int                    i;
  76.     XEventClass                *buf, *tbuf;
  77.     WindowPtr                 pWin;
  78.     xGetDeviceDontPropagateListReply    rep;
  79.     XEventClass             *ClassFromMask ();
  80.     void                Swap32Write();
  81.     OtherInputMasks            *others;
  82.  
  83.     REQUEST(xGetDeviceDontPropagateListReq);
  84.     REQUEST_SIZE_MATCH(xGetDeviceDontPropagateListReq);
  85.  
  86.     rep.repType = X_Reply;
  87.     rep.RepType = X_GetDeviceDontPropagateList;
  88.     rep.sequenceNumber = client->sequence;
  89.     rep.length = 0;
  90.     rep.count = 0;
  91.  
  92.     pWin = (WindowPtr) LookupWindow (stuff->window, client);
  93.     if (!pWin)
  94.         {
  95.     client->errorValue = stuff->window;
  96.     SendErrorToClient(client, IReqCode, X_GetDeviceDontPropagateList, 0, 
  97.         BadWindow);
  98.     return Success;
  99.         }
  100.  
  101.     if (others = wOtherInputMasks(pWin))
  102.     {
  103.     for (i=0; i<EMASKSIZE; i++)
  104.         tbuf = ClassFromMask (NULL, others->dontPropagateMask[i], i, 
  105.         &count, COUNT);
  106.     if (count)
  107.         {
  108.         rep.count = count;
  109.         buf = (XEventClass *) Xalloc (rep.count * sizeof(XEventClass));
  110.         rep.length = (rep.count * sizeof (XEventClass) + 3) >> 2;
  111.  
  112.         tbuf = buf;
  113.         for (i=0; i<EMASKSIZE; i++)
  114.         tbuf = ClassFromMask (tbuf, others->dontPropagateMask[i], i, 
  115.             NULL, CREATE);
  116.         }
  117.     }
  118.  
  119.     WriteReplyToClient (client, sizeof (xGetDeviceDontPropagateListReply), 
  120.     &rep);
  121.  
  122.     if (count)
  123.     {
  124.     client->pSwapReplyFunc = Swap32Write;
  125.     WriteSwappedDataToClient( client, count * sizeof(XEventClass), buf);
  126.     Xfree (buf);
  127.     }
  128.     return Success;
  129.     }
  130.  
  131. /***********************************************************************
  132.  *
  133.  * This procedure gets a list of event classes from a mask word.
  134.  * A single mask may translate to more than one event class.
  135.  *
  136.  */
  137.  
  138. XEventClass
  139. *ClassFromMask (buf, mask, maskndx, count, mode)
  140.     XEventClass *buf;
  141.     Mask    mask;
  142.     int        maskndx;
  143.     CARD16    *count;
  144.     int        mode;
  145.     {
  146.     int        i,j;
  147.     int        id = maskndx;
  148.     Mask    tmask = 0x80000000;
  149.     extern int    ExtEventIndex;
  150.  
  151.     for (i=0; i<32; i++,tmask>>=1)
  152.     if (tmask & mask)
  153.         {
  154.         for (j=0; j<ExtEventIndex; j++)
  155.         if (EventInfo[j].mask == tmask)
  156.             {
  157.             if (mode == COUNT)
  158.             (*count)++;
  159.             else
  160.                 *buf++ = (id << 8) | EventInfo[j].type;
  161.             }
  162.         }
  163.     return (buf);
  164.     }
  165.  
  166. /***********************************************************************
  167.  *
  168.  * This procedure writes the reply for the XGetDeviceDontPropagateList function,
  169.  * if the client and server have a different byte ordering.
  170.  *
  171.  */
  172.  
  173. SRepXGetDeviceDontPropagateList (client, size, rep)
  174.     ClientPtr    client;
  175.     int        size;
  176.     xGetDeviceDontPropagateListReply    *rep;
  177.     {
  178.     register char n;
  179.  
  180.     swaps(&rep->sequenceNumber, n);
  181.     swapl(&rep->length, n);
  182.     swaps(&rep->count, n);
  183.     WriteToClient(client, size, rep);
  184.     }
  185.