xisetdevfocus.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2008 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 set and get an input device's focus.
  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 <X11/extensions/XI2.h>
  36. #include <X11/extensions/XI2proto.h>
  37. #include "exglobals.h" /* BadDevice */
  38. #include "xisetdevfocus.h"
  39. int
  40. SProcXISetFocus(ClientPtr client)
  41. {
  42. REQUEST(xXISetFocusReq);
  43. REQUEST_AT_LEAST_SIZE(xXISetFocusReq);
  44. swaps(&stuff->length);
  45. swaps(&stuff->deviceid);
  46. swapl(&stuff->focus);
  47. swapl(&stuff->time);
  48. return ProcXISetFocus(client);
  49. }
  50. int
  51. SProcXIGetFocus(ClientPtr client)
  52. {
  53. REQUEST(xXIGetFocusReq);
  54. REQUEST_AT_LEAST_SIZE(xXIGetFocusReq);
  55. swaps(&stuff->length);
  56. swaps(&stuff->deviceid);
  57. return ProcXIGetFocus(client);
  58. }
  59. int
  60. ProcXISetFocus(ClientPtr client)
  61. {
  62. DeviceIntPtr dev;
  63. int ret;
  64. REQUEST(xXISetFocusReq);
  65. REQUEST_AT_LEAST_SIZE(xXISetFocusReq);
  66. ret = dixLookupDevice(&dev, stuff->deviceid, client, DixSetFocusAccess);
  67. if (ret != Success)
  68. return ret;
  69. if (!dev->focus)
  70. return BadDevice;
  71. return SetInputFocus(client, dev, stuff->focus, RevertToParent,
  72. stuff->time, TRUE);
  73. }
  74. int
  75. ProcXIGetFocus(ClientPtr client)
  76. {
  77. xXIGetFocusReply rep;
  78. DeviceIntPtr dev;
  79. int ret;
  80. REQUEST(xXIGetFocusReq);
  81. REQUEST_AT_LEAST_SIZE(xXIGetFocusReq);
  82. ret = dixLookupDevice(&dev, stuff->deviceid, client, DixGetFocusAccess);
  83. if (ret != Success)
  84. return ret;
  85. if (!dev->focus)
  86. return BadDevice;
  87. rep = (xXIGetFocusReply) {
  88. .repType = X_Reply,
  89. .RepType = X_XIGetFocus,
  90. .sequenceNumber = client->sequence,
  91. .length = 0
  92. };
  93. if (dev->focus->win == NoneWin)
  94. rep.focus = None;
  95. else if (dev->focus->win == PointerRootWin)
  96. rep.focus = PointerRoot;
  97. else if (dev->focus->win == FollowKeyboardWin)
  98. rep.focus = FollowKeyboard;
  99. else
  100. rep.focus = dev->focus->win->drawable.id;
  101. WriteReplyToClient(client, sizeof(xXIGetFocusReply), &rep);
  102. return Success;
  103. }
  104. void
  105. SRepXIGetFocus(ClientPtr client, int len, xXIGetFocusReply * rep)
  106. {
  107. swaps(&rep->sequenceNumber);
  108. swapl(&rep->length);
  109. swapl(&rep->focus);
  110. WriteToClient(client, len, rep);
  111. }