litest-device-wacom-isdv4-524c-pen.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright © 2019 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 "litest-int.h"
  25. #include "litest.h"
  26. struct priv {
  27. unsigned int tool;
  28. };
  29. static bool
  30. create(struct litest_device *d)
  31. {
  32. d->private = zalloc(sizeof(struct priv));
  33. return true; /* we want litest to create our device */
  34. }
  35. static struct input_event proximity_in[] = {
  36. { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
  37. { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
  38. { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
  39. { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
  40. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  41. { .type = -1, .code = -1 },
  42. };
  43. static struct input_event proximity_out[] = {
  44. { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
  45. { .type = EV_ABS, .code = ABS_PRESSURE, .value = 0 },
  46. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  47. { .type = -1, .code = -1 },
  48. };
  49. static struct input_event motion[] = {
  50. { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
  51. { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
  52. { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
  53. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  54. { .type = -1, .code = -1 },
  55. };
  56. static int
  57. get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
  58. {
  59. switch (evcode) {
  60. case ABS_PRESSURE:
  61. *value = 4000;
  62. return 0;
  63. case ABS_TILT_X:
  64. case ABS_TILT_Y:
  65. abort();
  66. }
  67. return 1;
  68. }
  69. static bool
  70. prox_in(struct litest_device *d,
  71. unsigned int tool_type,
  72. double *x,
  73. double *y,
  74. struct axis_replacement *axes)
  75. {
  76. struct priv *priv = d->private;
  77. priv->tool = tool_type;
  78. return false;
  79. }
  80. static bool
  81. prox_out(struct litest_device *d, unsigned int tool_type)
  82. {
  83. struct priv *priv = d->private;
  84. priv->tool = 0;
  85. return false;
  86. }
  87. static bool
  88. tip_down(struct litest_device *d, double *x, double *y, struct axis_replacement *axes)
  89. {
  90. litest_event(d, EV_KEY, BTN_TOOL_PEN, 1);
  91. return false; /* use the default behavior otherwise */
  92. }
  93. static bool
  94. tip_up(struct litest_device *d, double *x, double *y, struct axis_replacement *axes)
  95. {
  96. struct priv *priv = d->private;
  97. if (priv->tool != BTN_TOOL_PEN)
  98. litest_event(d, EV_KEY, BTN_TOOL_PEN, 0);
  99. return false; /* use the default behavior otherwise */
  100. }
  101. static struct litest_device_interface interface = {
  102. .tablet_proximity_in_events = proximity_in,
  103. .tablet_proximity_out_events = proximity_out,
  104. .tablet_motion_events = motion,
  105. .tablet_proximity_in = prox_in,
  106. .tablet_proximity_out = prox_out,
  107. .tablet_tip_down = tip_down,
  108. .tablet_tip_up = tip_up,
  109. .get_axis_default = get_axis_default,
  110. };
  111. /* clang-format off */
  112. static struct input_absinfo absinfo[] = {
  113. { ABS_X, 0, 30931, 0, 0, 100 },
  114. { ABS_Y, 0, 17399, 0, 0, 100 },
  115. /* This pen has tilt, but doesn't send events */
  116. { ABS_TILT_X, -90, 90, 0, 0, 57 },
  117. { ABS_TILT_Y, -90, 90, 0, 0, 57 },
  118. { ABS_PRESSURE, 0, 4095, 0, 0, 0 },
  119. { .value = -1 },
  120. };
  121. /* clang-format on */
  122. static struct input_id input_id = {
  123. .bustype = 0x3,
  124. .vendor = 0x2d1f, /* Note: this is Wacom's Android VID */
  125. .product = 0x524c,
  126. };
  127. /* clang-format off */
  128. static int events[] = {
  129. EV_KEY, BTN_TOOL_PEN,
  130. EV_KEY, BTN_TOOL_RUBBER,
  131. EV_KEY, BTN_TOUCH,
  132. EV_KEY, BTN_STYLUS,
  133. EV_KEY, BTN_STYLUS2,
  134. INPUT_PROP_MAX, INPUT_PROP_DIRECT,
  135. -1, -1,
  136. };
  137. /* clang-format on */
  138. TEST_DEVICE(LITEST_WACOM_ISDV4_524C_PEN,
  139. .features = LITEST_TABLET | LITEST_HOVER,
  140. .interface = &interface,
  141. .name = "Wacom Co.,Ltd. Pen and multitouch sensor Stylus",
  142. .id = &input_id,
  143. .events = events,
  144. .absinfo = absinfo,
  145. .create = create,
  146. .udev_properties = {
  147. { "ID_INTEGRATION", "external" },
  148. { NULL },
  149. }, )