summaryrefslogtreecommitdiffstats
path: root/libs/ui/InputReader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/ui/InputReader.cpp')
-rw-r--r--libs/ui/InputReader.cpp117
1 files changed, 72 insertions, 45 deletions
diff --git a/libs/ui/InputReader.cpp b/libs/ui/InputReader.cpp
index 3197ab2..daff2d0 100644
--- a/libs/ui/InputReader.cpp
+++ b/libs/ui/InputReader.cpp
@@ -24,6 +24,7 @@
#include <cutils/log.h>
#include <ui/InputReader.h>
+#include <ui/Keyboard.h>
#include <stddef.h>
#include <stdlib.h>
@@ -70,43 +71,6 @@ static inline const char* toString(bool value) {
return value ? "true" : "false";
}
-
-int32_t updateMetaState(int32_t keyCode, bool down, int32_t oldMetaState) {
- int32_t mask;
- switch (keyCode) {
- case AKEYCODE_ALT_LEFT:
- mask = AMETA_ALT_LEFT_ON;
- break;
- case AKEYCODE_ALT_RIGHT:
- mask = AMETA_ALT_RIGHT_ON;
- break;
- case AKEYCODE_SHIFT_LEFT:
- mask = AMETA_SHIFT_LEFT_ON;
- break;
- case AKEYCODE_SHIFT_RIGHT:
- mask = AMETA_SHIFT_RIGHT_ON;
- break;
- case AKEYCODE_SYM:
- mask = AMETA_SYM_ON;
- break;
- default:
- return oldMetaState;
- }
-
- int32_t newMetaState = down ? oldMetaState | mask : oldMetaState & ~ mask
- & ~ (AMETA_ALT_ON | AMETA_SHIFT_ON);
-
- if (newMetaState & (AMETA_ALT_LEFT_ON | AMETA_ALT_RIGHT_ON)) {
- newMetaState |= AMETA_ALT_ON;
- }
-
- if (newMetaState & (AMETA_SHIFT_LEFT_ON | AMETA_SHIFT_RIGHT_ON)) {
- newMetaState |= AMETA_SHIFT_ON;
- }
-
- return newMetaState;
-}
-
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
@@ -841,6 +805,17 @@ KeyboardInputMapper::~KeyboardInputMapper() {
void KeyboardInputMapper::initializeLocked() {
mLocked.metaState = AMETA_NONE;
mLocked.downTime = 0;
+
+ initializeLedStateLocked(mLocked.capsLockLedState, LED_CAPSL);
+ initializeLedStateLocked(mLocked.numLockLedState, LED_NUML);
+ initializeLedStateLocked(mLocked.scrollLockLedState, LED_SCROLLL);
+
+ updateLedStateLocked(true);
+}
+
+void KeyboardInputMapper::initializeLedStateLocked(LockedState::LedState& ledState, int32_t led) {
+ ledState.avail = getEventHub()->hasLed(getDeviceId(), led);
+ ledState.on = false;
}
uint32_t KeyboardInputMapper::getSources() {
@@ -923,8 +898,8 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
// Note: getDisplayInfo is non-reentrant so we can continue holding the lock.
if (mAssociatedDisplayId >= 0) {
int32_t orientation;
- if (! getPolicy()->getDisplayInfo(mAssociatedDisplayId, NULL, NULL, & orientation)) {
- return;
+ if (!getPolicy()->getDisplayInfo(mAssociatedDisplayId, NULL, NULL, & orientation)) {
+ orientation = InputReaderPolicyInterface::ROTATION_0;
}
keyCode = rotateKeyCode(keyCode, orientation);
@@ -965,6 +940,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
if (oldMetaState != newMetaState) {
mLocked.metaState = newMetaState;
metaStateChanged = true;
+ updateLedStateLocked(false);
}
downTime = mLocked.downTime;
@@ -974,6 +950,9 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
getContext()->updateGlobalMetaState();
}
+ if (policyFlags & POLICY_FLAG_FUNCTION) {
+ newMetaState |= AMETA_FUNCTION_ON;
+ }
getDispatcher()->notifyKey(when, getDeviceId(), AINPUT_SOURCE_KEYBOARD, policyFlags,
down ? AKEY_EVENT_ACTION_DOWN : AKEY_EVENT_ACTION_UP,
AKEY_EVENT_FLAG_FROM_SYSTEM, keyCode, scanCode, newMetaState, downTime);
@@ -1009,6 +988,26 @@ int32_t KeyboardInputMapper::getMetaState() {
} // release lock
}
+void KeyboardInputMapper::updateLedStateLocked(bool reset) {
+ updateLedStateForModifierLocked(mLocked.capsLockLedState, LED_CAPSL,
+ AMETA_CAPS_LOCK_ON, reset);
+ updateLedStateForModifierLocked(mLocked.numLockLedState, LED_NUML,
+ AMETA_NUM_LOCK_ON, reset);
+ updateLedStateForModifierLocked(mLocked.scrollLockLedState, LED_SCROLLL,
+ AMETA_SCROLL_LOCK_ON, reset);
+}
+
+void KeyboardInputMapper::updateLedStateForModifierLocked(LockedState::LedState& ledState,
+ int32_t led, int32_t modifier, bool reset) {
+ if (ledState.avail) {
+ bool desiredState = (mLocked.metaState & modifier) != 0;
+ if (ledState.on != desiredState) {
+ getEventHub()->setLedState(getDeviceId(), led, desiredState);
+ ledState.on = desiredState;
+ }
+ }
+}
+
// --- TrackballInputMapper ---
@@ -1161,7 +1160,7 @@ void TrackballInputMapper::sync(nsecs_t when) {
// Note: getDisplayInfo is non-reentrant so we can continue holding the lock.
int32_t orientation;
if (! getPolicy()->getDisplayInfo(mAssociatedDisplayId, NULL, NULL, & orientation)) {
- return;
+ orientation = InputReaderPolicyInterface::ROTATION_0;
}
float temp;
@@ -1276,7 +1275,7 @@ void TouchInputMapper::dump(String8& dump) {
dumpRawAxes(dump);
dumpCalibration(dump);
dumpSurfaceLocked(dump);
- dump.appendFormat(INDENT3 "Translation and Scaling Factors:");
+ dump.appendFormat(INDENT3 "Translation and Scaling Factors:\n");
dump.appendFormat(INDENT4 "XOrigin: %d\n", mLocked.xOrigin);
dump.appendFormat(INDENT4 "YOrigin: %d\n", mLocked.yOrigin);
dump.appendFormat(INDENT4 "XScale: %0.3f\n", mLocked.xScale);
@@ -1413,10 +1412,18 @@ bool TouchInputMapper::configureSurfaceLocked() {
// Configure X and Y factors.
if (mRawAxes.x.valid && mRawAxes.y.valid) {
- mLocked.xOrigin = mRawAxes.x.minValue;
- mLocked.yOrigin = mRawAxes.y.minValue;
- mLocked.xScale = float(width) / mRawAxes.x.getRange();
- mLocked.yScale = float(height) / mRawAxes.y.getRange();
+ mLocked.xOrigin = mCalibration.haveXOrigin
+ ? mCalibration.xOrigin
+ : mRawAxes.x.minValue;
+ mLocked.yOrigin = mCalibration.haveYOrigin
+ ? mCalibration.yOrigin
+ : mRawAxes.y.minValue;
+ mLocked.xScale = mCalibration.haveXScale
+ ? mCalibration.xScale
+ : float(width) / mRawAxes.x.getRange();
+ mLocked.yScale = mCalibration.haveYScale
+ ? mCalibration.yScale
+ : float(height) / mRawAxes.y.getRange();
mLocked.xPrecision = 1.0f / mLocked.xScale;
mLocked.yPrecision = 1.0f / mLocked.yScale;
@@ -1682,6 +1689,12 @@ void TouchInputMapper::parseCalibration() {
const InputDeviceCalibration& in = getDevice()->getCalibration();
Calibration& out = mCalibration;
+ // Position
+ out.haveXOrigin = in.tryGetProperty(String8("touch.position.xOrigin"), out.xOrigin);
+ out.haveYOrigin = in.tryGetProperty(String8("touch.position.yOrigin"), out.yOrigin);
+ out.haveXScale = in.tryGetProperty(String8("touch.position.xScale"), out.xScale);
+ out.haveYScale = in.tryGetProperty(String8("touch.position.yScale"), out.yScale);
+
// Touch Size
out.touchSizeCalibration = Calibration::TOUCH_SIZE_CALIBRATION_DEFAULT;
String8 touchSizeCalibrationString;
@@ -1891,6 +1904,20 @@ void TouchInputMapper::resolveCalibration() {
void TouchInputMapper::dumpCalibration(String8& dump) {
dump.append(INDENT3 "Calibration:\n");
+ // Position
+ if (mCalibration.haveXOrigin) {
+ dump.appendFormat(INDENT4 "touch.position.xOrigin: %d\n", mCalibration.xOrigin);
+ }
+ if (mCalibration.haveYOrigin) {
+ dump.appendFormat(INDENT4 "touch.position.yOrigin: %d\n", mCalibration.yOrigin);
+ }
+ if (mCalibration.haveXScale) {
+ dump.appendFormat(INDENT4 "touch.position.xScale: %0.3f\n", mCalibration.xScale);
+ }
+ if (mCalibration.haveYScale) {
+ dump.appendFormat(INDENT4 "touch.position.yScale: %0.3f\n", mCalibration.yScale);
+ }
+
// Touch Size
switch (mCalibration.touchSizeCalibration) {
case Calibration::TOUCH_SIZE_CALIBRATION_NONE: