Index: ui/events/ozone/evdev/event_device_info.cc |
diff --git a/ui/events/ozone/evdev/event_device_info.cc b/ui/events/ozone/evdev/event_device_info.cc |
index 6d75ea9e0c7272cb0726c5052ea41e3e12d9dc19..e5311f226757cfebcd099f53cd9e0076fe3f5cbb 100644 |
--- a/ui/events/ozone/evdev/event_device_info.cc |
+++ b/ui/events/ozone/evdev/event_device_info.cc |
@@ -13,6 +13,11 @@ namespace ui { |
namespace { |
+struct MTSlotRequest { |
spang
2014/10/21 19:38:36
For consistency: MtSlotRequest
(and everywhere el
dnicoara
2014/10/21 20:32:12
Removed the struct for simplicity.
|
+ uint32_t code; |
+ int32_t* values; |
spang
2014/10/21 19:38:36
Should be an array.
|
+}; |
+ |
bool GetEventBits(int fd, unsigned int type, void* buf, unsigned int size) { |
if (ioctl(fd, EVIOCGBIT(type, size), buf) < 0) { |
DLOG(ERROR) << "failed EVIOCGBIT(" << type << ", " << size << ") on fd " |
@@ -40,6 +45,29 @@ bool GetAbsInfo(int fd, int code, struct input_absinfo* absinfo) { |
return true; |
} |
+bool GetSlotValues(int fd, int code, int32_t* slot_values, unsigned int size) { |
+ MTSlotRequest request; |
+ request.code = code; |
+ request.values = slot_values; |
+ |
+ if (ioctl(fd, |
+ EVIOCGMTSLOTS(sizeof(uint32_t) + sizeof(int32_t) * size), |
+ &request) < 0) { |
+ LOG(ERROR) << "failed EVIOCGMTSLOTS(" << code << ") on fd " << fd; |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
+int IndexToMTCode(int index) { |
+ return index + ABS_MT_SLOT + 1; |
+} |
+ |
+int MTCodeToIndex(int code) { |
+ return code - ABS_MT_SLOT - 1; |
spang
2014/10/21 19:38:36
Can you make this a member function:
int32_t* slo
dnicoara
2014/10/21 20:32:12
Done.
|
+} |
+ |
} // namespace |
EventDeviceInfo::EventDeviceInfo() { |
@@ -52,9 +80,14 @@ EventDeviceInfo::EventDeviceInfo() { |
memset(led_bits_, 0, sizeof(led_bits_)); |
memset(prop_bits_, 0, sizeof(prop_bits_)); |
memset(abs_info_, 0, sizeof(abs_info_)); |
+ memset(slot_values_, 0, sizeof(slot_values_)); |
} |
-EventDeviceInfo::~EventDeviceInfo() {} |
+EventDeviceInfo::~EventDeviceInfo() { |
+ for (size_t i = 0; i < arraysize(slot_values_); ++i) |
+ if (slot_values_[i]) |
+ delete[] slot_values_[i]; |
+} |
bool EventDeviceInfo::Initialize(int fd) { |
if (!GetEventBits(fd, 0, ev_bits_, sizeof(ev_bits_))) |
@@ -86,6 +119,14 @@ bool EventDeviceInfo::Initialize(int fd) { |
if (!GetAbsInfo(fd, i, &abs_info_[i])) |
return false; |
+ int max_num_slots = abs_info_[ABS_MT_SLOT].maximum + 1; |
+ for (unsigned int i = 0; i < ABS_MT_COUNT; ++i) { |
spang
2014/10/21 19:38:36
I think this should iterate over codes rather than
dnicoara
2014/10/21 20:32:12
Done.
|
+ slot_values_[i] = new int32[max_num_slots]; |
+ memset(slot_values_[i], 0, sizeof(int32) * max_num_slots); |
+ if (!GetSlotValues(fd, IndexToMTCode(i), slot_values_[i], max_num_slots)) |
+ return false; |
+ } |
+ |
return true; |
} |
@@ -145,6 +186,11 @@ int32 EventDeviceInfo::GetAbsMaximum(unsigned int code) const { |
return abs_info_[code].maximum; |
} |
+int32 EventDeviceInfo::GetSlotValue(unsigned int code, |
+ unsigned int slot) const { |
+ return slot_values_[MTCodeToIndex(code)][slot]; |
+} |
+ |
bool EventDeviceInfo::HasAbsXY() const { |
if (HasAbsEvent(ABS_X) && HasAbsEvent(ABS_Y)) |
return true; |