[feat] Make touch work on the H2O2 (#3715)

This commit is contained in:
cairnsh
2018-03-04 12:31:46 -05:00
committed by Frans de Jonge
parent 68e63df442
commit f74f19bd9f
2 changed files with 38 additions and 5 deletions

36
frontend/device/input.lua Normal file → Executable file
View File

@@ -376,16 +376,22 @@ end. Upon receiving an MT event, one simply updates the appropriate
attribute of the current slot.
--]]
function Input:handleTouchEv(ev)
local function switchSlotTo(value)
if self.cur_slot ~= value then
table.insert(self.MTSlots, self:getMtSlot(value))
end
self.cur_slot = value
end
if ev.type == EV_ABS then
if #self.MTSlots == 0 then
table.insert(self.MTSlots, self:getMtSlot(self.cur_slot))
end
if ev.code == ABS_MT_SLOT then
if self.cur_slot ~= ev.value then
table.insert(self.MTSlots, self:getMtSlot(ev.value))
end
self.cur_slot = ev.value
switchSlotTo(ev.value)
elseif ev.code == ABS_MT_TRACKING_ID then
if self.snow_protocol then
switchSlotTo(ev.value)
end
self:setCurrentMtSlot("id", ev.value)
elseif ev.code == ABS_MT_POSITION_X then
self:setCurrentMtSlot("x", ev.value)
@@ -411,10 +417,32 @@ function Input:handleTouchEv(ev)
if ev.code == SYN_REPORT then
for _, MTSlot in pairs(self.MTSlots) do
self:setMtSlot(MTSlot.slot, "timev", TimeVal:new(ev.time))
if self.snow_protocol then
-- if a slot appears in the current touch event, set "used"
self:setMtSlot(MTSlot.slot, "used", true)
end
end
if self.snow_protocol then
-- reset every slot that doesn't appear in the current touch event
-- (because on the H2O2, this is the only way we detect finger-up)
self.MTSlots = {}
for _, slot in pairs(self.ev_slots) do
table.insert(self.MTSlots, slot)
if not slot.used then
slot.id = -1
slot.timev = TimeVal:new(ev.time)
end
end
end
-- feed ev in all slots to state machine
local touch_ges = self.gesture_detector:feedEvent(self.MTSlots)
self.MTSlots = {}
if self.snow_protocol then
-- go through all the ev_slots and clear used
for _, slot in pairs(self.ev_slots) do
slot.used = nil
end
end
if touch_ges then
self:gestureAdjustHook(touch_ges)
return Event:new("Gesture",