litest-device-wacom-calibrated-tablet.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*
  2. * Copyright © 2023 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 bool
  27. inverter(struct litest_device *dev, double *x, double *y, struct axis_replacement *axes)
  28. {
  29. /* Input data is in percent (0-100), so let's swap x and y around.
  30. * With our matrix this should be undone by libinput later
  31. * and the tablet behaves as if normal */
  32. *x = 100 - *x;
  33. *y = 100 - *y;
  34. /* let the generic code handle the event */
  35. return false;
  36. }
  37. static bool
  38. proximity_in_handler(struct litest_device *dev,
  39. unsigned int tool_type,
  40. double *x,
  41. double *y,
  42. struct axis_replacement *axes)
  43. {
  44. /* let the generic code handle the event */
  45. return inverter(dev, x, y, axes);
  46. }
  47. static struct input_event proximity_in[] = {
  48. { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
  49. { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
  50. { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
  51. { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 1 },
  52. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  53. { .type = -1, .code = -1 },
  54. };
  55. static struct input_event proximity_out[] = {
  56. { .type = EV_ABS, .code = ABS_X, .value = 0 },
  57. { .type = EV_ABS, .code = ABS_Y, .value = 0 },
  58. { .type = EV_ABS, .code = ABS_PRESSURE, .value = 0 },
  59. { .type = EV_KEY, .code = LITEST_BTN_TOOL_AUTO, .value = 0 },
  60. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  61. { .type = -1, .code = -1 },
  62. };
  63. static struct input_event motion[] = {
  64. { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
  65. { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
  66. { .type = EV_ABS, .code = ABS_PRESSURE, .value = LITEST_AUTO_ASSIGN },
  67. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  68. { .type = -1, .code = -1 },
  69. };
  70. static int
  71. get_axis_default(struct litest_device *d, unsigned int evcode, int32_t *value)
  72. {
  73. switch (evcode) {
  74. case ABS_PRESSURE:
  75. *value = 100;
  76. return 0;
  77. }
  78. return 1;
  79. }
  80. static struct litest_device_interface interface = {
  81. .tablet_proximity_in = proximity_in_handler,
  82. .tablet_tip_down = inverter,
  83. .tablet_tip_up = inverter,
  84. .tablet_motion = inverter,
  85. .tablet_proximity_in_events = proximity_in,
  86. .tablet_proximity_out_events = proximity_out,
  87. .tablet_motion_events = motion,
  88. .get_axis_default = get_axis_default,
  89. };
  90. /* clang-format off */
  91. static struct input_absinfo absinfo[] = {
  92. { ABS_X, 0, 29476, 4, 0, 100 },
  93. { ABS_Y, 0, 16624, 4, 0, 100 },
  94. { ABS_PRESSURE, 0, 1023, 0, 0, 0 },
  95. { .value = -1 },
  96. };
  97. /* clang-format on */
  98. static struct input_id input_id = {
  99. .bustype = 0x3,
  100. .vendor = 0x56a,
  101. .product = 0x501e,
  102. .version = 0x111,
  103. };
  104. /* clang-format off */
  105. static int events[] = {
  106. EV_KEY, BTN_TOOL_PEN,
  107. EV_KEY, BTN_TOOL_RUBBER,
  108. EV_KEY, BTN_TOUCH,
  109. EV_KEY, BTN_STYLUS,
  110. EV_KEY, BTN_STYLUS2,
  111. INPUT_PROP_MAX, INPUT_PROP_DIRECT,
  112. -1, -1,
  113. };
  114. /* clang-format on */
  115. TEST_DEVICE(LITEST_WACOM_CALIBRATED_TABLET_PEN,
  116. .features = LITEST_TABLET | LITEST_PRECALIBRATED,
  117. .interface = &interface,
  118. .name = "Wacom MultiTouch Sensor Pen",
  119. .id = &input_id,
  120. .events = events,
  121. .absinfo = absinfo,
  122. .udev_properties = {
  123. { "LIBINPUT_CALIBRATION_MATRIX", "-1 0 1 0 -1 1" },
  124. { "ID_INTEGRATION", "external" },
  125. { NULL },
  126. }, )