mt.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /**
  18. * struct input_mt_slot - represents the state of an input MT slot
  19. * @abs: holds current values of ABS_MT axes for this slot
  20. * @frame: last frame at which input_mt_report_slot_state() was called
  21. */
  22. struct input_mt_slot {
  23. int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
  24. unsigned int frame;
  25. };
  26. /**
  27. * struct input_mt - state of tracked contacts
  28. * @trkid: stores MT tracking ID for the next contact
  29. * @num_slots: number of MT slots the device uses
  30. * @slot: MT slot currently being transmitted
  31. * @flags: input_mt operation flags
  32. * @frame: increases every time input_mt_sync_frame() is called
  33. * @slots: array of slots holding current values of tracked contacts
  34. */
  35. struct input_mt {
  36. int trkid;
  37. int num_slots;
  38. int slot;
  39. unsigned int flags;
  40. unsigned int frame;
  41. struct input_mt_slot slots[];
  42. };
  43. static inline void input_mt_set_value(struct input_mt_slot *slot,
  44. unsigned code, int value)
  45. {
  46. slot->abs[code - ABS_MT_FIRST] = value;
  47. }
  48. static inline int input_mt_get_value(const struct input_mt_slot *slot,
  49. unsigned code)
  50. {
  51. return slot->abs[code - ABS_MT_FIRST];
  52. }
  53. int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
  54. unsigned int flags);
  55. void input_mt_destroy_slots(struct input_dev *dev);
  56. static inline int input_mt_new_trkid(struct input_mt *mt)
  57. {
  58. return mt->trkid++ & TRKID_MAX;
  59. }
  60. static inline void input_mt_slot(struct input_dev *dev, int slot)
  61. {
  62. input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
  63. }
  64. static inline bool input_is_mt_value(int axis)
  65. {
  66. return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
  67. }
  68. static inline bool input_is_mt_axis(int axis)
  69. {
  70. return axis == ABS_MT_SLOT || input_is_mt_value(axis);
  71. }
  72. void input_mt_report_slot_state(struct input_dev *dev,
  73. unsigned int tool_type, bool active);
  74. void input_mt_report_finger_count(struct input_dev *dev, int count);
  75. void input_mt_report_pointer_emulation(struct input_dev *dev, bool use_count);
  76. void input_mt_sync_frame(struct input_dev *dev);
  77. #endif