blob: 75be85abb95ce1fbeebd00c51568a9828aaf4b0d [file] [log] [blame]
Jeff Brown46b9ac02010-04-22 18:58:52 -07001/*
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>
Dianne Hackborn68267412010-07-02 18:52:01 -070045#include <android/looper.h>
Jeff Brown46b9ac02010-04-22 18:58:52 -070046
47#ifdef __cplusplus
48extern "C" {
49#endif
50
51/*
52 * Input device classes.
53 */
54enum {
55 /* The input device is a keyboard. */
56 INPUT_DEVICE_CLASS_KEYBOARD = 0x00000001,
57
58 /* The input device is an alpha-numeric keyboard (not just a dial pad). */
59 INPUT_DEVICE_CLASS_ALPHAKEY = 0x00000002,
60
61 /* The input device is a touchscreen (either single-touch or multi-touch). */
62 INPUT_DEVICE_CLASS_TOUCHSCREEN = 0x00000004,
63
64 /* The input device is a trackball. */
65 INPUT_DEVICE_CLASS_TRACKBALL = 0x00000008,
66
67 /* The input device is a multi-touch touchscreen. */
68 INPUT_DEVICE_CLASS_TOUCHSCREEN_MT= 0x00000010,
69
70 /* The input device is a directional pad. */
71 INPUT_DEVICE_CLASS_DPAD = 0x00000020
72};
73
74/*
75 * Key states (may be returned by queries about the current state of a
76 * particular key code, scan code or switch).
77 *
78 * XXX should we call this BUTTON_STATE_XXX?
79 */
80enum {
81 /* The key state is unknown or the requested key itself is not supported. */
82 KEY_STATE_UNKNOWN = -1,
83
84 /* The key is up. */
85 KEY_STATE_UP = 0,
86
87 /* The key is down. */
88 KEY_STATE_DOWN = 1,
89
90 /* The key is down but is a virtual key press that is being emulated by the system. */
91 KEY_STATE_VIRTUAL = 2
92};
93
94/*
95 * Meta key / modifer state.
96 */
97enum {
98 /* No meta keys are pressed. */
99 META_NONE = 0,
100
101 /* This mask is used to check whether one of the ALT meta keys is pressed. */
102 META_ALT_ON = 0x02,
103
104 /* This mask is used to check whether the left ALT meta key is pressed. */
105 META_ALT_LEFT_ON = 0x10,
106
107 /* This mask is used to check whether the right ALT meta key is pressed. */
108 META_ALT_RIGHT_ON = 0x20,
109
110 /* This mask is used to check whether one of the SHIFT meta keys is pressed. */
111 META_SHIFT_ON = 0x01,
112
113 /* This mask is used to check whether the left SHIFT meta key is pressed. */
114 META_SHIFT_LEFT_ON = 0x40,
115
116 /* This mask is used to check whether the right SHIFT meta key is pressed. */
117 META_SHIFT_RIGHT_ON = 0x80,
118
119 /* This mask is used to check whether the SYM meta key is pressed. */
120 META_SYM_ON = 0x04
121};
122
123/*
124 * Input events.
125 *
126 * Input events are opaque structures. Use the provided accessors functions to
127 * read their properties.
128 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700129struct AInputEvent;
130typedef struct AInputEvent AInputEvent;
Jeff Brown46b9ac02010-04-22 18:58:52 -0700131
132/*
133 * Input event types.
134 */
135enum {
136 /* Indicates that the input event is a key event. */
137 INPUT_EVENT_TYPE_KEY = 1,
138
139 /* Indicates that the input event is a motion event. */
140 INPUT_EVENT_TYPE_MOTION = 2
141};
142
143/*
144 * Key event actions.
145 */
146enum {
147 /* The key has been pressed down. */
148 KEY_EVENT_ACTION_DOWN = 0,
149
150 /* The key has been released. */
151 KEY_EVENT_ACTION_UP = 1,
152
153 /* Multiple duplicate key events have occurred in a row, or a complex string is
154 * being delivered. The repeat_count property of the key event contains the number
155 * of times the given key code should be executed.
156 */
157 KEY_EVENT_ACTION_MULTIPLE = 2
158};
159
160/*
161 * Key event flags.
162 */
163enum {
164 /* This mask is set if the device woke because of this key event. */
165 KEY_EVENT_FLAG_WOKE_HERE = 0x1,
166
167 /* This mask is set if the key event was generated by a software keyboard. */
168 KEY_EVENT_FLAG_SOFT_KEYBOARD = 0x2,
169
170 /* This mask is set if we don't want the key event to cause us to leave touch mode. */
171 KEY_EVENT_FLAG_KEEP_TOUCH_MODE = 0x4,
172
173 /* This mask is set if an event was known to come from a trusted part
174 * of the system. That is, the event is known to come from the user,
175 * and could not have been spoofed by a third party component. */
176 KEY_EVENT_FLAG_FROM_SYSTEM = 0x8,
177
178 /* This mask is used for compatibility, to identify enter keys that are
179 * coming from an IME whose enter key has been auto-labelled "next" or
180 * "done". This allows TextView to dispatch these as normal enter keys
181 * for old applications, but still do the appropriate action when
182 * receiving them. */
183 KEY_EVENT_FLAG_EDITOR_ACTION = 0x10,
184
185 /* When associated with up key events, this indicates that the key press
186 * has been canceled. Typically this is used with virtual touch screen
187 * keys, where the user can slide from the virtual key area on to the
188 * display: in that case, the application will receive a canceled up
189 * event and should not perform the action normally associated with the
190 * key. Note that for this to work, the application can not perform an
191 * action for a key until it receives an up or the long press timeout has
192 * expired. */
193 KEY_EVENT_FLAG_CANCELED = 0x20,
194
195 /* This key event was generated by a virtual (on-screen) hard key area.
196 * Typically this is an area of the touchscreen, outside of the regular
197 * display, dedicated to "hardware" buttons. */
198 KEY_EVENT_FLAG_VIRTUAL_HARD_KEY = 0x40,
199
200 /* This flag is set for the first key repeat that occurs after the
201 * long press timeout. */
202 KEY_EVENT_FLAG_LONG_PRESS = 0x80,
203
204 /* Set when a key event has KEY_EVENT_FLAG_CANCELED set because a long
205 * press action was executed while it was down. */
206 KEY_EVENT_FLAG_CANCELED_LONG_PRESS = 0x100,
207
208 /* Set for KEY_EVENT_ACTION_UP when this event's key code is still being
209 * tracked from its initial down. That is, somebody requested that tracking
210 * started on the key down and a long press has not caused
211 * the tracking to be canceled. */
212 KEY_EVENT_FLAG_TRACKING = 0x200
213};
214
215/*
216 * Motion event actions.
217 */
218
219/* Bit shift for the action bits holding the pointer index as
220 * defined by MOTION_EVENT_ACTION_POINTER_INDEX_MASK.
221 */
222#define MOTION_EVENT_ACTION_POINTER_INDEX_SHIFT 8
223
224enum {
225 /* Bit mask of the parts of the action code that are the action itself.
226 */
227 MOTION_EVENT_ACTION_MASK = 0xff,
228
229 /* Bits in the action code that represent a pointer index, used with
230 * MOTION_EVENT_ACTION_POINTER_DOWN and MOTION_EVENT_ACTION_POINTER_UP. Shifting
231 * down by MOTION_EVENT_ACTION_POINTER_INDEX_SHIFT provides the actual pointer
232 * index where the data for the pointer going up or down can be found.
233 */
234 MOTION_EVENT_ACTION_POINTER_INDEX_MASK = 0xff00,
235
236 /* A pressed gesture has started, the motion contains the initial starting location.
237 */
238 MOTION_EVENT_ACTION_DOWN = 0,
239
240 /* A pressed gesture has finished, the motion contains the final release location
241 * as well as any intermediate points since the last down or move event.
242 */
243 MOTION_EVENT_ACTION_UP = 1,
244
245 /* A change has happened during a press gesture (between MOTION_EVENT_ACTION_DOWN and
246 * MOTION_EVENT_ACTION_UP). The motion contains the most recent point, as well as
247 * any intermediate points since the last down or move event.
248 */
249 MOTION_EVENT_ACTION_MOVE = 2,
250
251 /* The current gesture has been aborted.
252 * You will not receive any more points in it. You should treat this as
253 * an up event, but not perform any action that you normally would.
254 */
255 MOTION_EVENT_ACTION_CANCEL = 3,
256
257 /* A movement has happened outside of the normal bounds of the UI element.
258 * This does not provide a full gesture, but only the initial location of the movement/touch.
259 */
260 MOTION_EVENT_ACTION_OUTSIDE = 4,
261
262 /* A non-primary pointer has gone down.
263 * The bits in MOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
264 */
265 MOTION_EVENT_ACTION_POINTER_DOWN = 5,
266
267 /* A non-primary pointer has gone up.
268 * The bits in MOTION_EVENT_ACTION_POINTER_INDEX_MASK indicate which pointer changed.
269 */
270 MOTION_EVENT_ACTION_POINTER_UP = 6
271};
272
273/*
274 * Motion event edge touch flags.
275 */
276enum {
277 /* No edges intersected */
278 MOTION_EVENT_EDGE_FLAG_NONE = 0,
279
280 /* Flag indicating the motion event intersected the top edge of the screen. */
281 MOTION_EVENT_EDGE_FLAG_TOP = 0x01,
282
283 /* Flag indicating the motion event intersected the bottom edge of the screen. */
284 MOTION_EVENT_EDGE_FLAG_BOTTOM = 0x02,
285
286 /* Flag indicating the motion event intersected the left edge of the screen. */
287 MOTION_EVENT_EDGE_FLAG_LEFT = 0x04,
288
289 /* Flag indicating the motion event intersected the right edge of the screen. */
290 MOTION_EVENT_EDGE_FLAG_RIGHT = 0x08
291};
292
293/*
294 * Specifies the logical nature of an input event.
295 * For example, the nature distinguishes between motion events that represent touches and
296 * those that represent trackball moves.
297 *
298 * XXX This concept is tentative. Another idea would be to associate events with logical
299 * controllers rather than physical devices. The interpretation of an event would
300 * be made with respect to the nature of the controller that is considered the logical
301 * source of an event. The decoupling is beneficial since multiple physical (and virtual)
302 * devices could be responsible for producing events that would be associated with
303 * various logical controllers. For example, the hard keyboard, on screen keyboard,
304 * and peripheral keyboard could be mapped onto a single logical "keyboard" controller
305 * (or treated independently, if desired).
306 */
307enum {
308 INPUT_EVENT_NATURE_KEY = 1,
309 INPUT_EVENT_NATURE_TOUCH = 2,
310 INPUT_EVENT_NATURE_TRACKBALL = 3
311};
312
313/*
314 * Input event accessors.
315 *
316 * Note that most functions can only be used on input events that are of a given type.
317 * Calling these functions on input events of other types will yield undefined behavior.
318 */
319
320/*** Accessors for all input events. ***/
321
322/* Get the input event type. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700323int32_t AInputEvent_getType(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700324
325/* Get the id for the device that an input event came from.
326 *
327 * Input events can be generated by multiple different input devices.
328 * Use the input device id to obtain information about the input
329 * device that was responsible for generating a particular event.
330 *
331 * An input device id of 0 indicates that the event didn't come from a physical device;
332 * other numbers are arbitrary and you shouldn't depend on the values.
333 * Use the provided input device query API to obtain information about input devices.
334 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700335int32_t AInputEvent_getDeviceId(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700336
337/* Get the input event nature. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700338int32_t AInputEvent_getNature(const AInputEvent* event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700339
340/*** Accessors for key events only. ***/
341
342/* Get the key event action. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700343int32_t AKeyEvent_getAction(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700344
345/* Get the key event flags. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700346int32_t AKeyEvent_getFlags(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700347
348/* Get the key code of the key event.
349 * This is the physical key that was pressed, not the Unicode character. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700350int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700351
352/* Get the hardware key id of this key event.
353 * These values are not reliable and vary from device to device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700354int32_t AKeyEvent_getScanCode(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700355
356/* Get the meta key state. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700357int32_t AKeyEvent_getMetaState(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700358
359/* Get the repeat count of the event.
360 * For both key up an key down events, this is the number of times the key has
361 * repeated with the first down starting at 0 and counting up from there. For
362 * multiple key events, this is the number of down/up pairs that have occurred. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700363int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700364
365/* Get the time of the most recent key down event, in the
366 * java.lang.System.nanoTime() time base. If this is a down event,
367 * this will be the same as eventTime.
368 * Note that when chording keys, this value is the down time of the most recently
369 * pressed key, which may not be the same physical key of this event. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700370int64_t AKeyEvent_getDownTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700371
372/* Get the time this event occurred, in the
373 * java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700374int64_t AKeyEvent_getEventTime(const AInputEvent* key_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700375
376/*** Accessors for motion events only. ***/
377
378/* Get the combined motion event action code and pointer index. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700379int32_t AMotionEvent_getAction(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700380
381/* Get the state of any meta / modifier keys that were in effect when the
382 * event was generated. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700383int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700384
385/* Get a bitfield indicating which edges, if any, were touched by this motion event.
386 * For touch events, clients can use this to determine if the user's finger was
387 * touching the edge of the display. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700388int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700389
390/* Get the time when the user originally pressed down to start a stream of
391 * position events, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700392int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700393
394/* Get the time when this specific event was generated,
395 * in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700396int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700397
Jeff Brown5c225b12010-06-16 01:53:36 -0700398/* Get the X coordinate offset.
399 * For touch events on the screen, this is the delta that was added to the raw
400 * screen coordinates to adjust for the absolute position of the containing windows
401 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700402float AMotionEvent_getXOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700403
404/* Get the precision of the Y coordinates being reported.
405 * For touch events on the screen, this is the delta that was added to the raw
406 * screen coordinates to adjust for the absolute position of the containing windows
407 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700408float AMotionEvent_getYOffset(const AInputEvent* motion_event);
Jeff Brown5c225b12010-06-16 01:53:36 -0700409
Jeff Brown46b9ac02010-04-22 18:58:52 -0700410/* Get the precision of the X coordinates being reported.
411 * You can multiply this number with an X coordinate sample to find the
412 * actual hardware value of the X coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700413float AMotionEvent_getXPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700414
415/* Get the precision of the Y coordinates being reported.
416 * You can multiply this number with a Y coordinate sample to find the
417 * actual hardware value of the Y coordinate. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700418float AMotionEvent_getYPrecision(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700419
420/* Get the number of pointers of data contained in this event.
421 * Always >= 1. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700422size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700423
424/* Get the pointer identifier associated with a particular pointer
425 * data index is this event. The identifier tells you the actual pointer
426 * number associated with the data, accounting for individual pointers
427 * going up and down since the start of the current gesture. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700428int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700429
Jeff Brown5c225b12010-06-16 01:53:36 -0700430/* Get the original raw X coordinate of this event.
431 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700432 * on the screen, before it had been adjusted for the containing window
433 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700434float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700435
Jeff Brown5c225b12010-06-16 01:53:36 -0700436/* Get the original raw X coordinate of this event.
437 * For touch events on the screen, this is the original location of the event
Jeff Brown46b9ac02010-04-22 18:58:52 -0700438 * on the screen, before it had been adjusted for the containing window
439 * and views. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700440float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700441
442/* Get the current X coordinate of this event for the given pointer index.
443 * Whole numbers are pixels; the value may have a fraction for input devices
444 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700445float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700446
447/* Get the current Y coordinate of this event for the given pointer index.
448 * Whole numbers are pixels; the value may have a fraction for input devices
449 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700450float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700451
452/* Get the current pressure of this event for the given pointer index.
453 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
454 * however values higher than 1 may be generated depending on the calibration of
455 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700456float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700457
458/* Get the current scaled value of the approximate size for the given pointer index.
459 * This represents some approximation of the area of the screen being
460 * pressed; the actual value in pixels corresponding to the
461 * touch is normalized with the device specific range of values
462 * and scaled to a value between 0 and 1. The value of size can be used to
463 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700464float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700465
466/* Get the number of historical points in this event. These are movements that
467 * have occurred between this event and the previous event. This only applies
468 * to MOTION_EVENT_ACTION_MOVE events -- all other actions will have a size of 0.
469 * Historical samples are indexed from oldest to newest. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700470size_t AMotionEvent_get_history_size(const AInputEvent* motion_event);
Jeff Brown46b9ac02010-04-22 18:58:52 -0700471
472/* Get the time that a historical movement occurred between this event and
473 * the previous event, in the java.lang.System.nanoTime() time base. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700474int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700475 size_t history_index);
476
Jeff Brown5c225b12010-06-16 01:53:36 -0700477/* Get the historical raw X coordinate of this event for the given pointer index that
478 * occurred between this event and the previous motion event.
479 * For touch events on the screen, this is the original location of the event
480 * on the screen, before it had been adjusted for the containing window
481 * and views.
482 * Whole numbers are pixels; the value may have a fraction for input devices
483 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700484float AMotionEvent_getHistoricalRawX(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700485
486/* Get the historical raw Y coordinate of this event for the given pointer index that
487 * occurred between this event and the previous motion event.
488 * For touch events on the screen, this is the original location of the event
489 * on the screen, before it had been adjusted for the containing window
490 * and views.
491 * Whole numbers are pixels; the value may have a fraction for input devices
492 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700493float AMotionEvent_getHistoricalRawY(const AInputEvent* motion_event, size_t pointer_index);
Jeff Brown5c225b12010-06-16 01:53:36 -0700494
Jeff Brown46b9ac02010-04-22 18:58:52 -0700495/* Get the historical X coordinate of this event for the given pointer index that
496 * occurred between this event and the previous motion event.
497 * Whole numbers are pixels; the value may have a fraction for input devices
498 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700499float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700500 size_t history_index);
501
502/* Get the historical Y coordinate of this event for the given pointer index that
503 * occurred between this event and the previous motion event.
504 * Whole numbers are pixels; the value may have a fraction for input devices
505 * that are sub-pixel precise. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700506float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700507 size_t history_index);
508
509/* Get the historical pressure of this event for the given pointer index that
510 * occurred between this event and the previous motion event.
511 * The pressure generally ranges from 0 (no pressure at all) to 1 (normal pressure),
512 * however values higher than 1 may be generated depending on the calibration of
513 * the input device. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700514float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700515 size_t history_index);
516
517/* Get the current scaled value of the approximate size for the given pointer index that
518 * occurred between this event and the previous motion event.
519 * This represents some approximation of the area of the screen being
520 * pressed; the actual value in pixels corresponding to the
521 * touch is normalized with the device specific range of values
522 * and scaled to a value between 0 and 1. The value of size can be used to
523 * determine fat touch events. */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700524float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index,
Jeff Brown46b9ac02010-04-22 18:58:52 -0700525 size_t history_index);
526
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700527/*
528 * Input queue
529 *
530 * An input queue is the facility through which you retrieve input
531 * events.
532 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700533struct AInputQueue;
534typedef struct AInputQueue AInputQueue;
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700535
536/*
Dianne Hackborn68267412010-07-02 18:52:01 -0700537 * Add this input queue to a looper for processing.
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700538 */
Dianne Hackborn68267412010-07-02 18:52:01 -0700539void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
540 ALooper_callbackFunc callback, void* data);
541
542/*
543 * Remove the input queue from the looper it is currently attached to.
544 */
545void AInputQueue_detachLooper(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700546
547/*
548 * Returns true if there are one or more events available in the
549 * input queue. Returns 1 if the queue has events; 0 if
550 * it does not have events; and a negative value if there is an error.
551 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700552int AInputQueue_hasEvents(AInputQueue* queue);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700553
554/*
555 * Returns the next available event from the queue. Returns a negative
556 * value if no events are available or an error has occurred.
557 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700558int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700559
560/*
561 * Report that dispatching has finished with the given event.
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700562 * This must be called after receiving an event with AInputQueue_get_event().
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700563 */
Dianne Hackborn2e9f93e2010-06-28 15:27:30 -0700564void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled);
Dianne Hackborna95e4cb2010-06-18 18:09:33 -0700565
Jeff Brown46b9ac02010-04-22 18:58:52 -0700566#ifdef __cplusplus
567}
568#endif
569
570#endif // _ANDROID_INPUT_H