mt.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. #ifndef _INPUT_MT_H
  3. #define _INPUT_MT_H
  4. /*
  5. * Input Multitouch Library
  6. *
  7. * Copyright (c) 2010 Henrik Rydberg
  8. */
  9. #include <linux/input.h>
  10. #define TRKID_MAX 0xffff
  11. #define INPUT_MT_POINTER 0x0001 /* pointer device, e.g. trackpad */
  12. #define INPUT_MT_DIRECT 0x0002 /* direct device, e.g. touchscreen */
  13. #define INPUT_MT_DROP_UNUSED 0x0004 /* drop contacts not seen in frame */
  14. #define INPUT_MT_TRACK 0x0008 /* use in-kernel tracking */
  15. #define INPUT_MT_SEMI_MT 0x0010 /* semi-mt device, finger count handled manually */
  16. /**
  17. * struct input_mt_slot - represents the state of an input MT slot
  18. * @abs: holds current values of ABS_MT axes for this slot
  19. * @frame: last frame at which input_mt_report_slot_state() was called
  20. * @key: optional driver designation of this slot
  21. */
  22. struct input_mt_slot {
  23. int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
  24. unsigned int frame;
  25. unsigned int key;
  26. };
  27. /**
  28. * struct input_mt - state of tracked contacts
  29. * @trkid: stores MT tracking ID for the next contact
  30. * @num_slots: number of MT slots the device uses
  31. * @slot: MT slot currently being transmitted
  32. * @flags: input_mt operation flags
  33. * @frame: increases every time input_mt_sync_frame() is called
  34. * @red: reduced cost matrix for in-kernel tracking
  35. * @slots: array of slots holding current values of tracked contacts
  36. */
  37. struct input_mt {
  38. int trkid;
  39. int num_slots;
  40. int slot;
  41. unsigned int flags;
  42. unsigned int frame;
  43. int *red;
  44. struct input_mt_slot slots[];
  45. };
  46. static inline void input_mt_set_value(struct input_mt_slot *slot,
  47. unsigned code, int value)
  48. {
  49. slot->abs[code - ABS_MT_FIRST] = value;
  50. }
  51. static inline int input_mt_get_value(const struct input_mt_slot *slot,
  52. unsigned code)
  53. {
  54. return slot->abs[code - ABS_MT_FIRST];
  55. }
  56. static inline bool input_mt_is_active(const struct input_mt_slot *slot)
  57. {
  58. return input_mt_get_value(slot, ABS_MT_TRACKING_ID) >= 0;
  59. }
  60. static inline bool input_mt_is_used(const struct input_mt *mt,
  61. const struct input_mt_slot *slot)
  62. {
  63. return slot->frame == mt->frame;
  64. }
  65. int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
  66. unsigned int flags);
  67. void input_mt_destroy_slots(struct input_dev *dev);
  68. static inline int input_mt_new_trkid(struct input_mt *mt)
  69. {
  70. return mt->trkid++ & TRKID_MAX;
  71. }
  72. static inline void input_mt_slot(struct input_dev *dev, int slot)
  73. {
  74. input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
  75. }
  76. static inline bool input_is_mt_value(int axis)
  77. {
  78. return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
  79. }
  80. static inline bool input_is_mt_axis(int axis)
  81. {
  82. return axis == ABS_MT_SLOT || input_is_mt_value(axis);
  83. }
  84. bool input_mt_report_slot_state(struct input_dev *dev,
  85. unsigned int tool_type, bool active);
  86. static inline void input_mt_report_slot_inactive(struct input_dev *dev)
  87. {
  88. input_mt_report_slot_state(dev, 0, false);
  89. }
  90. void input_mt_report_finger_count(struct input_dev *dev, int count);
  91. void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
  92. void input_mt_drop_unused(struct input_dev *dev);
  93. void input_mt_sync_frame(struct input_dev *dev);
  94. /**
  95. * struct input_mt_pos - contact position
  96. * @x: horizontal coordinate
  97. * @y: vertical coordinate
  98. */
  99. struct input_mt_pos {
  100. s16 x, y;
  101. };
  102. int input_mt_assign_slots(struct input_dev *dev, int *slots,
  103. const struct input_mt_pos *pos, int num_pos,
  104. int dmax);
  105. int input_mt_get_slot_by_key(struct input_dev *dev, int key);
  106. #endif