Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef _ANDROID_INPUT_H |
| 18 | #define _ANDROID_INPUT_H |
| 19 | |
| 20 | /****************************************************************** |
| 21 | * |
| 22 | * IMPORTANT NOTICE: |
| 23 | * |
| 24 | * This file is part of Android's set of stable system headers |
| 25 | * exposed by the Android NDK (Native Development Kit). |
| 26 | * |
| 27 | * Third-party source AND binary code relies on the definitions |
| 28 | * here to be FROZEN ON ALL UPCOMING PLATFORM RELEASES. |
| 29 | * |
| 30 | * - DO NOT MODIFY ENUMS (EXCEPT IF YOU ADD NEW 32-BIT VALUES) |
| 31 | * - DO NOT MODIFY CONSTANTS OR FUNCTIONAL MACROS |
| 32 | * - DO NOT CHANGE THE SIGNATURE OF FUNCTIONS IN ANY WAY |
| 33 | * - DO NOT CHANGE THE LAYOUT OR SIZE OF STRUCTURES |
| 34 | */ |
| 35 | |
| 36 | /* |
| 37 | * Structures and functions to receive and process input events in |
| 38 | * native code. |
| 39 | * |
| 40 | * NOTE: These functions MUST be implemented by /system/lib/libui.so |
| 41 | */ |
| 42 | |
| 43 | #include <sys/types.h> |
| 44 | #include <android/keycodes.h> |
| 45 | |
| 46 | #ifdef __cplusplus |
| 47 | extern "C" { |
| 48 | #endif |
| 49 | |
| 50 | /* |
| 51 | * Input device classes. |
| 52 | */ |
| 53 | enum { |
| 54 | /* The input device is a keyboard. */ |
| 55 | INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001, |
| 56 | |
| 57 | /* The input device is an alpha-numeric keyboard (not just a dial pad). */ |
| 58 | INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002, |
| 59 | |
| 60 | /* The input device is a touchscreen (either single-touch or multi-touch). */ |
| 61 | INPUT_DEVICE_CLASS_TOUCHSCREEN = 0x00000004, |
| 62 | |
| 63 | /* The input device is a trackball. */ |
| 64 | INPUT_DEVICE_CLASS_TRACKBALL = 0x00000008, |
| 65 | |
| 66 | /* The input device is a multi-touch touchscreen. */ |
| 67 | INPUT_DEVICE_CLASS_TOUCHSCREEN_MT= 0x00000010, |
| 68 | |
| 69 | /* The input device is a directional pad. */ |
| 70 | INPUT_DEVICE_CLASS_DPAD = 0x00000020 |
| 71 | }; |
| 72 | |
| 73 | /* |
| 74 | * Key states (may be returned by queries about the current state of a |
| 75 | * particular key code, scan code or switch). |
| 76 | * |
| 77 | * XXX should we call this BUTTON_STATE_XXX? |
| 78 | */ |
| 79 | enum { |
| 80 | /* The key state is unknown or the requested key itself is not supported. */ |
| 81 | KEY_STATE_UNKNOWN = -1, |
| 82 | |
| 83 | /* The key is up. */ |
| 84 | KEY_STATE_UP = 0, |
| 85 | |
| 86 | /* The key is down. */ |
| 87 | KEY_STATE_DOWN = 1, |
| 88 | |
| 89 | /* The key is down but is a virtual key press that is being emulated by the system. */ |
| 90 | KEY_STATE_VIRTUAL = 2 |
| 91 | }; |
| 92 | |
| 93 | /* |
| 94 | * Meta key / modifer state. |
| 95 | */ |
| 96 | enum { |
| 97 | /* No meta keys are pressed. */ |
| 98 | META_NONE = 0, |
| 99 | |
| 100 | /* This mask is used to check whether one of the ALT meta keys is pressed. */ |
| 101 | META_ALT_ON = 0x02, |
| 102 | |
| 103 | /* This mask is used to check whether the left ALT meta key is pressed. */ |
| 104 | META_ALT_LEFT_ON = 0x10, |
| 105 | |
| 106 | /* This mask is used to check whether the right ALT meta key is pressed. */ |
| 107 | META_ALT_RIGHT_ON = 0x20, |
| 108 | |
| 109 | /* This mask is used to check whether one of the SHIFT meta keys is pressed. */ |
| 110 | META_SHIFT_ON = 0x01, |
| 111 | |
| 112 | /* This mask is used to check whether the left SHIFT meta key is pressed. */ |
| 113 | META_SHIFT_LEFT_ON = 0x40, |
| 114 | |
| 115 | /* This mask is used to check whether the right SHIFT meta key is pressed. */ |
| 116 | META_SHIFT_RIGHT_ON = 0x80, |
| 117 | |
| 118 | /* This mask is used to check whether the SYM meta key is pressed. */ |
| 119 | META_SYM_ON = 0x04 |
| 120 | }; |
| 121 | |
| 122 | /* |
| 123 | * Input events. |
| 124 | * |
| 125 | * Input events are opaque structures. Use the provided accessors functions to |
| 126 | * read their properties. |
| 127 | */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 128 | struct AInputEvent; |
| 129 | typedef struct AInputEvent AInputEvent; |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 130 | |
| 131 | /* |
| 132 | * Input event types. |
| 133 | */ |
| 134 | enum { |
| 135 | /* Indicates that the input event is a key event. */ |
| 136 | INPUT_EVENT_TYPE_KEY = 1, |
| 137 | |
| 138 | /* Indicates that the input event is a motion event. */ |
| 139 | INPUT_EVENT_TYPE_MOTION = 2 |
| 140 | }; |
| 141 | |
| 142 | /* |
| 143 | * Key event actions. |
| 144 | */ |
| 145 | enum { |
| 146 | /* The key has been pressed down. */ |
| 147 | KEY_EVENT_ACTION_DOWN = 0, |
| 148 | |
| 149 | /* The key has been released. */ |
| 150 | KEY_EVENT_ACTION_UP = 1, |
| 151 | |
| 152 | /* Multiple duplicate key events have occurred in a row, or a complex string is |
| 153 | * being delivered. The repeat_count property of the key event contains the number |
| 154 | * of times the given key code should be executed. |
| 155 | */ |
| 156 | KEY_EVENT_ACTION_MULTIPLE = 2 |
| 157 | }; |
| 158 | |
| 159 | /* |
| 160 | * Key event flags. |
| 161 | */ |
| 162 | enum { |
| 163 | /* This mask is set if the device woke because of this key event. */ |
| 164 | KEY_EVENT_FLAG_WOKE_HERE = 0x1, |
| 165 | |
| 166 | /* This mask is set if the key event was generated by a software keyboard. */ |
| 167 | KEY_EVENT_FLAG_SOFT_KEYBOARD = 0x2, |
| 168 | |
| 169 | /* This mask is set if we don't want the key event to cause us to leave touch mode. */ |
| 170 | KEY_EVENT_FLAG_KEEP_TOUCH_MODE = 0x4, |
| 171 | |
| 172 | /* This mask is set if an event was known to come from a trusted part |
| 173 | * of the system. That is, the event is known to come from the user, |
| 174 | * and could not have been spoofed by a third party component. */ |
| 175 | KEY_EVENT_FLAG_FROM_SYSTEM = 0x8, |
| 176 | |
| 177 | /* This mask is used for compatibility, to identify enter keys that are |
| 178 | * coming from an IME whose enter key has been auto-labelled "next" or |
| 179 | * "done". This allows TextView to dispatch these as normal enter keys |
| 180 | * for old applications, but still do the appropriate action when |
| 181 | * receiving them. */ |
| 182 | KEY_EVENT_FLAG_EDITOR_ACTION = 0x10, |
| 183 | |
| 184 | /* When associated with up key events, this indicates that the key press |
| 185 | * has been canceled. Typically this is used with virtual touch screen |
| 186 | * keys, where the user can slide from the virtual key area on to the |
| 187 | * display: in that case, the application will receive a canceled up |
| 188 | * event and should not perform the action normally associated with the |
| 189 | * key. Note that for this to work, the application can not perform an |
| 190 | * action for a key until it receives an up or the long press timeout has |
| 191 | * expired. */ |
| 192 | KEY_EVENT_FLAG_CANCELED = 0x20, |
| 193 | |
| 194 | /* This key event was generated by a virtual (on-screen) hard key area. |
| 195 | * Typically this is an area of the touchscreen, outside of the regular |
| 196 | * display, dedicated to "hardware" buttons. */ |
| 197 | KEY_EVENT_FLAG_VIRTUAL_HARD_KEY = 0x40, |
| 198 | |
| 199 | /* This flag is set for the first key repeat that occurs after the |
| 200 | * long press timeout. */ |
| 201 | KEY_EVENT_FLAG_LONG_PRESS = 0x80, |
| 202 | |
| 203 | /* Set when a key event has KEY_EVENT_FLAG_CANCELED set because a long |
| 204 | * press action was executed while it was down. */ |
| 205 | KEY_EVENT_FLAG_CANCELED_LONG_PRESS = 0x100, |
| 206 | |
| 207 | /* Set for KEY_EVENT_ACTION_UP when this event's key code is still being |
| 208 | * tracked from its initial down. That is, somebody requested that tracking |
| 209 | * started on the key down and a long press has not caused |
| 210 | * the tracking to be canceled. */ |
| 211 | KEY_EVENT_FLAG_TRACKING = 0x200 |
| 212 | }; |
| 213 | |
| 214 | /* |
| 215 | * Motion event actions. |
| 216 | */ |
| 217 | |
| 218 | /* Bit shift for the action bits holding the pointer index as |
| 219 | * defined by MOTION_EVENT_ACTION_POINTER_INDEX_MASK. |
| 220 | */ |
| 221 | #define MOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8 |
| 222 | |
| 223 | enum { |
| 224 | /* Bit mask of the parts of the action code that are the action itself. |
| 225 | */ |
| 226 | MOTION_EVENT_ACTION_MASK = 0xff, |
| 227 | |
| 228 | /* Bits in the action code that represent a pointer index, used with |
| 229 | * MOTION_EVENT_ACTION_POINTER_DOWN and MOTION_EVENT_ACTION_POINTER_UP. Shifting |
| 230 | * down by MOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer |
| 231 | * index where the data for the pointer going up or down can be found. |
| 232 | */ |
| 233 | MOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00, |
| 234 | |
| 235 | /* A pressed gesture has started, the motion contains the initial starting location. |
| 236 | */ |
| 237 | MOTION_EVENT_ACTION_DOWN = 0, |
| 238 | |
| 239 | /* A pressed gesture has finished, the motion contains the final release location |
| 240 | * as well as any intermediate points since the last down or move event. |
| 241 | */ |
| 242 | MOTION_EVENT_ACTION_UP = 1, |
| 243 | |
| 244 | /* A change has happened during a press gesture (between MOTION_EVENT_ACTION_DOWN and |
| 245 | * MOTION_EVENT_ACTION_UP). The motion contains the most recent point, as well as |
| 246 | * any intermediate points since the last down or move event. |
| 247 | */ |
| 248 | MOTION_EVENT_ACTION_MOVE = 2, |
| 249 | |
| 250 | /* The current gesture has been aborted. |
| 251 | * You will not receive any more points in it. You should treat this as |
| 252 | * an up event, but not perform any action that you normally would. |
| 253 | */ |
| 254 | MOTION_EVENT_ACTION_CANCEL = 3, |
| 255 | |
| 256 | /* A movement has happened outside of the normal bounds of the UI element. |
| 257 | * This does not provide a full gesture, but only the initial location of the movement/touch. |
| 258 | */ |
| 259 | MOTION_EVENT_ACTION_OUTSIDE = 4, |
| 260 | |
| 261 | /* A non-primary pointer has gone down. |
| 262 | * The bits in MOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed. |
| 263 | */ |
| 264 | MOTION_EVENT_ACTION_POINTER_DOWN = 5, |
| 265 | |
| 266 | /* A non-primary pointer has gone up. |
| 267 | * The bits in MOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed. |
| 268 | */ |
| 269 | MOTION_EVENT_ACTION_POINTER_UP = 6 |
| 270 | }; |
| 271 | |
| 272 | /* |
| 273 | * Motion event edge touch flags. |
| 274 | */ |
| 275 | enum { |
| 276 | /* No edges intersected */ |
| 277 | MOTION_EVENT_EDGE_FLAG_NONE = 0, |
| 278 | |
| 279 | /* Flag indicating the motion event intersected the top edge of the screen. */ |
| 280 | MOTION_EVENT_EDGE_FLAG_TOP = 0x01, |
| 281 | |
| 282 | /* Flag indicating the motion event intersected the bottom edge of the screen. */ |
| 283 | MOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02, |
| 284 | |
| 285 | /* Flag indicating the motion event intersected the left edge of the screen. */ |
| 286 | MOTION_EVENT_EDGE_FLAG_LEFT = 0x04, |
| 287 | |
| 288 | /* Flag indicating the motion event intersected the right edge of the screen. */ |
| 289 | MOTION_EVENT_EDGE_FLAG_RIGHT = 0x08 |
| 290 | }; |
| 291 | |
| 292 | /* |
| 293 | * Specifies the logical nature of an input event. |
| 294 | * For example, the nature distinguishes between motion events that represent touches and |
| 295 | * those that represent trackball moves. |
| 296 | * |
| 297 | * XXX This concept is tentative. Another idea would be to associate events with logical |
| 298 | * controllers rather than physical devices. The interpretation of an event would |
| 299 | * be made with respect to the nature of the controller that is considered the logical |
| 300 | * source of an event. The decoupling is beneficial since multiple physical (and virtual) |
| 301 | * devices could be responsible for producing events that would be associated with |
| 302 | * various logical controllers. For example, the hard keyboard, on screen keyboard, |
| 303 | * and peripheral keyboard could be mapped onto a single logical "keyboard" controller |
| 304 | * (or treated independently, if desired). |
| 305 | */ |
| 306 | enum { |
| 307 | INPUT_EVENT_NATURE_KEY = 1, |
| 308 | INPUT_EVENT_NATURE_TOUCH = 2, |
| 309 | INPUT_EVENT_NATURE_TRACKBALL = 3 |
| 310 | }; |
| 311 | |
| 312 | /* |
| 313 | * Input event accessors. |
| 314 | * |
| 315 | * Note that most functions can only be used on input events that are of a given type. |
| 316 | * Calling these functions on input events of other types will yield undefined behavior. |
| 317 | */ |
| 318 | |
| 319 | /*** Accessors for all input events. ***/ |
| 320 | |
| 321 | /* Get the input event type. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 322 | int32_t AInputEvent_getType(const AInputEvent* event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 323 | |
| 324 | /* Get the id for the device that an input event came from. |
| 325 | * |
| 326 | * Input events can be generated by multiple different input devices. |
| 327 | * Use the input device id to obtain information about the input |
| 328 | * device that was responsible for generating a particular event. |
| 329 | * |
| 330 | * An input device id of 0 indicates that the event didn't come from a physical device; |
| 331 | * other numbers are arbitrary and you shouldn't depend on the values. |
| 332 | * Use the provided input device query API to obtain information about input devices. |
| 333 | */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 334 | int32_t AInputEvent_getDeviceId(const AInputEvent* event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 335 | |
| 336 | /* Get the input event nature. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 337 | int32_t AInputEvent_getNature(const AInputEvent* event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 338 | |
| 339 | /*** Accessors for key events only. ***/ |
| 340 | |
| 341 | /* Get the key event action. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 342 | int32_t AKeyEvent_getAction(const AInputEvent* key_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 343 | |
| 344 | /* Get the key event flags. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 345 | int32_t AKeyEvent_getFlags(const AInputEvent* key_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 346 | |
| 347 | /* Get the key code of the key event. |
| 348 | * This is the physical key that was pressed, not the Unicode character. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 349 | int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 350 | |
| 351 | /* Get the hardware key id of this key event. |
| 352 | * These values are not reliable and vary from device to device. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 353 | int32_t AKeyEvent_getScanCode(const AInputEvent* key_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 354 | |
| 355 | /* Get the meta key state. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 356 | int32_t AKeyEvent_getMetaState(const AInputEvent* key_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 357 | |
| 358 | /* Get the repeat count of the event. |
| 359 | * For both key up an key down events, this is the number of times the key has |
| 360 | * repeated with the first down starting at 0 and counting up from there. For |
| 361 | * multiple key events, this is the number of down/up pairs that have occurred. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 362 | int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 363 | |
| 364 | /* Get the time of the most recent key down event, in the |
| 365 | * java.lang.System.nanoTime() time base. If this is a down event, |
| 366 | * this will be the same as eventTime. |
| 367 | * Note that when chording keys, this value is the down time of the most recently |
| 368 | * pressed key, which may not be the same physical key of this event. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 369 | int64_t AKeyEvent_getDownTime(const AInputEvent* key_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 370 | |
| 371 | /* Get the time this event occurred, in the |
| 372 | * java.lang.System.nanoTime() time base. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 373 | int64_t AKeyEvent_getEventTime(const AInputEvent* key_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 374 | |
| 375 | /*** Accessors for motion events only. ***/ |
| 376 | |
| 377 | /* Get the combined motion event action code and pointer index. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 378 | int32_t AMotionEvent_getAction(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 379 | |
| 380 | /* Get the state of any meta / modifier keys that were in effect when the |
| 381 | * event was generated. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 382 | int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 383 | |
| 384 | /* Get a bitfield indicating which edges, if any, were touched by this motion event. |
| 385 | * For touch events, clients can use this to determine if the user's finger was |
| 386 | * touching the edge of the display. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 387 | int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 388 | |
| 389 | /* Get the time when the user originally pressed down to start a stream of |
| 390 | * position events, in the java.lang.System.nanoTime() time base. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 391 | int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 392 | |
| 393 | /* Get the time when this specific event was generated, |
| 394 | * in the java.lang.System.nanoTime() time base. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 395 | int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 396 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 397 | /* Get the X coordinate offset. |
| 398 | * For touch events on the screen, this is the delta that was added to the raw |
| 399 | * screen coordinates to adjust for the absolute position of the containing windows |
| 400 | * and views. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 401 | float AMotionEvent_getXOffset(const AInputEvent* motion_event); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 402 | |
| 403 | /* Get the precision of the Y coordinates being reported. |
| 404 | * For touch events on the screen, this is the delta that was added to the raw |
| 405 | * screen coordinates to adjust for the absolute position of the containing windows |
| 406 | * and views. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 407 | float AMotionEvent_getYOffset(const AInputEvent* motion_event); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 408 | |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 409 | /* Get the precision of the X coordinates being reported. |
| 410 | * You can multiply this number with an X coordinate sample to find the |
| 411 | * actual hardware value of the X coordinate. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 412 | float AMotionEvent_getXPrecision(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 413 | |
| 414 | /* Get the precision of the Y coordinates being reported. |
| 415 | * You can multiply this number with a Y coordinate sample to find the |
| 416 | * actual hardware value of the Y coordinate. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 417 | float AMotionEvent_getYPrecision(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 418 | |
| 419 | /* Get the number of pointers of data contained in this event. |
| 420 | * Always >= 1. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 421 | size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 422 | |
| 423 | /* Get the pointer identifier associated with a particular pointer |
| 424 | * data index is this event. The identifier tells you the actual pointer |
| 425 | * number associated with the data, accounting for individual pointers |
| 426 | * going up and down since the start of the current gesture. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 427 | int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 428 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 429 | /* Get the original raw X coordinate of this event. |
| 430 | * For touch events on the screen, this is the original location of the event |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 431 | * on the screen, before it had been adjusted for the containing window |
| 432 | * and views. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 433 | float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 434 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 435 | /* Get the original raw X coordinate of this event. |
| 436 | * For touch events on the screen, this is the original location of the event |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 437 | * on the screen, before it had been adjusted for the containing window |
| 438 | * and views. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 439 | float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 440 | |
| 441 | /* Get the current X coordinate of this event for the given pointer index. |
| 442 | * Whole numbers are pixels; the value may have a fraction for input devices |
| 443 | * that are sub-pixel precise. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 444 | float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 445 | |
| 446 | /* Get the current Y coordinate of this event for the given pointer index. |
| 447 | * Whole numbers are pixels; the value may have a fraction for input devices |
| 448 | * that are sub-pixel precise. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 449 | float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 450 | |
| 451 | /* Get the current pressure of this event for the given pointer index. |
| 452 | * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), |
| 453 | * however values higher than 1 may be generated depending on the calibration of |
| 454 | * the input device. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 455 | float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 456 | |
| 457 | /* Get the current scaled value of the approximate size for the given pointer index. |
| 458 | * This represents some approximation of the area of the screen being |
| 459 | * pressed; the actual value in pixels corresponding to the |
| 460 | * touch is normalized with the device specific range of values |
| 461 | * and scaled to a value between 0 and 1. The value of size can be used to |
| 462 | * determine fat touch events. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 463 | float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 464 | |
| 465 | /* Get the number of historical points in this event. These are movements that |
| 466 | * have occurred between this event and the previous event. This only applies |
| 467 | * to MOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0. |
| 468 | * Historical samples are indexed from oldest to newest. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 469 | size_t AMotionEvent_get_history_size(const AInputEvent* motion_event); |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 470 | |
| 471 | /* Get the time that a historical movement occurred between this event and |
| 472 | * the previous event, in the java.lang.System.nanoTime() time base. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 473 | int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 474 | size_t history_index); |
| 475 | |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 476 | /* Get the historical raw X coordinate of this event for the given pointer index that |
| 477 | * occurred between this event and the previous motion event. |
| 478 | * For touch events on the screen, this is the original location of the event |
| 479 | * on the screen, before it had been adjusted for the containing window |
| 480 | * and views. |
| 481 | * Whole numbers are pixels; the value may have a fraction for input devices |
| 482 | * that are sub-pixel precise. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 483 | float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 484 | |
| 485 | /* Get the historical raw Y coordinate of this event for the given pointer index that |
| 486 | * occurred between this event and the previous motion event. |
| 487 | * For touch events on the screen, this is the original location of the event |
| 488 | * on the screen, before it had been adjusted for the containing window |
| 489 | * and views. |
| 490 | * Whole numbers are pixels; the value may have a fraction for input devices |
| 491 | * that are sub-pixel precise. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 492 | float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index); |
Jeff Brown | 5c225b1 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 493 | |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 494 | /* Get the historical X coordinate of this event for the given pointer index that |
| 495 | * occurred between this event and the previous motion event. |
| 496 | * Whole numbers are pixels; the value may have a fraction for input devices |
| 497 | * that are sub-pixel precise. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 498 | float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 499 | size_t history_index); |
| 500 | |
| 501 | /* Get the historical Y coordinate of this event for the given pointer index that |
| 502 | * occurred between this event and the previous motion event. |
| 503 | * Whole numbers are pixels; the value may have a fraction for input devices |
| 504 | * that are sub-pixel precise. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 505 | float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 506 | size_t history_index); |
| 507 | |
| 508 | /* Get the historical pressure of this event for the given pointer index that |
| 509 | * occurred between this event and the previous motion event. |
| 510 | * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure), |
| 511 | * however values higher than 1 may be generated depending on the calibration of |
| 512 | * the input device. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 513 | float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 514 | size_t history_index); |
| 515 | |
| 516 | /* Get the current scaled value of the approximate size for the given pointer index that |
| 517 | * occurred between this event and the previous motion event. |
| 518 | * This represents some approximation of the area of the screen being |
| 519 | * pressed; the actual value in pixels corresponding to the |
| 520 | * touch is normalized with the device specific range of values |
| 521 | * and scaled to a value between 0 and 1. The value of size can be used to |
| 522 | * determine fat touch events. */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 523 | float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index, |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 524 | size_t history_index); |
| 525 | |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 526 | /* |
| 527 | * Input queue |
| 528 | * |
| 529 | * An input queue is the facility through which you retrieve input |
| 530 | * events. |
| 531 | */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 532 | struct AInputQueue; |
| 533 | typedef struct AInputQueue AInputQueue; |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 534 | |
| 535 | /* |
| 536 | * Return a file descriptor for the queue, which you |
| 537 | * can use to determine if there are events available. This |
| 538 | * is typically used with select() or poll() to multiplex |
| 539 | * with other kinds of events. |
| 540 | */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 541 | int AInputQueue_getFd(AInputQueue* queue); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 542 | |
| 543 | /* |
| 544 | * Returns true if there are one or more events available in the |
| 545 | * input queue. Returns 1 if the queue has events; 0 if |
| 546 | * it does not have events; and a negative value if there is an error. |
| 547 | */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 548 | int AInputQueue_hasEvents(AInputQueue* queue); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 549 | |
| 550 | /* |
| 551 | * Returns the next available event from the queue. Returns a negative |
| 552 | * value if no events are available or an error has occurred. |
| 553 | */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 554 | int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 555 | |
| 556 | /* |
| 557 | * Report that dispatching has finished with the given event. |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 558 | * This must be called after receiving an event with AInputQueue_get_event(). |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 559 | */ |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame^] | 560 | void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 561 | |
Jeff Brown | 46b9ac0a | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 562 | #ifdef __cplusplus |
| 563 | } |
| 564 | #endif |
| 565 | |
| 566 | #endif // _ANDROID_INPUT_H |