xiallowev.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * Copyright © 2009 Red Hat, Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  21. * DEALINGS IN THE SOFTWARE.
  22. *
  23. * Author: Peter Hutterer
  24. */
  25. /***********************************************************************
  26. *
  27. * Request to allow some device events.
  28. *
  29. */
  30. #ifdef HAVE_DIX_CONFIG_H
  31. #include <dix-config.h>
  32. #endif
  33. #include "inputstr.h" /* DeviceIntPtr */
  34. #include "windowstr.h" /* window structure */
  35. #include "mi.h"
  36. #include "eventstr.h"
  37. #include <X11/extensions/XI2.h>
  38. #include <X11/extensions/XI2proto.h>
  39. #include "exglobals.h" /* BadDevice */
  40. #include "exevents.h"
  41. #include "xiallowev.h"
  42. int
  43. SProcXIAllowEvents(ClientPtr client)
  44. {
  45. REQUEST(xXIAllowEventsReq);
  46. REQUEST_AT_LEAST_SIZE(xXIAllowEventsReq);
  47. swaps(&stuff->length);
  48. swaps(&stuff->deviceid);
  49. swapl(&stuff->time);
  50. if (stuff->length > 3) {
  51. xXI2_2AllowEventsReq *req_xi22 = (xXI2_2AllowEventsReq *) stuff;
  52. REQUEST_AT_LEAST_SIZE(xXI2_2AllowEventsReq);
  53. swapl(&req_xi22->touchid);
  54. swapl(&req_xi22->grab_window);
  55. }
  56. return ProcXIAllowEvents(client);
  57. }
  58. int
  59. ProcXIAllowEvents(ClientPtr client)
  60. {
  61. TimeStamp time;
  62. DeviceIntPtr dev;
  63. int ret = Success;
  64. XIClientPtr xi_client;
  65. Bool have_xi22 = FALSE;
  66. REQUEST(xXI2_2AllowEventsReq);
  67. xi_client = dixLookupPrivate(&client->devPrivates, XIClientPrivateKey);
  68. if (version_compare(xi_client->major_version,
  69. xi_client->minor_version, 2, 2) >= 0) {
  70. REQUEST_AT_LEAST_SIZE(xXI2_2AllowEventsReq);
  71. have_xi22 = TRUE;
  72. }
  73. else {
  74. REQUEST_AT_LEAST_SIZE(xXIAllowEventsReq);
  75. }
  76. ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetAttrAccess);
  77. if (ret != Success)
  78. return ret;
  79. time = ClientTimeToServerTime(stuff->time);
  80. switch (stuff->mode) {
  81. case XIReplayDevice:
  82. AllowSome(client, time, dev, NOT_GRABBED);
  83. break;
  84. case XISyncDevice:
  85. AllowSome(client, time, dev, FREEZE_NEXT_EVENT);
  86. break;
  87. case XIAsyncDevice:
  88. AllowSome(client, time, dev, THAWED);
  89. break;
  90. case XIAsyncPairedDevice:
  91. if (IsMaster(dev))
  92. AllowSome(client, time, dev, THAW_OTHERS);
  93. break;
  94. case XISyncPair:
  95. if (IsMaster(dev))
  96. AllowSome(client, time, dev, FREEZE_BOTH_NEXT_EVENT);
  97. break;
  98. case XIAsyncPair:
  99. if (IsMaster(dev))
  100. AllowSome(client, time, dev, THAWED_BOTH);
  101. break;
  102. case XIRejectTouch:
  103. case XIAcceptTouch:
  104. {
  105. int rc;
  106. WindowPtr win;
  107. if (!have_xi22)
  108. return BadValue;
  109. rc = dixLookupWindow(&win, stuff->grab_window, client, DixReadAccess);
  110. if (rc != Success)
  111. return rc;
  112. ret = TouchAcceptReject(client, dev, stuff->mode, stuff->touchid,
  113. stuff->grab_window, &client->errorValue);
  114. }
  115. break;
  116. default:
  117. client->errorValue = stuff->mode;
  118. ret = BadValue;
  119. }
  120. return ret;
  121. }