mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
fix bug in timer_callbacks scheduling & change variable name
watiEvent should stop checking timer_callbacks when execceds wait timeout set by timeout_us.
This commit is contained in:
@@ -179,12 +179,12 @@ function GestureDetector:tapState(ev)
|
||||
-- set current tap to last tap
|
||||
self.last_tap = cur_tap
|
||||
|
||||
local dead_line = self.cur_ev.timev + TimeVal:new{
|
||||
DEBUG("set up tap timer")
|
||||
local deadline = self.cur_ev.timev + TimeVal:new{
|
||||
sec = 0, usec = self.DOUBLE_TAP_INTERVAL,
|
||||
}
|
||||
DEBUG("set up tap timer")
|
||||
Input:setTimeOut(function()
|
||||
print("in tap timer", self.last_tap ~= nil)
|
||||
DEBUG("in tap timer", self.last_tap ~= nil)
|
||||
-- double tap will set last_tap to nil
|
||||
-- so if it is not, then user must only
|
||||
-- tapped once
|
||||
@@ -193,7 +193,7 @@ function GestureDetector:tapState(ev)
|
||||
-- we are using closure here
|
||||
return ges_ev
|
||||
end
|
||||
end, dead_line)
|
||||
end, deadline)
|
||||
-- we are already at the end of touch event
|
||||
-- so reset the state
|
||||
self:clearState()
|
||||
@@ -204,7 +204,7 @@ function GestureDetector:tapState(ev)
|
||||
self.cur_x = ev.x
|
||||
self.cur_y = ev.y
|
||||
DEBUG("set up hold timer")
|
||||
local dead_line = self.cur_ev.timev + TimeVal:new{
|
||||
local deadline = self.cur_ev.timev + TimeVal:new{
|
||||
sec = 0, usec = self.HOLD_INTERVAL
|
||||
}
|
||||
Input:setTimeOut(function()
|
||||
@@ -213,7 +213,7 @@ function GestureDetector:tapState(ev)
|
||||
-- timer set in tapState, so we switch to hold
|
||||
return self:switchState("holdState")
|
||||
end
|
||||
end, dead_line)
|
||||
end, deadline)
|
||||
else
|
||||
-- it is not end of touch event, see if we need to switch to
|
||||
-- other states
|
||||
|
||||
@@ -271,10 +271,10 @@ end
|
||||
function Input:setTimeOut(cb, tv_out)
|
||||
local item = {
|
||||
callback = cb,
|
||||
dead_line = tv_out,
|
||||
deadline = tv_out,
|
||||
}
|
||||
for k,v in ipairs(self.timer_callbacks) do
|
||||
if v.dead_line > tv_out then
|
||||
if v.deadline > tv_out then
|
||||
table.insert(self.timer_callbacks, k, item)
|
||||
break
|
||||
end
|
||||
@@ -300,7 +300,7 @@ function Input:waitEvent(timeout_us, timeout_s)
|
||||
local tv_now = TimeVal:now()
|
||||
if ((not timeout_us and not timeout_s) or tv_now < wait_deadline) then
|
||||
-- check whether timer is up
|
||||
if tv_now >= self.timer_callbacks[1].dead_line then
|
||||
if tv_now >= self.timer_callbacks[1].deadline then
|
||||
local ges = self.timer_callbacks[1].callback()
|
||||
table.remove(self.timer_callbacks, 1)
|
||||
if ges then
|
||||
@@ -308,13 +308,15 @@ function Input:waitEvent(timeout_us, timeout_s)
|
||||
-- decided a gesture? FIXME
|
||||
Input.timer_callbacks = {}
|
||||
return Event:new("Gesture", ges)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end -- EOF if ges
|
||||
end -- EOF if deadline reached
|
||||
else
|
||||
break
|
||||
end -- EOF if not exceed wait timeout
|
||||
end -- while #timer_callbacks > 0
|
||||
else
|
||||
ok, ev = pcall(input.waitForEvent, timeout_us)
|
||||
end
|
||||
end -- EOF if #timer_callbacks > 0
|
||||
if ok then
|
||||
break
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user