Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | #define LOG_TAG "input" |
| 18 | #include <utils/Log.h> |
| 19 | |
| 20 | #include <android/input.h> |
| 21 | #include <ui/Input.h> |
| 22 | #include <ui/InputTransport.h> |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 23 | #include <utils/PollLoop.h> |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 24 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 25 | #include <android_runtime/android_app_NativeActivity.h> |
| 26 | |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 27 | #include <poll.h> |
| 28 | |
| 29 | using android::InputEvent; |
| 30 | using android::KeyEvent; |
| 31 | using android::MotionEvent; |
| 32 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 33 | int32_t AInputEvent_getType(const AInputEvent* event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 34 | return static_cast<const InputEvent*>(event)->getType(); |
| 35 | } |
| 36 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 37 | int32_t AInputEvent_getDeviceId(const AInputEvent* event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 38 | return static_cast<const InputEvent*>(event)->getDeviceId(); |
| 39 | } |
| 40 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 41 | int32_t AInputEvent_getSource(const AInputEvent* event) { |
| 42 | return static_cast<const InputEvent*>(event)->getSource(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 43 | } |
| 44 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 45 | int32_t AKeyEvent_getAction(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 46 | return static_cast<const KeyEvent*>(key_event)->getAction(); |
| 47 | } |
| 48 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 49 | int32_t AKeyEvent_getFlags(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 50 | return static_cast<const KeyEvent*>(key_event)->getFlags(); |
| 51 | } |
| 52 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 53 | int32_t AKeyEvent_getKeyCode(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 54 | return static_cast<const KeyEvent*>(key_event)->getKeyCode(); |
| 55 | } |
| 56 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 57 | int32_t AKeyEvent_getScanCode(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 58 | return static_cast<const KeyEvent*>(key_event)->getScanCode(); |
| 59 | } |
| 60 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 61 | int32_t AKeyEvent_getMetaState(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 62 | return static_cast<const KeyEvent*>(key_event)->getMetaState(); |
| 63 | } |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 64 | int32_t AKeyEvent_getRepeatCount(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 65 | return static_cast<const KeyEvent*>(key_event)->getRepeatCount(); |
| 66 | } |
| 67 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 68 | int64_t AKeyEvent_getDownTime(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 69 | return static_cast<const KeyEvent*>(key_event)->getDownTime(); |
| 70 | } |
| 71 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 72 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 73 | int64_t AKeyEvent_getEventTime(const AInputEvent* key_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 74 | return static_cast<const KeyEvent*>(key_event)->getEventTime(); |
| 75 | } |
| 76 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 77 | int32_t AMotionEvent_getAction(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 78 | return static_cast<const MotionEvent*>(motion_event)->getAction(); |
| 79 | } |
| 80 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 81 | int32_t AMotionEvent_getMetaState(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 82 | return static_cast<const MotionEvent*>(motion_event)->getMetaState(); |
| 83 | } |
| 84 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 85 | int32_t AMotionEvent_getEdgeFlags(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 86 | return reinterpret_cast<const MotionEvent*>(motion_event)->getEdgeFlags(); |
| 87 | } |
| 88 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 89 | int64_t AMotionEvent_getDownTime(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 90 | return static_cast<const MotionEvent*>(motion_event)->getDownTime(); |
| 91 | } |
| 92 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 93 | int64_t AMotionEvent_getEventTime(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 94 | return static_cast<const MotionEvent*>(motion_event)->getEventTime(); |
| 95 | } |
| 96 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 97 | float AMotionEvent_getXOffset(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 98 | return static_cast<const MotionEvent*>(motion_event)->getXOffset(); |
| 99 | } |
| 100 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 101 | float AMotionEvent_getYOffset(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 102 | return static_cast<const MotionEvent*>(motion_event)->getYOffset(); |
| 103 | } |
| 104 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 105 | float AMotionEvent_getXPrecision(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 106 | return static_cast<const MotionEvent*>(motion_event)->getXPrecision(); |
| 107 | } |
| 108 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 109 | float AMotionEvent_getYPrecision(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 110 | return static_cast<const MotionEvent*>(motion_event)->getYPrecision(); |
| 111 | } |
| 112 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 113 | size_t AMotionEvent_getPointerCount(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 114 | return static_cast<const MotionEvent*>(motion_event)->getPointerCount(); |
| 115 | } |
| 116 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 117 | int32_t AMotionEvent_getPointerId(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 118 | return static_cast<const MotionEvent*>(motion_event)->getPointerId(pointer_index); |
| 119 | } |
| 120 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 121 | float AMotionEvent_getRawX(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 122 | return static_cast<const MotionEvent*>(motion_event)->getRawX(pointer_index); |
| 123 | } |
| 124 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 125 | float AMotionEvent_getRawY(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 126 | return static_cast<const MotionEvent*>(motion_event)->getRawY(pointer_index); |
| 127 | } |
| 128 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 129 | float AMotionEvent_getX(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 130 | return static_cast<const MotionEvent*>(motion_event)->getX(pointer_index); |
| 131 | } |
| 132 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 133 | float AMotionEvent_getY(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 134 | return static_cast<const MotionEvent*>(motion_event)->getY(pointer_index); |
| 135 | } |
| 136 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 137 | float AMotionEvent_getPressure(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 138 | return static_cast<const MotionEvent*>(motion_event)->getPressure(pointer_index); |
| 139 | } |
| 140 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 141 | float AMotionEvent_getSize(const AInputEvent* motion_event, size_t pointer_index) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 142 | return static_cast<const MotionEvent*>(motion_event)->getSize(pointer_index); |
| 143 | } |
| 144 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 145 | float AMotionEvent_getTouchMajor(const AInputEvent* motion_event, size_t pointer_index) { |
| 146 | return static_cast<const MotionEvent*>(motion_event)->getTouchMajor(pointer_index); |
| 147 | } |
| 148 | |
| 149 | float AMotionEvent_getTouchMinor(const AInputEvent* motion_event, size_t pointer_index) { |
| 150 | return static_cast<const MotionEvent*>(motion_event)->getTouchMinor(pointer_index); |
| 151 | } |
| 152 | |
| 153 | float AMotionEvent_getToolMajor(const AInputEvent* motion_event, size_t pointer_index) { |
| 154 | return static_cast<const MotionEvent*>(motion_event)->getToolMajor(pointer_index); |
| 155 | } |
| 156 | |
| 157 | float AMotionEvent_getToolMinor(const AInputEvent* motion_event, size_t pointer_index) { |
| 158 | return static_cast<const MotionEvent*>(motion_event)->getToolMinor(pointer_index); |
| 159 | } |
| 160 | |
| 161 | float AMotionEvent_getOrientation(const AInputEvent* motion_event, size_t pointer_index) { |
| 162 | return static_cast<const MotionEvent*>(motion_event)->getOrientation(pointer_index); |
| 163 | } |
| 164 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 165 | size_t AMotionEvent_getHistorySize(const AInputEvent* motion_event) { |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 166 | return static_cast<const MotionEvent*>(motion_event)->getHistorySize(); |
| 167 | } |
| 168 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 169 | int64_t AMotionEvent_getHistoricalEventTime(AInputEvent* motion_event, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 170 | size_t history_index) { |
| 171 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalEventTime( |
| 172 | history_index); |
| 173 | } |
| 174 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 175 | float AMotionEvent_getHistoricalRawX(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 176 | size_t history_index) { |
| 177 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawX( |
| 178 | pointer_index, history_index); |
| 179 | } |
| 180 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 181 | float AMotionEvent_getHistoricalRawY(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 182 | size_t history_index) { |
| 183 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalRawY( |
| 184 | pointer_index, history_index); |
| 185 | } |
| 186 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 187 | float AMotionEvent_getHistoricalX(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 188 | size_t history_index) { |
| 189 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalX( |
| 190 | pointer_index, history_index); |
| 191 | } |
| 192 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 193 | float AMotionEvent_getHistoricalY(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 194 | size_t history_index) { |
| 195 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalY( |
| 196 | pointer_index, history_index); |
| 197 | } |
| 198 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 199 | float AMotionEvent_getHistoricalPressure(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 200 | size_t history_index) { |
| 201 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalPressure( |
| 202 | pointer_index, history_index); |
| 203 | } |
| 204 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 205 | float AMotionEvent_getHistoricalSize(AInputEvent* motion_event, size_t pointer_index, |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 206 | size_t history_index) { |
| 207 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalSize( |
| 208 | pointer_index, history_index); |
| 209 | } |
| 210 | |
Jeff Brown | c5ed591 | 2010-07-14 18:48:53 -0700 | [diff] [blame^] | 211 | float AMotionEvent_getHistoricalTouchMajor(AInputEvent* motion_event, size_t pointer_index, |
| 212 | size_t history_index) { |
| 213 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMajor( |
| 214 | pointer_index, history_index); |
| 215 | } |
| 216 | |
| 217 | float AMotionEvent_getHistoricalTouchMinor(AInputEvent* motion_event, size_t pointer_index, |
| 218 | size_t history_index) { |
| 219 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalTouchMinor( |
| 220 | pointer_index, history_index); |
| 221 | } |
| 222 | |
| 223 | float AMotionEvent_getHistoricalToolMajor(AInputEvent* motion_event, size_t pointer_index, |
| 224 | size_t history_index) { |
| 225 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMajor( |
| 226 | pointer_index, history_index); |
| 227 | } |
| 228 | |
| 229 | float AMotionEvent_getHistoricalToolMinor(AInputEvent* motion_event, size_t pointer_index, |
| 230 | size_t history_index) { |
| 231 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalToolMinor( |
| 232 | pointer_index, history_index); |
| 233 | } |
| 234 | |
| 235 | float AMotionEvent_getHistoricalOrientation(AInputEvent* motion_event, size_t pointer_index, |
| 236 | size_t history_index) { |
| 237 | return static_cast<const MotionEvent*>(motion_event)->getHistoricalOrientation( |
| 238 | pointer_index, history_index); |
| 239 | } |
| 240 | |
| 241 | |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 242 | void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper, |
Dianne Hackborn | 85448bb | 2010-07-07 14:27:31 -0700 | [diff] [blame] | 243 | ALooper_callbackFunc* callback, void* data) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 244 | queue->attachLooper(looper, callback, data); |
Dianne Hackborn | 6826741 | 2010-07-02 18:52:01 -0700 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | void AInputQueue_detachLooper(AInputQueue* queue) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 248 | queue->detachLooper(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 251 | int AInputQueue_hasEvents(AInputQueue* queue) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 252 | return queue->hasEvents(); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 253 | } |
| 254 | |
Dianne Hackborn | 2e9f93e | 2010-06-28 15:27:30 -0700 | [diff] [blame] | 255 | int32_t AInputQueue_getEvent(AInputQueue* queue, AInputEvent** outEvent) { |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 256 | return queue->getEvent(outEvent); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Dianne Hackborn | d76b67c | 2010-07-13 17:48:30 -0700 | [diff] [blame] | 259 | void AInputQueue_finishEvent(AInputQueue* queue, AInputEvent* event, int handled) { |
| 260 | queue->finishEvent(event, handled != 0); |
Dianne Hackborn | a95e4cb | 2010-06-18 18:09:33 -0700 | [diff] [blame] | 261 | } |