xref: /linux-6.15/include/linux/input/mt.h (revision 55e49089)
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 /**
22  * struct input_mt_slot - represents the state of an input MT slot
23  * @abs: holds current values of ABS_MT axes for this slot
24  * @frame: last frame at which input_mt_report_slot_state() was called
25  */
26 struct input_mt_slot {
27 	int abs[ABS_MT_LAST - ABS_MT_FIRST + 1];
28 	unsigned int frame;
29 };
30 
31 /**
32  * struct input_mt - state of tracked contacts
33  * @trkid: stores MT tracking ID for the next contact
34  * @num_slots: number of MT slots the device uses
35  * @slot: MT slot currently being transmitted
36  * @flags: input_mt operation flags
37  * @frame: increases every time input_mt_sync_frame() is called
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 	struct input_mt_slot slots[];
47 };
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 
55 static inline int input_mt_get_value(const struct input_mt_slot *slot,
56 				     unsigned code)
57 {
58 	return slot->abs[code - ABS_MT_FIRST];
59 }
60 
61 int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,
62 			unsigned int flags);
63 void input_mt_destroy_slots(struct input_dev *dev);
64 
65 static inline int input_mt_new_trkid(struct input_mt *mt)
66 {
67 	return mt->trkid++ & TRKID_MAX;
68 }
69 
70 static inline void input_mt_slot(struct input_dev *dev, int slot)
71 {
72 	input_event(dev, EV_ABS, ABS_MT_SLOT, slot);
73 }
74 
75 static inline bool input_is_mt_value(int axis)
76 {
77 	return axis >= ABS_MT_FIRST && axis <= ABS_MT_LAST;
78 }
79 
80 static inline bool input_is_mt_axis(int axis)
81 {
82 	return axis == ABS_MT_SLOT || input_is_mt_value(axis);
83 }
84 
85 void input_mt_report_slot_state(struct input_dev *dev,
86 				unsigned int tool_type, bool active);
87 
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 
91 void input_mt_sync_frame(struct input_dev *dev);
92 
93 #endif
94