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:
parent
bdaddea29a
commit
70412b520b
|
@ -378,6 +378,8 @@ function core.on_event(type, ...)
|
||||||
core.root_view:open_doc(doc)
|
core.root_view:open_doc(doc)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif type == "focuslost" then
|
||||||
|
core.root_view:on_focus_lost(...)
|
||||||
elseif type == "quit" then
|
elseif type == "quit" then
|
||||||
core.quit()
|
core.quit()
|
||||||
end
|
end
|
||||||
|
@ -487,8 +489,13 @@ function core.run()
|
||||||
-- do not wait of events at idle_iterations = 1 to give a chance at core.step to run
|
-- do not wait of events at idle_iterations = 1 to give a chance at core.step to run
|
||||||
-- and set "redraw" flag.
|
-- and set "redraw" flag.
|
||||||
if idle_iterations > 1 then
|
if idle_iterations > 1 then
|
||||||
|
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()
|
system.wait_event()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
idle_iterations = 0
|
idle_iterations = 0
|
||||||
end
|
end
|
||||||
|
|
|
@ -504,6 +504,11 @@ function RootView:on_text_input(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function RootView:on_focus_lost(...)
|
||||||
|
-- We force a redraw so documents can redraw without the cursor.
|
||||||
|
core.redraw = true
|
||||||
|
end
|
||||||
|
|
||||||
function RootView:update()
|
function RootView:update()
|
||||||
copy_position_and_size(self.root_node, self)
|
copy_position_and_size(self.root_node, self)
|
||||||
self.root_node:update()
|
self.root_node:update()
|
||||||
|
|
|
@ -61,6 +61,10 @@ top:
|
||||||
lua_pushstring(L, "exposed");
|
lua_pushstring(L, "exposed");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (e.window.event == SDL_WINDOWEVENT_FOCUS_LOST) {
|
||||||
|
lua_pushstring(L, "focuslost");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
/* on some systems, when alt-tabbing to the window SDL will queue up
|
/* on some systems, when alt-tabbing to the window SDL will queue up
|
||||||
** several KEYDOWN events for the `tab` key; we flush all keydown
|
** several KEYDOWN events for the `tab` key; we flush all keydown
|
||||||
** events on focus so these are discarded */
|
** events on focus so these are discarded */
|
||||||
|
|
Loading…
Reference in New Issue