summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornadlabak <pavel@doshaska.net>2014-12-21 00:10:54 +0200
committerRashed Abdel-Tawab <rashedabdeltawab@gmail.com>2018-01-13 01:16:56 +0000
commit938b1800fa47539db68e4c94af49639c9fe71465 (patch)
tree8be78782da0ed62808848baf90304a0d918c0318
parente7268e54dbd7e72c3972f7474b73cf9bac08c305 (diff)
downloadandroid_frameworks_native-938b1800fa47539db68e4c94af49639c9fe71465.tar.gz
android_frameworks_native-938b1800fa47539db68e4c94af49639c9fe71465.tar.bz2
android_frameworks_native-938b1800fa47539db68e4c94af49639c9fe71465.zip
Forward port 'Swap volume buttons' (2/3)
[mikeioannina]: Adjust for 5.0 changes [LuK1337]: Adjust for 8.1 changes Change-Id: I5ed4ae2b7e69e2ada067ed1d3524b3d3fad30e2e
-rw-r--r--services/inputflinger/InputReader.cpp29
-rw-r--r--services/inputflinger/InputReader.h13
2 files changed, 34 insertions, 8 deletions
diff --git a/services/inputflinger/InputReader.cpp b/services/inputflinger/InputReader.cpp
index d4266f6df..44a6e368e 100644
--- a/services/inputflinger/InputReader.cpp
+++ b/services/inputflinger/InputReader.cpp
@@ -117,9 +117,9 @@ 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];
}
@@ -131,6 +131,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 },
@@ -171,11 +181,11 @@ static int32_t stemKeyRotationMap[][2] = {
static const size_t stemKeyRotationMapSize =
sizeof(stemKeyRotationMap) / sizeof(stemKeyRotationMap[0]);
-static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation) {
+static int32_t rotateKeyCode(int32_t keyCode, int32_t orientation, int32_t rotationMapOffset) {
keyCode = rotateStemKey(keyCode, orientation,
stemKeyRotationMap, stemKeyRotationMapSize);
return rotateValueUsingRotationMap(keyCode, orientation,
- keyCodeRotationMap, keyCodeRotationMapSize);
+ keyCodeRotationMap, keyCodeRotationMapSize, rotationMapOffset);
}
static void rotateDelta(int32_t orientation, float* deltaX, float* deltaY) {
@@ -2284,6 +2294,13 @@ 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;
+ }
}
static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const *property) {
@@ -2299,7 +2316,7 @@ static void mapStemKey(int32_t keyCode, const PropertyMap& config, char const *p
}
void KeyboardInputMapper::configureParameters() {
- mParameters.orientationAware = false;
+ mParameters.orientationAware = !getDevice()->isExternal();
const PropertyMap& config = getDevice()->getConfiguration();
config.tryGetProperty(String8("keyboard.orientationAware"),
mParameters.orientationAware);
@@ -2418,7 +2435,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t scanCode,
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.
diff --git a/services/inputflinger/InputReader.h b/services/inputflinger/InputReader.h
index a6b979875..3b0d12700 100644
--- a/services/inputflinger/InputReader.h
+++ b/services/inputflinger/InputReader.h
@@ -90,6 +90,9 @@ struct InputReaderConfiguration {
// The set of disabled input devices (disabledDevices) has changed.
CHANGE_ENABLED_STATE = 1 << 9,
+ // Volume keys rotation option changed.
+ CHANGE_VOLUME_KEYS_ROTATION = 1 << 10,
+
// All devices must be reopened.
CHANGE_MUST_REOPEN = 1 << 31,
};
@@ -183,6 +186,10 @@ struct InputReaderConfiguration {
// The set of currently disabled input devices.
SortedVector<int32_t> disabledDevices;
+ // Remap volume keys according to display rotation
+ // 0 - disabled, 1 - phone or hybrid rotation mode, 2 - tablet rotation mode
+ int volumeKeysRotationMode;
+
InputReaderConfiguration() :
virtualKeyQuietTime(0),
pointerVelocityControlParameters(1.0f, 500.0f, 3000.0f, 3.0f),
@@ -199,7 +206,8 @@ struct InputReaderConfiguration {
pointerGestureSwipeMaxWidthRatio(0.25f),
pointerGestureMovementSpeedRatio(0.8f),
pointerGestureZoomSpeedRatio(0.3f),
- showTouches(false) { }
+ showTouches(false),
+ volumeKeysRotationMode(0) { }
bool getDisplayViewport(ViewportType viewportType, const String8* displayId,
DisplayViewport* outViewport) const;
@@ -1101,7 +1109,8 @@ private:
uint32_t mSource;
int32_t mKeyboardType;
- int32_t mOrientation; // orientation for dpad keys
+ int32_t mRotationMapOffset; // determines if and how volume keys rotate
+ int32_t mOrientation; // orientation for dpad and volume keys
Vector<KeyDown> mKeyDowns; // keys that are down
int32_t mMetaState;