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