mt.h 3.4 KB

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