diff options
Diffstat (limited to 'services/input/EventHub.cpp')
-rw-r--r-- | services/input/EventHub.cpp | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/services/input/EventHub.cpp b/services/input/EventHub.cpp index 2fe5980..e2da740 100644 --- a/services/input/EventHub.cpp +++ b/services/input/EventHub.cpp @@ -352,14 +352,13 @@ status_t EventHub::mapKey(int32_t deviceId, int scancode, return NAME_NOT_FOUND; } -status_t EventHub::mapAxis(int32_t deviceId, int scancode, - int32_t* outAxis) const +status_t EventHub::mapAxis(int32_t deviceId, int scancode, AxisInfo* outAxisInfo) const { AutoMutex _l(mLock); Device* device = getDeviceLocked(deviceId); if (device && device->keyMap.haveKeyLayout()) { - status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxis); + status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxisInfo); if (err == NO_ERROR) { return NO_ERROR; } @@ -369,14 +368,13 @@ status_t EventHub::mapAxis(int32_t deviceId, int scancode, device = getDeviceLocked(mBuiltInKeyboardId); if (device && device->keyMap.haveKeyLayout()) { - status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxis); + status_t err = device->keyMap.keyLayoutMap->mapAxis(scancode, outAxisInfo); if (err == NO_ERROR) { return NO_ERROR; } } } - *outAxis = -1; return NAME_NOT_FOUND; } @@ -822,8 +820,10 @@ int EventHub::openDevice(const char *devicePath) { bool haveKeyboardKeys = containsNonZeroByte(key_bitmask, 0, sizeof_bit_array(BTN_MISC)) || containsNonZeroByte(key_bitmask, sizeof_bit_array(KEY_OK), sizeof_bit_array(KEY_MAX + 1)); - bool haveGamepadButtons =containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_JOYSTICK), - sizeof_bit_array(BTN_DIGI)); + bool haveGamepadButtons = containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_MISC), + sizeof_bit_array(BTN_MOUSE)) + || containsNonZeroByte(key_bitmask, sizeof_bit_array(BTN_JOYSTICK), + sizeof_bit_array(BTN_DIGI)); if (haveKeyboardKeys || haveGamepadButtons) { device->classes |= INPUT_DEVICE_CLASS_KEYBOARD; } @@ -852,6 +852,16 @@ int EventHub::openDevice(const char *devicePath) { device->classes |= INPUT_DEVICE_CLASS_TOUCH; } + // See if this device is a joystick. + // Ignore touchscreens because they use the same absolute axes for other purposes. + // Assumes that joysticks always have gamepad buttons in order to distinguish them + // from other devices such as accelerometers that also have absolute axes. + if (haveGamepadButtons + && !(device->classes & INPUT_DEVICE_CLASS_TOUCH) + && containsNonZeroByte(abs_bitmask, 0, sizeof_bit_array(ABS_MAX + 1))) { + device->classes |= INPUT_DEVICE_CLASS_JOYSTICK; + } + // figure out the switches this device reports bool haveSwitches = false; for (int i=0; i<EV_SW; i++) { @@ -876,15 +886,21 @@ int EventHub::openDevice(const char *devicePath) { } } - if ((device->classes & INPUT_DEVICE_CLASS_KEYBOARD) != 0) { + // Load the key map. + // We need to do this for joysticks too because the key layout may specify axes. + status_t keyMapStatus = NAME_NOT_FOUND; + if (device->classes & (INPUT_DEVICE_CLASS_KEYBOARD | INPUT_DEVICE_CLASS_JOYSTICK)) { // Load the keymap for the device. - status_t status = loadKeyMap(device); + keyMapStatus = loadKeyMap(device); + } + // Configure the keyboard, gamepad or virtual keyboard. + if (device->classes & INPUT_DEVICE_CLASS_KEYBOARD) { // Set system properties for the keyboard. setKeyboardProperties(device, false); // Register the keyboard as a built-in keyboard if it is eligible. - if (!status + if (!keyMapStatus && mBuiltInKeyboardId == -1 && isEligibleBuiltInKeyboard(device->identifier, device->configuration, &device->keyMap)) { @@ -915,16 +931,6 @@ int EventHub::openDevice(const char *devicePath) { } } - // See if this device is a joystick. - // Ignore touchscreens because they use the same absolute axes for other purposes. - // Assumes that joysticks always have buttons and the keymap has been loaded. - if (device->classes & INPUT_DEVICE_CLASS_GAMEPAD - && !(device->classes & INPUT_DEVICE_CLASS_TOUCH)) { - if (containsNonZeroByte(abs_bitmask, 0, sizeof_bit_array(ABS_MAX + 1))) { - device->classes |= INPUT_DEVICE_CLASS_JOYSTICK; - } - } - // If the device isn't recognized as something we handle, don't monitor it. if (device->classes == 0) { LOGV("Dropping device: id=%d, path='%s', name='%s'", |