Jeff Brown | e839a58 | 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 _UI_INPUT_H |
| 18 | #define _UI_INPUT_H |
| 19 | |
| 20 | /** |
| 21 | * Native input event structures. |
| 22 | */ |
| 23 | |
| 24 | #include <android/input.h> |
| 25 | #include <utils/Vector.h> |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 26 | #include <utils/KeyedVector.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 27 | #include <utils/Timers.h> |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
| 29 | #include <utils/String8.h> |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 30 | |
| 31 | /* |
| 32 | * Additional private constants not defined in ndk/ui/input.h. |
| 33 | */ |
| 34 | enum { |
| 35 | /* |
| 36 | * Private control to determine when an app is tracking a key sequence. |
| 37 | */ |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 38 | AKEY_EVENT_FLAG_START_TRACKING = 0x40000000 |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Jeff Brown | 430c21e | 2011-01-19 18:41:38 -0800 | [diff] [blame] | 41 | enum { |
| 42 | /* |
| 43 | * Indicates that an input device has switches. |
| 44 | * This input source flag is hidden from the API because switches are only used by the system |
| 45 | * and applications have no way to interact with them. |
| 46 | */ |
| 47 | AINPUT_SOURCE_SWITCH = 0x80000000, |
| 48 | }; |
| 49 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 50 | /* |
| 51 | * Maximum number of pointers supported per motion event. |
Jeff Brown | d1b0a2b | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 52 | * Smallest number of pointers is 1. |
Jeff Brown | eb8b9d8 | 2011-01-25 16:02:22 -0800 | [diff] [blame^] | 53 | * (We want at least 10 but some touch controllers obstensibly configured for 10 pointers |
| 54 | * will occasionally emit 11. There is not much harm making this constant bigger.) |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 55 | */ |
Jeff Brown | eb8b9d8 | 2011-01-25 16:02:22 -0800 | [diff] [blame^] | 56 | #define MAX_POINTERS 16 |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 57 | |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 58 | /* |
Jeff Brown | d1b0a2b | 2010-09-26 22:20:12 -0700 | [diff] [blame] | 59 | * Maximum pointer id value supported in a motion event. |
| 60 | * Smallest pointer id is 0. |
| 61 | * (This is limited by our use of BitSet32 to track pointer assignments.) |
| 62 | */ |
| 63 | #define MAX_POINTER_ID 31 |
| 64 | |
| 65 | /* |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 66 | * Declare a concrete type for the NDK's input event forward declaration. |
| 67 | */ |
Dianne Hackborn | ce838a2 | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 68 | struct AInputEvent { |
| 69 | virtual ~AInputEvent() { } |
| 70 | }; |
Dianne Hackborn | 4d96bb6 | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 71 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 72 | /* |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 73 | * Declare a concrete type for the NDK's input device forward declaration. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 74 | */ |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 75 | struct AInputDevice { |
| 76 | virtual ~AInputDevice() { } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 79 | |
| 80 | namespace android { |
| 81 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 82 | /* |
| 83 | * Flags that flow alongside events in the input dispatch system to help with certain |
| 84 | * policy decisions such as waking from device sleep. |
Jeff Brown | 90f0cee | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 85 | * |
| 86 | * These flags are also defined in frameworks/base/core/java/android/view/WindowManagerPolicy.java. |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 87 | */ |
| 88 | enum { |
Jeff Brown | 956c0fb | 2010-10-01 14:55:30 -0700 | [diff] [blame] | 89 | /* These flags originate in RawEvents and are generally set in the key map. |
Jeff Brown | 6a817e2 | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 90 | * NOTE: If you edit these flags, also edit labels in KeycodeLabels.h. */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 91 | |
| 92 | POLICY_FLAG_WAKE = 0x00000001, |
| 93 | POLICY_FLAG_WAKE_DROPPED = 0x00000002, |
| 94 | POLICY_FLAG_SHIFT = 0x00000004, |
| 95 | POLICY_FLAG_CAPS_LOCK = 0x00000008, |
| 96 | POLICY_FLAG_ALT = 0x00000010, |
| 97 | POLICY_FLAG_ALT_GR = 0x00000020, |
| 98 | POLICY_FLAG_MENU = 0x00000040, |
| 99 | POLICY_FLAG_LAUNCHER = 0x00000080, |
Jeff Brown | 956c0fb | 2010-10-01 14:55:30 -0700 | [diff] [blame] | 100 | POLICY_FLAG_VIRTUAL = 0x00000100, |
Jeff Brown | 6a817e2 | 2010-09-12 17:55:08 -0700 | [diff] [blame] | 101 | POLICY_FLAG_FUNCTION = 0x00000200, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 102 | |
Jeff Brown | 51d45a7 | 2010-06-17 20:52:56 -0700 | [diff] [blame] | 103 | POLICY_FLAG_RAW_MASK = 0x0000ffff, |
| 104 | |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 105 | /* These flags are set by the input dispatcher. */ |
| 106 | |
| 107 | // Indicates that the input event was injected. |
| 108 | POLICY_FLAG_INJECTED = 0x01000000, |
| 109 | |
Jeff Brown | 33d54ce | 2010-10-11 14:20:19 -0700 | [diff] [blame] | 110 | // Indicates that the input event is from a trusted source such as a directly attached |
| 111 | // input device or an application with system-wide event injection permission. |
| 112 | POLICY_FLAG_TRUSTED = 0x02000000, |
| 113 | |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 114 | /* These flags are set by the input reader policy as it intercepts each event. */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 115 | |
| 116 | // Indicates that the screen was off when the event was received and the event |
| 117 | // should wake the device. |
| 118 | POLICY_FLAG_WOKE_HERE = 0x10000000, |
| 119 | |
| 120 | // Indicates that the screen was dim when the event was received and the event |
| 121 | // should brighten the device. |
| 122 | POLICY_FLAG_BRIGHT_HERE = 0x20000000, |
Jeff Brown | 90f0cee | 2010-10-08 22:31:17 -0700 | [diff] [blame] | 123 | |
| 124 | // Indicates that the event should be dispatched to applications. |
| 125 | // The input event should still be sent to the InputDispatcher so that it can see all |
| 126 | // input events received include those that it will not deliver. |
| 127 | POLICY_FLAG_PASS_TO_USER = 0x40000000, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | /* |
Jeff Brown | 54bc281 | 2010-06-15 01:31:58 -0700 | [diff] [blame] | 131 | * Describes the basic configuration of input devices that are present. |
| 132 | */ |
| 133 | struct InputConfiguration { |
| 134 | enum { |
| 135 | TOUCHSCREEN_UNDEFINED = 0, |
| 136 | TOUCHSCREEN_NOTOUCH = 1, |
| 137 | TOUCHSCREEN_STYLUS = 2, |
| 138 | TOUCHSCREEN_FINGER = 3 |
| 139 | }; |
| 140 | |
| 141 | enum { |
| 142 | KEYBOARD_UNDEFINED = 0, |
| 143 | KEYBOARD_NOKEYS = 1, |
| 144 | KEYBOARD_QWERTY = 2, |
| 145 | KEYBOARD_12KEY = 3 |
| 146 | }; |
| 147 | |
| 148 | enum { |
| 149 | NAVIGATION_UNDEFINED = 0, |
| 150 | NAVIGATION_NONAV = 1, |
| 151 | NAVIGATION_DPAD = 2, |
| 152 | NAVIGATION_TRACKBALL = 3, |
| 153 | NAVIGATION_WHEEL = 4 |
| 154 | }; |
| 155 | |
| 156 | int32_t touchScreen; |
| 157 | int32_t keyboard; |
| 158 | int32_t navigation; |
| 159 | }; |
| 160 | |
| 161 | /* |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 162 | * Pointer coordinate data. |
| 163 | */ |
| 164 | struct PointerCoords { |
| 165 | float x; |
| 166 | float y; |
| 167 | float pressure; |
| 168 | float size; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 169 | float touchMajor; |
| 170 | float touchMinor; |
| 171 | float toolMajor; |
| 172 | float toolMinor; |
| 173 | float orientation; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | /* |
| 177 | * Input events. |
| 178 | */ |
Dianne Hackborn | 9c7f818 | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 179 | class InputEvent : public AInputEvent { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 180 | public: |
| 181 | virtual ~InputEvent() { } |
| 182 | |
| 183 | virtual int32_t getType() const = 0; |
| 184 | |
| 185 | inline int32_t getDeviceId() const { return mDeviceId; } |
| 186 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 187 | inline int32_t getSource() const { return mSource; } |
Dianne Hackborn | 189ed23 | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 188 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 189 | protected: |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 190 | void initialize(int32_t deviceId, int32_t source); |
Dianne Hackborn | 0e88527 | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 191 | void initialize(const InputEvent& from); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 192 | |
| 193 | private: |
| 194 | int32_t mDeviceId; |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 195 | int32_t mSource; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 196 | }; |
| 197 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 198 | /* |
| 199 | * Key events. |
| 200 | */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 201 | class KeyEvent : public InputEvent { |
| 202 | public: |
| 203 | virtual ~KeyEvent() { } |
| 204 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 205 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_KEY; } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 206 | |
| 207 | inline int32_t getAction() const { return mAction; } |
| 208 | |
| 209 | inline int32_t getFlags() const { return mFlags; } |
| 210 | |
| 211 | inline int32_t getKeyCode() const { return mKeyCode; } |
| 212 | |
| 213 | inline int32_t getScanCode() const { return mScanCode; } |
| 214 | |
| 215 | inline int32_t getMetaState() const { return mMetaState; } |
| 216 | |
| 217 | inline int32_t getRepeatCount() const { return mRepeatCount; } |
| 218 | |
| 219 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 220 | |
| 221 | inline nsecs_t getEventTime() const { return mEventTime; } |
| 222 | |
Dianne Hackborn | 189ed23 | 2010-06-29 19:20:40 -0700 | [diff] [blame] | 223 | // Return true if this event may have a default action implementation. |
| 224 | static bool hasDefaultAction(int32_t keyCode); |
| 225 | bool hasDefaultAction() const; |
| 226 | |
| 227 | // Return true if this event represents a system key. |
| 228 | static bool isSystemKey(int32_t keyCode); |
| 229 | bool isSystemKey() const; |
| 230 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 231 | void initialize( |
| 232 | int32_t deviceId, |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 233 | int32_t source, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 234 | int32_t action, |
| 235 | int32_t flags, |
| 236 | int32_t keyCode, |
| 237 | int32_t scanCode, |
| 238 | int32_t metaState, |
| 239 | int32_t repeatCount, |
| 240 | nsecs_t downTime, |
| 241 | nsecs_t eventTime); |
Dianne Hackborn | 0e88527 | 2010-07-15 17:44:53 -0700 | [diff] [blame] | 242 | void initialize(const KeyEvent& from); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 243 | |
| 244 | private: |
| 245 | int32_t mAction; |
| 246 | int32_t mFlags; |
| 247 | int32_t mKeyCode; |
| 248 | int32_t mScanCode; |
| 249 | int32_t mMetaState; |
| 250 | int32_t mRepeatCount; |
| 251 | nsecs_t mDownTime; |
| 252 | nsecs_t mEventTime; |
| 253 | }; |
| 254 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 255 | /* |
| 256 | * Motion events. |
| 257 | */ |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 258 | class MotionEvent : public InputEvent { |
| 259 | public: |
| 260 | virtual ~MotionEvent() { } |
| 261 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 262 | virtual int32_t getType() const { return AINPUT_EVENT_TYPE_MOTION; } |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 263 | |
| 264 | inline int32_t getAction() const { return mAction; } |
| 265 | |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 266 | inline int32_t getFlags() const { return mFlags; } |
| 267 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 268 | inline int32_t getEdgeFlags() const { return mEdgeFlags; } |
| 269 | |
| 270 | inline int32_t getMetaState() const { return mMetaState; } |
| 271 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 272 | inline float getXOffset() const { return mXOffset; } |
| 273 | |
| 274 | inline float getYOffset() const { return mYOffset; } |
| 275 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 276 | inline float getXPrecision() const { return mXPrecision; } |
| 277 | |
| 278 | inline float getYPrecision() const { return mYPrecision; } |
| 279 | |
| 280 | inline nsecs_t getDownTime() const { return mDownTime; } |
| 281 | |
| 282 | inline size_t getPointerCount() const { return mPointerIds.size(); } |
| 283 | |
| 284 | inline int32_t getPointerId(size_t pointerIndex) const { return mPointerIds[pointerIndex]; } |
| 285 | |
| 286 | inline nsecs_t getEventTime() const { return mSampleEventTimes[getHistorySize()]; } |
| 287 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 288 | inline float getRawX(size_t pointerIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 289 | return getCurrentPointerCoords(pointerIndex).x; |
| 290 | } |
| 291 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 292 | inline float getRawY(size_t pointerIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 293 | return getCurrentPointerCoords(pointerIndex).y; |
| 294 | } |
| 295 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 296 | inline float getX(size_t pointerIndex) const { |
| 297 | return getRawX(pointerIndex) + mXOffset; |
| 298 | } |
| 299 | |
| 300 | inline float getY(size_t pointerIndex) const { |
| 301 | return getRawY(pointerIndex) + mYOffset; |
| 302 | } |
| 303 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 304 | inline float getPressure(size_t pointerIndex) const { |
| 305 | return getCurrentPointerCoords(pointerIndex).pressure; |
| 306 | } |
| 307 | |
| 308 | inline float getSize(size_t pointerIndex) const { |
| 309 | return getCurrentPointerCoords(pointerIndex).size; |
| 310 | } |
| 311 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 312 | inline float getTouchMajor(size_t pointerIndex) const { |
| 313 | return getCurrentPointerCoords(pointerIndex).touchMajor; |
| 314 | } |
| 315 | |
| 316 | inline float getTouchMinor(size_t pointerIndex) const { |
| 317 | return getCurrentPointerCoords(pointerIndex).touchMinor; |
| 318 | } |
| 319 | |
| 320 | inline float getToolMajor(size_t pointerIndex) const { |
| 321 | return getCurrentPointerCoords(pointerIndex).toolMajor; |
| 322 | } |
| 323 | |
| 324 | inline float getToolMinor(size_t pointerIndex) const { |
| 325 | return getCurrentPointerCoords(pointerIndex).toolMinor; |
| 326 | } |
| 327 | |
| 328 | inline float getOrientation(size_t pointerIndex) const { |
| 329 | return getCurrentPointerCoords(pointerIndex).orientation; |
| 330 | } |
| 331 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 332 | inline size_t getHistorySize() const { return mSampleEventTimes.size() - 1; } |
| 333 | |
| 334 | inline nsecs_t getHistoricalEventTime(size_t historicalIndex) const { |
| 335 | return mSampleEventTimes[historicalIndex]; |
| 336 | } |
| 337 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 338 | inline float getHistoricalRawX(size_t pointerIndex, size_t historicalIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 339 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).x; |
| 340 | } |
| 341 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 342 | inline float getHistoricalRawY(size_t pointerIndex, size_t historicalIndex) const { |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 343 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).y; |
| 344 | } |
| 345 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 346 | inline float getHistoricalX(size_t pointerIndex, size_t historicalIndex) const { |
| 347 | return getHistoricalRawX(pointerIndex, historicalIndex) + mXOffset; |
| 348 | } |
| 349 | |
| 350 | inline float getHistoricalY(size_t pointerIndex, size_t historicalIndex) const { |
| 351 | return getHistoricalRawY(pointerIndex, historicalIndex) + mYOffset; |
| 352 | } |
| 353 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 354 | inline float getHistoricalPressure(size_t pointerIndex, size_t historicalIndex) const { |
| 355 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).pressure; |
| 356 | } |
| 357 | |
| 358 | inline float getHistoricalSize(size_t pointerIndex, size_t historicalIndex) const { |
| 359 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).size; |
| 360 | } |
| 361 | |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 362 | inline float getHistoricalTouchMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 363 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMajor; |
| 364 | } |
| 365 | |
| 366 | inline float getHistoricalTouchMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 367 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).touchMinor; |
| 368 | } |
| 369 | |
| 370 | inline float getHistoricalToolMajor(size_t pointerIndex, size_t historicalIndex) const { |
| 371 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMajor; |
| 372 | } |
| 373 | |
| 374 | inline float getHistoricalToolMinor(size_t pointerIndex, size_t historicalIndex) const { |
| 375 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).toolMinor; |
| 376 | } |
| 377 | |
| 378 | inline float getHistoricalOrientation(size_t pointerIndex, size_t historicalIndex) const { |
| 379 | return getHistoricalPointerCoords(pointerIndex, historicalIndex).orientation; |
| 380 | } |
| 381 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 382 | void initialize( |
| 383 | int32_t deviceId, |
Jeff Brown | 5c1ed84 | 2010-07-14 18:48:53 -0700 | [diff] [blame] | 384 | int32_t source, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 385 | int32_t action, |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 386 | int32_t flags, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 387 | int32_t edgeFlags, |
| 388 | int32_t metaState, |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 389 | float xOffset, |
| 390 | float yOffset, |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 391 | float xPrecision, |
| 392 | float yPrecision, |
| 393 | nsecs_t downTime, |
| 394 | nsecs_t eventTime, |
| 395 | size_t pointerCount, |
| 396 | const int32_t* pointerIds, |
| 397 | const PointerCoords* pointerCoords); |
| 398 | |
| 399 | void addSample( |
| 400 | nsecs_t eventTime, |
| 401 | const PointerCoords* pointerCoords); |
| 402 | |
| 403 | void offsetLocation(float xOffset, float yOffset); |
| 404 | |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 405 | // Low-level accessors. |
| 406 | inline const int32_t* getPointerIds() const { return mPointerIds.array(); } |
| 407 | inline const nsecs_t* getSampleEventTimes() const { return mSampleEventTimes.array(); } |
| 408 | inline const PointerCoords* getSamplePointerCoords() const { |
| 409 | return mSamplePointerCoords.array(); |
| 410 | } |
| 411 | |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 412 | private: |
| 413 | int32_t mAction; |
Jeff Brown | af30ff6 | 2010-09-01 17:01:00 -0700 | [diff] [blame] | 414 | int32_t mFlags; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 415 | int32_t mEdgeFlags; |
| 416 | int32_t mMetaState; |
Jeff Brown | f4a4ec2 | 2010-06-16 01:53:36 -0700 | [diff] [blame] | 417 | float mXOffset; |
| 418 | float mYOffset; |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 419 | float mXPrecision; |
| 420 | float mYPrecision; |
| 421 | nsecs_t mDownTime; |
| 422 | Vector<int32_t> mPointerIds; |
| 423 | Vector<nsecs_t> mSampleEventTimes; |
| 424 | Vector<PointerCoords> mSamplePointerCoords; |
| 425 | |
| 426 | inline const PointerCoords& getCurrentPointerCoords(size_t pointerIndex) const { |
| 427 | return mSamplePointerCoords[getHistorySize() * getPointerCount() + pointerIndex]; |
| 428 | } |
| 429 | |
| 430 | inline const PointerCoords& getHistoricalPointerCoords( |
| 431 | size_t pointerIndex, size_t historicalIndex) const { |
| 432 | return mSamplePointerCoords[historicalIndex * getPointerCount() + pointerIndex]; |
| 433 | } |
| 434 | }; |
| 435 | |
| 436 | /* |
| 437 | * Input event factory. |
| 438 | */ |
| 439 | class InputEventFactoryInterface { |
| 440 | protected: |
| 441 | virtual ~InputEventFactoryInterface() { } |
| 442 | |
| 443 | public: |
| 444 | InputEventFactoryInterface() { } |
| 445 | |
| 446 | virtual KeyEvent* createKeyEvent() = 0; |
| 447 | virtual MotionEvent* createMotionEvent() = 0; |
| 448 | }; |
| 449 | |
| 450 | /* |
| 451 | * A simple input event factory implementation that uses a single preallocated instance |
| 452 | * of each type of input event that are reused for each request. |
| 453 | */ |
| 454 | class PreallocatedInputEventFactory : public InputEventFactoryInterface { |
| 455 | public: |
| 456 | PreallocatedInputEventFactory() { } |
| 457 | virtual ~PreallocatedInputEventFactory() { } |
| 458 | |
| 459 | virtual KeyEvent* createKeyEvent() { return & mKeyEvent; } |
| 460 | virtual MotionEvent* createMotionEvent() { return & mMotionEvent; } |
| 461 | |
| 462 | private: |
| 463 | KeyEvent mKeyEvent; |
| 464 | MotionEvent mMotionEvent; |
| 465 | }; |
| 466 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 467 | /* |
| 468 | * Describes the characteristics and capabilities of an input device. |
| 469 | */ |
| 470 | class InputDeviceInfo { |
| 471 | public: |
| 472 | InputDeviceInfo(); |
| 473 | InputDeviceInfo(const InputDeviceInfo& other); |
| 474 | ~InputDeviceInfo(); |
| 475 | |
| 476 | struct MotionRange { |
| 477 | float min; |
| 478 | float max; |
| 479 | float flat; |
| 480 | float fuzz; |
| 481 | }; |
| 482 | |
| 483 | void initialize(int32_t id, const String8& name); |
| 484 | |
| 485 | inline int32_t getId() const { return mId; } |
| 486 | inline const String8 getName() const { return mName; } |
| 487 | inline uint32_t getSources() const { return mSources; } |
| 488 | |
| 489 | const MotionRange* getMotionRange(int32_t rangeType) const; |
| 490 | |
| 491 | void addSource(uint32_t source); |
| 492 | void addMotionRange(int32_t rangeType, float min, float max, float flat, float fuzz); |
| 493 | void addMotionRange(int32_t rangeType, const MotionRange& range); |
| 494 | |
| 495 | inline void setKeyboardType(int32_t keyboardType) { mKeyboardType = keyboardType; } |
| 496 | inline int32_t getKeyboardType() const { return mKeyboardType; } |
| 497 | |
Jeff Brown | 38a7fab | 2010-08-30 03:02:23 -0700 | [diff] [blame] | 498 | inline const KeyedVector<int32_t, MotionRange> getMotionRanges() const { |
| 499 | return mMotionRanges; |
| 500 | } |
| 501 | |
Jeff Brown | e57e895 | 2010-07-23 21:28:06 -0700 | [diff] [blame] | 502 | private: |
| 503 | int32_t mId; |
| 504 | String8 mName; |
| 505 | uint32_t mSources; |
| 506 | int32_t mKeyboardType; |
| 507 | |
| 508 | KeyedVector<int32_t, MotionRange> mMotionRanges; |
| 509 | }; |
| 510 | |
Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 511 | /* |
| 512 | * Identifies a device. |
| 513 | */ |
| 514 | struct InputDeviceIdentifier { |
| 515 | inline InputDeviceIdentifier() : |
| 516 | bus(0), vendor(0), product(0), version(0) { |
| 517 | } |
| 518 | |
| 519 | String8 name; |
| 520 | String8 location; |
| 521 | String8 uniqueId; |
| 522 | uint16_t bus; |
| 523 | uint16_t vendor; |
| 524 | uint16_t product; |
| 525 | uint16_t version; |
| 526 | }; |
| 527 | |
Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 528 | /* Types of input device configuration files. */ |
| 529 | enum InputDeviceConfigurationFileType { |
| 530 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_CONFIGURATION = 0, /* .idc file */ |
| 531 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_LAYOUT = 1, /* .kl file */ |
| 532 | INPUT_DEVICE_CONFIGURATION_FILE_TYPE_KEY_CHARACTER_MAP = 2, /* .kcm file */ |
| 533 | }; |
| 534 | |
| 535 | /* |
Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 536 | * Gets the path of an input device configuration file, if one is available. |
Jeff Brown | 53c1664 | 2010-11-18 20:53:46 -0800 | [diff] [blame] | 537 | * Considers both system provided and user installed configuration files. |
Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 538 | * |
Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 539 | * The device identifier is used to construct several default configuration file |
| 540 | * names to try based on the device name, vendor, product, and version. |
| 541 | * |
Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 542 | * Returns an empty string if not found. |
| 543 | */ |
Jeff Brown | db36064 | 2010-12-02 13:50:46 -0800 | [diff] [blame] | 544 | extern String8 getInputDeviceConfigurationFilePathByDeviceIdentifier( |
| 545 | const InputDeviceIdentifier& deviceIdentifier, |
| 546 | InputDeviceConfigurationFileType type); |
| 547 | |
| 548 | /* |
| 549 | * Gets the path of an input device configuration file, if one is available. |
| 550 | * Considers both system provided and user installed configuration files. |
| 551 | * |
| 552 | * The name is case-sensitive and is used to construct the filename to resolve. |
| 553 | * All characters except 'a'-'z', 'A'-'Z', '0'-'9', '-', and '_' are replaced by underscores. |
| 554 | * |
| 555 | * Returns an empty string if not found. |
| 556 | */ |
| 557 | extern String8 getInputDeviceConfigurationFilePathByName( |
Jeff Brown | 6688837 | 2010-11-29 17:37:49 -0800 | [diff] [blame] | 558 | const String8& name, InputDeviceConfigurationFileType type); |
Jeff Brown | e839a58 | 2010-04-22 18:58:52 -0700 | [diff] [blame] | 559 | |
| 560 | } // namespace android |
| 561 | |
| 562 | #endif // _UI_INPUT_H |