diff --git a/frontend/device/cervantes/device.lua b/frontend/device/cervantes/device.lua index 1d1bfc5db..d18cc0d9f 100644 --- a/frontend/device/cervantes/device.lua +++ b/frontend/device/cervantes/device.lua @@ -1,5 +1,4 @@ local Generic = require("device/generic/device") -local TimeVal = require("ui/timeval") local logger = require("logger") local function yes() return true end @@ -56,7 +55,6 @@ local Cervantes = Generic:new{ touch_legacy = true, -- SingleTouch input events touch_switch_xy = true, touch_mirrored_x = true, - touch_probe_ev_epoch_time = true, hasOTAUpdates = yes, hasFastWifiStatusQuery = yes, hasKeys = yes, @@ -119,38 +117,17 @@ local Cervantes4 = Cervantes:new{ } -- input events -local probeEvEpochTime --- this function will update itself after the first touch event -probeEvEpochTime = function(self, ev) - local now = TimeVal:now() - -- This check should work as long as main UI loop is not blocked for more - -- than 10 minute before handling the first touch event. - if ev.time.sec <= now.sec - 600 then - -- time is seconds since boot, force it to epoch - probeEvEpochTime = function(_, _ev) - _ev.time = TimeVal:now() - end - ev.time = now - else - -- time is already epoch time, no need to do anything - probeEvEpochTime = function(_, _) end - end -end function Cervantes:initEventAdjustHooks() if self.touch_switch_xy then self.input:registerEventAdjustHook(self.input.adjustTouchSwitchXY) end + if self.touch_mirrored_x then self.input:registerEventAdjustHook( self.input.adjustTouchMirrorX, self.screen:getWidth() ) end - if self.touch_probe_ev_epoch_time then - self.input:registerEventAdjustHook(function(_, ev) - probeEvEpochTime(_, ev) - end) - end if self.touch_legacy then self.input.handleTouchEv = self.input.handleTouchEvLegacy diff --git a/frontend/device/gesturedetector.lua b/frontend/device/gesturedetector.lua index c31eb76c9..e7e1a7ca2 100644 --- a/frontend/device/gesturedetector.lua +++ b/frontend/device/gesturedetector.lua @@ -430,7 +430,10 @@ function GestureDetector:handleDoubleTap(tev) -- a timer if no second tap happened in the double tap delay. logger.dbg("set up single/double tap timer") -- deadline should be calculated by adding current tap time and the interval - local deadline = cur_tap.timev + TimeVal:new{ + -- (No need to compute self._has_real_clock_time_ev_time here, we should always + -- have been thru handleNonTap() where it is computed, before getting here) + local ref_time = self._has_real_clock_time_ev_time and cur_tap.timev or TimeVal:now() + local deadline = ref_time + TimeVal:new{ sec = 0, usec = not self.input.disable_double_tap and ges_double_tap_interval or 0, } @@ -456,8 +459,22 @@ function GestureDetector:handleNonTap(tev) -- switched from other state, probably from initialState -- we return nil in this case self.states[slot] = self.tapState + if self._has_real_clock_time_ev_time == nil then + if tev.timev.sec < TimeVal:now().sec - 600 then + -- ev.timev is probably the uptime since device boot + -- (which might pause on suspend) that we can't use + -- with setTimeout(): we'll use TimeVal:now() + self._has_real_clock_time_ev_time = false + logger.info("event times are not real clock time: some adjustments will be made") + else + -- assume they are real clock time + self._has_real_clock_time_ev_time = true + logger.info("event times are real clock time: no adjustment needed") + end + end logger.dbg("set up hold timer") - local deadline = tev.timev + TimeVal:new{ + local ref_time = self._has_real_clock_time_ev_time and tev.timev or TimeVal:now() + local deadline = ref_time + TimeVal:new{ sec = 0, usec = ges_hold_interval } -- Be sure the following setTimeout only react to this tapState diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua index 0476beb8c..78ad1900f 100644 --- a/frontend/device/kobo/device.lua +++ b/frontend/device/kobo/device.lua @@ -1,6 +1,5 @@ local Generic = require("device/generic/device") local Geom = require("ui/geometry") -local TimeVal = require("ui/timeval") local WakeupMgr = require("device/wakeupmgr") local logger = require("logger") local util = require("ffi/util") @@ -59,10 +58,6 @@ local KoboTrilogy = Kobo:new{ model = "Kobo_trilogy", needsTouchScreenProbe = yes, touch_switch_xy = false, - -- Some Kobo Touch models' kernel does not generate touch event with epoch - -- timestamp. This flag will probe for those models and setup event adjust - -- hook accordingly - touch_probe_ev_epoch_time = true, hasKeys = yes, hasMultitouch = no, } @@ -80,7 +75,6 @@ local KoboPixie = Kobo:new{ local KoboDaylight = Kobo:new{ model = "Kobo_daylight", hasFrontlight = yes, - touch_probe_ev_epoch_time = true, touch_phoenix_protocol = true, display_dpi = 300, hasNaturalLight = yes, @@ -136,7 +130,6 @@ local KoboSnow = Kobo:new{ hasFrontlight = yes, touch_snow_protocol = true, touch_mirrored_x = false, - touch_probe_ev_epoch_time = true, display_dpi = 265, hasNaturalLight = yes, frontlight_settings = { @@ -164,7 +157,6 @@ local KoboSnowRev2 = Kobo:new{ local KoboStar = Kobo:new{ model = "Kobo_star", hasFrontlight = yes, - touch_probe_ev_epoch_time = true, touch_phoenix_protocol = true, display_dpi = 212, } @@ -174,7 +166,6 @@ local KoboStar = Kobo:new{ local KoboStarRev2 = Kobo:new{ model = "Kobo_star_r2", hasFrontlight = yes, - touch_probe_ev_epoch_time = true, touch_phoenix_protocol = true, display_dpi = 212, } @@ -273,24 +264,6 @@ local KoboLuna = Kobo:new{ display_dpi = 212, } --- This function will update itself after the first touch event -local probeEvEpochTime -probeEvEpochTime = function(self, ev) - local now = TimeVal:now() - -- This check should work as long as main UI loop is not blocked for more - -- than 10 minute before handling the first touch event. - if ev.time.sec <= now.sec - 600 then - -- time is seconds since boot, force it to epoch - probeEvEpochTime = function(_, _ev) - _ev.time = TimeVal:now() - end - ev.time = now - else - -- time is already epoch time, no need to do anything - probeEvEpochTime = function(_, _) end - end -end - function Kobo:init() self.screen = require("ffi/framebuffer_mxcfb"):new{device = self, debug = logger.dbg, is_always_portrait = self.isAlwaysPortrait()} if self.screen.fb_bpp == 32 then @@ -347,15 +320,6 @@ function Kobo:init() else -- if touch probe is required, we postpone EventAdjustHook -- initialization to when self:touchScreenProbe is called - -- Except we may need bits of EventAdjustHook for stuff to be functional, so, - -- re-order things in the most horrible way possible! - if self.touch_probe_ev_epoch_time then - self.input:registerEventAdjustHook(function(_, ev) - probeEvEpochTime(_, ev) - end) - -- And don't do it again during the real initEventAdjustHooks ;) - self.touch_probe_ev_epoch_time = nil - end self.touchScreenProbe = function() -- if user has not set KOBO_TOUCH_MIRRORED yet if KOBO_TOUCH_MIRRORED == nil then @@ -455,7 +419,6 @@ function Kobo:supportsScreensaver() return true end local ABS_MT_TRACKING_ID = 57 local EV_ABS = 3 local adjustTouchAlyssum = function(self, ev) - ev.time = TimeVal:now() if ev.type == EV_ABS and ev.code == ABS_MT_TRACKING_ID then ev.value = ev.value - 1 end @@ -488,12 +451,6 @@ function Kobo:initEventAdjustHooks() self.input.snow_protocol = true end - if self.touch_probe_ev_epoch_time then - self.input:registerEventAdjustHook(function(_, ev) - probeEvEpochTime(_, ev) - end) - end - if self.touch_phoenix_protocol then self.input.handleTouchEv = self.input.handleTouchEvPhoenix end diff --git a/frontend/device/sony-prstux/device.lua b/frontend/device/sony-prstux/device.lua index 6a1626994..3a8498ad7 100644 --- a/frontend/device/sony-prstux/device.lua +++ b/frontend/device/sony-prstux/device.lua @@ -1,6 +1,5 @@ local Generic = require("device/generic/device") -- <= look at this file! local PluginShare = require("pluginshare") -local TimeVal = require("ui/timeval") local ffi = require("ffi") local logger = require("logger") @@ -32,9 +31,6 @@ local EV_ABS = 3 local SYN_REPORT = 0 local SYN_MT_REPORT = 2 local adjustTouchEvt = function(self, ev) - ev.time = TimeVal:now() - logger.dbg('updated time to ',ev.time) - if ev.type == EV_ABS and ev.code == ABS_MT_TOUCH_MAJOR then ev.code = ABS_MT_TRACKING_ID if ev.value ~= 0 then diff --git a/spec/unit/device_spec.lua b/spec/unit/device_spec.lua index d49117235..0400c9689 100644 --- a/spec/unit/device_spec.lua +++ b/spec/unit/device_spec.lua @@ -83,8 +83,6 @@ describe("device module", function() assert.is.same("Kobo_trilogy", kobo_dev.model) assert.truthy(kobo_dev:needsTouchScreenProbe()) - -- This gets reset to nil during Kobo:init() since #4450 - assert.falsy(kobo_dev.touch_probe_ev_epoch_time) G_reader_settings:saveSetting("kobo_touch_switch_xy", true) kobo_dev:touchScreenProbe() local x, y = Screen:getWidth()-5, 10 @@ -117,6 +115,11 @@ describe("device module", function() end) it("should setup eventAdjustHooks properly for trilogy with non-epoch ev time", function() + -- This has no more value since #6798 as ev time can now stay + -- non-epoch. Adjustments are made on first event handled, and + -- have only effects when handling long-press (so, the long-press + -- for dict lookup tests with test this). + -- We just check here it still works with non-epoch ev time, as previous test os.getenv.invokes(function(key) if key == "PRODUCT" then return "trilogy" @@ -132,8 +135,6 @@ describe("device module", function() assert.is.same("Kobo_trilogy", kobo_dev.model) assert.truthy(kobo_dev:needsTouchScreenProbe()) - -- This gets reset to nil during Kobo:init() since #4450 - assert.falsy(kobo_dev.touch_probe_ev_epoch_time) kobo_dev:touchScreenProbe() local x, y = Screen:getWidth()-5, 10 local EV_ABS = 3 @@ -142,21 +143,22 @@ describe("device module", function() local ev_x = { type = EV_ABS, code = ABS_X, - value = x, + value = y, time = {sec = 1000} } local ev_y = { type = EV_ABS, code = ABS_Y, - value = y, + value = Screen:getWidth()-x, time = {sec = 1000} } kobo_dev.input:eventAdjustHook(ev_x) kobo_dev.input:eventAdjustHook(ev_y) - local cur_sec = TimeVal:now().sec - assert.truthy(cur_sec - ev_x.time.sec < 10) - assert.truthy(cur_sec - ev_y.time.sec < 10) + assert.is.same(x, ev_y.value) + assert.is.same(ABS_X, ev_y.code) + assert.is.same(y, ev_x.value) + assert.is.same(ABS_Y, ev_x.code) -- reset eventAdjustHook kobo_dev.input.eventAdjustHook = function() end