From f31db30975479cb6b57247f124a65f4362f80bfe Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 30 Jun 2022 13:26:31 +0600 Subject: feat(lua): vim.ui_attach to get ui events from lua Co-authored-by: Famiu Haque --- src/nvim/ui_compositor.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 2216e25db9..5167f291c3 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -20,6 +20,7 @@ #include "nvim/log.h" #include "nvim/lua/executor.h" #include "nvim/main.h" +#include "nvim/map.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/os/os.h" @@ -54,6 +55,8 @@ static bool msg_was_scrolled = false; static int msg_sep_row = -1; static schar_T msg_sep_char = { ' ', NUL }; +static PMap(uint32_t) ui_event_cbs = MAP_INIT; + static int dbghl_normal, dbghl_clear, dbghl_composed, dbghl_recompose; void ui_comp_init(void) @@ -69,14 +72,18 @@ void ui_comp_init(void) compositor->grid_cursor_goto = ui_comp_grid_cursor_goto; compositor->raw_line = ui_comp_raw_line; compositor->msg_set_pos = ui_comp_msg_set_pos; + compositor->event = ui_comp_event; // Be unopinionated: will be attached together with a "real" ui anyway compositor->width = INT_MAX; compositor->height = INT_MAX; - for (UIExtension i = 0; (int)i < kUIExtCount; i++) { + for (UIExtension i = kUIGlobalCount; (int)i < kUIExtCount; i++) { compositor->ui_ext[i] = true; } + // TODO(bfredl): one day. in the future. + compositor->ui_ext[kUIMultigrid] = false; + // TODO(bfredl): this will be more complicated if we implement // hlstate per UI (i e reduce hl ids for non-hlstate UIs) compositor->ui_ext[kUIHlState] = false; @@ -87,6 +94,15 @@ void ui_comp_init(void) ui_attach_impl(compositor, 0); } +void ui_comp_free_all_mem(void) +{ + UIEventCallback *event_cb; + map_foreach_value(&ui_event_cbs, event_cb, { + xfree(event_cb); + }) + pmap_destroy(uint32_t)(&ui_event_cbs); +} + void ui_comp_syn_init(void) { dbghl_normal = syn_check_group(S_LEN("RedrawDebugNormal")); @@ -676,3 +692,72 @@ static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer hei } } } + +static void ui_comp_event(UI *ui, char *name, Array args) +{ + Error err = ERROR_INIT; + UIEventCallback *event_cb; + bool handled = false; + + map_foreach_value(&ui_event_cbs, event_cb, { + Object res = nlua_call_ref(event_cb->cb, name, args, false, &err); + if (res.type == kObjectTypeBoolean && res.data.boolean == true) { + handled = true; + } + }) + + if (!handled) { + ui_composed_call_event(name, args); + } +} + +static void ui_comp_update_ext(void) +{ + memset(compositor->ui_ext, 0, ARRAY_SIZE(compositor->ui_ext)); + + for (size_t i = 0; i < kUIGlobalCount; i++) { + UIEventCallback *event_cb; + + map_foreach_value(&ui_event_cbs, event_cb, { + if (event_cb->ext_widgets[i]) { + compositor->ui_ext[i] = true; + break; + } + }) + } +} + +void free_ui_event_callback(UIEventCallback *event_cb) +{ + api_free_luaref(event_cb->cb); + xfree(event_cb); +} + +void ui_comp_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) +{ + UIEventCallback *event_cb = xcalloc(1, sizeof(UIEventCallback)); + event_cb->cb = cb; + memcpy(event_cb->ext_widgets, ext_widgets, ARRAY_SIZE(event_cb->ext_widgets)); + if (event_cb->ext_widgets[kUIMessages]) { + event_cb->ext_widgets[kUICmdline] = true; + } + + UIEventCallback **item = (UIEventCallback **)pmap_ref(uint32_t)(&ui_event_cbs, ns_id, true); + if (*item) { + free_ui_event_callback(*item); + } + *item = event_cb; + + ui_comp_update_ext(); + ui_schedule_refresh(); +} + +void ui_comp_remove_cb(uint32_t ns_id) +{ + if (pmap_has(uint32_t)(&ui_event_cbs, ns_id)) { + free_ui_event_callback(pmap_get(uint32_t)(&ui_event_cbs, ns_id)); + pmap_del(uint32_t)(&ui_event_cbs, ns_id); + } + ui_comp_update_ext(); + ui_schedule_refresh(); +} -- cgit From db2e5f46f5aa5a6300395eaa9c4923835683c770 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 1 Sep 2022 16:37:29 +0800 Subject: fix(lua): make ui_attach()/ui_detach() take effect immediately (#20037) --- src/nvim/ui_compositor.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 5167f291c3..b8c7834e2b 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -749,7 +749,7 @@ void ui_comp_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) *item = event_cb; ui_comp_update_ext(); - ui_schedule_refresh(); + ui_refresh(); } void ui_comp_remove_cb(uint32_t ns_id) @@ -759,5 +759,5 @@ void ui_comp_remove_cb(uint32_t ns_id) pmap_del(uint32_t)(&ui_event_cbs, ns_id); } ui_comp_update_ext(); - ui_schedule_refresh(); + ui_refresh(); } -- cgit From 2dd55f81f736d5fe9697cd0e15c96f763eb90458 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Fri, 2 Sep 2022 17:44:14 +0600 Subject: fix(ui): ui compositor does not correctly free event callbacks Prior to this PR, when freeing event callbacks, UI compositor did not free the luarefs which could cause potential memory leaks. This PR fixes that by freeing the luarefs properly. --- src/nvim/ui_compositor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index b8c7834e2b..2fb70eae8a 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -98,7 +98,7 @@ void ui_comp_free_all_mem(void) { UIEventCallback *event_cb; map_foreach_value(&ui_event_cbs, event_cb, { - xfree(event_cb); + free_ui_event_callback(event_cb); }) pmap_destroy(uint32_t)(&ui_event_cbs); } -- cgit From 708bd686516b420c2b65f4bc4d2c58fe43fb945e Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 13 Sep 2022 12:56:30 +0200 Subject: feat(ui): use msg_grid based implementation for cmdheight=0 --- src/nvim/ui_compositor.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 2fb70eae8a..9f9a32036c 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -485,6 +485,10 @@ static void compose_debug(Integer startrow, Integer endrow, Integer startcol, In endcol = MIN(endcol, default_grid.cols); int attr = syn_id2attr(syn_id); + if (delay) { + debug_delay(endrow - startrow); + } + for (int row = (int)startrow; row < endrow; row++) { ui_composed_call_raw_line(1, row, startcol, startcol, endcol, attr, false, (const schar_T *)linebuf, @@ -610,7 +614,7 @@ static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrol if (row > msg_current_row && ui_comp_should_draw()) { compose_area(MAX(msg_current_row - 1, 0), row, 0, default_grid.cols); } else if (row < msg_current_row && ui_comp_should_draw() - && msg_current_row < Rows) { + && (msg_current_row < Rows || (scrolled && !msg_was_scrolled))) { int delta = msg_current_row - (int)row; if (msg_grid.blending) { int first_row = MAX((int)row - (scrolled?1:0), 0); -- cgit From 00cfc1dcebd1c81dd0d8c111740782e86cf2e385 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 16 Sep 2022 19:21:32 +0200 Subject: fix(redraw): avoid unnecessary redraws and glitches with floats+messages fixes #20106 fixes #20229 --- src/nvim/ui_compositor.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 9f9a32036c..f23615180e 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -590,12 +590,14 @@ static void ui_comp_raw_line(UI *ui, Integer grid, Integer row, Integer startcol /// The screen is invalid and will soon be cleared /// /// Don't redraw floats until screen is cleared -void ui_comp_set_screen_valid(bool valid) +bool ui_comp_set_screen_valid(bool valid) { + bool old_val = valid_screen; valid_screen = valid; if (!valid) { msg_sep_row = -1; } + return old_val; } static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrolled, -- cgit From 91e912f8d40284c74d4a997c8c95961eebb35d91 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 25 Sep 2022 15:26:37 +0200 Subject: refactor: move klib out of src/nvim/ #20341 It's confusing to mix vendored dependencies with neovim source code. A clean separation is simpler to keep track of and simpler to document. --- src/nvim/ui_compositor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index f23615180e..8ef24b484e 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -11,12 +11,12 @@ #include #include +#include "klib/kvec.h" #include "nvim/api/private/helpers.h" #include "nvim/ascii.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/highlight_group.h" -#include "nvim/lib/kvec.h" #include "nvim/log.h" #include "nvim/lua/executor.h" #include "nvim/main.h" -- cgit From 6679687bb3909f853ae97dfa01ae08ea2baf7f97 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 26 Sep 2022 15:17:10 +0200 Subject: refactor(redraw): no type argument in update_screen() This was used in the past with assumption that curwin/curbuf is "special" but this has not been true since basically forever at this point. Reduce NOT_VALID/CLEAR panic in options.lua . These should not be set if an effect of the option is causing something which by itself invokes redraw_later(). --- src/nvim/ui_compositor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 8ef24b484e..47c83b8ed1 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -138,7 +138,7 @@ bool ui_comp_should_draw(void) /// /// TODO(bfredl): later on the compositor should just use win_float_pos events, /// though that will require slight event order adjustment: emit the win_pos -/// events in the beginning of update_screen(0), rather than in ui_flush() +/// events in the beginning of update_screen(), rather than in ui_flush() bool ui_comp_put_grid(ScreenGrid *grid, int row, int col, int height, int width, bool valid, bool on_top) { -- cgit From 784e498c4a9c1f03266ced5ec3f55c3a6c94b80d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 21 Oct 2022 14:47:44 +0200 Subject: refactor: clang-tidy fixes to silence clangd warning (#20683) * refactor: readability-uppercase-literal-suffix * refactor: readability-named-parameter * refactor: bugprone-suspicious-string-compare * refactor: google-readability-casting * refactor: readability-redundant-control-flow * refactor: bugprone-too-small-loop-variable * refactor: readability-non-const-parameter * refactor: readability-avoid-const-params-in-decls * refactor: google-readability-todo * refactor: readability-inconsistent-declaration-parameter-name * refactor: bugprone-suspicious-missing-comma * refactor: remove noisy or slow warnings --- src/nvim/ui_compositor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 47c83b8ed1..84e1a5e513 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -505,7 +505,7 @@ static void debug_delay(Integer lines) ui_call_flush(); uint64_t wd = (uint64_t)labs(p_wd); uint64_t factor = (uint64_t)MAX(MIN(lines, 5), 1); - os_microdelay(factor * wd * 1000u, true); + os_microdelay(factor * wd * 1000U, true); } static void compose_area(Integer startrow, Integer endrow, Integer startcol, Integer endcol) -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/ui_compositor.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 84e1a5e513..32bdb7d273 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -7,25 +7,30 @@ // Layer-based compositing: https://en.wikipedia.org/wiki/Digital_compositing #include +#include #include #include #include +#include +#include #include "klib/kvec.h" -#include "nvim/api/private/helpers.h" +#include "nvim/api/private/defs.h" #include "nvim/ascii.h" +#include "nvim/buffer_defs.h" +#include "nvim/globals.h" #include "nvim/grid.h" #include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/log.h" #include "nvim/lua/executor.h" -#include "nvim/main.h" +#include "nvim/macros.h" #include "nvim/map.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/os/os.h" -#include "nvim/popupmenu.h" -#include "nvim/ugrid.h" +#include "nvim/option_defs.h" +#include "nvim/os/time.h" +#include "nvim/types.h" #include "nvim/ui.h" #include "nvim/ui_compositor.h" #include "nvim/vim.h" -- cgit From 282dda643ae598d5c8e9f34c379d931563b4891b Mon Sep 17 00:00:00 2001 From: Andrew Willette Date: Wed, 30 Nov 2022 14:32:57 -0600 Subject: fix(ui-ext): log and clear error in ui_comp_event (#21147) * fix: log and clear error in ui_comp_event * fix: handling error in each map_foreach_value iteration * fix: handling error decl in for_each loop * fix: updating initerr to const, removing initerr free-ing * fix: using ERROR_SET for error check * fix: wrapping ERROR_INIT in parens to allow for including inside macro --- src/nvim/ui_compositor.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 32bdb7d273..26a17ef747 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -706,15 +706,18 @@ static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer hei static void ui_comp_event(UI *ui, char *name, Array args) { - Error err = ERROR_INIT; UIEventCallback *event_cb; bool handled = false; - map_foreach_value(&ui_event_cbs, event_cb, { + Error err = ERROR_INIT; Object res = nlua_call_ref(event_cb->cb, name, args, false, &err); if (res.type == kObjectTypeBoolean && res.data.boolean == true) { handled = true; } + if (ERROR_SET(&err)) { + ELOG("Error while executing ui_comp_event callback: %s", err.msg); + } + api_clear_error(&err); }) if (!handled) { -- cgit From 47ba78f89a1f0bba8168b4408bc55a3024d5ab97 Mon Sep 17 00:00:00 2001 From: bfredl Date: Fri, 30 Dec 2022 22:17:01 +0100 Subject: refactor(ui): devirtualize the ui layer - The defined interface for the UI is only the RPC protocol. The original UI interface as an array of function pointers fill no function. - On the server, all the UI:s are all RPC channels. - ui.c is only used on the server. - The compositor is a preprocessing step for single-grid UI:s - on the client, ui_client and tui talk directly to each other - we still do module separation, as ui_client.c could form the basis of a libnvim client module later. Items for later PR:s - vim.ui_attach is still an unhappy child, reconsider based on plugin experience. - the flags in ui_events.in.h are still a mess. Can be simplified now. - UX for remote attachment needs more work. - startup for client can be simplified further (think of the millisecs we can save) --- src/nvim/ui_compositor.c | 133 ++++------------------------------------------- 1 file changed, 9 insertions(+), 124 deletions(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 26a17ef747..0f9b0af1c1 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -23,7 +23,6 @@ #include "nvim/highlight.h" #include "nvim/highlight_group.h" #include "nvim/log.h" -#include "nvim/lua/executor.h" #include "nvim/macros.h" #include "nvim/map.h" #include "nvim/memory.h" @@ -39,7 +38,6 @@ # include "ui_compositor.c.generated.h" #endif -static UI *compositor = NULL; static int composed_uis = 0; kvec_t(ScreenGrid *) layers = KV_INITIAL_VALUE; @@ -60,52 +58,12 @@ static bool msg_was_scrolled = false; static int msg_sep_row = -1; static schar_T msg_sep_char = { ' ', NUL }; -static PMap(uint32_t) ui_event_cbs = MAP_INIT; - static int dbghl_normal, dbghl_clear, dbghl_composed, dbghl_recompose; void ui_comp_init(void) { - if (compositor != NULL) { - return; - } - compositor = xcalloc(1, sizeof(UI)); - - compositor->rgb = true; - compositor->grid_resize = ui_comp_grid_resize; - compositor->grid_scroll = ui_comp_grid_scroll; - compositor->grid_cursor_goto = ui_comp_grid_cursor_goto; - compositor->raw_line = ui_comp_raw_line; - compositor->msg_set_pos = ui_comp_msg_set_pos; - compositor->event = ui_comp_event; - - // Be unopinionated: will be attached together with a "real" ui anyway - compositor->width = INT_MAX; - compositor->height = INT_MAX; - for (UIExtension i = kUIGlobalCount; (int)i < kUIExtCount; i++) { - compositor->ui_ext[i] = true; - } - - // TODO(bfredl): one day. in the future. - compositor->ui_ext[kUIMultigrid] = false; - - // TODO(bfredl): this will be more complicated if we implement - // hlstate per UI (i e reduce hl ids for non-hlstate UIs) - compositor->ui_ext[kUIHlState] = false; - kv_push(layers, &default_grid); curgrid = &default_grid; - - ui_attach_impl(compositor, 0); -} - -void ui_comp_free_all_mem(void) -{ - UIEventCallback *event_cb; - map_foreach_value(&ui_event_cbs, event_cb, { - free_ui_event_callback(event_cb); - }) - pmap_destroy(uint32_t)(&ui_event_cbs); } void ui_comp_syn_init(void) @@ -258,7 +216,7 @@ bool ui_comp_set_grid(handle_T handle) return false; } -static void ui_comp_raise_grid(ScreenGrid *grid, size_t new_index) +void ui_comp_raise_grid(ScreenGrid *grid, size_t new_index) { size_t old_index = grid->comp_index; for (size_t i = old_index; i < new_index; i++) { @@ -278,7 +236,7 @@ static void ui_comp_raise_grid(ScreenGrid *grid, size_t new_index) } } -static void ui_comp_grid_cursor_goto(UI *ui, Integer grid_handle, Integer r, Integer c) +void ui_comp_grid_cursor_goto(Integer grid_handle, Integer r, Integer c) { if (!ui_comp_should_draw() || !ui_comp_set_grid((int)grid_handle)) { return; @@ -538,9 +496,9 @@ void ui_comp_compose_grid(ScreenGrid *grid) } } -static void ui_comp_raw_line(UI *ui, Integer grid, Integer row, Integer startcol, Integer endcol, - Integer clearcol, Integer clearattr, LineFlags flags, - const schar_T *chunk, const sattr_T *attrs) +void ui_comp_raw_line(Integer grid, Integer row, Integer startcol, Integer endcol, Integer clearcol, + Integer clearattr, LineFlags flags, const schar_T *chunk, + const sattr_T *attrs) { if (!ui_comp_should_draw() || !ui_comp_set_grid((int)grid)) { return; @@ -605,8 +563,7 @@ bool ui_comp_set_screen_valid(bool valid) return old_val; } -static void ui_comp_msg_set_pos(UI *ui, Integer grid, Integer row, Boolean scrolled, - String sep_char) +void ui_comp_msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep_char) { msg_grid.comp_row = (int)row; if (scrolled && row > 0) { @@ -650,8 +607,8 @@ static bool curgrid_covered_above(int row) return kv_size(layers) - (above_msg?1:0) > curgrid->comp_index + 1; } -static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, Integer left, - Integer right, Integer rows, Integer cols) +void ui_comp_grid_scroll(Integer grid, Integer top, Integer bot, Integer left, Integer right, + Integer rows, Integer cols) { if (!ui_comp_should_draw() || !ui_comp_set_grid((int)grid)) { return; @@ -685,7 +642,7 @@ static void ui_comp_grid_scroll(UI *ui, Integer grid, Integer top, Integer bot, } } -static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer height) +void ui_comp_grid_resize(Integer grid, Integer width, Integer height) { if (grid == 1) { ui_composed_call_grid_resize(1, width, height); @@ -703,75 +660,3 @@ static void ui_comp_grid_resize(UI *ui, Integer grid, Integer width, Integer hei } } } - -static void ui_comp_event(UI *ui, char *name, Array args) -{ - UIEventCallback *event_cb; - bool handled = false; - map_foreach_value(&ui_event_cbs, event_cb, { - Error err = ERROR_INIT; - Object res = nlua_call_ref(event_cb->cb, name, args, false, &err); - if (res.type == kObjectTypeBoolean && res.data.boolean == true) { - handled = true; - } - if (ERROR_SET(&err)) { - ELOG("Error while executing ui_comp_event callback: %s", err.msg); - } - api_clear_error(&err); - }) - - if (!handled) { - ui_composed_call_event(name, args); - } -} - -static void ui_comp_update_ext(void) -{ - memset(compositor->ui_ext, 0, ARRAY_SIZE(compositor->ui_ext)); - - for (size_t i = 0; i < kUIGlobalCount; i++) { - UIEventCallback *event_cb; - - map_foreach_value(&ui_event_cbs, event_cb, { - if (event_cb->ext_widgets[i]) { - compositor->ui_ext[i] = true; - break; - } - }) - } -} - -void free_ui_event_callback(UIEventCallback *event_cb) -{ - api_free_luaref(event_cb->cb); - xfree(event_cb); -} - -void ui_comp_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) -{ - UIEventCallback *event_cb = xcalloc(1, sizeof(UIEventCallback)); - event_cb->cb = cb; - memcpy(event_cb->ext_widgets, ext_widgets, ARRAY_SIZE(event_cb->ext_widgets)); - if (event_cb->ext_widgets[kUIMessages]) { - event_cb->ext_widgets[kUICmdline] = true; - } - - UIEventCallback **item = (UIEventCallback **)pmap_ref(uint32_t)(&ui_event_cbs, ns_id, true); - if (*item) { - free_ui_event_callback(*item); - } - *item = event_cb; - - ui_comp_update_ext(); - ui_refresh(); -} - -void ui_comp_remove_cb(uint32_t ns_id) -{ - if (pmap_has(uint32_t)(&ui_event_cbs, ns_id)) { - free_ui_event_callback(pmap_get(uint32_t)(&ui_event_cbs, ns_id)); - pmap_del(uint32_t)(&ui_event_cbs, ns_id); - } - ui_comp_update_ext(); - ui_refresh(); -} -- cgit From 149209400383c673fdb4fdd1c9a7639139f17936 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Mon, 9 Jan 2023 14:13:06 +0100 Subject: refactor: replace char_u with char 17 - remove STRLCPY (#21235) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/ui_compositor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui_compositor.c') diff --git a/src/nvim/ui_compositor.c b/src/nvim/ui_compositor.c index 0f9b0af1c1..ad44e2ca22 100644 --- a/src/nvim/ui_compositor.c +++ b/src/nvim/ui_compositor.c @@ -569,7 +569,7 @@ void ui_comp_msg_set_pos(Integer grid, Integer row, Boolean scrolled, String sep if (scrolled && row > 0) { msg_sep_row = (int)row - 1; if (sep_char.data) { - STRLCPY(msg_sep_char, sep_char.data, sizeof(msg_sep_char)); + xstrlcpy(msg_sep_char, sep_char.data, sizeof(msg_sep_char)); } } else { msg_sep_row = -1; -- cgit