mt.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. /**
  19. * struct input_mt_slot - represents the state of an input MT slot
  20. * @abs: holds current values of ABS_MT axes for this slot
  21. * @frame: last frame at which input_mt_report_slot_state() was called
  22. * @key: optional driver designation of this slot
  23. */
  24. struct input_mt_slot {
  25. int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
  26. unsigned int frame;
  27. unsigned int key;
  28. };
  29. /**
  30. * struct input_mt - state of tracked contacts
  31. * @trkid: stores MT tracking ID for the next contact
  32. * @num_slots: number of MT slots the device uses
  33. * @slot: MT slot currently being transmitted
  34. * @flags: input_mt operation flags
  35. * @frame: increases every time input_mt_sync_frame() is called
  36. * @red: reduced cost matrix for in-kernel tracking
  37. * @slots: array of slots holding current values of tracked contacts
  38. */
  39. struct input_mt {
  40. int trkid;
  41. int num_slots;
  42. int slot;
  43. unsigned int flags;
  44. unsigned int frame;
  45. int *red;
  46. struct input_mt_slot slots[];
  47. };
  48. static inline void input_mt_set_value(struct input_mt_slot *slot,
  49. unsigned code, int value)
  50. {
  51. slot->abs[code - ABS_MT_FIRST] = value;
  52. }
  53. static inline int input_mt_get_value(const struct input_mt_slot *slot,
  54. unsigned code)
  55. {
  56. return slot->abs[code - ABS_MT_FIRST];
  57. }
  58. static inline bool input_mt_is_active(const struct input_mt_slot *slot)
  59. {
  60. return input_mt_get_value(slot, ABS_MT_TRACKING_ID) >= 0;
  61. }
  62. static inline bool input_mt_is_used(const struct input_mt *mt,
  63. const struct input_mt_slot *slot)
  64. {
  65. return slot->frame == mt->frame;
  66. }
  67. int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
  68. unsigned int flags);
  69. void input_mt_destroy_slots(struct input_dev *dev);
  70. static inline int input_mt_new_trkid(struct input_mt *mt)
  71. {
  72. return mt->trkid++ & TRKID_MAX;
  73. }
  74. static inline void input_mt_slot(struct input_dev *dev, int slot)
  75. {
  76. input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
  77. }
  78. static inline bool input_is_mt_value(int axis)
  79. {
  80. return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
  81. }
  82. static inline bool input_is_mt_axis(int axis)
  83. {
  84. return axis == ABS_MT_SLOT || input_is_mt_value(axis);
  85. }
  86. void input_mt_report_slot_state(struct input_dev *dev,
  87. unsigned int tool_type, bool active);
  88. void input_mt_report_finger_count(struct input_dev *dev, int count);
  89. void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
  90. void input_mt_sync_frame(struct input_dev *dev);
  91. /**
  92. * struct input_mt_pos - contact position
  93. * @x: horizontal coordinate
  94. * @y: vertical coordinate
  95. */
  96. struct input_mt_pos {
  97. s16 x, y;
  98. };
  99. int input_mt_assign_slots(struct input_dev *dev, int *slots,
  100. const struct input_mt_pos *pos, int num_pos);
  101. int input_mt_get_slot_by_key(struct input_dev *dev, int key);
  102. #endif