diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-09-02 11:35:14 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-09-05 15:01:06 +0200 |
commit | d30abd8857a41f439de01f8c0e6d1075acf124d9 (patch) | |
tree | cce39752eb468dc0a13285a357c05800d843ca82 | |
parent | 46fdacc5b5abb05d49c0f16fe5ffc4ceb7795dee (diff) | |
download | rneovim-d30abd8857a41f439de01f8c0e6d1075acf124d9.tar.gz rneovim-d30abd8857a41f439de01f8c0e6d1075acf124d9.tar.bz2 rneovim-d30abd8857a41f439de01f8c0e6d1075acf124d9.zip |
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.
-rw-r--r-- | src/nvim/aucmd.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c index 8b86d89bf2..a69881431e 100644 --- a/src/nvim/aucmd.c +++ b/src/nvim/aucmd.c @@ -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; } |