Skip to content

Commit

Permalink
Do not rotate keyboard D-Pad events for USB keyboards
Browse files Browse the repository at this point in the history
As their bluetooth counterparts, their rotation
doesn't match the device's, so we should not rotate
the events.

Heavily inspired on f4b4cf5
by dbehr <dominikbehr@yahoo.com>

Change-Id: I95f955020e248efc0ace999586d58c8c84e89f29
  • Loading branch information
turl authored and tpruvot committed Jan 31, 2012
1 parent 033d3f3 commit c3d1068
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 17 deletions.
10 changes: 6 additions & 4 deletions include/ui/EventHub.h
Expand Up @@ -158,7 +158,7 @@ class EventHubInterface : public virtual RefBase {

virtual String8 getDeviceName(int32_t deviceId) const = 0;

virtual bool getDeviceBluetooth(int32_t deviceId) const = 0;
virtual uint32_t getDeviceBusType(int32_t deviceId) const = 0;

virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
RawAbsoluteAxisInfo* outAxisInfo) const = 0;
Expand Down Expand Up @@ -206,7 +206,7 @@ class EventHub : public EventHubInterface

virtual String8 getDeviceName(int32_t deviceId) const;

virtual bool getDeviceBluetooth(int32_t deviceId) const;
virtual uint32_t getDeviceBusType(int32_t deviceId) const;

virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
RawAbsoluteAxisInfo* outAxisInfo) const;
Expand Down Expand Up @@ -249,10 +249,12 @@ class EventHub : public EventHubInterface
KeyLayoutMap* layoutMap;
String8 keylayoutFilename;
int fd;
uint32_t bustype;
bool bluetooth;
bool usb;
device_t* next;
device_t(int32_t _id, const char* _path, const char* name, bool _bluetooth);

device_t(int32_t _id, const char* _path, const char* name, uint32_t bustype);
~device_t();
};

Expand Down
5 changes: 4 additions & 1 deletion include/ui/InputReader.h
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, bool bluetooth = false);
int32_t keyboardType, uint32_t bustype = 0);
virtual ~KeyboardInputMapper();

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

uint32_t mBusType;
bool mBluetooth;
bool mUSB;

struct LockedState {
Vector<KeyDown> keyDowns; // keys that are down
Expand Down
12 changes: 7 additions & 5 deletions libs/ui/EventHub.cpp
Expand Up @@ -95,9 +95,11 @@ 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, bool _bluetooth)
EventHub::device_t::device_t(int32_t _id, const char* _path, const char* name, uint32_t _bustype)
: id(_id), path(_path), name(name), classes(0)
, keyBitmask(NULL), layoutMap(new KeyLayoutMap()), fd(-1), bluetooth(_bluetooth), next(NULL) {
, keyBitmask(NULL), layoutMap(new KeyLayoutMap()), fd(-1), bustype(_bustype), next(NULL) {
bluetooth = (_bustype == BUS_BLUETOOTH);
usb = (_bustype == BUS_USB);
}

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

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

uint32_t EventHub::getDeviceClasses(int32_t deviceId) const
Expand Down Expand Up @@ -676,7 +678,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, BUS_BLUETOOTH == id.bustype);
device_t* device = new device_t(devid|mDevicesById[devid].seq, deviceName, name, id.bustype);
if (device == NULL) {
LOGE("out of memory");
return -1;
Expand Down
12 changes: 7 additions & 5 deletions libs/ui/InputReader.cpp
Expand Up @@ -334,8 +334,8 @@ InputDevice* InputReader::createDevice(int32_t deviceId, const String8& name, ui
}

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

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

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

KeyboardInputMapper::~KeyboardInputMapper() {
Expand Down Expand Up @@ -968,7 +970,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 (!mBluetooth && mAssociatedDisplayId >= 0) {
if (!mBluetooth && !mUSB && mAssociatedDisplayId >= 0) {
int32_t orientation;
if (! getPolicy()->getDisplayInfo(mAssociatedDisplayId, NULL, NULL, & orientation)) {
return;
Expand Down
4 changes: 2 additions & 2 deletions libs/ui/tests/InputReader_test.cpp
Expand Up @@ -486,8 +486,8 @@ class FakeEventHub : public EventHubInterface {
return device ? device->name : String8("unknown");
}

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

virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
Expand Down

0 comments on commit c3d1068

Please sign in to comment.