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

  1. /************************************************************
  2. Copyright (c) 1989 by Hewlett-Packard Company, Palo Alto, California, and the 
  3. Massachusetts Institute of Technology, Cambridge, Massachusetts.
  4.  
  5.             All Rights Reserved
  6.  
  7. Permission to use, copy, modify, and distribute this software and its
  8. documentation for any purpose and without fee is hereby granted,
  9. provided that the above copyright notice appear in all copies and that
  10. both that copyright notice and this permission notice appear in
  11. supporting documentation, and that the names of Hewlett-Packard or MIT not be
  12. used in advertising or publicity pertaining to distribution of the
  13. software without specific, written prior permission.
  14.  
  15. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  16. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  17. HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  18. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  19. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  20. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21. SOFTWARE.
  22.  
  23. ********************************************************/
  24.  
  25. /* $XConsortium: xgetselev.c,v 1.9 90/05/18 15:35:21 rws Exp $ */
  26.  
  27. /***********************************************************************
  28.  *
  29.  * Extension function to get the current selected events for a given window.
  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 struct     */
  41.  
  42. extern    int         IReqCode;
  43. extern    void        (* ReplySwapVector[256]) ();
  44. DeviceIntPtr        LookupDeviceIntRec();
  45.  
  46. /***********************************************************************
  47.  *
  48.  * This procedure gets the current selected extension events.
  49.  *
  50.  */
  51.  
  52. int
  53. SProcXGetSelectedExtensionEvents(client)
  54.     register ClientPtr client;
  55.     {
  56.     register char n;
  57.  
  58.     REQUEST(xGetSelectedExtensionEventsReq);
  59.     swaps(&stuff->length, n);
  60.     swapl(&stuff->window, n);
  61.     return(ProcXGetSelectedExtensionEvents(client));
  62.     }
  63.  
  64. /***********************************************************************
  65.  *
  66.  * This procedure gets the current device select mask,
  67.  * if the client and server have a different byte ordering.
  68.  *
  69.  */
  70.  
  71. int
  72. ProcXGetSelectedExtensionEvents(client)
  73.     register ClientPtr client;
  74.     {
  75.     int                    i;
  76.     int                    total_length = 0;
  77.     xGetSelectedExtensionEventsReply    rep;
  78.     WindowPtr                pWin;
  79.     XEventClass                *buf;
  80.     XEventClass                *tclient;
  81.     XEventClass                *aclient;
  82.     XEventClass             *ClassFromMask ();
  83.     void                Swap32Write();
  84.     OtherInputMasks            *pOthers;
  85.     InputClientsPtr            others;
  86.  
  87.     REQUEST(xGetSelectedExtensionEventsReq);
  88.     REQUEST_SIZE_MATCH(xGetSelectedExtensionEventsReq);
  89.  
  90.     rep.repType = X_Reply;
  91.     rep.RepType = X_GetSelectedExtensionEvents;
  92.     rep.length = 0;
  93.     rep.sequenceNumber = client->sequence;
  94.     rep.this_client_count = 0;
  95.     rep.all_clients_count = 0;
  96.  
  97.     if (!(pWin = LookupWindow(stuff->window, client)))
  98.         {
  99.     SendErrorToClient(client, IReqCode, X_GetSelectedExtensionEvents, 0, 
  100.         BadWindow);
  101.     return Success;
  102.         }
  103.  
  104.     if (pOthers=wOtherInputMasks(pWin))
  105.     {
  106.     for (others = pOthers->inputClients; others; others=others->next)
  107.         for (i=0; i<EMASKSIZE; i++)
  108.         tclient = ClassFromMask (NULL, others->mask[i], i, 
  109.             &rep.all_clients_count, COUNT);
  110.  
  111.     for (others = pOthers->inputClients; others; others=others->next)
  112.         if (SameClient(others, client))
  113.         {
  114.         for (i=0; i<EMASKSIZE; i++)
  115.             tclient = ClassFromMask (NULL, others->mask[i], i, 
  116.             &rep.this_client_count, COUNT);
  117.         break;
  118.         }
  119.  
  120.     total_length = (rep.all_clients_count + rep.this_client_count) * 
  121.         sizeof (XEventClass);
  122.     rep.length = (total_length + 3) >> 2;
  123.     buf = (XEventClass *) Xalloc (total_length);
  124.  
  125.     tclient = buf;
  126.     aclient = buf + rep.this_client_count;
  127.     if (others)
  128.         for (i=0; i<EMASKSIZE; i++)
  129.         tclient = ClassFromMask (tclient, others->mask[i], i, NULL, CREATE);
  130.  
  131.     for (others = pOthers->inputClients; others; others=others->next)
  132.         for (i=0; i<EMASKSIZE; i++)
  133.         aclient = ClassFromMask (aclient, others->mask[i], i, NULL, CREATE);
  134.     }
  135.  
  136.     WriteReplyToClient (client, sizeof(xGetSelectedExtensionEventsReply), &rep);
  137.  
  138.     if (total_length)
  139.     {
  140.     client->pSwapReplyFunc = Swap32Write;
  141.     WriteSwappedDataToClient( client, total_length, buf);
  142.     Xfree (buf);
  143.     }
  144.     return Success;
  145.     }
  146.  
  147. /***********************************************************************
  148.  *
  149.  * This procedure writes the reply for the XGetSelectedExtensionEvents function,
  150.  * if the client and server have a different byte ordering.
  151.  *
  152.  */
  153.  
  154. SRepXGetSelectedExtensionEvents (client, size, rep)
  155.     ClientPtr    client;
  156.     int        size;
  157.     xGetSelectedExtensionEventsReply    *rep;
  158.     {
  159.     register char n;
  160.  
  161.     swaps(&rep->sequenceNumber, n);
  162.     swapl(&rep->length, n);
  163.     swaps(&rep->this_client_count, n);
  164.     swaps(&rep->all_clients_count, n);
  165.     WriteToClient(client, size, rep);
  166.     }
  167.