mt.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. */
  23. struct input_mt_slot {
  24. int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
  25. unsigned int frame;
  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. int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
  61. unsigned int flags);
  62. void input_mt_destroy_slots(struct input_dev *dev);
  63. static inline int input_mt_new_trkid(struct input_mt *mt)
  64. {
  65. return mt->trkid++ & TRKID_MAX;
  66. }
  67. static inline void input_mt_slot(struct input_dev *dev, int slot)
  68. {
  69. input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
  70. }
  71. static inline bool input_is_mt_value(int axis)
  72. {
  73. return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
  74. }
  75. static inline bool input_is_mt_axis(int axis)
  76. {
  77. return axis == ABS_MT_SLOT || input_is_mt_value(axis);
  78. }
  79. void input_mt_report_slot_state(struct input_dev *dev,
  80. unsigned int tool_type, bool active);
  81. void input_mt_report_finger_count(struct input_dev *dev, int count);
  82. void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
  83. void input_mt_sync_frame(struct input_dev *dev);
  84. /**
  85. * struct input_mt_pos - contact position
  86. * @x: horizontal coordinate
  87. * @y: vertical coordinate
  88. */
  89. struct input_mt_pos {
  90. s16 x, y;
  91. };
  92. int input_mt_assign_slots(struct input_dev *dev, int *slots,
  93. const struct input_mt_pos *pos, int num_pos);
  94. #endif