1 <html devsite> 2 <head> 3 <title>Touch Devices</title> 4 <meta name="project_path" value="/_project.yaml" /> 5 <meta name="book_path" value="/_book.yaml" /> 6 </head> 7 <body> 8 <!-- 9 Copyright 2017 The Android Open Source Project 10 11 Licensed under the Apache License, Version 2.0 (the "License"); 12 you may not use this file except in compliance with the License. 13 You may obtain a copy of the License at 14 15 http://www.apache.org/licenses/LICENSE-2.0 16 17 Unless required by applicable law or agreed to in writing, software 18 distributed under the License is distributed on an "AS IS" BASIS, 19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 See the License for the specific language governing permissions and 21 limitations under the License. 22 --> 23 24 25 26 <p>Android supports a variety of touch screens and touch pads, including 27 stylus-based digitizer tablets.</p> 28 <p>Touch screens are touch devices that are associated with a display such that 29 the user has the impression of directly manipulating items on screen.</p> 30 <p>Touch pads are touch devices that are not associated with a display such as a 31 digitizer tablet. Touch pads are typically used for pointing or for 32 absolute indirect positioning or gesture-based control of a user interface.</p> 33 <p>Touch devices may have buttons whose functions are similar to mouse buttons.</p> 34 <p>Touch devices can sometimes be manipulated using a variety of different tools 35 such as fingers or a stylus depending on the underlying touch sensor technology.</p> 36 <p>Touch devices are sometimes used to implement virtual keys. For example, on 37 some Android devices, the touch screen sensor area extends beyond the edge of 38 the display and serves dual purpose as part of a touch sensitive key pad.</p> 39 <p>Due to the great variety of touch devices, Android relies on a large number of 40 configuration properties to describe the characteristics and desired behavior 41 of each device.</p> 42 <h2 id="touch-device-classification">Touch Device Classification</h2> 43 <p>An input device is classified as a <em>multi-touch</em> device if both of 44 the following conditions hold:</p> 45 <ul> 46 <li> 47 <p>The input device reports the presence of the <code>ABS_MT_POSITION_X</code> and 48 <code>ABS_MT_POSITION_Y</code> absolute axes.</p> 49 </li> 50 <li> 51 <p>The input device does not have any gamepad buttons. This condition 52 resolves an ambiguity with certain gamepads that report axes with codes 53 that overlaps those of the MT axes.</p> 54 </li> 55 </ul> 56 <p>An input device is classified as a <em>single-touch</em> device if both of the 57 following conditions hold:</p> 58 <ul> 59 <li> 60 <p>The input device is not classified as a multi-touch device. An input device 61 is either classified as a single-touch device or as a multi-touch device, 62 never both.</p> 63 </li> 64 <li> 65 <p>The input device reports the presence of the <code>ABS_X</code> and <code>ABS_Y</code> absolute 66 axes, and the presence of the <code>BTN_TOUCH</code> key code.</p> 67 </li> 68 </ul> 69 <p>Once an input device has been classified as a touch device, the presence 70 of virtual keys is determined by attempting to load the virtual key map file 71 for the device. If a virtual key map is available, then the key layout 72 file for the device is also loaded.</p> 73 <p>Refer to the section below about the location and format of virtual key map 74 files.</p> 75 <p>Next, the system loads the input device configuration file for the touch device.</p> 76 <p><strong>All built-in touch devices should have input device configuration files.</strong> 77 If no input device configuration file is present, the system will 78 choose a default configuration that is appropriate for typical general-purpose 79 touch peripherals such as external USB or Bluetooth HID touch screens 80 or touch pads. These defaults are not designed for built-in touch screens and 81 will most likely result in incorrect behavior.</p> 82 <p>After the input device configuration loaded, the system will classify the 83 input device as a <em>touch screen</em>, <em>touch pad</em> or <em>pointer</em> device.</p> 84 <ul> 85 <li> 86 <p>A <em>touch screen</em> device is used for direct manipulation of objects on the 87 screen. Since the user is directly touching the screen, the system does 88 not require any additional affordances to indicate the objects being 89 manipulated.</p> 90 </li> 91 <li> 92 <p>A <em>touch pad</em> device is used to provide absolute positioning information 93 to an application about touches on a given sensor area. It may be useful 94 for digitizer tablets.</p> 95 </li> 96 <li> 97 <p>A <em>pointer</em> device is used for indirect manipulation of objects on the 98 screen using a cursor. Fingers are interpreted as multi-touch pointer 99 gestures. Other tools, such as styluses, are interpreted using 100 absolute positions.</p> 101 <p>See <a href="#indirect-multi-touch-pointer-gestures">Indirect Multi-touch Pointer Gestures</a> 102 for more information.</p> 103 </li> 104 </ul> 105 <p>The following rules are used to classify the input device as a <em>touch screen</em>, 106 <em>touch pad</em> or <em>pointer</em> device.</p> 107 <ul> 108 <li> 109 <p>If the <code>touch.deviceType</code> property is set, then the device type will be 110 set as indicated.</p> 111 </li> 112 <li> 113 <p>If the input device reports the presence of the <code>INPUT_PROP_DIRECT</code> 114 input property (via the <code>EVIOCGPROP</code> ioctl), then the device type will 115 be set to <em>touch screen</em>. This condition assumes that direct input touch 116 devices are attached to a display that is also connected.</p> 117 </li> 118 <li> 119 <p>If the input device reports the presence of the <code>INPUT_PROP_POINTER</code> 120 input property (via the <code>EVIOCGPROP</code> ioctl), then the device type will 121 be set to <em>pointer</em>.</p> 122 </li> 123 <li> 124 <p>If the input device reports the presence of the <code>REL_X</code> or <code>REL_Y</code> relative 125 axes, then the device type will be set to <em>touch pad</em>. This condition 126 resolves an ambiguity for input devices that consist of both a mouse and 127 a touch pad. In this case, the touch pad will not be used to control 128 the pointer because the mouse already controls it.</p> 129 </li> 130 <li> 131 <p>Otherwise, the device type will be set to <em>pointer</em>. This default ensures 132 that touch pads that have not been designated any other special purpose 133 will serve to control the pointer.</p> 134 </li> 135 </ul> 136 <h2 id="buttons">Buttons</h2> 137 <p>Buttons are <em>optional</em> controls that may be used by applications to perform 138 additional functions. Buttons on touch devices behave similarly to mouse 139 buttons and are mainly of use with <em>pointer</em> type touch devices or with a 140 stylus.</p> 141 <p>The following buttons are supported:</p> 142 <ul> 143 <li> 144 <p><code>BTN_LEFT</code>: mapped to <code>MotionEvent.BUTTON_PRIMARY</code>.</p> 145 </li> 146 <li> 147 <p><code>BTN_RIGHT</code>: mapped to <code>MotionEvent.BUTTON_SECONDARY</code>.</p> 148 </li> 149 <li> 150 <p><code>BTN_MIDDLE</code>: mapped to <code>MotionEvent.BUTTON_MIDDLE</code>.</p> 151 </li> 152 <li> 153 <p><code>BTN_BACK</code> and <code>BTN_SIDE</code>: mapped to <code>MotionEvent.BUTTON_BACK</code>. 154 Pressing this button also synthesizes a key press with the key code 155 <code>KeyEvent.KEYCODE_BACK</code>.</p> 156 </li> 157 <li> 158 <p><code>BTN_FORWARD</code> and <code>BTN_EXTRA</code>: mapped to <code>MotionEvent.BUTTON_FORWARD</code>. 159 Pressing this button also synthesizes a key press with the key code 160 <code>KeyEvent.KEYCODE_FORWARD</code>.</p> 161 </li> 162 <li> 163 <p><code>BTN_STYLUS</code>: mapped to <code>MotionEvent.BUTTON_SECONDARY</code>.</p> 164 </li> 165 <li> 166 <p><code>BTN_STYLUS2</code>: mapped to <code>MotionEvent.BUTTON_TERTIARY</code>.</p> 167 </li> 168 </ul> 169 <h2 id="tools-and-tool-types">Tools and Tool Types</h2> 170 <p>A <em>tool</em> is a finger, stylus or other apparatus that is used to interact with 171 the touch device. Some touch devices can distinguish between different 172 types of tools.</p> 173 <p>Elsewhere in Android, as in the <code>MotionEvent</code> API, a <em>tool</em> is often referred 174 to as a <em>pointer</em>.</p> 175 <p>The following tool types are supported:</p> 176 <ul> 177 <li> 178 <p><code>BTN_TOOL_FINGER</code> and <code>MT_TOOL_FINGER</code>: mapped to <code>MotionEvent.TOOL_TYPE_FINGER</code>.</p> 179 </li> 180 <li> 181 <p><code>BTN_TOOL_PEN</code> and <code>MT_TOOL_PEN</code>: mapped to <code>MotionEvent.TOOL_TYPE_STYLUS</code>.</p> 182 </li> 183 <li> 184 <p><code>BTN_TOOL_RUBBER</code>: mapped to <code>MotionEvent.TOOL_TYPE_ERASER</code>.</p> 185 </li> 186 <li> 187 <p><code>BTN_TOOL_BRUSH</code>: mapped to <code>MotionEvent.TOOL_TYPE_STYLUS</code>.</p> 188 </li> 189 <li> 190 <p><code>BTN_TOOL_PENCIL</code>: mapped to <code>MotionEvent.TOOL_TYPE_STYLUS</code>.</p> 191 </li> 192 <li> 193 <p><code>BTN_TOOL_AIRBRUSH</code>: mapped to <code>MotionEvent.TOOL_TYPE_STYLUS</code>.</p> 194 </li> 195 <li> 196 <p><code>BTN_TOOL_MOUSE</code>: mapped to <code>MotionEvent.TOOL_TYPE_MOUSE</code>.</p> 197 </li> 198 <li> 199 <p><code>BTN_TOOL_LENS</code>: mapped to <code>MotionEvent.TOOL_TYPE_MOUSE</code>.</p> 200 </li> 201 <li> 202 <p><code>BTN_TOOL_DOUBLETAP</code>, <code>BTN_TOOL_TRIPLETAP</code>, and <code>BTN_TOOL_QUADTAP</code>: 203 mapped to <code>MotionEvent.TOOL_TYPE_FINGER</code>.</p> 204 </li> 205 </ul> 206 <h2 id="hovering-vs-touching-tools">Hovering vs. Touching Tools</h2> 207 <p>Tools can either be in contact with the touch device or in range and hovering 208 above it. Not all touch devices are able to sense the presence of a tool 209 hovering above the touch device. Those that do, such as RF-based stylus digitizers, 210 can often detect when the tool is within a limited range of the digitizer.</p> 211 <p>The <code>InputReader</code> component takes care to distinguish touching tools from hovering 212 tools. Likewise, touching tools and hovering tools are reported to applications 213 in different ways.</p> 214 <p>Touching tools are reported to applications as touch events 215 using <code>MotionEvent.ACTION_DOWN</code>, <code>MotionEvent.ACTION_MOVE</code>, <code>MotionEvent.ACTION_DOWN</code>, 216 <code>MotionEvent.ACTION_POINTER_DOWN</code> and <code>MotionEvent.ACTION_POINTER_UP</code>.</p> 217 <p>Hovering tools are reported to applications as generic motion events using 218 <code>MotionEvent.ACTION_HOVER_ENTER</code>, <code>MotionEvent.ACTION_HOVER_MOVE</code> 219 and <code>MotionEvent.ACTION_HOVER_EXIT</code>.</p> 220 <h2 id="touch-device-driver-requirements">Touch Device Driver Requirements</h2> 221 <ol> 222 <li> 223 <p>Touch device drivers should only register axes and key codes for the axes 224 and buttons that they actually support. Registering excess axes or key codes 225 may confuse the device classification algorithm or cause the system to incorrectly 226 detect the capabilities of the device.</p> 227 <p>For example, if the device reports the <code>BTN_TOUCH</code> key code, the system will 228 assume that <code>BTN_TOUCH</code> will always be used to indicate whether the tool is 229 actually touching the screen or is merely in range and hovering.</p> 230 </li> 231 <li> 232 <p>Single-touch devices use the following Linux input events:</p> 233 <ul> 234 <li> 235 <p><code>ABS_X</code>: <em>(REQUIRED)</em> Reports the X coordinate of the tool.</p> 236 </li> 237 <li> 238 <p><code>ABS_Y</code>: <em>(REQUIRED)</em> Reports the Y coordinate of the tool.</p> 239 </li> 240 <li> 241 <p><code>ABS_PRESSURE</code>: <em>(optional)</em> Reports the physical pressure applied to the tip 242 of the tool or the signal strength of the touch contact.</p> 243 </li> 244 <li> 245 <p><code>ABS_TOOL_WIDTH</code>: <em>(optional)</em> Reports the cross-sectional area or width of the 246 touch contact or of the tool itself.</p> 247 </li> 248 <li> 249 <p><code>ABS_DISTANCE</code>: <em>(optional)</em> Reports the distance of the tool from the surface of 250 the touch device.</p> 251 </li> 252 <li> 253 <p><code>ABS_TILT_X</code>: <em>(optional)</em> Reports the tilt of the tool from the surface of the 254 touch device along the X axis.</p> 255 </li> 256 <li> 257 <p><code>ABS_TILT_Y</code>: <em>(optional)</em> Reports the tilt of the tool from the surface of the 258 touch device along the Y axis.</p> 259 </li> 260 <li> 261 <p><code>BTN_TOUCH</code>: <em>(REQUIRED)</em> Indicates whether the tool is touching the device.</p> 262 </li> 263 <li> 264 <p><code>BTN_LEFT</code>, <code>BTN_RIGHT</code>, <code>BTN_MIDDLE</code>, <code>BTN_BACK</code>, <code>BTN_SIDE</code>, <code>BTN_FORWARD</code>, 265 <code>BTN_EXTRA</code>, <code>BTN_STYLUS</code>, <code>BTN_STYLUS2</code>: 266 <em>(optional)</em> Reports <a href="#buttons">button</a> states.</p> 267 </li> 268 <li> 269 <p><code>BTN_TOOL_FINGER</code>, <code>BTN_TOOL_PEN</code>, <code>BTN_TOOL_RUBBER</code>, <code>BTN_TOOL_BRUSH</code>, 270 <code>BTN_TOOL_PENCIL</code>, <code>BTN_TOOL_AIRBRUSH</code>, <code>BTN_TOOL_MOUSE</code>, <code>BTN_TOOL_LENS</code>, 271 <code>BTN_TOOL_DOUBLETAP</code>, <code>BTN_TOOL_TRIPLETAP</code>, <code>BTN_TOOL_QUADTAP</code>: 272 <em>(optional)</em> Reports the <a href="#tools-and-tool-types">tool type</a>.</p> 273 </li> 274 </ul> 275 </li> 276 <li> 277 <p>Multi-touch devices use the following Linux input events:</p> 278 <ul> 279 <li> 280 <p><code>ABS_MT_POSITION_X</code>: <em>(REQUIRED)</em> Reports the X coordinate of the tool.</p> 281 </li> 282 <li> 283 <p><code>ABS_MT_POSITION_Y</code>: <em>(REQUIRED)</em> Reports the Y coordinate of the tool.</p> 284 </li> 285 <li> 286 <p><code>ABS_MT_PRESSURE</code>: <em>(optional)</em> Reports the physical pressure applied to the 287 tip of the tool or the signal strength of the touch contact.</p> 288 </li> 289 <li> 290 <p><code>ABS_MT_TOUCH_MAJOR</code>: <em>(optional)</em> Reports the cross-sectional area of the 291 touch contact, or the length of the longer dimension of the touch contact.</p> 292 </li> 293 <li> 294 <p><code>ABS_MT_TOUCH_MINOR</code>: <em>(optional)</em> Reports the length of the shorter dimension of the 295 touch contact. This axis should not be used if <code>ABS_MT_TOUCH_MAJOR</code> is reporting an 296 area measurement.</p> 297 </li> 298 <li> 299 <p><code>ABS_MT_WIDTH_MAJOR</code>: <em>(optional)</em> Reports the cross-sectional area of the tool itself, 300 or the length of the longer dimension of the tool itself. 301 This axis should not be used if the dimensions of the tool itself are unknown.</p> 302 </li> 303 <li> 304 <p><code>ABS_MT_WIDTH_MINOR</code>: <em>(optional)</em> Reports the length of the shorter dimension of 305 the tool itself. This axis should not be used if <code>ABS_MT_WIDTH_MAJOR</code> is reporting 306 an area measurement or if the dimensions of the tool itself are unknown.</p> 307 </li> 308 <li> 309 <p><code>ABS_MT_ORIENTATION</code>: <em>(optional)</em> Reports the orientation of the tool.</p> 310 </li> 311 <li> 312 <p><code>ABS_MT_DISTANCE</code>: <em>(optional)</em> Reports the distance of the tool from the 313 surface of the touch device.</p> 314 </li> 315 <li> 316 <p><code>ABS_MT_TOOL_TYPE</code>: <em>(optional)</em> Reports the <a href="#tools-and-tool-types">tool type</a> as 317 <code>MT_TOOL_FINGER</code> or <code>MT_TOOL_PEN</code>.</p> 318 </li> 319 <li> 320 <p><code>ABS_MT_TRACKING_ID</code>: <em>(optional)</em> Reports the tracking id of the tool. 321 The tracking id is an arbitrary non-negative integer that is used to identify 322 and track each tool independently when multiple tools are active. For example, 323 when multiple fingers are touching the device, each finger should be assigned a distinct 324 tracking id that is used as long as the finger remains in contact. Tracking ids 325 may be reused when their associated tools move out of range.</p> 326 </li> 327 <li> 328 <p><code>ABS_MT_SLOT</code>: <em>(optional)</em> Reports the slot id of the tool, when using the Linux 329 multi-touch protocol 'B'. Refer to the Linux multi-touch protocol documentation 330 for more details.</p> 331 </li> 332 <li> 333 <p><code>BTN_TOUCH</code>: <em>(REQUIRED)</em> Indicates whether the tool is touching the device.</p> 334 </li> 335 <li> 336 <p><code>BTN_LEFT</code>, <code>BTN_RIGHT</code>, <code>BTN_MIDDLE</code>, <code>BTN_BACK</code>, <code>BTN_SIDE</code>, <code>BTN_FORWARD</code>, 337 <code>BTN_EXTRA</code>, <code>BTN_STYLUS</code>, <code>BTN_STYLUS2</code>: 338 <em>(optional)</em> Reports <a href="#buttons">button</a> states.</p> 339 </li> 340 <li> 341 <p><code>BTN_TOOL_FINGER</code>, <code>BTN_TOOL_PEN</code>, <code>BTN_TOOL_RUBBER</code>, <code>BTN_TOOL_BRUSH</code>, 342 <code>BTN_TOOL_PENCIL</code>, <code>BTN_TOOL_AIRBRUSH</code>, <code>BTN_TOOL_MOUSE</code>, <code>BTN_TOOL_LENS</code>, 343 <code>BTN_TOOL_DOUBLETAP</code>, <code>BTN_TOOL_TRIPLETAP</code>, <code>BTN_TOOL_QUADTAP</code>: 344 <em>(optional)</em> Reports the <a href="#tools-and-tool-types">tool type</a>.</p> 345 </li> 346 </ul> 347 </li> 348 <li> 349 <p>If axes for both the single-touch and multi-touch protocol are defined, then 350 only the multi-touch axes will be used and the single-touch axes will be ignored.</p> 351 </li> 352 <li> 353 <p>The minimum and maximum values of the <code>ABS_X</code>, <code>ABS_Y</code>, <code>ABS_MT_POSITION_X</code> 354 and <code>ABS_MT_POSITION_Y</code> axes define the bounds of the active area of the device 355 in device-specific surface units. In the case of a touch screen, the active area 356 describes the part of the touch device that actually covers the display.</p> 357 <p>For a touch screen, the system automatically interpolates the reported touch 358 positions in surface units to obtain touch positions in display pixels according 359 to the following calculation:</p> 360 <pre class="devsite-click-to-copy"> 361 displayX = (x - minX) * displayWidth / (maxX - minX + 1) 362 displayY = (y - minY) * displayHeight / (maxY - minY + 1) 363 </pre> 364 <p>A touch screen may report touches outside of the reported active area.</p> 365 <p>Touches that are initiated outside the active area are not delivered to applications 366 but may be used for virtual keys.</p> 367 <p>Touches that are initiated inside the active area, or that enter and exit the display 368 area are delivered to applications. Consequently, if a touch starts within the 369 bounds of an application and then moves outside of the active area, the application 370 may receive touch events with display coordinates that are negative or beyond the 371 bounds of the display. This is expected behavior.</p> 372 <p>A touch device should never clamp touch coordinates to the bounds of the active 373 area. If a touch exits the active area, it should be reported as being outside of 374 the active area, or it should not be reported at all.</p> 375 <p>For example, if the user's finger is touching near the top-left corner of the 376 touch screen, it may report a coordinate of (minX, minY). If the finger continues 377 to move further outside of the active area, the touch screen should either start 378 reporting coordinates with components less than minX and minY, such as 379 (minX - 2, minY - 3), or it should stop reporting the touch altogether. 380 In other words, the touch screen should <em>not</em> be reporting (minX, minY) 381 when the user's finger is really touching outside of the active area.</p> 382 <p>Clamping touch coordinates to the display edge creates an artificial 383 hard boundary around the edge of the screen which prevents the system from 384 smoothly tracking motions that enter or exit the bounds of the display area.</p> 385 </li> 386 <li> 387 <p>The values reported by <code>ABS_PRESSURE</code> or <code>ABS_MT_PRESSURE</code>, if they 388 are reported at all, must be non-zero when the tool is touching the device 389 and zero otherwise to indicate that the tool is hovering.</p> 390 <p>Reporting pressure information is <em>optional</em> but strongly recommended. 391 Applications can use pressure information to implement pressure-sensitive drawing 392 and other effects.</p> 393 </li> 394 <li> 395 <p>The values reported by <code>ABS_TOOL_WIDTH</code>, <code>ABS_MT_TOUCH_MAJOR</code>, <code>ABS_MT_TOUCH_MINOR</code>, 396 <code>ABS_MT_WIDTH_MAJOR</code>, or <code>ABS_MT_WIDTH_MINOR</code> should be non-zero when the tool 397 is touching the device and zero otherwise, but this is not required. 398 For example, the touch device may be able to measure the size of finger touch 399 contacts but not stylus touch contacts.</p> 400 <p>Reporting size information is <em>optional</em> but strongly recommended. 401 Applications can use pressure information to implement size-sensitive drawing 402 and other effects.</p> 403 </li> 404 <li> 405 <p>The values reported by <code>ABS_DISTANCE</code> or <code>ABS_MT_DISTANCE</code> should approach 406 zero when the tool is touching the device. The distance may remain non-zero 407 even when the tool is in direct contact. The exact values reported depend 408 on the manner in which the hardware measures distance.</p> 409 <p>Reporting distance information is <em>optional</em> but recommended for 410 stylus devices.</p> 411 </li> 412 <li> 413 <p>The values reported by <code>ABS_TILT_X</code> and <code>ABS_TILT_Y</code> should be zero when the 414 tool is perpendicular to the device. A non-zero tilt is taken as an indication 415 that the tool is held at an incline.</p> 416 <p>The tilt angles along the X and Y axes are assumed to be specified in degrees 417 from perpendicular. The center point (perfectly perpendicular) is given 418 by <code>(max + min) / 2</code> for each axis. Values smaller than the center point 419 represent a tilt up or to the left, values larger than the center point 420 represent a tilt down or to the right.</p> 421 <p>The <code>InputReader</code> converts the X and Y tilt components into a perpendicular 422 tilt angle ranging from 0 to <code>PI / 2</code> radians and a planar orientation angle 423 ranging from <code>-PI</code> to <code>PI</code> radians. This representation results in a 424 description of orientation that is compatible with what is used to describe 425 finger touches.</p> 426 <p>Reporting tilt information is <em>optional</em> but recommended for stylus devices.</p> 427 </li> 428 <li> 429 <p>If the tool type is reported by <code>ABS_MT_TOOL_TYPE</code>, it will supersede any tool 430 type information reported by <code>BTN_TOOL_*</code>. 431 If no tool type information is available at all, the tool type defaults to 432 <code>MotionEvent.TOOL_TYPE_FINGER</code>.</p> 433 </li> 434 <li> 435 <p>A tool is determined to be active based on the following conditions:</p> 436 <ul> 437 <li> 438 <p>When using the single-touch protocol, the tool is active if <code>BTN_TOUCH</code>, 439 or <code>BTN_TOOL_*</code> is 1.</p> 440 <p>This condition implies that the <code>InputReader</code> needs to have at least some 441 information about the nature of the tool, either whether it is touching, 442 or at least its tool type. If no information is available, 443 then the tool is assumed to be inactive (out of range).</p> 444 </li> 445 <li> 446 <p>When using the multi-touch protocol 'A', the tool is active whenever it 447 appears in the most recent sync report. When the tool stops appearing in 448 sync reports, it ceases to exist.</p> 449 </li> 450 <li> 451 <p>When using the multi-touch protocol 'B', the tool is active as long as 452 it has an active slot. When the slot it cleared, the tool ceases to exist.</p> 453 </li> 454 </ul> 455 </li> 456 <li> 457 <p>A tool is determined to be hovering based on the following conditions:</p> 458 <ul> 459 <li> 460 <p>If the tool is <code>BTN_TOOL_MOUSE</code> or <code>BTN_TOOL_LENS</code>, then the tool 461 is not hovering, even if either of the following conditions are true.</p> 462 </li> 463 <li> 464 <p>If the tool is active and the driver reports pressure information, 465 and the reported pressure is zero, then the tool is hovering.</p> 466 </li> 467 <li> 468 <p>If the tool is active and the driver supports the <code>BTN_TOUCH</code> key code and 469 <code>BTN_TOUCH</code> has a value of zero, then the tool is hovering.</p> 470 </li> 471 </ul> 472 </li> 473 <li> 474 <p>The <code>InputReader</code> supports both multi-touch protocol 'A' and 'B'. New drivers 475 should use the 'B' protocol but either will work.</p> 476 </li> 477 <li> 478 <p><strong>As of Android Ice Cream Sandwich 4.0, touch screen drivers may need to be changed 479 to comply with the Linux input protocol specification.</strong></p> 480 <p>The following changes may be required:</p> 481 <ul> 482 <li> 483 <p>When a tool becomes inactive (finger goes "up"), it should stop appearing 484 in subsequent multi-touch sync reports. When all tools become inactive 485 (all fingers go "up"), the driver should send an empty sync report packet, 486 such as <code>SYN_MT_REPORT</code> followed by <code>SYN_REPORT</code>.</p> 487 <p>Previous versions of Android expected "up" events to be reported by sending 488 a pressure value of 0. The old behavior was incompatible with the 489 Linux input protocol specification and is no longer supported.</p> 490 </li> 491 <li> 492 <p>Physical pressure or signal strength information should be reported using 493 <code>ABS_MT_PRESSURE</code>.</p> 494 <p>Previous versions of Android retrieved pressure information from 495 <code>ABS_MT_TOUCH_MAJOR</code>. The old behavior was incompatible with the 496 Linux input protocol specification and is no longer supported.</p> 497 </li> 498 <li> 499 <p>Touch size information should be reported using <code>ABS_MT_TOUCH_MAJOR</code>.</p> 500 <p>Previous versions of Android retrieved size information from 501 <code>ABS_MT_TOOL_MAJOR</code>. The old behavior was incompatible with the 502 Linux input protocol specification and is no longer supported.</p> 503 </li> 504 </ul> 505 <p>Touch device drivers no longer need Android-specific customizations. 506 By relying on the standard Linux input protocol, Android can support a 507 wider variety of touch peripherals, such as external HID multi-touch 508 touch screens, using unmodified drivers.</p> 509 </li> 510 </ol> 511 <h2 id="touch-device-operation">Touch Device Operation</h2> 512 <p>The following is a brief summary of the touch device operation on Android.</p> 513 <ol> 514 <li> 515 <p>The <code>EventHub</code> reads raw events from the <code>evdev</code> driver.</p> 516 </li> 517 <li> 518 <p>The <code>InputReader</code> consumes the raw events and updates internal state about 519 the position and other characteristics of each tool. It also tracks 520 button states.</p> 521 </li> 522 <li> 523 <p>If the BACK or FORWARD buttons were pressed or released, the <code>InputReader</code> 524 notifies the <code>InputDispatcher</code> about the key event.</p> 525 </li> 526 <li> 527 <p>The <code>InputReader</code> determines whether a virtual key press occurred. If so, 528 it notifies the <code>InputDispatcher</code> about the key event.</p> 529 </li> 530 <li> 531 <p>The <code>InputReader</code> determines whether the touch was initiated within the 532 bounds of the display. If so, it notifies the <code>InputDispatcher</code> about 533 the touch event.</p> 534 </li> 535 <li> 536 <p>If there are no touching tools but there is at least one hovering tool, 537 the <code>InputReader</code> notifies the <code>InputDispatcher</code> about the hover event.</p> 538 </li> 539 <li> 540 <p>If the touch device type is <em>pointer</em>, the <code>InputReader</code> performs pointer 541 gesture detection, moves the pointer and spots accordingly and notifies 542 the <code>InputDispatcher</code> about the pointer event.</p> 543 </li> 544 <li> 545 <p>The <code>InputDispatcher</code> uses the <code>WindowManagerPolicy</code> to determine whether 546 the events should be dispatched and whether they should wake the device. 547 Then, the <code>InputDispatcher</code> delivers the events to the appropriate applications.</p> 548 </li> 549 </ol> 550 <h2 id="touch-device-configuration">Touch Device Configuration</h2> 551 <p>Touch device behavior is determined by the device's axes, buttons, input properties, 552 input device configuration, virtual key map and key layout.</p> 553 <p>Refer to the following sections for more details about the files that 554 participate in keyboard configuration:</p> 555 <ul> 556 <li><a href="input-device-configuration-files.html">Input Device Configuration Files</a></li> 557 <li><a href="#virtual-key-map-files">Virtual Key Map Files</a></li> 558 </ul> 559 <h3 id="properties">Properties</h3> 560 <p>The system relies on many input device configuration properties to configure 561 and calibrate touch device behavior.</p> 562 <p>One reason for this is that the device drivers for touch devices often report 563 the characteristics of touches using device-specific units.</p> 564 <p>For example, many touch devices measure the touch contact area 565 using an internal device-specific scale, such as the total number of 566 sensor nodes that were triggered by the touch. This raw size value would 567 not be meaningful applications because they would need to know about the 568 physical size and other characteristics of the touch device sensor nodes.</p> 569 <p>The system uses calibration parameters encoded in input device configuration 570 files to decode, transform, and normalize the values reported by the touch 571 device into a simpler standard representation that applications can understand.</p> 572 <h3 id="documentation-conventions">Documentation Conventions</h3> 573 <p>For documentation purposes, we will use the following conventions to describe 574 the values used by the system during the calibration process.</p> 575 <h4 id="raw-axis-values">Raw Axis Values</h4> 576 <p>The following expressions denote the raw values reported by the touch 577 device driver as <code>EV_ABS</code> events.</p> 578 <dl> 579 <dt><code>raw.x</code></dt> 580 <dd>The value of the <code>ABS_X</code> or <code>ABS_MT_POSITION_X</code> axis.</dd> 581 <dt><code>raw.y</code></dt> 582 <dd>The value of the <code>ABS_Y</code> or <code>ABS_MT_POSITION_Y</code> axis.</dd> 583 <dt><code>raw.pressure</code></dt> 584 <dd>The value of the <code>ABS_PRESSURE</code> or <code>ABS_MT_PRESSURE</code> axis, or 0 if not available.</dd> 585 <dt><code>raw.touchMajor</code></dt> 586 <dd>The value of the <code>ABS_MT_TOUCH_MAJOR</code> axis, or 0 if not available.</dd> 587 <dt><code>raw.touchMinor</code></dt> 588 <dd>The value of the <code>ABS_MT_TOUCH_MINOR</code> axis, or <code>raw.touchMajor</code> if not available.</dd> 589 <dt><code>raw.toolMajor</code></dt> 590 <dd>The value of the <code>ABS_TOOL_WIDTH</code> or <code>ABS_MT_WIDTH_MAJOR</code> axis, or 0 if not available.</dd> 591 <dt><code>raw.toolMinor</code></dt> 592 <dd>The value of the <code>ABS_MT_WIDTH_MINOR</code> axis, or <code>raw.toolMajor</code> if not available.</dd> 593 <dt><code>raw.orientation</code></dt> 594 <dd>The value of the <code>ABS_MT_ORIENTATION</code> axis, or 0 if not available.</dd> 595 <dt><code>raw.distance</code></dt> 596 <dd>The value of the <code>ABS_DISTANCE</code> or <code>ABS_MT_DISTANCE</code> axis, or 0 if not available.</dd> 597 <dt><code>raw.tiltX</code></dt> 598 <dd>The value of the <code>ABS_TILT_X</code> axis, or 0 if not available.</dd> 599 <dt><code>raw.tiltY</code></dt> 600 <dd>The value of the <code>ABS_TILT_Y</code> axis, or 0 if not available.</dd> 601 </dl> 602 <h4 id="raw-axis-ranges">Raw Axis Ranges</h4> 603 <p>The following expressions denote the bounds of raw values. They are obtained 604 by calling <code>EVIOCGABS</code> ioctl for each axis.</p> 605 <dl> 606 <dt><code>raw.*.min</code></dt> 607 <dd>The inclusive minimum value of the raw axis.</dd> 608 <dt><code>raw.*.max</code></dt> 609 <dd>The inclusive maximum value of the raw axis.</dd> 610 <dt><code>raw.*.range</code></dt> 611 <dd>Equivalent to <code>raw.*.max - raw.*.min</code>.</dd> 612 <dt><code>raw.*.fuzz</code></dt> 613 <dd>The accuracy of the raw axis. eg. fuzz = 1 implies values are accurate to +/- 1 unit.</dd> 614 <dt><code>raw.width</code></dt> 615 <dd>The inclusive width of the touch area, equivalent to <code>raw.x.range + 1</code>.</dd> 616 <dt><code>raw.height</code></dt> 617 <dd>The inclusive height of the touch area, equivalent to <code>raw.y.range + 1</code>.</dd> 618 </dl> 619 <h4 id="output-ranges">Output Ranges</h4> 620 <p>The following expressions denote the characteristics of the output coordinate system. 621 The system uses linear interpolation to translate touch position information from 622 the surface units used by the touch device into the output units that will 623 be reported to applications such as display pixels.</p> 624 <dl> 625 <dt><code>output.width</code></dt> 626 <dd>The output width. For touch screens (associated with a display), this 627 is the display width in pixels. For touch pads (not associated with a display), 628 the output width equals <code>raw.width</code>, indicating that no interpolation will 629 be performed.</dd> 630 <dt><code>output.height</code></dt> 631 <dd>The output height. For touch screens (associated with a display), this 632 is the display height in pixels. For touch pads (not associated with a display), 633 the output height equals <code>raw.height</code>, indicating that no interpolation will 634 be performed.</dd> 635 <dt><code>output.diag</code></dt> 636 <dd>The diagonal length of the output coordinate system, equivalent to 637 <code>sqrt(output.width ^2 + output.height ^2)</code>.</dd> 638 </dl> 639 <h3 id="basic-configuration">Basic Configuration</h3> 640 <p>The touch input mapper uses many configuration properties in the input device 641 configuration file to specify calibration values. The following table describes 642 some general purpose configuration properties. All other properties are described 643 in the following sections along with the fields they are used to calibrate.</p> 644 <h4 id="touchdevicetype"><code>touch.deviceType</code></h4> 645 <p><em>Definition:</em> <code>touch.deviceType</code> = <code>touchScreen</code> | <code>touchPad</code> | <code>pointer</code> | <code>default</code></p> 646 <p>Specifies the touch device type.</p> 647 <ul> 648 <li> 649 <p>If the value is <code>touchScreen</code>, the touch device is a touch screen associated 650 with a display.</p> 651 </li> 652 <li> 653 <p>If the value is <code>touchPad</code>, the touch device is a touch pad not associated 654 with a display.</p> 655 </li> 656 <li> 657 <p>If the value is <code>pointer</code>, the touch device is a touch pad not associated 658 with a display, and its motions are used for 659 <a href="#indirect-multi-touch-pointer-gestures">indirect multi-touch pointer gestures</a>.</p> 660 </li> 661 <li> 662 <p>If the value is <code>default</code>, the system automatically detects the device type 663 according to the classification algorithm.</p> 664 </li> 665 </ul> 666 <p>Refer to the <a href="#touch-device-classification">Classification</a> section for more details 667 about how the device type influences the behavior of the touch device.</p> 668 <p>Prior to Honeycomb, all touch devices were assumed to be touch screens.</p> 669 <h4 id="touchorientationaware"><code>touch.orientationAware</code></h4> 670 <p><em>Definition:</em> <code>touch.orientationAware</code> = <code>0</code> | <code>1</code></p> 671 <p>Specifies whether the touch device should react to display orientation changes.</p> 672 <ul> 673 <li> 674 <p>If the value is <code>1</code>, touch positions reported by the touch device are rotated 675 whenever the display orientation changes.</p> 676 </li> 677 <li> 678 <p>If the value is <code>0</code>, touch positions reported by the touch device are immune 679 to display orientation changes.</p> 680 </li> 681 </ul> 682 <p>The default value is <code>1</code> if the device is a touch screen, <code>0</code> otherwise.</p> 683 <p>The system distinguishes between internal and external touch screens and displays. 684 An orientation aware internal touch screen is rotated based on the orientation 685 of the internal display. An orientation aware external touch screen is rotated 686 based on the orientation of the external display.</p> 687 <p>Orientation awareness is used to support rotation of touch screens on devices 688 like the Nexus One. For example, when the device is rotated clockwise 90 degrees 689 from its natural orientation, the absolute positions of touches are remapped such 690 that a touch in the top-left corner of the touch screen's absolute coordinate system 691 is reported as a touch in the top-left corner of the display's rotated coordinate system. 692 This is done so that touches are reported with the same coordinate system that 693 applications use to draw their visual elements.</p> 694 <p>Prior to Honeycomb, all touch devices were assumed to be orientation aware.</p> 695 <h4 id="touchgesturemode"><code>touch.gestureMode</code></h4> 696 <p><em>Definition:</em> <code>touch.gestureMode</code> = <code>pointer</code> | <code>spots</code> | <code>default</code></p> 697 <p>Specifies the presentation mode for pointer gestures. This configuration property 698 is only relevant when the touch device is of type <em>pointer</em>.</p> 699 <ul> 700 <li> 701 <p>If the value is <code>pointer</code>, the touch pad gestures are presented by way of a cursor 702 similar to a mouse pointer.</p> 703 </li> 704 <li> 705 <p>If the value is <code>spots</code>, the touch pad gestures are presented by an anchor 706 that represents the centroid of the gesture and a set of circular spots 707 that represent the position of individual fingers.</p> 708 </li> 709 </ul> 710 <p>The default value is <code>pointer</code> when the <code>INPUT_PROP_SEMI_MT</code> input property 711 is set, or <code>spots</code> otherwise.</p> 712 <h3 id="x-and-y-fields"><code>X</code> and <code>Y</code> Fields</h3> 713 <p>The X and Y fields provide positional information for the center of the contact area.</p> 714 <h4 id="calculation">Calculation</h4> 715 <p>The calculation is straightforward: positional information from the touch driver is 716 linearly interpolated to the output coordinate system.</p> 717 <pre class="devsite-click-to-copy"> 718 xScale = output.width / raw.width 719 yScale = output.height / raw.height 720 721 If not orientation aware or screen rotation is 0 degrees: 722 output.x = (raw.x - raw.x.min) * xScale 723 output.y = (raw.y - raw.y.min) * yScale 724 Else If rotation is 90 degrees: 725 output.x = (raw.y - raw.y.min) * yScale 726 output.y = (raw.x.max - raw.x) * xScale 727 Else If rotation is 180 degrees: 728 output.x = (raw.x.max - raw.x) * xScale 729 output.y = (raw.y.max - raw.y) * yScale 730 Else If rotation is 270 degrees: 731 output.x = (raw.y.max - raw.y) * yScale 732 output.y = (raw.x - raw.x.min) * xScale 733 End If 734 </pre> 735 <h3 id="touchmajor-touchminor-toolmajor-toolminor-size-fields"><code>TouchMajor</code>, <code>TouchMinor</code>, <code>ToolMajor</code>, <code>ToolMinor</code>, <code>Size</code> Fields</h3> 736 <p>The <code>TouchMajor</code> and <code>TouchMinor</code> fields describe the approximate dimensions 737 of the contact area in output units (pixels).</p> 738 <p>The <code>ToolMajor</code> and <code>ToolMinor</code> fields describe the approximate dimensions 739 of the <a href="#tools-and-tool-types">tool</a> itself in output units (pixels).</p> 740 <p>The <code>Size</code> field describes the normalized size of the touch relative to 741 the largest possible touch that the touch device can sense. The smallest 742 possible normalized size is 0.0 (no contact, or it is unmeasurable), and the largest 743 possible normalized size is 1.0 (sensor area is saturated).</p> 744 <p>When both the approximate length and breadth can be measured, then the <code>TouchMajor</code> field 745 specifies the longer dimension and the <code>TouchMinor</code> field specifies the shorter dimension 746 of the contact area. When only the approximate diameter of the contact area can be measured, 747 then the <code>TouchMajor</code> and <code>TouchMinor</code> fields will be equal.</p> 748 <p>Likewise, the <code>ToolMajor</code> field specifies the longer dimension and the <code>ToolMinor</code> 749 field specifies the shorter dimension of the tool's cross-sectional area.</p> 750 <p>If the touch size is unavailable but the tool size is available, then the tool size 751 will be set equal to the touch size. Conversely, if the tool size is unavailable 752 but the touch size is available, then the touch size will be set equal to the tool size.</p> 753 <p>Touch devices measure or report the touch size and tool size in various ways. 754 The current implementation supports three different kinds of measurements: 755 diameter, area, and geometric bounding box in surface units.</p> 756 <h4 id="touchsizecalibration"><code>touch.size.calibration</code></h4> 757 <p><em>Definition:</em> <code>touch.size.calibration</code> = <code>none</code> | <code>geometric</code> | <code>diameter</code> 758 | <code>area</code> | <code>default</code></p> 759 <p>Specifies the kind of measurement used by the touch driver to report the 760 touch size and tool size.</p> 761 <ul> 762 <li> 763 <p>If the value is <code>none</code>, the size is set to zero.</p> 764 </li> 765 <li> 766 <p>If the value is <code>geometric</code>, the size is assumed to be specified in the same 767 surface units as the position, so it is scaled in the same manner.</p> 768 </li> 769 <li> 770 <p>If the value is <code>diameter</code>, the size is assumed to be proportional to 771 the diameter (width) of the touch or tool.</p> 772 </li> 773 <li> 774 <p>If the value is <code>area</code>, the size is assumed to be proportional to the 775 area of the touch or tool.</p> 776 </li> 777 <li> 778 <p>If the value is <code>default</code>, the system uses the <code>geometric</code> calibration if the 779 <code>raw.touchMajor</code> or <code>raw.toolMajor</code> axis is available, otherwise it uses 780 the <code>none</code> calibration.</p> 781 </li> 782 </ul> 783 <h4 id="touchsizescale"><code>touch.size.scale</code></h4> 784 <p><em>Definition:</em> <code>touch.size.scale</code> = <a non-negative floating point number></p> 785 <p>Specifies a constant scale factor used in the calibration.</p> 786 <p>The default value is <code>1.0</code>.</p> 787 <h4 id="touchsizebias"><code>touch.size.bias</code></h4> 788 <p><em>Definition:</em> <code>touch.size.bias</code> = <a non-negative floating point number></p> 789 <p>Specifies a constant bias value used in the calibration.</p> 790 <p>The default value is <code>0.0</code>.</p> 791 <h4 id="touchsizeissummed"><code>touch.size.isSummed</code></h4> 792 <p><em>Definition:</em> <code>touch.size.isSummed</code> = <code>0</code> | <code>1</code></p> 793 <p>Specifies whether the size is reported as the sum of the sizes of all 794 active contacts, or is reported individually for each contact.</p> 795 <ul> 796 <li> 797 <p>If the value is <code>1</code>, the reported size will be divided by the number 798 of contacts prior to use.</p> 799 </li> 800 <li> 801 <p>If the value is <code>0</code>, the reported size will be used as is.</p> 802 </li> 803 </ul> 804 <p>The default value is <code>0</code>.</p> 805 <p>Some touch devices, particularly "Semi-MT" devices cannot distinguish the 806 individual dimensions of multiple contacts so they report a size measurement 807 that represents their total area or width. This property should only be set to 808 <code>1</code> for such devices. If in doubt, set this value to <code>0</code>.</p> 809 <h4 id="calculation_1">Calculation</h4> 810 <p>The calculation of the <code>TouchMajor</code>, <code>TouchMinor</code>, <code>ToolMajor</code>, <code>ToolMinor</code> 811 and <code>Size</code> fields depends on the specified calibration parameters.</p> 812 <pre class="devsite-click-to-copy"> 813 If raw.touchMajor and raw.toolMajor are available: 814 touchMajor = raw.touchMajor 815 touchMinor = raw.touchMinor 816 toolMajor = raw.toolMajor 817 toolMinor = raw.toolMinor 818 Else If raw.touchMajor is available: 819 toolMajor = touchMajor = raw.touchMajor 820 toolMinor = touchMinor = raw.touchMinor 821 Else If raw.toolMajor is available: 822 touchMajor = toolMajor = raw.toolMajor 823 touchMinor = toolMinor = raw.toolMinor 824 Else 825 touchMajor = toolMajor = 0 826 touchMinor = toolMinor = 0 827 size = 0 828 End If 829 830 size = avg(touchMajor, touchMinor) 831 832 If touch.size.isSummed == 1: 833 touchMajor = touchMajor / numberOfActiveContacts 834 touchMinor = touchMinor / numberOfActiveContacts 835 toolMajor = toolMajor / numberOfActiveContacts 836 toolMinor = toolMinor / numberOfActiveContacts 837 size = size / numberOfActiveContacts 838 End If 839 840 If touch.size.calibration == "none": 841 touchMajor = toolMajor = 0 842 touchMinor = toolMinor = 0 843 size = 0 844 Else If touch.size.calibration == "geometric": 845 outputScale = average(output.width / raw.width, output.height / raw.height) 846 touchMajor = touchMajor * outputScale 847 touchMinor = touchMinor * outputScale 848 toolMajor = toolMajor * outputScale 849 toolMinor = toolMinor * outputScale 850 Else If touch.size.calibration == "area": 851 touchMajor = sqrt(touchMajor) 852 touchMinor = touchMajor 853 toolMajor = sqrt(toolMajor) 854 toolMinor = toolMajor 855 Else If touch.size.calibration == "diameter": 856 touchMinor = touchMajor 857 toolMinor = toolMajor 858 End If 859 860 If touchMajor != 0: 861 output.touchMajor = touchMajor * touch.size.scale + touch.size.bias 862 Else 863 output.touchMajor = 0 864 End If 865 866 If touchMinor != 0: 867 output.touchMinor = touchMinor * touch.size.scale + touch.size.bias 868 Else 869 output.touchMinor = 0 870 End If 871 872 If toolMajor != 0: 873 output.toolMajor = toolMajor * touch.size.scale + touch.size.bias 874 Else 875 output.toolMajor = 0 876 End If 877 878 If toolMinor != 0: 879 output.toolMinor = toolMinor * touch.size.scale + touch.size.bias 880 Else 881 output.toolMinor = 0 882 End If 883 884 output.size = size 885 </pre> 886 <h3 id="pressure-field"><code>Pressure</code> Field</h3> 887 <p>The <code>Pressure</code> field describes the approximate physical pressure applied to the 888 touch device as a normalized value between 0.0 (no touch) and 1.0 (full force).</p> 889 <p>A zero pressure indicates that the tool is hovering.</p> 890 <h4 id="touchpressurecalibration"><code>touch.pressure.calibration</code></h4> 891 <p><em>Definition:</em> <code>touch.pressure.calibration</code> = <code>none</code> | <code>physical</code> | <code>amplitude</code> | <code>default</code></p> 892 <p>Specifies the kind of measurement used by the touch driver to report the pressure.</p> 893 <ul> 894 <li> 895 <p>If the value is <code>none</code>, the pressure is unknown so it is set to 1.0 when 896 touching and 0.0 when hovering.</p> 897 </li> 898 <li> 899 <p>If the value is <code>physical</code>, the pressure axis is assumed to measure the actual 900 physical intensity of pressure applied to the touch pad.</p> 901 </li> 902 <li> 903 <p>If the value is <code>amplitude</code>, the pressure axis is assumed to measure the signal 904 amplitude, which is related to the size of the contact and the pressure applied.</p> 905 </li> 906 <li> 907 <p>If the value is <code>default</code>, the system uses the <code>physical</code> calibration if the 908 pressure axis available, otherwise uses <code>none</code>.</p> 909 </li> 910 </ul> 911 <h4 id="touchpressurescale"><code>touch.pressure.scale</code></h4> 912 <p><em>Definition:</em> <code>touch.pressure.scale</code> = <a non-negative floating point number></p> 913 <p>Specifies a constant scale factor used in the calibration.</p> 914 <p>The default value is <code>1.0 / raw.pressure.max</code>.</p> 915 <h4 id="calculation_2">Calculation</h4> 916 <p>The calculation of the <code>Pressure</code> field depends on the specified calibration parameters.</p> 917 <pre class="devsite-click-to-copy">If touch.pressure.calibration == "physical" or "amplitude": 918 output.pressure = raw.pressure * touch.pressure.scale 919 Else 920 If hovering: 921 output.pressure = 0 922 Else 923 output.pressure = 1 924 End If 925 End If 926 </pre> 927 <h3 id="orientation-and-tilt-fields"><code>Orientation</code> and <code>Tilt</code> Fields</h3> 928 <p>The <code>Orientation</code> field describes the orientation of the touch and tool as an 929 angular measurement. An orientation of <code>0</code> indicates that the major axis is 930 oriented vertically, <code>-PI/2</code> indicates that the major axis is oriented to the left, 931 <code>PI/2</code> indicates that the major axis is oriented to the right. When a stylus 932 tool is present, the orientation range may be described in a full circle range 933 from <code>-PI</code> or <code>PI</code>.</p> 934 <p>The <code>Tilt</code> field describes the inclination of the tool as an angular measurement. 935 A tilt of <code>0</code> indicates that the tool is perpendicular to the surface. 936 A tilt of <code>PI/2</code> indicates that the tool is flat on the surface.</p> 937 <h4 id="touchorientationcalibration"><code>touch.orientation.calibration</code></h4> 938 <p><em>Definition:</em> <code>touch.orientation.calibration</code> = <code>none</code> | <code>interpolated</code> | <code>vector</code> | <code>default</code></p> 939 <p>Specifies the kind of measurement used by the touch driver to report the orientation.</p> 940 <ul> 941 <li> 942 <p>If the value is <code>none</code>, the orientation is unknown so it is set to 0.</p> 943 </li> 944 <li> 945 <p>If the value is <code>interpolated</code>, the orientation is linearly interpolated such that a 946 raw value of <code>raw.orientation.min</code> maps to <code>-PI/2</code> and a raw value of 947 <code>raw.orientation.max</code> maps to <code>PI/2</code>. The center value of 948 <code>(raw.orientation.min + raw.orientation.max) / 2</code> maps to <code>0</code>.</p> 949 </li> 950 <li> 951 <p>If the value is <code>vector</code>, the orientation is interpreted as a packed vector consisiting 952 of two signed 4-bit fields. This representation is used on Atmel Object Based Protocol 953 parts. When decoded, the vector yields an orientation angle and confidence 954 magnitude. The confidence magnitude is used to scale the size information, 955 unless it is geometric.</p> 956 </li> 957 <li> 958 <p>If the value is <code>default</code>, the system uses the <code>interpolated</code> calibration if the 959 orientation axis available, otherwise uses <code>none</code>.</p> 960 </li> 961 </ul> 962 <h4 id="calculation_3">Calculation</h4> 963 <p>The calculation of the <code>Orientation</code> and <code>Tilt</code> fields depends on the specified 964 calibration parameters and available input.</p> 965 <pre class="devsite-click-to-copy"> 966 If touch.tiltX and touch.tiltY are available: 967 tiltXCenter = average(raw.tiltX.min, raw.tiltX.max) 968 tiltYCenter = average(raw.tiltY.min, raw.tiltY.max) 969 tiltXAngle = (raw.tiltX - tiltXCenter) * PI / 180 970 tiltYAngle = (raw.tiltY - tiltYCenter) * PI / 180 971 output.orientation = atan2(-sin(tiltXAngle), sinf(tiltYAngle)) 972 output.tilt = acos(cos(tiltXAngle) * cos(tiltYAngle)) 973 Else If touch.orientation.calibration == "interpolated": 974 center = average(raw.orientation.min, raw.orientation.max) 975 output.orientation = PI / (raw.orientation.max - raw.orientation.min) 976 output.tilt = 0 977 Else If touch.orientation.calibration == "vector": 978 c1 = (raw.orientation & 0xF0) >> 4 979 c2 = raw.orientation & 0x0F 980 981 If c1 != 0 or c2 != 0: 982 If c1 >= 8 Then c1 = c1 - 16 983 If c2 >= 8 Then c2 = c2 - 16 984 angle = atan2(c1, c2) / 2 985 confidence = sqrt(c1*c1 + c2*c2) 986 987 output.orientation = angle 988 989 If touch.size.calibration == "diameter" or "area": 990 scale = 1.0 + confidence / 16 991 output.touchMajor *= scale 992 output.touchMinor /= scale 993 output.toolMajor *= scale 994 output.toolMinor /= scale 995 End If 996 Else 997 output.orientation = 0 998 End If 999 output.tilt = 0 1000 Else 1001 output.orientation = 0 1002 output.tilt = 0 1003 End If 1004 1005 If orientation aware: 1006 If screen rotation is 90 degrees: 1007 output.orientation = output.orientation - PI / 2 1008 Else If screen rotation is 270 degrees: 1009 output.orientation = output.orientation + PI / 2 1010 End If 1011 End If 1012 </pre> 1013 <h3 id="distance-field"><code>Distance</code> Field</h3> 1014 <p>The <code>Distance</code> field describes the distance between the tool and the touch device 1015 surface. A value of 0.0 indicates direct contact and larger values indicate 1016 increasing distance from the surface.</p> 1017 <h4 id="touchdistancecalibration"><code>touch.distance.calibration</code></h4> 1018 <p><em>Definition:</em> <code>touch.distance.calibration</code> = <code>none</code> | <code>scaled</code> | <code>default</code></p> 1019 <p>Specifies the kind of measurement used by the touch driver to report the distance.</p> 1020 <ul> 1021 <li> 1022 <p>If the value is <code>none</code>, the distance is unknown so it is set to 0.</p> 1023 </li> 1024 <li> 1025 <p>If the value is <code>scaled</code>, the reported distance is multiplied by a 1026 constant scale factor.</p> 1027 </li> 1028 <li> 1029 <p>If the value is <code>default</code>, the system uses the <code>scaled</code> calibration if the 1030 distance axis available, otherwise uses <code>none</code>.</p> 1031 </li> 1032 </ul> 1033 <h4 id="touchdistancescale"><code>touch.distance.scale</code></h4> 1034 <p><em>Definition:</em> <code>touch.distance.scale</code> = <a non-negative floating point number></p> 1035 <p>Specifies a constant scale factor used in the calibration.</p> 1036 <p>The default value is <code>1.0</code>.</p> 1037 <h4 id="calculation_4">Calculation</h4> 1038 <p>The calculation of the <code>Distance</code> field depends on the specified calibration parameters.</p> 1039 <pre class="devsite-click-to-copy">If touch.distance.calibration == "scaled": 1040 output.distance = raw.distance * touch.distance.scale 1041 Else 1042 output.distance = 0 1043 End If 1044 </pre> 1045 <h3 id="example">Example</h3> 1046 <pre class="devsite-click-to-copy"> 1047 # Input device configuration file for a touch screen that supports pressure, 1048 # size and orientation. The pressure and size scale factors were obtained 1049 # by measuring the characteristics of the device itself and deriving 1050 # useful approximations based on the resolution of the touch sensor and the 1051 # display. 1052 # 1053 # Note that these parameters are specific to a particular device model. 1054 # Different parameters will need to be used for other devices. 1055 1056 # Basic Parameters 1057 touch.deviceType = touchScreen 1058 touch.orientationAware = 1 1059 1060 # Size 1061 # Based on empirical measurements, we estimate the size of the contact 1062 # using size = sqrt(area) * 28 + 0. 1063 touch.size.calibration = area 1064 touch.size.scale = 28 1065 touch.size.bias = 0 1066 touch.size.isSummed = 0 1067 1068 # Pressure 1069 # Driver reports signal strength as pressure. 1070 # 1071 # A normal index finger touch typically registers about 80 signal strength 1072 # units although we don't expect these values to be accurate. 1073 touch.pressure.calibration = amplitude 1074 touch.pressure.scale = 0.0125 1075 1076 # Orientation 1077 touch.orientation.calibration = vector 1078 </pre> 1079 <h3 id="compatibility-notes">Compatibility Notes</h3> 1080 <p>The configuration properties for touch devices changed significantly in 1081 Android Ice Cream Sandwich 4.0. <strong>All input device configuration files for touch 1082 devices must be updated to use the new configuration properties.</strong></p> 1083 <p>Older touch device <a href="#touch-device-driver-requirements">drivers</a> may also need to be 1084 updated.</p> 1085 <h2 id="virtual-key-map-files">Virtual Key Map Files</h2> 1086 <p>Touch devices are often used to implement virtual keys.</p> 1087 <p>There are several ways of doing this, depending on the capabilities of the 1088 touch controller. Some touch controllers can be directly configured to implement 1089 soft keys by setting firmware registers. Other times it is desirable to perform 1090 the mapping from touch coordinates to key codes in software.</p> 1091 <p>When virtual keys are implemented in software, the kernel must export a virtual key map 1092 file called <code>virtualkeys.<devicename></code> as a board property. For example, 1093 if the touch screen device drivers reports its name as "touchyfeely" then 1094 the virtual key map file must have the path <code>/sys/board_properties/virtualkeys.touchyfeely</code>.</p> 1095 <p>A virtual key map file describes the coordinates and Linux key codes of virtual keys 1096 on the touch screen.</p> 1097 <p>In addition to the virtual key map file, there must be a corresponding key layout 1098 file and key character map file to map the Linux key codes to Android key codes and 1099 to specify the type of the keyboard device (usually <code>SPECIAL_FUNCTION</code>).</p> 1100 <h3 id="syntax">Syntax</h3> 1101 <p>A virtual key map file is a plain text file consisting of a sequence of virtual key 1102 layout descriptions either separated by newlines or by colons.</p> 1103 <p>Comment lines begin with '#' and continue to the end of the line.</p> 1104 <p>Each virtual key is described by 6 colon-delimited components:</p> 1105 <ul> 1106 <li><code>0x01</code>: A version code. Must always be <code>0x01</code>.</li> 1107 <li><Linux key code>: The Linux key code of the virtual key.</li> 1108 <li><centerX>: The X pixel coordinate of the center of the virtual key.</li> 1109 <li><centerY>: The Y pixel coordinate of the center of the virtual key.</li> 1110 <li><width>: The width of the virtual key in pixels.</li> 1111 <li><height>: The height of the virtual key in pixels.</li> 1112 </ul> 1113 <p>All coordinates and sizes are specified in terms of the display coordinate system.</p> 1114 <p>Here is a virtual key map file all written on one line.</p> 1115 <pre class="devsite-click-to-copy"> 1116 # All on one line 1117 0x01:158:55:835:90:55:0x01:139:172:835:125:55:0x01:102:298:835:115:55:0x01:217:412:835:95:55 1118 </pre> 1119 <p>The same virtual key map file can also be written on multiple lines.</p> 1120 <pre class="devsite-click-to-copy"> 1121 # One key per line 1122 0x01:158:55:835:90:55 1123 0x01:139:172:835:125:55 1124 0x01:102:298:835:115:55 1125 0x01:217:412:835:95:55 1126 </pre> 1127 <p>In the above example, the touch screen has a resolution of 480x800. Accordingly, all of 1128 the virtual keys have a <centerY> coordinate of 835, which is a little bit below 1129 the visible area of the touch screen.</p> 1130 <p>The first key has a Linux scan code of <code>158</code> (<code>KEY_BACK</code>), centerX of <code>55</code>, 1131 centerY of <code>835</code>, width of <code>90</code> and height of <code>55</code>.</p> 1132 <h3 id="example_1">Example</h3> 1133 <p>Virtual key map file: <code>/sys/board_properties/virtualkeys.touchyfeely</code>.</p> 1134 <pre class="devsite-click-to-copy"> 1135 0x01:158:55:835:90:55 1136 0x01:139:172:835:125:55 1137 0x01:102:298:835:115:55 1138 0x01:217:412:835:95:55 1139 </pre> 1140 <p>Key layout file: <code>/system/usr/keylayout/touchyfeely.kl</code>.</p> 1141 <pre class="devsite-click-to-copy">key 158 BACK 1142 key 139 MENU 1143 key 102 HOME 1144 key 217 SEARCH 1145 </pre> 1146 <p>Key character map file: <code>/system/usr/keychars/touchyfeely.kcm</code>.</p> 1147 <pre class="devsite-click-to-copy"> 1148 type SPECIAL_FUNCTION 1149 </pre> 1150 <h2 id="indirect-multi-touch-pointer-gestures">Indirect Multi-touch Pointer Gestures</h2> 1151 <p>In pointer mode, the system interprets the following gestures:</p> 1152 <ol> 1153 <li> 1154 <p>Single finger tap: click.</p> 1155 </li> 1156 <li> 1157 <p>Single finger motion: move the pointer.</p> 1158 </li> 1159 <li> 1160 <p>Single finger motion plus button presses: drag the pointer.</p> 1161 </li> 1162 <li> 1163 <p>Two finger motion both fingers moving in the same direction: drag the area under the pointer 1164 in that direction. The pointer itself does not move.</p> 1165 </li> 1166 <li> 1167 <p>Two finger motion both fingers moving towards each other or apart in 1168 different directions: pan/scale/rotate the area surrounding the pointer. 1169 The pointer itself does not move.</p> 1170 </li> 1171 <li> 1172 <p>Multiple finger motion: freeform gesture.</p> 1173 </li> 1174 </ol> 1175 <h2 id="further-reading">Further Reading</h2> 1176 <ol> 1177 <li><a href="http://www.kernel.org/doc/Documentation/input/multi-touch-protocol.txt">Linux multi-touch protocol</a></li> 1178 <li><a href="http://lii-enac.fr/en/architecture/linux-input/multitouch-devices.html">ENAC list of available multitouch devices on Linux</a></li> 1179 </ol> 1180 1181 </body> 1182 </html> 1183