Skip to content

Commit

Permalink
do not rotate keyboard dpad events for bluetooth keyboards (since the…
Browse files Browse the repository at this point in the history
…y are not attached to the device and do not rotate when device is rotated)
  • Loading branch information
techomancer committed Oct 7, 2011
1 parent 5dd3bd4 commit f4b4cf5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
11 changes: 8 additions & 3 deletions include/ui/EventHub.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ class EventHubInterface : public virtual RefBase {

virtual String8 getDeviceName(int32_t deviceId) const = 0;

virtual bool getDeviceBluetooth(int32_t deviceId) const = 0;

virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
RawAbsoluteAxisInfo* outAxisInfo) const = 0;

Expand Down Expand Up @@ -201,9 +203,11 @@ class EventHub : public EventHubInterface
status_t errorCheck() const;

virtual uint32_t getDeviceClasses(int32_t deviceId) const;

virtual String8 getDeviceName(int32_t deviceId) const;


virtual bool getDeviceBluetooth(int32_t deviceId) const;

virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
RawAbsoluteAxisInfo* outAxisInfo) const;

Expand Down Expand Up @@ -245,9 +249,10 @@ class EventHub : public EventHubInterface
KeyLayoutMap* layoutMap;
String8 keylayoutFilename;
int fd;
bool bluetooth;
device_t* next;

device_t(int32_t _id, const char* _path, const char* name);
device_t(int32_t _id, const char* _path, const char* name, bool _bluetooth);
~device_t();
};

Expand Down
3 changes: 2 additions & 1 deletion include/ui/InputReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ class SwitchInputMapper : public InputMapper {
class KeyboardInputMapper : public InputMapper {
public:
KeyboardInputMapper(InputDevice* device, int32_t associatedDisplayId, uint32_t sources,
int32_t keyboardType);
int32_t keyboardType, bool bluetooth = false);
virtual ~KeyboardInputMapper();

virtual uint32_t getSources();
Expand All @@ -432,6 +432,7 @@ class KeyboardInputMapper : public InputMapper {
int32_t mAssociatedDisplayId;
uint32_t mSources;
int32_t mKeyboardType;
bool mBluetooth;

struct LockedState {
Vector<KeyDown> keyDowns; // keys that are down
Expand Down
13 changes: 10 additions & 3 deletions libs/ui/EventHub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ static inline const char* toString(bool value) {
return value ? "true" : "false";
}

EventHub::device_t::device_t(int32_t _id, const char* _path, const char* name)
EventHub::device_t::device_t(int32_t _id, const char* _path, const char* name, bool _bluetooth)
: id(_id), path(_path), name(name), classes(0)
, keyBitmask(NULL), layoutMap(new KeyLayoutMap()), fd(-1), next(NULL) {
, keyBitmask(NULL), layoutMap(new KeyLayoutMap()), fd(-1), bluetooth(_bluetooth), next(NULL) {
}

EventHub::device_t::~device_t() {
Expand Down Expand Up @@ -137,6 +137,13 @@ String8 EventHub::getDeviceName(int32_t deviceId) const
return device->name;
}

bool EventHub::getDeviceBluetooth(int32_t deviceId) const
{
AutoMutex _l(mLock);
device_t* device = getDeviceLocked(deviceId);
return device->bluetooth;
}

uint32_t EventHub::getDeviceClasses(int32_t deviceId) const
{
AutoMutex _l(mLock);
Expand Down Expand Up @@ -669,7 +676,7 @@ int EventHub::openDevice(const char *deviceName) {
version >> 16, (version >> 8) & 0xff, version & 0xff);
#endif

device_t* device = new device_t(devid|mDevicesById[devid].seq, deviceName, name);
device_t* device = new device_t(devid|mDevicesById[devid].seq, deviceName, name, BUS_BLUETOOTH == id.bustype);
if (device == NULL) {
LOGE("out of memory");
return -1;
Expand Down
8 changes: 4 additions & 4 deletions libs/ui/InputReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ InputDevice* InputReader::createDevice(int32_t deviceId, const String8& name, ui

if (keyboardSources != 0) {
device->addMapper(new KeyboardInputMapper(device,
associatedDisplayId, keyboardSources, keyboardType));
associatedDisplayId, keyboardSources, keyboardType, mEventHub->getDeviceBluetooth(deviceId)));
}

// Trackball-like devices.
Expand Down Expand Up @@ -870,9 +870,9 @@ int32_t SwitchInputMapper::getSwitchState(uint32_t sourceMask, int32_t switchCod
// --- KeyboardInputMapper ---

KeyboardInputMapper::KeyboardInputMapper(InputDevice* device, int32_t associatedDisplayId,
uint32_t sources, int32_t keyboardType) :
uint32_t sources, int32_t keyboardType, bool bluetooth) :
InputMapper(device), mAssociatedDisplayId(associatedDisplayId), mSources(sources),
mKeyboardType(keyboardType) {
mKeyboardType(keyboardType), mBluetooth(bluetooth) {
initializeLocked();
}

Expand Down Expand Up @@ -962,7 +962,7 @@ void KeyboardInputMapper::processKey(nsecs_t when, bool down, int32_t keyCode,
if (down) {
// Rotate key codes according to orientation if needed.
// Note: getDisplayInfo is non-reentrant so we can continue holding the lock.
if (mAssociatedDisplayId >= 0) {
if (!mBluetooth && mAssociatedDisplayId >= 0) {
int32_t orientation;
if (! getPolicy()->getDisplayInfo(mAssociatedDisplayId, NULL, NULL, & orientation)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions libs/ui/tests/InputReader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ class FakeEventHub : public EventHubInterface {
return device ? device->name : String8("unknown");
}

virtual bool getDeviceBluetooth(int32_t deviceId) const {
return false;
}

virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
RawAbsoluteAxisInfo* outAxisInfo) const {
Device* device = getDevice(deviceId);
Expand Down

0 comments on commit f4b4cf5

Please sign in to comment.