diff --git a/frontend/device/input.lua b/frontend/device/input.lua index 215f2d32e..0a8ae532e 100644 --- a/frontend/device/input.lua +++ b/frontend/device/input.lua @@ -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() diff --git a/frontend/ui/uimanager.lua b/frontend/ui/uimanager.lua index 6e0e2bf97..e46590720 100644 --- a/frontend/ui/uimanager.lua +++ b/frontend/ui/uimanager.lua @@ -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