Fix cursor blinking problem

The problem was that when the editor had no events the cursor was not
blinking because the event loop was blocking on wait_event.

Now we no longer calls wait_event without a timeout if the windows has
the focus. When the window has the focus the timeout is set to 1 / fps
so that the cursor can blinks.

In addition we react to the "focus lost" event to ensure the documents
are redrawn without the cursor.
This commit is contained in:
Francesco Abbate
2020-11-21 16:36:32 +01:00
parent bdaddea29a
commit 70412b520b
3 changed files with 17 additions and 1 deletions
+8 -1
View File
@@ -378,6 +378,8 @@ function core.on_event(type, ...)
core.root_view:open_doc(doc)
end
end
elseif type == "focuslost" then
core.root_view:on_focus_lost(...)
elseif type == "quit" then
core.quit()
end
@@ -487,7 +489,12 @@ function core.run()
-- do not wait of events at idle_iterations = 1 to give a chance at core.step to run
-- and set "redraw" flag.
if idle_iterations > 1 then
system.wait_event()
if system.window_has_focus() then
-- keep running even with no events to make the cursor blinks
system.wait_event(1 / config.fps)
else
system.wait_event()
end
end
else
idle_iterations = 0