diff options
author | nadlabak <pavel@doshaska.net> | 2013-05-13 17:41:57 +0200 |
---|---|---|
committer | nadlabak <pavel@doshaska.net> | 2013-09-17 01:23:58 +0200 |
commit | 22a4d65f66a6155a60d77a22922c195fb22a1bd6 (patch) | |
tree | d282a402ce56e1bcb66eb515bbe08d19c568f781 /services/input/InputReader.cpp | |
parent | d8574e9aa82071f85b751e1f7dccd19759ffc7a9 (diff) | |
download | frameworks_base-22a4d65f66a6155a60d77a22922c195fb22a1bd6.zip frameworks_base-22a4d65f66a6155a60d77a22922c195fb22a1bd6.tar.gz frameworks_base-22a4d65f66a6155a60d77a22922c195fb22a1bd6.tar.bz2 |
Re-implement orientation aware volume buttons at lower level
Rework of http://review.cyanogenmod.org/31979
Fixes:
1. inconsistent volume button behaviour depending on app in use
- the buttons were not swapped for some NDK/OPENSL ES apps like
e.g. MX Player
2. the function of volume buttons on external input devices like BT/USB
keyboards should not be affected by the main unit orientation
This commit finishes http://review.cyanogenmod.org/18273 - use of system
property has been replaced with config push via JNI as suggested during
the original review.
Patch Set 7: Circumvent the need for "keyboard.orientationAware = 1" idc
Patch Set 8: Don't leak implementation details outside InputReader
Change-Id: I19cc60cb0acb0005ab13fa069f52e3d468d694e7
Diffstat (limited to 'services/input/InputReader.cpp')
-rw-r--r-- | services/input/InputReader.cpp | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/services/input/InputReader.cpp b/services/input/InputReader.cpp index baba77d..6f2339d 100644 --- a/services/input/InputReader.cpp +++ b/services/input/InputReader.cpp @@ -101,9 +101,10 @@ static inline const char* toString(bool value) { } static int32_t rotateValueUsingRotationMap(int32_t value, int32_t orientation, - const int32_t map[][4], size_t mapSize) { + const int32_t map[][4], size_t mapSize, + int32_t rotationMapOffset) { if (orientation != DISPLAY_ORIENTATION_0) { - for (size_t i = 0; i < mapSize; i++) { + for (size_t i = rotationMapOffset; i < mapSize; i++) { if (value == map[i][0]) { return map[i][orientation]; } @@ -115,6 +116,16 @@ static int32_t rotateValueUsingRotationMap(int32_t value, int32_t orientation, static const int32_t keyCodeRotationMap[][4] = { // key codes enumerated counter-clockwise with the original (unrotated) key first // no rotation, 90 degree rotation, 180 degree rotation, 270 degree rotation + + // volume keys - tablet + { AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN }, + { AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP }, + + // volume keys - phone or hybrid + { AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP }, + { AKEYCODE_VOLUME_DOWN, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_UP, AKEYCODE_VOLUME_DOWN }, + + // dpad keys - common { AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT }, { AKEYCODE_DPAD_RIGHT, AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN }, { AKEYCODE_DPAD_UP, AKEYCODE_DPAD_LEFT, AKEYCODE_DPAD_DOWN, AKEYCODE_DPAD_RIGHT }, @@ -123,9 +134,11 @@ static const int32_t keyCodeRotationMap[][4] = { static const size_t keyCodeRotationMapSize = sizeof(keyCodeRotationMap) / sizeof(keyCodeRotationMap[0]); -static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) { +static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation, + int32_t rotationMapOffset) { return rotateValueUsingRotationMap(keyCode, orientation, - keyCodeRotationMap, keyCodeRotationMapSize); + keyCodeRotationMap, keyCodeRotationMapSize, + rotationMapOffset); } static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) { @@ -2039,10 +2052,16 @@ void KeyboardInputMapper::configure(nsecs_t when, mOrientation = DISPLAY_ORIENTATION_0; } } + if (!changes || (changes & InputReaderConfiguration::CHANGE_VOLUME_KEYS_ROTATION)) { + // mode 0 (disabled) ~ offset 4 + // mode 1 (phone) ~ offset 2 + // mode 2 (tablet) ~ offset 0 + mRotationMapOffset = 4 - 2 * config->volumeKeysRotationMode; + } } void KeyboardInputMapper::configureParameters() { - mParameters.orientationAware = false; + mParameters.orientationAware = !getDevice()->isExternal(); getDevice()->getConfiguration().tryGetProperty(String8("keyboard.orientationAware"), mParameters.orientationAware); @@ -2116,7 +2135,8 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode, if (down) { // Rotate key codes according to orientation if needed. if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) { - keyCode = rotateKeyCode(keyCode, mOrientation); + keyCode = rotateKeyCode(keyCode, mOrientation, + mRotationMapOffset); } // Add key down. |