1 /* SPDX-License-Identifier: GPL-2.0-only */
6 * Input Multitouch Library
8 * Copyright (c) 2010 Henrik Rydberg
11 #include <linux/input.h>
13 #define TRKID_MAX 0xffff
15 #define INPUT_MT_POINTER 0x0001 /* pointer device, e.g. trackpad */
16 #define INPUT_MT_DIRECT 0x0002 /* direct device, e.g. touchscreen */
17 #define INPUT_MT_DROP_UNUSED 0x0004 /* drop contacts not seen in frame */
18 #define INPUT_MT_TRACK 0x0008 /* use in-kernel tracking */
19 #define INPUT_MT_SEMI_MT 0x0010 /* semi-mt device, finger count handled manually */
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 * @key: optional driver designation of this slot
27 struct input_mt_slot
{
28 int abs
[ABS_MT_LAST
- ABS_MT_FIRST
+ 1];
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
50 struct input_mt_slot slots
[] __counted_by(num_slots
);
53 static inline void input_mt_set_value(struct input_mt_slot
*slot
,
54 unsigned code
, int value
)
56 slot
->abs
[code
- ABS_MT_FIRST
] = value
;
59 static inline int input_mt_get_value(const struct input_mt_slot
*slot
,
62 return slot
->abs
[code
- ABS_MT_FIRST
];
65 static inline bool input_mt_is_active(const struct input_mt_slot
*slot
)
67 return input_mt_get_value(slot
, ABS_MT_TRACKING_ID
) >= 0;
70 static inline bool input_mt_is_used(const struct input_mt
*mt
,
71 const struct input_mt_slot
*slot
)
73 return slot
->frame
== mt
->frame
;
76 int input_mt_init_slots(struct input_dev
*dev
, unsigned int num_slots
,
78 void input_mt_destroy_slots(struct input_dev
*dev
);
80 static inline int input_mt_new_trkid(struct input_mt
*mt
)
82 return mt
->trkid
++ & TRKID_MAX
;
85 static inline void input_mt_slot(struct input_dev
*dev
, int slot
)
87 input_event(dev
, EV_ABS
, ABS_MT_SLOT
, slot
);
90 static inline bool input_is_mt_value(int axis
)
92 return axis
>= ABS_MT_FIRST
&& axis
<= ABS_MT_LAST
;
95 static inline bool input_is_mt_axis(int axis
)
97 return axis
== ABS_MT_SLOT
|| input_is_mt_value(axis
);
100 bool input_mt_report_slot_state(struct input_dev
*dev
,
101 unsigned int tool_type
, bool active
);
103 static inline void input_mt_report_slot_inactive(struct input_dev
*dev
)
105 input_mt_report_slot_state(dev
, 0, false);
108 void input_mt_report_finger_count(struct input_dev
*dev
, int count
);
109 void input_mt_report_pointer_emulation(struct input_dev
*dev
, bool use_count
);
110 void input_mt_drop_unused(struct input_dev
*dev
);
112 void input_mt_sync_frame(struct input_dev
*dev
);
115 * struct input_mt_pos - contact position
116 * @x: horizontal coordinate
117 * @y: vertical coordinate
119 struct input_mt_pos
{
123 int input_mt_assign_slots(struct input_dev
*dev
, int *slots
,
124 const struct input_mt_pos
*pos
, int num_pos
,
127 int input_mt_get_slot_by_key(struct input_dev
*dev
, int key
);