mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 11:28:22 +00:00
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:
@@ -14,15 +14,20 @@
|
|||||||
|
|
||||||
static void focusgained_event(void **argv)
|
static void focusgained_event(void **argv)
|
||||||
{
|
{
|
||||||
bool *gained = argv[0];
|
bool *gainedp = argv[0];
|
||||||
do_autocmd_focusgained(*gained);
|
do_autocmd_focusgained(*gainedp);
|
||||||
xfree(gained);
|
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)
|
void aucmd_schedule_focusgained(bool gained)
|
||||||
{
|
{
|
||||||
bool *gainedp = xmalloc(sizeof(*gainedp));
|
bool *gainedp = xmalloc(sizeof(*gainedp));
|
||||||
*gainedp = gained;
|
*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)
|
static void do_autocmd_focusgained(bool gained)
|
||||||
@@ -34,15 +39,8 @@ static void do_autocmd_focusgained(bool gained)
|
|||||||
return; // disallow recursion
|
return; // disallow recursion
|
||||||
}
|
}
|
||||||
recursive = true;
|
recursive = true;
|
||||||
bool has_any = has_event(EVENT_FOCUSGAINED) || has_event(EVENT_FOCUSLOST);
|
apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST),
|
||||||
bool did_any = apply_autocmds((gained ? EVENT_FOCUSGAINED : EVENT_FOCUSLOST),
|
|
||||||
NULL, NULL, false, curbuf);
|
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);
|
|
||||||
}
|
|
||||||
recursive = false;
|
recursive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user