← Documents Documentation/input/multi-touch-protocol.rst GitHub 원문 ↗

Linux 6.18.37 · Input

Multi-touch Protocol

Type B slot 기반 contact lifecycle, MT shape·pressure·tool event와 계산 규칙을 정의합니다.

Source pathDocumentation/input/multi-touch-protocol.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

multi-touch-protocol.rst:1-415

현재 kernel driver가 사용하는 stateful type B MT protocol을 중심으로 slot 선택, tracking ID 생명주기, position·touch·width·pressure·orientation event 의미와 hardware data 계산법을 설명합니다. Type A는 호환 설명만 남은 obsolete protocol입니다.

문서 개요
영역핵심 항목
ProtocolType A obsolete, type B slot
Slot`ABS_MT_SLOT`
Lifecycle`ABS_MT_TRACKING_ID`, -1 종료
Position`ABS_MT_POSITION_X/Y`, `TOOL_X/Y`
Shape`TOUCH_MAJOR/MINOR`, `WIDTH_MAJOR/MINOR`
Signal`PRESSURE`, `DISTANCE`, `ORIENTATION`
Core helper`input_mt_report_slot_state()`
TrackingEuclidean Bipartite Matching

MT driver 구현의 핵심 상태와 event입니다.

Type B frame
`input_mt_slot()`로 slot 선택필요하면 새 tracking ID로 contact 시작변경된 position·shape·pressure만 보고종료 contact는 tracking ID -1`input_sync()`로 frame 완료

변경된 contact attribute만 slot별로 전송합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 .. include:: <isonum.txt>
2
3 =========================
4 Multi-touch (MT) Protocol
5 =========================
6
7 :Copyright: |copy| 2009-2010 Henrik Rydberg <rydberg@euromail.se>
8
9
10 Introduction
11 ------------
12
13 In order to utilize the full power of the new multi-touch and multi-user
14 devices, a way to report detailed data from multiple contacts, i.e.,
15 objects in direct contact with the device surface, is needed. This
16 document describes the multi-touch (MT) protocol which allows kernel
17 drivers to report details for an arbitrary number of contacts.
18
19 The protocol is divided into two types, depending on the capabilities of the
20 hardware. For devices handling anonymous contacts (type A), the protocol
21 describes how to send the raw data for all contacts to the receiver. For
22 devices capable of tracking identifiable contacts (type B), the protocol
23 describes how to send updates for individual contacts via event slots.
24
25 .. note::
26 MT protocol type A is obsolete, all kernel drivers have been
27 converted to use type B.
28
29 Protocol Usage
30 --------------
31
32 Contact details are sent sequentially as separate packets of ABS_MT
33 events. Only the ABS_MT events are recognized as part of a contact
34 packet. Since these events are ignored by current single-touch (ST)
35 applications, the MT protocol can be implemented on top of the ST protocol
36 in an existing driver.
37
38 Drivers for type A devices separate contact packets by calling
39 input_mt_sync() at the end of each packet. This generates a SYN_MT_REPORT
40 event, which instructs the receiver to accept the data for the current
41 contact and prepare to receive another.
42
43 Drivers for type B devices separate contact packets by calling
44 input_mt_slot(), with a slot as argument, at the beginning of each packet.
45 This generates an ABS_MT_SLOT event, which instructs the receiver to
46 prepare for updates of the given slot.
47
48 All drivers mark the end of a multi-touch transfer by calling the usual
49 input_sync() function. This instructs the receiver to act upon events
50 accumulated since last EV_SYN/SYN_REPORT and prepare to receive a new set
51 of events/packets.
52
53 The main difference between the stateless type A protocol and the stateful
54 type B slot protocol lies in the usage of identifiable contacts to reduce
55 the amount of data sent to userspace. The slot protocol requires the use of
56 the ABS_MT_TRACKING_ID, either provided by the hardware or computed from
57 the raw data [#f5]_.
58
59 For type A devices, the kernel driver should generate an arbitrary
60 enumeration of the full set of anonymous contacts currently on the
61 surface. The order in which the packets appear in the event stream is not
62 important. Event filtering and finger tracking is left to user space [#f3]_.
63
64 For type B devices, the kernel driver should associate a slot with each
65 identified contact, and use that slot to propagate changes for the contact.
66 Creation, replacement and destruction of contacts is achieved by modifying
67 the ABS_MT_TRACKING_ID of the associated slot. A non-negative tracking id
68 is interpreted as a contact, and the value -1 denotes an unused slot. A
69 tracking id not previously present is considered new, and a tracking id no
70 longer present is considered removed. Since only changes are propagated,
71 the full state of each initiated contact has to reside in the receiving
72 end. Upon receiving an MT event, one simply updates the appropriate
73 attribute of the current slot.
74
75 Some devices identify and/or track more contacts than they can report to the
76 driver. A driver for such a device should associate one type B slot with each
77 contact that is reported by the hardware. Whenever the identity of the
78 contact associated with a slot changes, the driver should invalidate that
79 slot by changing its ABS_MT_TRACKING_ID. If the hardware signals that it is
80 tracking more contacts than it is currently reporting, the driver should use
81 a BTN_TOOL_*TAP event to inform userspace of the total number of contacts
82 being tracked by the hardware at that moment. The driver should do this by
83 explicitly sending the corresponding BTN_TOOL_*TAP event and setting
84 use_count to false when calling input_mt_report_pointer_emulation().
85 The driver should only advertise as many slots as the hardware can report.
86 Userspace can detect that a driver can report more total contacts than slots
87 by noting that the largest supported BTN_TOOL_*TAP event is larger than the
88 total number of type B slots reported in the absinfo for the ABS_MT_SLOT axis.
89
90 The minimum value of the ABS_MT_SLOT axis must be 0.
91
92 Protocol Example A
93 ------------------
94
95 Here is what a minimal event sequence for a two-contact touch would look
96 like for a type A device::
97
98 ABS_MT_POSITION_X x[0]
99 ABS_MT_POSITION_Y y[0]
100 SYN_MT_REPORT
101 ABS_MT_POSITION_X x[1]
102 ABS_MT_POSITION_Y y[1]
103 SYN_MT_REPORT
104 SYN_REPORT
105
106 The sequence after moving one of the contacts looks exactly the same; the
107 raw data for all present contacts are sent between every synchronization
108 with SYN_REPORT.
109
110 Here is the sequence after lifting the first contact::
111
112 ABS_MT_POSITION_X x[1]
113 ABS_MT_POSITION_Y y[1]
114 SYN_MT_REPORT
115 SYN_REPORT
116
117 And here is the sequence after lifting the second contact::
118
119 SYN_MT_REPORT
120 SYN_REPORT
121
122 If the driver reports one of BTN_TOUCH or ABS_PRESSURE in addition to the
123 ABS_MT events, the last SYN_MT_REPORT event may be omitted. Otherwise, the
124 last SYN_REPORT will be dropped by the input core, resulting in no
125 zero-contact event reaching userland.
126
127
128 Protocol Example B
129 ------------------
130
131 Here is what a minimal event sequence for a two-contact touch would look
132 like for a type B device::
133
134 ABS_MT_SLOT 0
135 ABS_MT_TRACKING_ID 45
136 ABS_MT_POSITION_X x[0]
137 ABS_MT_POSITION_Y y[0]
138 ABS_MT_SLOT 1
139 ABS_MT_TRACKING_ID 46
140 ABS_MT_POSITION_X x[1]
141 ABS_MT_POSITION_Y y[1]
142 SYN_REPORT
143
144 Here is the sequence after moving contact 45 in the x direction::
145
146 ABS_MT_SLOT 0
147 ABS_MT_POSITION_X x[0]
148 SYN_REPORT
149
150 Here is the sequence after lifting the contact in slot 0::
151
152 ABS_MT_TRACKING_ID -1
153 SYN_REPORT
154
155 The slot being modified is already 0, so the ABS_MT_SLOT is omitted. The
156 message removes the association of slot 0 with contact 45, thereby
157 destroying contact 45 and freeing slot 0 to be reused for another contact.
158
159 Finally, here is the sequence after lifting the second contact::
160
161 ABS_MT_SLOT 1
162 ABS_MT_TRACKING_ID -1
163 SYN_REPORT
164
165
166 Event Usage
167 -----------
168
169 A set of ABS_MT events with the desired properties is defined. The events
170 are divided into categories, to allow for partial implementation. The
171 minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which
172 allows for multiple contacts to be tracked. If the device supports it, the
173 ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size
174 of the contact area and approaching tool, respectively.
175
176 The TOUCH and WIDTH parameters have a geometrical interpretation; imagine
177 looking through a window at someone gently holding a finger against the
178 glass. You will see two regions, one inner region consisting of the part
179 of the finger actually touching the glass, and one outer region formed by
180 the perimeter of the finger. The center of the touching region (a) is
181 ABS_MT_POSITION_X/Y and the center of the approaching finger (b) is
182 ABS_MT_TOOL_X/Y. The touch diameter is ABS_MT_TOUCH_MAJOR and the finger
183 diameter is ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger
184 harder against the glass. The touch region will increase, and in general,
185 the ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller
186 than unity, is related to the contact pressure. For pressure-based devices,
187 ABS_MT_PRESSURE may be used to provide the pressure on the contact area
188 instead. Devices capable of contact hovering can use ABS_MT_DISTANCE to
189 indicate the distance between the contact and the surface.
190
191 ::
192
193
194 Linux MT Win8
195 __________ _______________________
196 / \ | |
197 / \ | |
198 / ____ \ | |
199 / / \ \ | |
200 \ \ a \ \ | a |
201 \ \____/ \ | |
202 \ \ | |
203 \ b \ | b |
204 \ \ | |
205 \ \ | |
206 \ \ | |
207 \ / | |
208 \ / | |
209 \ / | |
210 \__________/ |_______________________|
211
212
213 In addition to the MAJOR parameters, the oval shape of the touch and finger
214 regions can be described by adding the MINOR parameters, such that MAJOR
215 and MINOR are the major and minor axis of an ellipse. The orientation of
216 the touch ellipse can be described with the ORIENTATION parameter, and the
217 direction of the finger ellipse is given by the vector (a - b).
218
219 For type A devices, further specification of the touch shape is possible
220 via ABS_MT_BLOB_ID.
221
222 The ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is a
223 finger or a pen or something else. Finally, the ABS_MT_TRACKING_ID event
224 may be used to track identified contacts over time [#f5]_.
225
226 In the type B protocol, ABS_MT_TOOL_TYPE and ABS_MT_TRACKING_ID are
227 implicitly handled by input core; drivers should instead call
228 input_mt_report_slot_state().
229
230
231 Event Semantics
232 ---------------
233
234 ABS_MT_TOUCH_MAJOR
235 The length of the major axis of the contact. The length should be given in
236 surface units. If the surface has an X times Y resolution, the largest
237 possible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [#f4]_.
238
239 ABS_MT_TOUCH_MINOR
240 The length, in surface units, of the minor axis of the contact. If the
241 contact is circular, this event can be omitted [#f4]_.
242
243 ABS_MT_WIDTH_MAJOR
244 The length, in surface units, of the major axis of the approaching
245 tool. This should be understood as the size of the tool itself. The
246 orientation of the contact and the approaching tool are assumed to be the
247 same [#f4]_.
248
249 ABS_MT_WIDTH_MINOR
250 The length, in surface units, of the minor axis of the approaching
251 tool. Omit if circular [#f4]_.
252
253 The above four values can be used to derive additional information about
254 the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates
255 the notion of pressure. The fingers of the hand and the palm all have
256 different characteristic widths.
257
258 ABS_MT_PRESSURE
259 The pressure, in arbitrary units, on the contact area. May be used instead
260 of TOUCH and WIDTH for pressure-based devices or any device with a spatial
261 signal intensity distribution.
262
263 If the resolution is zero, the pressure data is in arbitrary units.
264 If the resolution is non-zero, the pressure data is in units/gram. See
265 :ref:`input-event-codes` for details.
266
267 ABS_MT_DISTANCE
268 The distance, in surface units, between the contact and the surface. Zero
269 distance means the contact is touching the surface. A positive number means
270 the contact is hovering above the surface.
271
272 ABS_MT_ORIENTATION
273 The orientation of the touching ellipse. The value should describe a signed
274 quarter of a revolution clockwise around the touch center. The signed value
275 range is arbitrary, but zero should be returned for an ellipse aligned with
276 the Y axis (north) of the surface, a negative value when the ellipse is
277 turned to the left, and a positive value when the ellipse is turned to the
278 right. When aligned with the X axis in the positive direction, the range
279 max should be returned; when aligned with the X axis in the negative
280 direction, the range -max should be returned.
281
282 Touch ellipses are symmetrical by default. For devices capable of true 360
283 degree orientation, the reported orientation must exceed the range max to
284 indicate more than a quarter of a revolution. For an upside-down finger,
285 range max * 2 should be returned.
286
287 Orientation can be omitted if the touch area is circular, or if the
288 information is not available in the kernel driver. Partial orientation
289 support is possible if the device can distinguish between the two axes, but
290 not (uniquely) any values in between. In such cases, the range of
291 ABS_MT_ORIENTATION should be [0, 1] [#f4]_.
292
293 ABS_MT_POSITION_X
294 The surface X coordinate of the center of the touching ellipse.
295
296 ABS_MT_POSITION_Y
297 The surface Y coordinate of the center of the touching ellipse.
298
299 ABS_MT_TOOL_X
300 The surface X coordinate of the center of the approaching tool. Omit if
301 the device cannot distinguish between the intended touch point and the
302 tool itself.
303
304 ABS_MT_TOOL_Y
305 The surface Y coordinate of the center of the approaching tool. Omit if the
306 device cannot distinguish between the intended touch point and the tool
307 itself.
308
309 The four position values can be used to separate the position of the touch
310 from the position of the tool. If both positions are present, the major
311 tool axis points towards the touch point [#f1]_. Otherwise, the tool axes are
312 aligned with the touch axes.
313
314 ABS_MT_TOOL_TYPE
315 The type of approaching tool. A lot of kernel drivers cannot distinguish
316 between different tool types, such as a finger or a pen. In such cases, the
317 event should be omitted. The protocol currently mainly supports
318 MT_TOOL_FINGER, MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_.
319 For type B devices, this event is handled by input core; drivers should
320 instead use input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may
321 change over time while still touching the device, because the firmware may
322 not be able to determine which tool is being used when it first appears.
323
324 ABS_MT_BLOB_ID
325 The BLOB_ID groups several packets together into one arbitrarily shaped
326 contact. The sequence of points forms a polygon which defines the shape of
327 the contact. This is a low-level anonymous grouping for type A devices, and
328 should not be confused with the high-level trackingID [#f5]_. Most type A
329 devices do not have blob capability, so drivers can safely omit this event.
330
331 ABS_MT_TRACKING_ID
332 The TRACKING_ID identifies an initiated contact throughout its life cycle
333 [#f5]_. The value range of the TRACKING_ID should be large enough to ensure
334 unique identification of a contact maintained over an extended period of
335 time. For type B devices, this event is handled by input core; drivers
336 should instead use input_mt_report_slot_state().
337
338
339 Event Computation
340 -----------------
341
342 The flora of different hardware unavoidably leads to some devices fitting
343 better to the MT protocol than others. To simplify and unify the mapping,
344 this section gives recipes for how to compute certain events.
345
346 For devices reporting contacts as rectangular shapes, signed orientation
347 cannot be obtained. Assuming X and Y are the lengths of the sides of the
348 touching rectangle, here is a simple formula that retains the most
349 information possible::
350
351 ABS_MT_TOUCH_MAJOR := max(X, Y)
352 ABS_MT_TOUCH_MINOR := min(X, Y)
353 ABS_MT_ORIENTATION := bool(X > Y)
354
355 The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that
356 the device can distinguish between a finger along the Y axis (0) and a
357 finger along the X axis (1).
358
359 For Win8 devices with both T and C coordinates, the position mapping is::
360
361 ABS_MT_POSITION_X := T_X
362 ABS_MT_POSITION_Y := T_Y
363 ABS_MT_TOOL_X := C_X
364 ABS_MT_TOOL_Y := C_Y
365
366 Unfortunately, there is not enough information to specify both the touching
367 ellipse and the tool ellipse, so one has to resort to approximations. One
368 simple scheme, which is compatible with earlier usage, is::
369
370 ABS_MT_TOUCH_MAJOR := min(X, Y)
371 ABS_MT_TOUCH_MINOR := <not used>
372 ABS_MT_ORIENTATION := <not used>
373 ABS_MT_WIDTH_MAJOR := min(X, Y) + distance(T, C)
374 ABS_MT_WIDTH_MINOR := min(X, Y)
375
376 Rationale: We have no information about the orientation of the touching
377 ellipse, so approximate it with an inscribed circle instead. The tool
378 ellipse should align with the vector (T - C), so the diameter must
379 increase with distance(T, C). Finally, assume that the touch diameter is
380 equal to the tool thickness, and we arrive at the formulas above.
381
382 Finger Tracking
383 ---------------
384
385 The process of finger tracking, i.e., to assign a unique trackingID to each
386 initiated contact on the surface, is a Euclidean Bipartite Matching
387 problem. At each event synchronization, the set of actual contacts is
388 matched to the set of contacts from the previous synchronization. A full
389 implementation can be found in [#f3]_.
390
391
392 Gestures
393 --------
394
395 In the specific application of creating gesture events, the TOUCH and WIDTH
396 parameters can be used to, e.g., approximate finger pressure or distinguish
397 between index finger and thumb. With the addition of the MINOR parameters,
398 one can also distinguish between a sweeping finger and a pointing finger,
399 and with ORIENTATION, one can detect twisting of fingers.
400
401
402 Notes
403 -----
404
405 In order to stay compatible with existing applications, the data reported
406 in a finger packet must not be recognized as single-touch events.
407
408 For type A devices, all finger data bypasses input filtering, since
409 subsequent events of the same type refer to different fingers.
410
411 .. [#f1] Also, the difference (TOOL_X - POSITION_X) can be used to model tilt.
412 .. [#f2] The list can of course be extended.
413 .. [#f3] The mtdev project: http://bitmath.org/code/mtdev/.
414 .. [#f4] See the section on event computation.
415 .. [#f5] See the section on finger tracking.
416

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

MT protocol type과 contact slot

1-91

새 multi-touch와 multi-user 장치를 온전히 사용하려면 장치 표면에 직접 닿은 여러 contact의 상세 data를 보고할 방법이 필요합니다. MT protocol은 kernel driver가 임의 개수 contact의 세부 정보를 전달하게 합니다.

Hardware가 contact를 식별하지 못하는 type A는 모든 anonymous contact의 raw data를 수신자에게 전송합니다. 식별 가능한 contact를 추적하는 type B는 event slot별로 개별 contact 변경만 전송합니다. Type A는 obsolete이며 모든 kernel driver가 type B로 전환됐습니다.

MT protocol type
Type상태 모델전송현재 상태
AStateless anonymous contacts매 frame 모든 contact raw dataObsolete
BStateful identifiable contactsSlot별 변경 attribute모든 새 driver가 사용

Hardware contact 식별 능력에 따른 차이입니다.

Contact 세부 정보는 `ABS_MT` event packet으로 순서대로 전송하며 `ABS_MT` event만 contact packet 일부로 인식합니다. 기존 single-touch application은 이를 무시하므로 기존 driver의 ST protocol 위에 MT protocol을 추가할 수 있습니다.

Type A driver는 contact packet 끝에 `input_mt_sync()`를 호출해 `SYN_MT_REPORT`를 생성합니다. Type B driver는 각 packet 시작에 slot 인자를 넣어 `input_mt_slot()`을 호출해 `ABS_MT_SLOT`을 생성합니다. 모든 driver는 전체 multi-touch transfer 끝에 `input_sync()`를 호출해 `SYN_REPORT` 이전에 누적된 packet을 적용하게 합니다.

Packet 경계 API
단계API생성 event
Type A contact 끝`input_mt_sync()``SYN_MT_REPORT`
Type B contact 시작`input_mt_slot(slot)``ABS_MT_SLOT`
모든 MT frame 끝`input_sync()``SYN_REPORT`

Type A contact 경계, type B slot 선택, frame 완료를 구분합니다.

Type B는 identifiable contact를 사용해 변경된 값만 사용자 공간에 보내 data 양을 줄이며 hardware가 제공하거나 raw data에서 계산한 `ABS_MT_TRACKING_ID`가 필수입니다.

Type A는 현재 표면의 anonymous contact 전체를 임의 순서로 열거하며 event filtering과 finger tracking은 사용자 공간이 담당합니다. Type B는 각 contact에 slot을 연결하고 그 slot으로 변경을 보냅니다.

Type B slot의 `ABS_MT_TRACKING_ID`를 바꾸어 contact 생성·교체·삭제를 나타냅니다. Non-negative ID는 활성 contact, -1은 사용하지 않는 slot입니다. 이전에 없던 ID는 새 contact, 더 이상 없는 ID는 제거된 contact입니다. 변경만 전송하므로 수신자는 시작된 각 contact의 전체 상태를 보관하고 MT event가 오면 현재 slot의 해당 attribute만 갱신합니다.

Type B contact 생명주기
빈 slot 선택새 non-negative `ABS_MT_TRACKING_ID` 설정Position·shape attribute 초기값 보고변경된 attribute만 같은 slot에 보고Contact 종료 시 tracking ID를 -1로 설정Slot을 다음 contact에 재사용

Slot은 유지되고 tracking ID가 contact association을 정의합니다.

일부 hardware는 driver에 보고할 수 있는 수보다 더 많은 contact를 식별·추적합니다. Driver는 실제로 보고되는 각 contact에 type B slot 하나를 연결하고 slot의 contact identity가 바뀔 때 tracking ID를 바꿔 무효화해야 합니다.

Hardware가 보고 중인 수보다 더 많은 contact를 추적한다고 알리면 `BTN_TOOL_*TAP`을 명시적으로 보내 총 contact 수를 사용자 공간에 알려야 하며 `input_mt_report_pointer_emulation()` 호출 때 `use_count=false`로 둡니다. Driver는 hardware가 실제 보고할 수 있는 수만큼만 slot을 광고합니다.

사용자 공간은 가장 큰 `BTN_TOOL_*TAP` 지원 수가 `ABS_MT_SLOT` absinfo의 slot 총수보다 큰지 비교해 총 추적 contact 수가 slot 수보다 많음을 알 수 있습니다. `ABS_MT_SLOT` axis의 최소값은 반드시 0입니다.

보고 slot보다 많은 contact
정보보고 방법
실제 report 가능한 contact각 contact에 type B slot 하나
Slot identity 변경`ABS_MT_TRACKING_ID` 변경으로 무효화
추적 중인 총 contact 수`BTN_TOOL_*TAP`
Pointer emulation`use_count=false`
광고 slot 수Hardware report capacity만큼
Slot axis 최소값0

Hardware total tracking과 driver report capacity를 분리합니다.

.. include:: <isonum.txt>

=========================
Multi-touch (MT) Protocol
=========================

:Copyright: |copy| 2009-2010        Henrik Rydberg <rydberg@euromail.se>


Introduction
------------

In order to utilize the full power of the new multi-touch and multi-user
devices, a way to report detailed data from multiple contacts, i.e.,
objects in direct contact with the device surface, is needed.  This
document describes the multi-touch (MT) protocol which allows kernel
drivers to report details for an arbitrary number of contacts.

The protocol is divided into two types, depending on the capabilities of the
hardware. For devices handling anonymous contacts (type A), the protocol
describes how to send the raw data for all contacts to the receiver. For
devices capable of tracking identifiable contacts (type B), the protocol
describes how to send updates for individual contacts via event slots.

.. note::
   MT protocol type A is obsolete, all kernel drivers have been
   converted to use type B.

Protocol Usage
--------------

Contact details are sent sequentially as separate packets of ABS_MT
events. Only the ABS_MT events are recognized as part of a contact
packet. Since these events are ignored by current single-touch (ST)
applications, the MT protocol can be implemented on top of the ST protocol
in an existing driver.

Drivers for type A devices separate contact packets by calling
input_mt_sync() at the end of each packet. This generates a SYN_MT_REPORT
event, which instructs the receiver to accept the data for the current
contact and prepare to receive another.

Drivers for type B devices separate contact packets by calling
input_mt_slot(), with a slot as argument, at the beginning of each packet.
This generates an ABS_MT_SLOT event, which instructs the receiver to
prepare for updates of the given slot.

All drivers mark the end of a multi-touch transfer by calling the usual
input_sync() function. This instructs the receiver to act upon events
accumulated since last EV_SYN/SYN_REPORT and prepare to receive a new set
of events/packets.

The main difference between the stateless type A protocol and the stateful
type B slot protocol lies in the usage of identifiable contacts to reduce
the amount of data sent to userspace. The slot protocol requires the use of
the ABS_MT_TRACKING_ID, either provided by the hardware or computed from
the raw data [#f5]_.

For type A devices, the kernel driver should generate an arbitrary
enumeration of the full set of anonymous contacts currently on the
surface. The order in which the packets appear in the event stream is not
important.  Event filtering and finger tracking is left to user space [#f3]_.

For type B devices, the kernel driver should associate a slot with each
identified contact, and use that slot to propagate changes for the contact.
Creation, replacement and destruction of contacts is achieved by modifying
the ABS_MT_TRACKING_ID of the associated slot.  A non-negative tracking id
is interpreted as a contact, and the value -1 denotes an unused slot.  A
tracking id not previously present is considered new, and a tracking id no
longer present is considered removed.  Since only changes are propagated,
the full state of each initiated contact has to reside in the receiving
end.  Upon receiving an MT event, one simply updates the appropriate
attribute of the current slot.

Some devices identify and/or track more contacts than they can report to the
driver.  A driver for such a device should associate one type B slot with each
contact that is reported by the hardware.  Whenever the identity of the
contact associated with a slot changes, the driver should invalidate that
slot by changing its ABS_MT_TRACKING_ID.  If the hardware signals that it is
tracking more contacts than it is currently reporting, the driver should use
a BTN_TOOL_*TAP event to inform userspace of the total number of contacts
being tracked by the hardware at that moment.  The driver should do this by
explicitly sending the corresponding BTN_TOOL_*TAP event and setting
use_count to false when calling input_mt_report_pointer_emulation().
The driver should only advertise as many slots as the hardware can report.
Userspace can detect that a driver can report more total contacts than slots
by noting that the largest supported BTN_TOOL_*TAP event is larger than the
total number of type B slots reported in the absinfo for the ABS_MT_SLOT axis.

The minimum value of the ABS_MT_SLOT axis must be 0.

Type A와 type B event sequence

92-165

Type A의 두 contact touch는 첫 contact X·Y와 `SYN_MT_REPORT`, 둘째 contact X·Y와 `SYN_MT_REPORT`, 마지막 `SYN_REPORT` 순서입니다. Contact 하나만 움직여도 매 `SYN_REPORT` 사이에 현재 존재하는 모든 contact의 raw data를 다시 보냅니다.

Type A 두 contact frame
순서Event
1`ABS_MT_POSITION_X x[0]`
2`ABS_MT_POSITION_Y y[0]`
3`SYN_MT_REPORT`
4`ABS_MT_POSITION_X x[1]`
5`ABS_MT_POSITION_Y y[1]`
6`SYN_MT_REPORT`
7`SYN_REPORT`

Stateless protocol은 frame마다 전체 contact를 열거합니다.

Type A에서 첫 contact를 떼면 둘째 contact X·Y와 `SYN_MT_REPORT`, `SYN_REPORT`만 보냅니다. 둘째 contact까지 떼면 `SYN_MT_REPORT`, `SYN_REPORT`을 보냅니다.

Driver가 MT event 외에 `BTN_TOUCH` 또는 `ABS_PRESSURE`도 보고하면 마지막 `SYN_MT_REPORT`을 생략할 수 있습니다. 그렇지 않으면 input core가 마지막 `SYN_REPORT`을 drop해 zero-contact event가 사용자 공간에 도달하지 않습니다.

Type A contact 감소
Frame 시작남아 있는 각 contact X·Y 보고각 contact 뒤 `SYN_MT_REPORT`Contact가 0개면 zero-contact marker 보장`SYN_REPORT`으로 frame 완료

활성 contact 전체를 다시 열거해 상태를 나타냅니다.

Type B의 두 contact 시작은 slot 0, tracking ID 45, X·Y, slot 1, tracking ID 46, X·Y, `SYN_REPORT` 순서입니다.

Type B 두 contact 시작
순서Event
1`ABS_MT_SLOT 0`
2`ABS_MT_TRACKING_ID 45`
3`ABS_MT_POSITION_X x[0]`
4`ABS_MT_POSITION_Y y[0]`
5`ABS_MT_SLOT 1`
6`ABS_MT_TRACKING_ID 46`
7`ABS_MT_POSITION_X x[1]`
8`ABS_MT_POSITION_Y y[1]`
9`SYN_REPORT`

각 identifiable contact를 slot에 연결하고 초기 attribute를 보냅니다.

Contact 45의 X만 움직이면 slot 0을 선택하고 X만 보고한 뒤 `SYN_REPORT`을 보냅니다. Slot 0 contact를 떼면 현재 slot이 이미 0이므로 `ABS_MT_SLOT`을 생략하고 `ABS_MT_TRACKING_ID -1`, `SYN_REPORT`만 보냅니다. 이로써 slot 0과 contact 45의 association을 제거하고 slot을 재사용할 수 있게 합니다.

둘째 contact를 떼면 slot 1을 선택하고 tracking ID -1을 보낸 뒤 `SYN_REPORT`을 보냅니다.

Type B 변경 event
작업Event sequence
Contact 45 X 이동`SLOT 0` → `POSITION_X` → `SYN_REPORT`
현재 slot 0 contact 종료`TRACKING_ID -1` → `SYN_REPORT`
Slot 1 contact 종료`SLOT 1` → `TRACKING_ID -1` → `SYN_REPORT`

현재 slot과 변경된 attribute만 전송합니다.

Type B delta 적용
`ABS_MT_SLOT`로 current slot 선택Tracking ID event면 contact association 갱신Position·shape event면 해당 attribute만 갱신Tracking ID -1이면 contact 제거`SYN_REPORT`에서 frame 상태 적용

수신자는 slot별 전체 상태를 보관하고 들어온 field만 바꿉니다.

Protocol Example A
------------------

Here is what a minimal event sequence for a two-contact touch would look
like for a type A device::

   ABS_MT_POSITION_X x[0]
   ABS_MT_POSITION_Y y[0]
   SYN_MT_REPORT
   ABS_MT_POSITION_X x[1]
   ABS_MT_POSITION_Y y[1]
   SYN_MT_REPORT
   SYN_REPORT

The sequence after moving one of the contacts looks exactly the same; the
raw data for all present contacts are sent between every synchronization
with SYN_REPORT.

Here is the sequence after lifting the first contact::

   ABS_MT_POSITION_X x[1]
   ABS_MT_POSITION_Y y[1]
   SYN_MT_REPORT
   SYN_REPORT

And here is the sequence after lifting the second contact::

   SYN_MT_REPORT
   SYN_REPORT

If the driver reports one of BTN_TOUCH or ABS_PRESSURE in addition to the
ABS_MT events, the last SYN_MT_REPORT event may be omitted. Otherwise, the
last SYN_REPORT will be dropped by the input core, resulting in no
zero-contact event reaching userland.


Protocol Example B
------------------

Here is what a minimal event sequence for a two-contact touch would look
like for a type B device::

   ABS_MT_SLOT 0
   ABS_MT_TRACKING_ID 45
   ABS_MT_POSITION_X x[0]
   ABS_MT_POSITION_Y y[0]
   ABS_MT_SLOT 1
   ABS_MT_TRACKING_ID 46
   ABS_MT_POSITION_X x[1]
   ABS_MT_POSITION_Y y[1]
   SYN_REPORT

Here is the sequence after moving contact 45 in the x direction::

   ABS_MT_SLOT 0
   ABS_MT_POSITION_X x[0]
   SYN_REPORT

Here is the sequence after lifting the contact in slot 0::

   ABS_MT_TRACKING_ID -1
   SYN_REPORT

The slot being modified is already 0, so the ABS_MT_SLOT is omitted.  The
message removes the association of slot 0 with contact 45, thereby
destroying contact 45 and freeing slot 0 to be reused for another contact.

Finally, here is the sequence after lifting the second contact::

   ABS_MT_SLOT 1
   ABS_MT_TRACKING_ID -1
   SYN_REPORT

Contact·tool 기하와 event 조합

166-230

MT property는 `ABS_MT` event 집합으로 정의되며 부분 구현이 가능하도록 category로 나뉩니다. 최소 집합은 여러 contact 위치를 추적하는 `ABS_MT_POSITION_X`, `ABS_MT_POSITION_Y`입니다. Hardware가 지원하면 contact area 크기는 `ABS_MT_TOUCH_MAJOR`, 접근 tool 크기는 `ABS_MT_WIDTH_MAJOR`로 제공합니다.

유리창에 손가락을 대는 모습을 생각하면 실제 유리에 닿는 안쪽 영역과 손가락 둘레가 이루는 바깥 영역이 있습니다. 접촉 영역 중심 a는 `ABS_MT_POSITION_X/Y`, 접근한 손가락 중심 b는 `ABS_MT_TOOL_X/Y`입니다. 접촉 지름은 `ABS_MT_TOUCH_MAJOR`, 손가락 지름은 `ABS_MT_WIDTH_MAJOR`입니다.

더 세게 누르면 touch 영역이 커지며 항상 1보다 작은 `TOUCH_MAJOR / WIDTH_MAJOR` 비율은 접촉 pressure와 관련됩니다. Pressure 기반 장치는 대신 `ABS_MT_PRESSURE`를 사용할 수 있고 hover 장치는 표면과 contact 사이 거리를 `ABS_MT_DISTANCE`로 나타냅니다.

MT 접촉 기하
기하 요소중심·크기 event의미
Touching regiona = `POSITION_X/Y`; `TOUCH_MAJOR/MINOR`표면에 실제로 닿은 ellipse
Approaching toolb = `TOOL_X/Y`; `WIDTH_MAJOR/MINOR`손가락·pen 자체의 ellipse
Tool directionVector a - bTool 중심에서 touch point 방향
Pressure proxy`TOUCH_MAJOR / WIDTH_MAJOR`1 미만, 커질수록 접촉 비율 증가
Hover distance`ABS_MT_DISTANCE`0 touch, positive hover

원문의 Linux MT/Win8 ASCII 형상을 중심점과 ellipse 관계로 구조화했습니다.

MAJOR에 MINOR를 더하면 touch와 finger 영역의 타원형을 major·minor axis로 표현할 수 있습니다. `ABS_MT_ORIENTATION`은 touch ellipse 방향, vector `(a - b)`는 finger ellipse 방향입니다.

Type A는 `ABS_MT_BLOB_ID`로 touch shape를 더 자세히 지정할 수 있습니다. `ABS_MT_TOOL_TYPE`은 finger, pen 또는 다른 tool 종류를 나타내고 `ABS_MT_TRACKING_ID`는 식별된 contact를 시간에 따라 추적합니다.

Type B에서는 input core가 `ABS_MT_TOOL_TYPE`과 `ABS_MT_TRACKING_ID`를 암묵적으로 처리하므로 driver는 직접 event를 쓰는 대신 `input_mt_report_slot_state()`를 호출해야 합니다.

MT 최소·선택 event
수준Event
필수 위치`ABS_MT_POSITION_X`, `ABS_MT_POSITION_Y`
Contact 크기`ABS_MT_TOUCH_MAJOR/MINOR`
Tool 크기`ABS_MT_WIDTH_MAJOR/MINOR`
Tool 중심`ABS_MT_TOOL_X/Y`
방향`ABS_MT_ORIENTATION`
압력·거리`ABS_MT_PRESSURE`, `ABS_MT_DISTANCE`
도구·추적`ABS_MT_TOOL_TYPE`, `ABS_MT_TRACKING_ID`
Type A shape group`ABS_MT_BLOB_ID`

Driver capability에 따라 위치에서 shape·pressure·tracking으로 확장합니다.

MT property 선택
모든 contact에 POSITION_X/Y 제공Contact 면적이 있으면 TOUCH axis 추가Tool 외곽을 알면 WIDTH와 TOOL position 추가방향을 알면 ORIENTATION 추가Sensor가 제공하면 PRESSURE·DISTANCE 추가Type B는 `input_mt_report_slot_state()`로 tool·tracking 처리

Hardware가 실제 제공하는 공간 정보를 단계적으로 매핑합니다.

Event Usage
-----------

A set of ABS_MT events with the desired properties is defined. The events
are divided into categories, to allow for partial implementation.  The
minimum set consists of ABS_MT_POSITION_X and ABS_MT_POSITION_Y, which
allows for multiple contacts to be tracked.  If the device supports it, the
ABS_MT_TOUCH_MAJOR and ABS_MT_WIDTH_MAJOR may be used to provide the size
of the contact area and approaching tool, respectively.

The TOUCH and WIDTH parameters have a geometrical interpretation; imagine
looking through a window at someone gently holding a finger against the
glass.  You will see two regions, one inner region consisting of the part
of the finger actually touching the glass, and one outer region formed by
the perimeter of the finger. The center of the touching region (a) is
ABS_MT_POSITION_X/Y and the center of the approaching finger (b) is
ABS_MT_TOOL_X/Y. The touch diameter is ABS_MT_TOUCH_MAJOR and the finger
diameter is ABS_MT_WIDTH_MAJOR. Now imagine the person pressing the finger
harder against the glass. The touch region will increase, and in general,
the ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR, which is always smaller
than unity, is related to the contact pressure. For pressure-based devices,
ABS_MT_PRESSURE may be used to provide the pressure on the contact area
instead. Devices capable of contact hovering can use ABS_MT_DISTANCE to
indicate the distance between the contact and the surface.

::


          Linux MT                               Win8
         __________                     _______________________
        /          \                   |                       |
       /            \                  |                       |
      /     ____     \                 |                       |
     /     /    \     \                |                       |
     \     \  a  \     \               |       a               |
      \     \____/      \              |                       |
       \                 \             |                       |
        \        b        \            |           b           |
         \                 \           |                       |
          \                 \          |                       |
           \                 \         |                       |
            \                /         |                       |
             \              /          |                       |
              \            /           |                       |
               \__________/            |_______________________|


In addition to the MAJOR parameters, the oval shape of the touch and finger
regions can be described by adding the MINOR parameters, such that MAJOR
and MINOR are the major and minor axis of an ellipse. The orientation of
the touch ellipse can be described with the ORIENTATION parameter, and the
direction of the finger ellipse is given by the vector (a - b).

For type A devices, further specification of the touch shape is possible
via ABS_MT_BLOB_ID.

The ABS_MT_TOOL_TYPE may be used to specify whether the touching tool is a
finger or a pen or something else. Finally, the ABS_MT_TRACKING_ID event
may be used to track identified contacts over time [#f5]_.

In the type B protocol, ABS_MT_TOOL_TYPE and ABS_MT_TRACKING_ID are
implicitly handled by input core; drivers should instead call
input_mt_report_slot_state().

`ABS_MT_*` event 의미

231-338

Touch·tool axis 길이는 surface unit으로 보고합니다. Surface 해상도가 X×Y라면 `ABS_MT_TOUCH_MAJOR` 최대 가능값은 대각선 `sqrt(X^2 + Y^2)`입니다. Circular contact는 `TOUCH_MINOR`, circular tool은 `WIDTH_MINOR`를 생략할 수 있습니다.

MT event semantics
Event의미단위·조건
`ABS_MT_TOUCH_MAJOR`Contact major axis 길이Surface unit, 최대 diagonal
`ABS_MT_TOUCH_MINOR`Contact minor axis 길이Circular이면 생략
`ABS_MT_WIDTH_MAJOR`Approaching tool major axisTool 자체 크기
`ABS_MT_WIDTH_MINOR`Approaching tool minor axisCircular이면 생략
`ABS_MT_PRESSURE`Contact area 압력Resolution 0 arbitrary, 아니면 units/gram
`ABS_MT_DISTANCE`Contact와 surface 거리0 touch, positive hover
`ABS_MT_ORIENTATION`Touch ellipse 방향Signed quarter revolution
`ABS_MT_POSITION_X/Y`Touch ellipse 중심Surface coordinate
`ABS_MT_TOOL_X/Y`Approaching tool 중심구분 불가하면 생략
`ABS_MT_TOOL_TYPE`Finger·pen·palm 종류구분 불가하면 생략
`ABS_MT_BLOB_ID`Type A polygon grouping대부분 생략 가능
`ABS_MT_TRACKING_ID`Contact lifecycle 식별장기간 unique해야 함

각 `ABS_MT_*` event의 단위, 범위와 생략 조건입니다.

`TOUCH_MAJOR / WIDTH_MAJOR` 비율은 pressure를 근사하며 손가락과 손바닥은 특징적인 width가 다릅니다. 공간 signal intensity를 가진 pressure 기반 장치는 TOUCH·WIDTH 대신 `ABS_MT_PRESSURE`를 쓸 수 있습니다. Pressure resolution이 0이면 arbitrary unit, 0이 아니면 units/gram입니다.

`ABS_MT_ORIENTATION`은 touch center 주위로 시계 방향 signed quarter revolution을 나타냅니다. Y axis north와 정렬하면 0, 왼쪽으로 돌면 음수, 오른쪽이면 양수입니다. Positive X 정렬은 range max, negative X 정렬은 -max입니다.

기본 touch ellipse는 대칭입니다. 실제 360도 방향을 보고할 수 있으면 quarter revolution을 넘는 값에 range max보다 큰 값을 쓰고 뒤집힌 손가락은 `range max * 2`입니다. Circular touch 또는 kernel driver가 정보를 얻지 못하면 orientation을 생략할 수 있습니다.

장치가 두 axis 방향만 구분하고 중간 각도를 유일하게 판별하지 못하면 `ABS_MT_ORIENTATION` range를 [0, 1]로 둬 partial orientation을 보고할 수 있습니다.

Orientation 기준
방향Value
Y axis north 정렬0
왼쪽 회전Negative
오른쪽 회전Positive
Positive X 정렬range max
Negative X 정렬-range max
Upside-down fingerrange max × 2
두 axis만 구분Range [0, 1]

Ellipse 방향과 event value의 기준점입니다.

Touch 중심은 `POSITION_X/Y`, tool 중심은 `TOOL_X/Y`입니다. 두 위치가 모두 있으면 tool major axis가 touch point를 향하며, tool 위치를 구분할 수 없으면 tool axis는 touch axis와 정렬되고 `TOOL_X/Y`를 생략합니다.

`ABS_MT_TOOL_TYPE`은 주로 `MT_TOOL_FINGER`, `MT_TOOL_PEN`, `MT_TOOL_PALM`을 지원합니다. Driver가 구분하지 못하면 생략합니다. Type B에서는 core가 처리하므로 `input_mt_report_slot_state()`를 사용합니다. Firmware가 접촉 시작 때 tool을 판별하지 못할 수 있어 같은 contact 중에도 type이 바뀔 수 있습니다.

`ABS_MT_BLOB_ID`는 여러 packet의 point sequence를 polygon으로 묶어 임의 shape contact를 만드는 type A 저수준 anonymous group이며 high-level tracking ID와 다릅니다. Type A 장치 대부분은 blob capability가 없어 생략할 수 있습니다.

`ABS_MT_TRACKING_ID`는 시작된 contact의 전체 lifecycle을 식별합니다. 장기간 유지되는 contact를 unique하게 구분할 만큼 range가 커야 합니다. Type B driver는 직접 다루지 않고 `input_mt_report_slot_state()`를 사용합니다.

Type B tool state 보고
Current slot 선택Hardware contact active 여부와 tool type 판정`input_mt_report_slot_state()` 호출Input core가 tracking ID lifecycle 관리Tool 판정이 바뀌면 같은 contact의 type 갱신

Driver는 core helper를 통해 tracking ID와 tool type을 함께 관리합니다.

Event Semantics
---------------

ABS_MT_TOUCH_MAJOR
    The length of the major axis of the contact. The length should be given in
    surface units. If the surface has an X times Y resolution, the largest
    possible value of ABS_MT_TOUCH_MAJOR is sqrt(X^2 + Y^2), the diagonal [#f4]_.

ABS_MT_TOUCH_MINOR
    The length, in surface units, of the minor axis of the contact. If the
    contact is circular, this event can be omitted [#f4]_.

ABS_MT_WIDTH_MAJOR
    The length, in surface units, of the major axis of the approaching
    tool. This should be understood as the size of the tool itself. The
    orientation of the contact and the approaching tool are assumed to be the
    same [#f4]_.

ABS_MT_WIDTH_MINOR
    The length, in surface units, of the minor axis of the approaching
    tool. Omit if circular [#f4]_.

    The above four values can be used to derive additional information about
    the contact. The ratio ABS_MT_TOUCH_MAJOR / ABS_MT_WIDTH_MAJOR approximates
    the notion of pressure. The fingers of the hand and the palm all have
    different characteristic widths.

ABS_MT_PRESSURE
    The pressure, in arbitrary units, on the contact area. May be used instead
    of TOUCH and WIDTH for pressure-based devices or any device with a spatial
    signal intensity distribution.

    If the resolution is zero, the pressure data is in arbitrary units.
    If the resolution is non-zero, the pressure data is in units/gram. See
    :ref:`input-event-codes` for details.

ABS_MT_DISTANCE
    The distance, in surface units, between the contact and the surface. Zero
    distance means the contact is touching the surface. A positive number means
    the contact is hovering above the surface.

ABS_MT_ORIENTATION
    The orientation of the touching ellipse. The value should describe a signed
    quarter of a revolution clockwise around the touch center. The signed value
    range is arbitrary, but zero should be returned for an ellipse aligned with
    the Y axis (north) of the surface, a negative value when the ellipse is
    turned to the left, and a positive value when the ellipse is turned to the
    right. When aligned with the X axis in the positive direction, the range
    max should be returned; when aligned with the X axis in the negative
    direction, the range -max should be returned.

    Touch ellipses are symmetrical by default. For devices capable of true 360
    degree orientation, the reported orientation must exceed the range max to
    indicate more than a quarter of a revolution. For an upside-down finger,
    range max * 2 should be returned.

    Orientation can be omitted if the touch area is circular, or if the
    information is not available in the kernel driver. Partial orientation
    support is possible if the device can distinguish between the two axes, but
    not (uniquely) any values in between. In such cases, the range of
    ABS_MT_ORIENTATION should be [0, 1] [#f4]_.

ABS_MT_POSITION_X
    The surface X coordinate of the center of the touching ellipse.

ABS_MT_POSITION_Y
    The surface Y coordinate of the center of the touching ellipse.

ABS_MT_TOOL_X
    The surface X coordinate of the center of the approaching tool. Omit if
    the device cannot distinguish between the intended touch point and the
    tool itself.

ABS_MT_TOOL_Y
    The surface Y coordinate of the center of the approaching tool. Omit if the
    device cannot distinguish between the intended touch point and the tool
    itself.

    The four position values can be used to separate the position of the touch
    from the position of the tool. If both positions are present, the major
    tool axis points towards the touch point [#f1]_. Otherwise, the tool axes are
    aligned with the touch axes.

ABS_MT_TOOL_TYPE
    The type of approaching tool. A lot of kernel drivers cannot distinguish
    between different tool types, such as a finger or a pen. In such cases, the
    event should be omitted. The protocol currently mainly supports
    MT_TOOL_FINGER, MT_TOOL_PEN, and MT_TOOL_PALM [#f2]_.
    For type B devices, this event is handled by input core; drivers should
    instead use input_mt_report_slot_state(). A contact's ABS_MT_TOOL_TYPE may
    change over time while still touching the device, because the firmware may
    not be able to determine which tool is being used when it first appears.

ABS_MT_BLOB_ID
    The BLOB_ID groups several packets together into one arbitrarily shaped
    contact. The sequence of points forms a polygon which defines the shape of
    the contact. This is a low-level anonymous grouping for type A devices, and
    should not be confused with the high-level trackingID [#f5]_. Most type A
    devices do not have blob capability, so drivers can safely omit this event.

ABS_MT_TRACKING_ID
    The TRACKING_ID identifies an initiated contact throughout its life cycle
    [#f5]_. The value range of the TRACKING_ID should be large enough to ensure
    unique identification of a contact maintained over an extended period of
    time. For type B devices, this event is handled by input core; drivers
    should instead use input_mt_report_slot_state().

Event 계산, finger tracking과 gesture

339-415

Hardware 차이를 MT protocol에 일관되게 매핑하기 위해 event 계산 규칙을 사용합니다. Rectangle contact의 signed orientation은 알 수 없으므로 변 길이 X, Y에서 major는 `max(X,Y)`, minor는 `min(X,Y)`, orientation은 `bool(X > Y)`로 둡니다.

Rectangle contact 계산
Event공식
`ABS_MT_TOUCH_MAJOR``max(X, Y)`
`ABS_MT_TOUCH_MINOR``min(X, Y)`
`ABS_MT_ORIENTATION``bool(X > Y)`
Orientation range[0, 1]

두 변 길이에서 보존 가능한 shape 정보를 계산합니다.

Orientation [0,1]은 finger가 Y axis 방향인지(0), X axis 방향인지(1)만 구분할 수 있음을 뜻합니다.

T와 C 좌표가 모두 있는 Win8 장치는 touch point T를 `POSITION_X/Y`, tool center C를 `TOOL_X/Y`로 매핑합니다.

Win8 T·C 위치 매핑
Linux MT eventWin8 coordinate
`ABS_MT_POSITION_X``T_X`
`ABS_MT_POSITION_Y``T_Y`
`ABS_MT_TOOL_X``C_X`
`ABS_MT_TOOL_Y``C_Y`

Touch point와 contact/tool center 좌표를 Linux MT event로 옮깁니다.

Touch ellipse와 tool ellipse를 모두 정할 정보가 부족하므로 근사가 필요합니다. 호환 가능한 단순 방식은 touch major를 `min(X,Y)`, touch minor와 orientation은 미사용, width major를 `min(X,Y) + distance(T,C)`, width minor를 `min(X,Y)`로 둡니다.

Win8 shape 근사
Event공식
`ABS_MT_TOUCH_MAJOR``min(X, Y)`
`ABS_MT_TOUCH_MINOR`미사용
`ABS_MT_ORIENTATION`미사용
`ABS_MT_WIDTH_MAJOR``min(X, Y) + distance(T, C)`
`ABS_MT_WIDTH_MINOR``min(X, Y)`

Inscribed touch circle과 T-C 거리로 tool ellipse를 근사합니다.

Touch orientation 정보가 없으므로 inscribed circle로 근사합니다. Tool ellipse는 vector `(T - C)`와 정렬돼야 하므로 지름은 `distance(T,C)`에 따라 커져야 합니다. Touch 지름이 tool thickness와 같다고 가정하면 위 공식이 나옵니다.

Finger tracking은 표면에서 시작된 각 contact에 unique tracking ID를 할당하는 Euclidean Bipartite Matching 문제입니다. 매 event synchronization마다 현재 contact 집합과 이전 synchronization의 contact 집합을 matching합니다. 전체 구현은 mtdev project를 참고합니다.

Finger tracking
이전 synchronization contact 집합 보관현재 contact 집합 수집두 집합 사이 Euclidean cost 계산Bipartite matching 수행Matched contact는 tracking ID 유지Unmatched current는 새 ID, unmatched previous는 종료

연속 frame의 anonymous contact를 거리 기반으로 연결합니다.

Gesture 생성에서는 TOUCH·WIDTH로 finger pressure를 근사하거나 검지와 엄지를 구분할 수 있습니다. MINOR를 추가하면 sweeping finger와 pointing finger를 구분하고 ORIENTATION으로 finger twist를 탐지할 수 있습니다.

Gesture에 쓰는 MT property
Property가능한 해석
TOUCH / WIDTH ratioFinger pressure 근사
WIDTH검지·엄지·손바닥 구분
MAJOR + MINORSweeping과 pointing finger 구분
ORIENTATIONFinger twisting 탐지

Shape·비율·방향이 제공하는 해석 단서입니다.

기존 application과 호환하려면 finger packet data가 single-touch event로 인식돼서는 안 됩니다. Type A에서는 같은 type의 연속 event가 서로 다른 finger를 뜻하므로 모든 finger data가 input filtering을 우회합니다.

추가 note로 `(TOOL_X - POSITION_X)` 차이는 tilt modeling에 사용할 수 있고 tool type 목록은 확장 가능합니다. Event 계산과 tracking의 상세 근거는 각각 해당 절과 mtdev project를 참고합니다.

Event Computation
-----------------

The flora of different hardware unavoidably leads to some devices fitting
better to the MT protocol than others. To simplify and unify the mapping,
this section gives recipes for how to compute certain events.

For devices reporting contacts as rectangular shapes, signed orientation
cannot be obtained. Assuming X and Y are the lengths of the sides of the
touching rectangle, here is a simple formula that retains the most
information possible::

   ABS_MT_TOUCH_MAJOR := max(X, Y)
   ABS_MT_TOUCH_MINOR := min(X, Y)
   ABS_MT_ORIENTATION := bool(X > Y)

The range of ABS_MT_ORIENTATION should be set to [0, 1], to indicate that
the device can distinguish between a finger along the Y axis (0) and a
finger along the X axis (1).

For Win8 devices with both T and C coordinates, the position mapping is::

   ABS_MT_POSITION_X := T_X
   ABS_MT_POSITION_Y := T_Y
   ABS_MT_TOOL_X := C_X
   ABS_MT_TOOL_Y := C_Y

Unfortunately, there is not enough information to specify both the touching
ellipse and the tool ellipse, so one has to resort to approximations.  One
simple scheme, which is compatible with earlier usage, is::

   ABS_MT_TOUCH_MAJOR := min(X, Y)
   ABS_MT_TOUCH_MINOR := <not used>
   ABS_MT_ORIENTATION := <not used>
   ABS_MT_WIDTH_MAJOR := min(X, Y) + distance(T, C)
   ABS_MT_WIDTH_MINOR := min(X, Y)

Rationale: We have no information about the orientation of the touching
ellipse, so approximate it with an inscribed circle instead. The tool
ellipse should align with the vector (T - C), so the diameter must
increase with distance(T, C). Finally, assume that the touch diameter is
equal to the tool thickness, and we arrive at the formulas above.

Finger Tracking
---------------

The process of finger tracking, i.e., to assign a unique trackingID to each
initiated contact on the surface, is a Euclidean Bipartite Matching
problem.  At each event synchronization, the set of actual contacts is
matched to the set of contacts from the previous synchronization. A full
implementation can be found in [#f3]_.


Gestures
--------

In the specific application of creating gesture events, the TOUCH and WIDTH
parameters can be used to, e.g., approximate finger pressure or distinguish
between index finger and thumb. With the addition of the MINOR parameters,
one can also distinguish between a sweeping finger and a pointing finger,
and with ORIENTATION, one can detect twisting of fingers.


Notes
-----

In order to stay compatible with existing applications, the data reported
in a finger packet must not be recognized as single-touch events.

For type A devices, all finger data bypasses input filtering, since
subsequent events of the same type refer to different fingers.

.. [#f1] Also, the difference (TOOL_X - POSITION_X) can be used to model tilt.
.. [#f2] The list can of course be extended.
.. [#f3] The mtdev project: http://bitmath.org/code/mtdev/.
.. [#f4] See the section on event computation.
.. [#f5] See the section on finger tracking.