diff options
author | Martin Herkt <lachs0r@srsfckn.biz> | 2016-10-19 19:09:00 +0200 |
---|---|---|
committer | Martin Herkt <lachs0r@srsfckn.biz> | 2016-10-19 19:09:00 +0200 |
commit | 5d74fa7dc0fa1617d1d11b69769423b1387ec785 (patch) | |
tree | 882752015b3500c91b8ab3a4d669696f23feb817 /player/lua/defaults.lua | |
parent | c226bc7616ab2ae9de6172660e9cf727f07dc374 (diff) | |
parent | a2fa0d0b68ce200598122145254f56ae1adff91e (diff) | |
download | mpv-5d74fa7dc0fa1617d1d11b69769423b1387ec785.tar.bz2 mpv-5d74fa7dc0fa1617d1d11b69769423b1387ec785.tar.xz |
Merge branch 'master' into release/current
Diffstat (limited to 'player/lua/defaults.lua')
-rw-r--r-- | player/lua/defaults.lua | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/player/lua/defaults.lua b/player/lua/defaults.lua index 901a8cf246..c65fda7c9b 100644 --- a/player/lua/defaults.lua +++ b/player/lua/defaults.lua @@ -412,6 +412,13 @@ mp.register_event("shutdown", function() mp.keep_running = false end) mp.register_event("client-message", message_dispatch) mp.register_event("property-change", property_change) +-- called before the event loop goes back to sleep +local idle_handlers = {} + +function mp.register_idle(cb) + idle_handlers[#idle_handlers + 1] = cb +end + -- sent by "script-binding" mp.register_script_message("key-binding", dispatch_key_binding) @@ -451,16 +458,17 @@ function mp.dispatch_events(allow_wait) mp.suspend() end while mp.keep_running do - local wait = process_timers() - if wait == nil then - wait = 1e20 -- infinity for all practical purposes - end - if more_events or wait < 0 then - wait = 0 - end - -- Resume playloop - important especially if an error happened while - -- suspended, and the error was handled, but no resume was done. - if wait > 0 then + local wait = 0 + if not more_events then + wait = process_timers() + if wait == nil then + for _, handler in ipairs(idle_handlers) do + handler() + end + wait = 1e20 -- infinity for all practical purposes + end + -- Resume playloop - important especially if an error happened while + -- suspended, and the error was handled, but no resume was done. mp.resume_all() if allow_wait ~= true then return @@ -472,9 +480,10 @@ function mp.dispatch_events(allow_wait) if mp.use_suspend then mp.suspend() end - more_events = (e.event ~= "none") - if more_events then + more_events = false + if e.event ~= "none" then call_event_handlers(e) + more_events = true end end end |