xtest.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #ifdef HAVE_DIX_CONFIG_H
  24. #include <dix-config.h>
  25. #endif
  26. #include <stdint.h>
  27. #include <X11/Xatom.h>
  28. #include "input.h"
  29. #include "inputstr.h"
  30. #include "scrnintstr.h"
  31. #include "exevents.h"
  32. #include "extinit.h"
  33. #include "xkbsrv.h"
  34. #include "xserver-properties.h"
  35. #include "syncsrv.h"
  36. /**
  37. */
  38. /* from Xext/xtest.c */
  39. extern DeviceIntPtr xtestpointer, xtestkeyboard;
  40. /* Needed for the screen setup, otherwise we crash during sprite initialization */
  41. static Bool
  42. device_cursor_init(DeviceIntPtr dev, ScreenPtr screen)
  43. {
  44. return TRUE;
  45. }
  46. static void
  47. device_cursor_cleanup(DeviceIntPtr dev, ScreenPtr screen)
  48. {
  49. }
  50. static void
  51. xtest_init_devices(void)
  52. {
  53. ScreenRec screen;
  54. ClientRec server_client;
  55. /* random stuff that needs initialization */
  56. memset(&screen, 0, sizeof(screen));
  57. screenInfo.numScreens = 1;
  58. screenInfo.screens[0] = &screen;
  59. screen.myNum = 0;
  60. screen.id = 100;
  61. screen.width = 640;
  62. screen.height = 480;
  63. screen.DeviceCursorInitialize = device_cursor_init;
  64. screen.DeviceCursorCleanup = device_cursor_cleanup;
  65. dixResetPrivates();
  66. serverClient = &server_client;
  67. InitClient(serverClient, 0, (void *) NULL);
  68. if (!InitClientResources(serverClient)) /* for root resources */
  69. FatalError("couldn't init server resources");
  70. InitAtoms();
  71. SyncExtensionInit();
  72. /* this also inits the xtest devices */
  73. InitCoreDevices();
  74. assert(xtestpointer);
  75. assert(xtestkeyboard);
  76. assert(IsXTestDevice(xtestpointer, NULL));
  77. assert(IsXTestDevice(xtestkeyboard, NULL));
  78. assert(IsXTestDevice(xtestpointer, inputInfo.pointer));
  79. assert(IsXTestDevice(xtestkeyboard, inputInfo.keyboard));
  80. assert(GetXTestDevice(inputInfo.pointer) == xtestpointer);
  81. assert(GetXTestDevice(inputInfo.keyboard) == xtestkeyboard);
  82. }
  83. /**
  84. * Each xtest devices has a property attached marking it. This property
  85. * cannot be changed.
  86. */
  87. static void
  88. xtest_properties(void)
  89. {
  90. int rc;
  91. char value = 1;
  92. XIPropertyValuePtr prop;
  93. Atom xtest_prop = XIGetKnownProperty(XI_PROP_XTEST_DEVICE);
  94. rc = XIGetDeviceProperty(xtestpointer, xtest_prop, &prop);
  95. assert(rc == Success);
  96. assert(prop);
  97. rc = XIGetDeviceProperty(xtestkeyboard, xtest_prop, &prop);
  98. assert(rc == Success);
  99. assert(prop != NULL);
  100. rc = XIChangeDeviceProperty(xtestpointer, xtest_prop,
  101. XA_INTEGER, 8, PropModeReplace, 1, &value,
  102. FALSE);
  103. assert(rc == BadAccess);
  104. rc = XIChangeDeviceProperty(xtestkeyboard, xtest_prop,
  105. XA_INTEGER, 8, PropModeReplace, 1, &value,
  106. FALSE);
  107. assert(rc == BadAccess);
  108. }
  109. int
  110. main(int argc, char **argv)
  111. {
  112. xtest_init_devices();
  113. xtest_properties();
  114. return 0;
  115. }