diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-08-28 01:27:57 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-09-05 15:01:06 +0200 |
commit | b6b6e4a96f37ba6a54d194ecbc042d5ef7d595e6 (patch) | |
tree | a2325b8f194daceab79e038ea58105634b4d48d9 /src/nvim/aucmd.c | |
parent | ce852bab04c63262ce8545c01a4ff4fc827148a1 (diff) | |
download | rneovim-b6b6e4a96f37ba6a54d194ecbc042d5ef7d595e6.tar.gz rneovim-b6b6e4a96f37ba6a54d194ecbc042d5ef7d595e6.tar.bz2 rneovim-b6b6e4a96f37ba6a54d194ecbc042d5ef7d595e6.zip |
eventloop: FocusGained: schedule event instead of pseudokey
closes #4840
closes #6164
Diffstat (limited to 'src/nvim/aucmd.c')
-rw-r--r-- | src/nvim/aucmd.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/nvim/aucmd.c b/src/nvim/aucmd.c new file mode 100644 index 0000000000..8b86d89bf2 --- /dev/null +++ b/src/nvim/aucmd.c @@ -0,0 +1,48 @@ +// This is an open source non-commercial project. Dear PVS-Studio, please check +// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com + +#include "nvim/os/os.h" +#include "nvim/fileio.h" +#include "nvim/vim.h" +#include "nvim/main.h" +#include "nvim/screen.h" +#include "nvim/ui.h" + +#ifdef INCLUDE_GENERATED_DECLARATIONS +# include "aucmd.c.generated.h" +#endif + +static void focusgained_event(void **argv) +{ + bool *gained = argv[0]; + do_autocmd_focusgained(*gained); + xfree(gained); +} +void aucmd_schedule_focusgained(bool gained) +{ + bool *gainedp = xmalloc(sizeof(*gainedp)); + *gainedp = gained; + loop_schedule(&main_loop, event_create(focusgained_event, 1, gainedp)); +} + +static void do_autocmd_focusgained(bool gained) + FUNC_ATTR_NONNULL_ALL +{ + static bool recursive = false; + + if (recursive) { + 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); + } + recursive = false; +} + |