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

  1. /* $Header: xclosedev.c,v 1.9 91/01/24 16:24:01 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.  * Extension function to close 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 "inputstr.h"            /* DeviceIntPtr         */
  38. #include "windowstr.h"            /* window structure  */
  39. #include "scrnintstr.h"            /* screen structure  */
  40. #include "XI.h"
  41. #include "XIproto.h"
  42.  
  43. extern    ScreenInfo    screenInfo;
  44. extern    WindowPtr    *WindowTable;
  45. extern    int         IReqCode;
  46. extern    int         BadDevice;
  47. extern    void        (* ReplySwapVector[256]) ();
  48. DeviceIntPtr        LookupDeviceIntRec();
  49.  
  50. /***********************************************************************
  51.  *
  52.  * This procedure closes an input device.
  53.  *
  54.  */
  55.  
  56. int
  57. SProcXCloseDevice(client)
  58.     register ClientPtr client;
  59.     {
  60.     register char n;
  61.  
  62.     REQUEST(xCloseDeviceReq);
  63.     swaps(&stuff->length, n);
  64.     return(ProcXCloseDevice(client));
  65.     }
  66.  
  67. /***********************************************************************
  68.  *
  69.  * This procedure closes an input device.
  70.  *
  71.  */
  72.  
  73. int
  74. ProcXCloseDevice(client)
  75.     register ClientPtr client;
  76.     {
  77.     int            i;
  78.     WindowPtr         pWin, p1;
  79.     DeviceIntPtr     d;
  80.  
  81.     REQUEST(xCloseDeviceReq);
  82.     REQUEST_SIZE_MATCH(xCloseDeviceReq);
  83.  
  84.     d = LookupDeviceIntRec (stuff->deviceid);
  85.     if (d == NULL)
  86.     {
  87.     SendErrorToClient(client, IReqCode, X_CloseDevice, 0, BadDevice);
  88.         return Success;
  89.     }
  90.  
  91.     if (d->grab && SameClient(d->grab, client))
  92.     (*d->DeactivateGrab)(d);               /* release active grab */
  93.  
  94.     /* Remove event selections from all windows for events from this device 
  95.        and selected by this client.
  96.        Delete passive grabs from all windows for this device.       */
  97.  
  98.     for (i=0; i<screenInfo.numScreens; i++)
  99.     {
  100.     pWin = WindowTable[i];
  101.         DeleteDeviceEvents (d, pWin, client);
  102.     p1 = pWin->firstChild;
  103.     DeleteEventsFromChildren (d, p1, client);
  104.     }
  105.  
  106.     CloseInputDevice (d, client);
  107.     return Success;
  108.     }
  109.  
  110. /***********************************************************************
  111.  *
  112.  * Walk througth the window tree, deleting event selections for this client
  113.  * from this device from all windows.
  114.  *
  115.  */
  116.  
  117. DeleteEventsFromChildren(dev, p1, client)
  118.     DeviceIntPtr    dev;
  119.     WindowPtr         p1;
  120.     ClientPtr        client;
  121.     {
  122.     WindowPtr p2;
  123.  
  124.     while (p1)
  125.         {
  126.         p2 = p1->firstChild;
  127.     DeleteDeviceEvents (dev, p1, client);
  128.     DeleteEventsFromChildren(dev, p2, client);
  129.     p1 = p1->nextSib;
  130.         }
  131.     }
  132.  
  133. /***********************************************************************
  134.  *
  135.  * Clear out event selections and passive grabs from a window for the
  136.  * specified device.
  137.  *
  138.  */
  139.  
  140. DeleteDeviceEvents (dev, pWin, client)
  141.     DeviceIntPtr    dev;
  142.     WindowPtr        pWin;
  143.     ClientPtr        client;
  144.     {
  145.     InputClientsPtr    others;
  146.     OtherInputMasks    *pOthers;
  147.     GrabPtr        grab, next;
  148.  
  149.     if (pOthers=wOtherInputMasks(pWin))
  150.     for (others=pOthers->inputClients; others; 
  151.         others = others->next)
  152.         if (SameClient(others,client))
  153.         others->mask[dev->id] = NoEventMask;
  154.  
  155.     for (grab = wPassiveGrabs(pWin); grab; grab=next)
  156.     {
  157.     next = grab->next;
  158.     if ((grab->device == dev) &&
  159.         (client->clientAsMask == CLIENT_BITS(grab->resource)))
  160.         FreeResource (grab->resource, RT_NONE);
  161.     }
  162.     }
  163.