mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #2099 from koreader/houqp-master
uimanager(fix): honor second when calling Input:waitEvent
This commit is contained in:
@@ -473,21 +473,20 @@ end
|
||||
|
||||
-- main event handling:
|
||||
|
||||
function Input:waitEvent(timeout_us, timeout_s)
|
||||
function Input:waitEvent(timeout_us)
|
||||
-- wrapper for input.waitForEvents that will retry for some cases
|
||||
local ok, ev
|
||||
local wait_deadline = TimeVal:now() + TimeVal:new{
|
||||
sec = timeout_s,
|
||||
usec = timeout_us
|
||||
}
|
||||
while true do
|
||||
if #self.timer_callbacks > 0 then
|
||||
local wait_deadline = TimeVal:now() + TimeVal:new{
|
||||
usec = timeout_us
|
||||
}
|
||||
-- we don't block if there is any timer, set wait to 10us
|
||||
while #self.timer_callbacks > 0 do
|
||||
ok, ev = pcall(input.waitForEvent, 100)
|
||||
if ok then break end
|
||||
local tv_now = TimeVal:now()
|
||||
if ((not timeout_us and not timeout_s) or tv_now < wait_deadline) then
|
||||
if (not timeout_us or tv_now < wait_deadline) then
|
||||
-- check whether timer is up
|
||||
if tv_now >= self.timer_callbacks[1].deadline then
|
||||
local touch_ges = self.timer_callbacks[1].callback()
|
||||
|
||||
@@ -637,13 +637,10 @@ function UIManager:handleInput()
|
||||
end
|
||||
elseif wait_until[1] > now[1]
|
||||
or wait_until[1] == now[1] and wait_until[2] > now[2] then
|
||||
local wait_for = { s = wait_until[1] - now[1], us = wait_until[2] - now[2] }
|
||||
if wait_for.us < 0 then
|
||||
wait_for.s = wait_for.s - 1
|
||||
wait_for.us = MILLION + wait_for.us
|
||||
end
|
||||
-- wait until next task is pending
|
||||
input_event = Input:waitEvent(wait_for.us, wait_for.s)
|
||||
local wait_us = (wait_until[1] - now[1]) * MILLION
|
||||
+ (wait_until[2] - now[2])
|
||||
input_event = Input:waitEvent(wait_us)
|
||||
end
|
||||
|
||||
-- delegate input_event to handler
|
||||
|
||||
Reference in New Issue
Block a user