eventloop: FocusGained: schedule the schedule

main_loop.fast_events does not manifest as K_EVENT, because it is
processed at a different stage than main_loop.events. In order to queue
into main_loop.events, we need to go through the threadsafe
loop_schedule(), which queues into main_loop.thread_events and
eventually main_loop.fast_events. _Then_ it is safe to directly queue
into main_loop.events.

This makes it more likely that the event is treated as K_EVENT.
This commit is contained in:
Justin M. Keyes 2017-09-02 11:35:14 +02:00
parent 46fdacc5b5
commit d30abd8857

View File

@ -14,15 +14,20 @@
static void focusgained_event(void **argv)
{
bool *gained = argv[0];
do_autocmd_focusgained(*gained);
xfree(gained);
bool *gainedp = argv[0];
do_autocmd_focusgained(*gainedp);
xfree(gainedp);
}
static void schedule_event(void **argv)
{
bool *gainedp = argv[0];
multiqueue_put(main_loop.events, focusgained_event, 1, gainedp);
}
void aucmd_schedule_focusgained(bool gained)
{
bool *gainedp = xmalloc(sizeof(*gainedp));
*gainedp = gained;
loop_schedule(&main_loop, event_create(focusgained_event, 1, gainedp));
loop_schedule(&main_loop, event_create(schedule_event, 1, gainedp));
}
static void do_autocmd_focusgained(bool gained)
@ -34,15 +39,8 @@ static void do_autocmd_focusgained(bool gained)
return; // disallow recursion
}
recursive = true;
bool has_any = has_event(EVENT_FOCUSGAINED) || has_event(EVENT_FOCUSLOST);
bool did_any = apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST),
NULL, NULL, false, curbuf);
if (has_any && !did_any) {
// HACK: Reschedule, hoping that the next event-loop tick will pick this up
// during a "regular" state (as opposed to a weird implicit state, e.g.
// early_init()..win_alloc_first() which disables autocommands).
aucmd_schedule_focusgained(gained);
}
apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST),
NULL, NULL, false, curbuf);
recursive = false;
}