litest-device-alps-3fg.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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 <assert.h>
  25. #include "libinput-util.h"
  26. #include "litest-int.h"
  27. #include "litest.h"
  28. struct alps {
  29. unsigned int first, second;
  30. unsigned int active_touches;
  31. };
  32. static bool
  33. alps_create(struct litest_device *d)
  34. {
  35. d->private = zalloc(sizeof(struct alps));
  36. return true; /* we want litest to create our device */
  37. }
  38. static bool
  39. touch_down(struct litest_device *d, unsigned int slot, double x, double y)
  40. {
  41. struct alps *alps = d->private;
  42. alps->active_touches++;
  43. if (alps->active_touches == 1)
  44. alps->first = slot;
  45. if (alps->active_touches == 2)
  46. alps->second = slot;
  47. /* This device announces 4 slots but only does two slots. So
  48. * anything over 2 slots we just drop for events,
  49. * litest takes care of BTN_TOOL_* for us. */
  50. if (alps->active_touches > 2) {
  51. /* Need to send SYN_REPORT to flush litest's BTN_TOOL_* updates */
  52. litest_event(d, EV_SYN, SYN_REPORT, 0);
  53. return true;
  54. }
  55. return false;
  56. }
  57. static bool
  58. touch_move(struct litest_device *d, unsigned int slot, double x, double y)
  59. {
  60. struct alps *alps = d->private;
  61. if (alps->active_touches > 2 && slot != alps->first && slot != alps->second)
  62. return true;
  63. return false;
  64. }
  65. static bool
  66. touch_up(struct litest_device *d, unsigned int slot)
  67. {
  68. struct alps *alps = d->private;
  69. assert(alps->active_touches >= 1);
  70. alps->active_touches--;
  71. /* Need to send SYN_REPORT to flush litest's BTN_TOOL_* updates */
  72. if (alps->active_touches > 2 && slot != alps->first && slot != alps->second) {
  73. litest_event(d, EV_SYN, SYN_REPORT, 0);
  74. return true;
  75. }
  76. if (slot == alps->first)
  77. alps->first = UINT_MAX;
  78. if (slot == alps->second)
  79. alps->second = UINT_MAX;
  80. return false;
  81. }
  82. static struct input_event down[] = {
  83. { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
  84. { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
  85. { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
  86. { .type = EV_ABS, .code = ABS_MT_TRACKING_ID, .value = LITEST_AUTO_ASSIGN },
  87. { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
  88. { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
  89. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  90. { .type = -1, .code = -1 },
  91. };
  92. static struct input_event move[] = {
  93. { .type = EV_ABS, .code = ABS_MT_SLOT, .value = LITEST_AUTO_ASSIGN },
  94. { .type = EV_ABS, .code = ABS_X, .value = LITEST_AUTO_ASSIGN },
  95. { .type = EV_ABS, .code = ABS_Y, .value = LITEST_AUTO_ASSIGN },
  96. { .type = EV_ABS, .code = ABS_MT_POSITION_X, .value = LITEST_AUTO_ASSIGN },
  97. { .type = EV_ABS, .code = ABS_MT_POSITION_Y, .value = LITEST_AUTO_ASSIGN },
  98. { .type = EV_SYN, .code = SYN_REPORT, .value = 0 },
  99. { .type = -1, .code = -1 },
  100. };
  101. static struct litest_device_interface interface = {
  102. .touch_down_events = down,
  103. .touch_move_events = move,
  104. .touch_down = touch_down,
  105. .touch_move = touch_move,
  106. .touch_up = touch_up,
  107. };
  108. static struct input_id input_id = {
  109. .bustype = 0x11,
  110. .vendor = 0x2,
  111. .product = 0x8,
  112. .version = 0x700,
  113. };
  114. /* clang-format off */
  115. static int events[] = {
  116. EV_KEY, BTN_LEFT,
  117. EV_KEY, BTN_RIGHT,
  118. EV_KEY, BTN_MIDDLE,
  119. EV_KEY, BTN_TOOL_FINGER,
  120. EV_KEY, BTN_TOUCH,
  121. EV_KEY, BTN_TOOL_DOUBLETAP,
  122. EV_KEY, BTN_TOOL_TRIPLETAP,
  123. EV_KEY, BTN_TOOL_QUADTAP,
  124. EV_KEY, BTN_TOOL_QUINTTAP,
  125. INPUT_PROP_MAX, INPUT_PROP_POINTER,
  126. -1, -1,
  127. };
  128. /* clang-format on */
  129. /* Note: we use the user-supplied resolution here, see #408 */
  130. /* clang-format off */
  131. static struct input_absinfo absinfo[] = {
  132. { ABS_X, 0, 4095, 0, 0, 37 },
  133. { ABS_Y, 0, 2047, 0, 0, 26 },
  134. { ABS_PRESSURE, 0, 127, 0, 0, 0 },
  135. { ABS_MT_SLOT, 0, 3, 0, 0, 0 },
  136. { ABS_MT_POSITION_X, 0, 4095, 0, 0, 37 },
  137. { ABS_MT_POSITION_Y, 0, 2047, 0, 0, 26 },
  138. { ABS_MT_TRACKING_ID, 0, 65535, 0, 0, 0 },
  139. { .value = -1 },
  140. };
  141. /* clang-format on */
  142. TEST_DEVICE(LITEST_ALPS_3FG,
  143. .features = LITEST_TOUCHPAD | LITEST_BUTTON,
  144. .interface = &interface,
  145. .name = "AlpsPS/2 ALPS GlidePoint",
  146. .id = &input_id,
  147. .events = events,
  148. .absinfo = absinfo,
  149. .create = alps_create,
  150. .udev_properties = {
  151. { "ID_INTEGRATION", "internal" },
  152. { NULL },
  153. }, )