closedev.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /************************************************************
  2. Copyright 1989, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included in
  9. all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  14. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  15. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. Except as contained in this notice, the name of The Open Group shall not be
  17. used in advertising or otherwise to promote the sale, use or other dealings
  18. in this Software without prior written authorization from The Open Group.
  19. Copyright 1989 by Hewlett-Packard Company, Palo Alto, California.
  20. All Rights Reserved
  21. Permission to use, copy, modify, and distribute this software and its
  22. documentation for any purpose and without fee is hereby granted,
  23. provided that the above copyright notice appear in all copies and that
  24. both that copyright notice and this permission notice appear in
  25. supporting documentation, and that the name of Hewlett-Packard not be
  26. used in advertising or publicity pertaining to distribution of the
  27. software without specific, written prior permission.
  28. HEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  29. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
  30. HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
  31. ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  32. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  33. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  34. SOFTWARE.
  35. ********************************************************/
  36. /***********************************************************************
  37. *
  38. * Extension function to close an extension input device.
  39. *
  40. */
  41. #ifdef HAVE_DIX_CONFIG_H
  42. #include <dix-config.h>
  43. #endif
  44. #include "inputstr.h" /* DeviceIntPtr */
  45. #include "windowstr.h" /* window structure */
  46. #include "scrnintstr.h" /* screen structure */
  47. #include <X11/extensions/XI.h>
  48. #include <X11/extensions/XIproto.h>
  49. #include "XIstubs.h"
  50. #include "exglobals.h"
  51. #include "closedev.h"
  52. /***********************************************************************
  53. *
  54. * This procedure closes an input device.
  55. *
  56. */
  57. int
  58. SProcXCloseDevice(ClientPtr client)
  59. {
  60. REQUEST(xCloseDeviceReq);
  61. swaps(&stuff->length);
  62. REQUEST_SIZE_MATCH(xCloseDeviceReq);
  63. return (ProcXCloseDevice(client));
  64. }
  65. /***********************************************************************
  66. *
  67. * Clear out event selections and passive grabs from a window for the
  68. * specified device.
  69. *
  70. */
  71. static void
  72. DeleteDeviceEvents(DeviceIntPtr dev, WindowPtr pWin, ClientPtr client)
  73. {
  74. InputClientsPtr others;
  75. OtherInputMasks *pOthers;
  76. GrabPtr grab, next;
  77. if ((pOthers = wOtherInputMasks(pWin)) != 0)
  78. for (others = pOthers->inputClients; others; others = others->next)
  79. if (SameClient(others, client))
  80. others->mask[dev->id] = NoEventMask;
  81. for (grab = wPassiveGrabs(pWin); grab; grab = next) {
  82. next = grab->next;
  83. if ((grab->device == dev) &&
  84. (client->clientAsMask == CLIENT_BITS(grab->resource)))
  85. FreeResource(grab->resource, RT_NONE);
  86. }
  87. }
  88. /***********************************************************************
  89. *
  90. * Walk througth the window tree, deleting event selections for this client
  91. * from this device from all windows.
  92. *
  93. */
  94. static void
  95. DeleteEventsFromChildren(DeviceIntPtr dev, WindowPtr p1, ClientPtr client)
  96. {
  97. WindowPtr p2;
  98. while (p1) {
  99. p2 = p1->firstChild;
  100. DeleteDeviceEvents(dev, p1, client);
  101. DeleteEventsFromChildren(dev, p2, client);
  102. p1 = p1->nextSib;
  103. }
  104. }
  105. /***********************************************************************
  106. *
  107. * This procedure closes an input device.
  108. *
  109. */
  110. int
  111. ProcXCloseDevice(ClientPtr client)
  112. {
  113. int rc, i;
  114. WindowPtr pWin, p1;
  115. DeviceIntPtr d;
  116. REQUEST(xCloseDeviceReq);
  117. REQUEST_SIZE_MATCH(xCloseDeviceReq);
  118. rc = dixLookupDevice(&d, stuff->deviceid, client, DixUseAccess);
  119. if (rc != Success)
  120. return rc;
  121. if (d->deviceGrab.grab && SameClient(d->deviceGrab.grab, client))
  122. (*d->deviceGrab.DeactivateGrab) (d); /* release active grab */
  123. /* Remove event selections from all windows for events from this device
  124. * and selected by this client.
  125. * Delete passive grabs from all windows for this device. */
  126. for (i = 0; i < screenInfo.numScreens; i++) {
  127. pWin = screenInfo.screens[i]->root;
  128. DeleteDeviceEvents(d, pWin, client);
  129. p1 = pWin->firstChild;
  130. DeleteEventsFromChildren(d, p1, client);
  131. }
  132. return Success;
  133. }