litest-device-elan-tablet.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * Copyright © 2020 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. static struct input_event proximity_in_events[] = {
  27. { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
  28. { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
  29. { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
  30. { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
  31. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  32. { .type = -1, .code = -1 },
  33. };
  34. static struct input_event proximity_out_events[] = {
  35. { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
  36. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  37. { .type = -1, .code = -1 },
  38. };
  39. static struct input_event motion_events[] = {
  40. { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
  41. { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
  42. { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
  43. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  44. { .type = -1, .code = -1 },
  45. };
  46. static bool
  47. proximity_in(struct litest_device *d,
  48. unsigned int tool_type,
  49. double *x,
  50. double *y,
  51. struct axis_replacement *axes)
  52. {
  53. /* nothing special needed for the pen tool, so let litest handle
  54. * this */
  55. if (tool_type == BTN_TOOL_PEN)
  56. return false;
  57. /* a non-pen tool requires the pen to be in proximity as well. */
  58. int sx = litest_scale(d, ABS_X, *x);
  59. int sy = litest_scale(d, ABS_Y, *y);
  60. litest_event(d, EV_ABS, ABS_X, sx);
  61. litest_event(d, EV_ABS, ABS_X, sy);
  62. litest_event(d, EV_KEY, BTN_TOOL_PEN, 1);
  63. litest_event(d, EV_SYN, SYN_REPORT, 0);
  64. /* litest will append the proximity_in_events if we return false,
  65. * including the right tool event */
  66. return false;
  67. }
  68. static bool
  69. proximity_out(struct litest_device *d, unsigned int tool_type)
  70. {
  71. /* a non-pen tool requires the pen to go out of proximity as well.
  72. * litest will append the proximity_out_events if we return false
  73. */
  74. if (tool_type != BTN_TOOL_PEN)
  75. litest_event(d, EV_KEY, BTN_TOOL_PEN, 0);
  76. return false;
  77. }
  78. static int
  79. get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
  80. {
  81. switch (evcode) {
  82. case ABS_PRESSURE:
  83. *value = 100;
  84. return 0;
  85. }
  86. return 1;
  87. }
  88. static struct litest_device_interface interface = {
  89. .tablet_proximity_in_events = proximity_in_events,
  90. .tablet_proximity_out_events = proximity_out_events,
  91. .tablet_motion_events = motion_events,
  92. .tablet_proximity_in = proximity_in,
  93. .tablet_proximity_out = proximity_out,
  94. .get_axis_default = get_axis_default,
  95. };
  96. /* clang-format off */
  97. static struct input_absinfo absinfo[] = {
  98. { ABS_X, 0, 18176, 0, 0, 62 },
  99. { ABS_Y, 0, 10240, 0, 0, 62 },
  100. { ABS_PRESSURE, 0, 4096, 0, 0, 0 },
  101. { .value = -1 },
  102. };
  103. /* clang-format on */
  104. static struct input_id input_id = {
  105. .bustype = 0x18,
  106. .vendor = 0x4f3,
  107. .product = 0x23b9,
  108. .version = 0x100,
  109. };
  110. /* Note: this tablet is one that sets both BTN_TOOL_PEN and BTN_TOOL_RUBBER,
  111. * see https://gitlab.freedesktop.org/libinput/libinput/-/issues/259
  112. * The one in the issue isn't the exact same model, but only the pid and x/y
  113. * axis max differs differs.
  114. */
  115. /* clang-format off */
  116. static int events[] = {
  117. EV_KEY, BTN_TOOL_PEN,
  118. EV_KEY, BTN_TOOL_RUBBER,
  119. EV_KEY, BTN_TOUCH,
  120. EV_KEY, BTN_STYLUS,
  121. EV_MSC, MSC_SCAN,
  122. -1, -1,
  123. };
  124. /* clang-format on */
  125. TEST_DEVICE(LITEST_ELAN_TABLET,
  126. .features = LITEST_TABLET,
  127. .interface = &interface,
  128. .name = "ELAN2514:00 04F3:23B9",
  129. .id = &input_id,
  130. .events = events,
  131. .absinfo = absinfo,
  132. .udev_properties = {
  133. { "ID_INTEGRATION", "internal" },
  134. { NULL },
  135. }, )