litest-device-xen-virtual-pointer.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright © 2014 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. #include "config.h"
  24. #include <assert.h>
  25. #include "litest-int.h"
  26. #include "litest.h"
  27. static bool
  28. touch_down(struct litest_device *d, unsigned int slot, double x, double y)
  29. {
  30. assert(slot == 0);
  31. litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
  32. litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
  33. litest_event(d, EV_SYN, SYN_REPORT, 0);
  34. return true; /* we handled the event */
  35. }
  36. static bool
  37. touch_move(struct litest_device *d, unsigned int slot, double x, double y)
  38. {
  39. assert(slot == 0);
  40. litest_event(d, EV_ABS, ABS_X, litest_scale(d, ABS_X, x));
  41. litest_event(d, EV_ABS, ABS_Y, litest_scale(d, ABS_Y, y));
  42. litest_event(d, EV_SYN, SYN_REPORT, 0);
  43. return true; /* we handled the event */
  44. }
  45. static bool
  46. touch_up(struct litest_device *d, unsigned int slot)
  47. {
  48. assert(slot == 0);
  49. litest_event(d, EV_SYN, SYN_REPORT, 0);
  50. return true; /* we handled the event */
  51. }
  52. static struct litest_device_interface interface = {
  53. .touch_down = touch_down,
  54. .touch_move = touch_move,
  55. .touch_up = touch_up,
  56. };
  57. /* clang-format off */
  58. static struct input_absinfo absinfo[] = {
  59. { ABS_X, 0, 800, 0, 0, 0 },
  60. { ABS_Y, 0, 800, 0, 0, 0 },
  61. { .value = -1 },
  62. };
  63. /* clang-format on */
  64. static struct input_id input_id = {
  65. .bustype = 0x01,
  66. .vendor = 0x5853,
  67. .product = 0xfffe,
  68. };
  69. /* clang-format off */
  70. static int events[] = {
  71. EV_KEY, BTN_LEFT,
  72. EV_KEY, BTN_RIGHT,
  73. EV_KEY, BTN_MIDDLE,
  74. EV_KEY, BTN_SIDE,
  75. EV_KEY, BTN_EXTRA,
  76. EV_KEY, BTN_FORWARD,
  77. EV_KEY, BTN_BACK,
  78. EV_KEY, BTN_TASK,
  79. EV_REL, REL_WHEEL,
  80. -1, -1,
  81. };
  82. /* clang-format on */
  83. TEST_DEVICE(LITEST_XEN_VIRTUAL_POINTER,
  84. .features = LITEST_WHEEL | LITEST_BUTTON | LITEST_ABSOLUTE,
  85. .interface = &interface,
  86. .name = "Xen Virtual Pointer",
  87. .id = &input_id,
  88. .events = events,
  89. .absinfo = absinfo,
  90. .udev_properties = {
  91. { "ID_INTEGRATION", "internal" },
  92. { NULL },
  93. }, )