Merge pull request #1168 from hwhw/master

Fix double-check of task list
pull/1171/head
Huang Xin 10 years ago
commit 2dbda247a2

@ -69,6 +69,7 @@ local UIManager = {
_running = true,
_window_stack = {},
_execution_stack = {},
_execution_stack_dirty = false,
_dirty = {},
_zeromqs = {},
}
@ -232,6 +233,7 @@ end
-- schedule an execution task
function UIManager:schedule(time, action)
table.insert(self._execution_stack, { time = time, action = action })
self._execution_stack_dirty = true
end
-- schedule task in a certain amount of seconds (fractions allowed) from now
@ -370,32 +372,12 @@ function UIManager:checkTasks()
end
end
until all_tasks_checked
return wait_until
self._execution_stack_dirty = false
return wait_until, now
end
-- this is the main loop of the UI controller
-- it is intended to manage input events and delegate
-- them to dialogs
function UIManager:run()
self._running = true
while self._running do
local now = { util.gettime() }
local wait_until = self:checkTasks()
--DEBUG("---------------------------------------------------")
--DEBUG("exec stack", self._execution_stack)
--DEBUG("window stack", self._window_stack)
--DEBUG("dirty stack", self._dirty)
--DEBUG("---------------------------------------------------")
-- stop when we have no window to show
if #self._window_stack == 0 then
DEBUG("no dialog left to show")
self:quit()
return nil
end
-- repaint dirty widgets
-- repaint dirty widgets
function UIManager:repaint()
local dirty = false
local request_full_refresh = false
local force_full_refresh = false
@ -490,11 +472,39 @@ function UIManager:run()
end
self.update_regions_func = nil
end
end
-- this is the main loop of the UI controller
-- it is intended to manage input events and delegate
-- them to dialogs
function UIManager:run()
self._running = true
while self._running do
local wait_until, now
-- run this in a loop, so that paints can trigger events
-- that will be honored when calculating the time to wait
-- for input events:
repeat
wait_until, now = self:checkTasks()
--DEBUG("---------------------------------------------------")
--DEBUG("exec stack", self._execution_stack)
--DEBUG("window stack", self._window_stack)
--DEBUG("dirty stack", self._dirty)
--DEBUG("---------------------------------------------------")
-- stop when we have no window to show
if #self._window_stack == 0 then
DEBUG("no dialog left to show")
self:quit()
return nil
end
self:checkTasks()
self:repaint()
until not self._execution_stack_dirty
-- wait for next event
-- note that we will skip that if in the meantime we have tasks that are ready to run
-- note that we will skip that if we have tasks that are ready to run
local input_event = nil
if not wait_until then
if #self._zeromqs > 0 then
@ -507,7 +517,7 @@ function UIManager:run()
end
end
else
-- no pending task, wait endlessly
-- no pending task, wait without timeout
input_event = Input:waitEvent()
end
elseif wait_until[1] > now[1]

Loading…
Cancel
Save