diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index 69931f63d..691529b9e 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -38,10 +38,6 @@ local ABS_MT_POSITION_Y = 54 local ABS_MT_TRACKING_ID = 57 local ABS_MT_PRESSURE = 58 -local dev_mod = Device:getModel() -local Phoenix = false -if dev_mod == 'Kobo_phoenix' then Phoenix = true end - --[[ an interface for key presses ]] @@ -285,7 +281,7 @@ function Input:init() -- SDL key codes self.event_map = self.sdl_event_map else - --local dev_mod = Device:getModel() + local dev_mod = Device:getModel() if not Device:isKobo() then input.open("fake_events") end @@ -325,7 +321,6 @@ function Input:init() Device:setTouchInputDev("/dev/input/event1") input.open("/dev/input/event0") -- Light button and sleep slider print(_("Auto-detected Kobo")) - self:adjustKoboEventMap() if dev_mod ~= 'Kobo_trilogy' then function Input:eventAdjustHook(ev) @@ -393,6 +388,16 @@ function Input:init() os.exit(-1) end end + + if Device:getModel() ~= 'Kobo_phoenix' then + function Input:handleTouchEv(ev) + return Input:handleTypeBTouchEv(ev) + end + else + function Input:handleTouchEv(ev) + return Input:handlePhoenixTouchEv(ev) + end + end end --[[ @@ -540,8 +545,7 @@ the full state of each initiated contact has to reside in the receiving end. Upon receiving an MT event, one simply updates the appropriate attribute of the current slot. --]] ---[[ -function Input:handleTouchEv(ev) +function Input:handleTypeBTouchEv(ev) if ev.type == EV_SYN then if ev.code == SYN_REPORT then for _, MTSlot in pairs(self.MTSlots) do @@ -589,122 +593,72 @@ function Input:handleTouchEv(ev) end end end ---]] -function Input:handleTouchEv(ev) --- local dev_mod = Device:getModel() - if Phoenix then - -- Hack on handleTouchEV for the Kobo Aura - if ev.type == EV_SYN then - if ev.code == SYN_REPORT then - for _, MTSlot in pairs(self.MTSlots) do - self:setMtSlot(MTSlot.slot, "timev", TimeVal:new(ev.time)) - end - -- feed ev in all slots to state machine - local touch_ges = GestureDetector:feedEvent(self.MTSlots) - self.MTSlots = {} - if touch_ges then - return Event:new("Gesture", - GestureDetector:adjustGesCoordinate(touch_ges) - ) - end - end - elseif ev.type == EV_ABS and ev.code ~= ABS_MT_TOUCH_MAJOR and ev.code ~= ABS_MT_WIDTH_MAJOR then - if #self.MTSlots == 0 then - table.insert(self.MTSlots, self:getMtSlot(self.cur_slot)) - -- I have to add id's without events for the AURA. - self:setMtSlot(self.cur_slot, "id", 0) - end - -- I have changed ABS_MT_SLOT to ABS_MT_TRACKING_ID - if ev.code == ABS_MT_TRACKING_ID then - if self.cur_slot ~= ev.value then - table.insert(self.MTSlots, self:getMtSlot(ev.value)) - -- I have to add id's without events for the AURA. Since there are only two - -- ID's 0 and 1 and it's not 0, - self:setMtSlot(ev.value, "id", 1) - end - self.cur_slot = ev.value - -- ABS_MT_TRACKING_ID is no longer used for assigning id's. - -- elseif ev.code == ABS_MT_TRACKING_ID then - -- self:setCurrentMtSlot("id", ev.value) - elseif ev.code == ABS_MT_POSITION_X then - self:setCurrentMtSlot("x", ev.value) - elseif ev.code == ABS_MT_POSITION_Y then - self:setCurrentMtSlot("y", ev.value) - -- code to emulate mt protocol on kobos - -- we "confirm" abs_x, abs_y only when pressure ~= 0 - ---[[ +function Input:handlePhoenixTouchEv(ev) + -- Hack on handleTouchEV for the Kobo Aura + if ev.type == EV_SYN then + if ev.code == SYN_REPORT then + for _, MTSlot in pairs(self.MTSlots) do + self:setMtSlot(MTSlot.slot, "timev", TimeVal:new(ev.time)) + end + -- feed ev in all slots to state machine + local touch_ges = GestureDetector:feedEvent(self.MTSlots) + self.MTSlots = {} + if touch_ges then + return Event:new("Gesture", + GestureDetector:adjustGesCoordinate(touch_ges) + ) + end + end + elseif ev.type == EV_ABS and ev.code ~= ABS_MT_TOUCH_MAJOR and ev.code ~= ABS_MT_WIDTH_MAJOR then + if #self.MTSlots == 0 then + table.insert(self.MTSlots, self:getMtSlot(self.cur_slot)) + -- I have to add id's without events for the AURA. + self:setMtSlot(self.cur_slot, "id", 0) + end + -- I have changed ABS_MT_SLOT to ABS_MT_TRACKING_ID + if ev.code == ABS_MT_TRACKING_ID then + if self.cur_slot ~= ev.value then + table.insert(self.MTSlots, self:getMtSlot(ev.value)) + -- I have to add id's without events for the AURA. Since there are only two + -- ID's 0 and 1 and it's not 0, + self:setMtSlot(ev.value, "id", 1) + end + self.cur_slot = ev.value + -- ABS_MT_TRACKING_ID is no longer used for assigning id's. + -- elseif ev.code == ABS_MT_TRACKING_ID then + -- self:setCurrentMtSlot("id", ev.value) + elseif ev.code == ABS_MT_POSITION_X then + self:setCurrentMtSlot("x", ev.value) + elseif ev.code == ABS_MT_POSITION_Y then + self:setCurrentMtSlot("y", ev.value) + + -- code to emulate mt protocol on kobos + -- we "confirm" abs_x, abs_y only when pressure ~= 0 + ---[[ elseif ev.code == ABS_X then self:setCurrentMtSlot("abs_x", ev.value) elseif ev.code == ABS_Y then self:setCurrentMtSlot("abs_y", ev.value) --]] - elseif ev.code == ABS_PRESSURE then - if ev.value ~= 0 then - -- Single tap events only use slot 0. - self:setMtSlot(0, "id", 1) - --Unnecessary for Aura - --self:confirmAbsxy() - else - --Unnecessary for Aura - --self:cleanAbsxy() - -- Pressure 0 events only invalidate slot 0. - self:setMtSlot(0, "id", -1) - -- If there are 2 slots active, invalidates slot 2. - if #self.MTSlots == 2 then - self:setMtSlot(1, "id", -1) - end + elseif ev.code == ABS_PRESSURE then + if ev.value ~= 0 then + -- Single tap events only use slot 0. + self:setMtSlot(0, "id", 1) + --Unnecessary for Aura + --self:confirmAbsxy() + else + --Unnecessary for Aura + --self:cleanAbsxy() + -- Pressure 0 events only invalidate slot 0. + self:setMtSlot(0, "id", -1) + -- If there are 2 slots active, invalidates slot 2. + if #self.MTSlots == 2 then + self:setMtSlot(1, "id", -1) end end end - -- Orignal handleTouchEV for all others - else if ev.type == EV_SYN then - if ev.code == SYN_REPORT then - for _, MTSlot in pairs(self.MTSlots) do - self:setMtSlot(MTSlot.slot, "timev", TimeVal:new(ev.time)) - end - -- feed ev in all slots to state machine - local touch_ges = GestureDetector:feedEvent(self.MTSlots) - self.MTSlots = {} - if touch_ges then - return Event:new("Gesture", - GestureDetector:adjustGesCoordinate(touch_ges) - ) - end - end - elseif 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 - elseif ev.code == ABS_MT_TRACKING_ID then - self:setCurrentMtSlot("id", ev.value) - elseif ev.code == ABS_MT_POSITION_X then - self:setCurrentMtSlot("x", ev.value) - elseif ev.code == ABS_MT_POSITION_Y then - self:setCurrentMtSlot("y", ev.value) - - -- code to emulate mt protocol on kobos - -- we "confirm" abs_x, abs_y only when pressure ~= 0 - elseif ev.code == ABS_X then - self:setCurrentMtSlot("abs_x", ev.value) - elseif ev.code == ABS_Y then - self:setCurrentMtSlot("abs_y", ev.value) - elseif ev.code == ABS_PRESSURE then - if ev.value ~= 0 then - self:setCurrentMtSlot("id", 1) - self:confirmAbsxy() - else - self:cleanAbsxy() - self:setCurrentMtSlot("id", -1) - end - end - end -end + end end function Input:waitEvent(timeout_us, timeout_s)