From 625e990976540a0e2d2bccb98deb57d0919d1e89 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 8 Feb 2023 16:16:16 +0100 Subject: refactor(ui): cleanup 'redrawdebug', introduce "flush" mode --- src/nvim/ui.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 9f1cb87eb0..b22dc4a661 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -419,7 +419,7 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, (const sattr_T *)grid->attrs + off); // 'writedelay': flush & delay each time. - if (p_wd && !(rdb_flags & RDB_COMPOSITOR)) { + if (p_wd && (rdb_flags & RDB_LINE)) { // If 'writedelay' is active, set the cursor to indicate what was drawn. ui_call_grid_cursor_goto(grid->handle, row, MIN(clearcol, (int)grid->cols - 1)); @@ -510,6 +510,10 @@ void ui_flush(void) pending_has_mouse = has_mouse; } ui_call_flush(); + + if (p_wd && (rdb_flags & RDB_FLUSH)) { + os_microdelay((uint64_t)labs(p_wd) * 1000U, true); + } } /// Check if 'mouse' is active for the current mode -- cgit From 30b29a36e80bfeed50bb6ea618401fe35100490f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 9 Feb 2023 20:56:30 +0100 Subject: refactor(ui): remove some superfluous ui_flush() calls - mapping has no business saving and restoring the low-level UI cursor. The cursor will be put in a reasonable position after input is processed, chill out. - TUI handles output needed for suspend - vgetc() family of function does flushing --- src/nvim/ui.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index b22dc4a661..8172a46773 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -472,11 +472,6 @@ int ui_current_col(void) return cursor_col; } -handle_T ui_cursor_grid(void) -{ - return cursor_grid_handle; -} - void ui_flush(void) { assert(!ui_client_channel_id); -- cgit From 46a87a5d2bac598fed0870f0d3c926087f95d30f Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 14 Feb 2023 05:19:04 -0500 Subject: refactor(api): VALIDATE macros #22187 Problem: - API validation involves too much boilerplate. - API validation errors are not consistently worded. Solution: Introduce some macros. Currently these are clumsy, but they at least help with consistency and avoid some nesting. --- src/nvim/ui.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 8172a46773..1693595ce8 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -11,6 +11,7 @@ #include "klib/kvec.h" #include "nvim/api/private/helpers.h" +#include "nvim/api/private/validate.h" #include "nvim/api/ui.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" @@ -608,7 +609,7 @@ Array ui_array(void) return all_uis; } -void ui_grid_resize(handle_T grid_handle, int width, int height, Error *error) +void ui_grid_resize(handle_T grid_handle, int width, int height, Error *err) { if (grid_handle == DEFAULT_GRID_HANDLE) { screen_resize(width, height); @@ -616,11 +617,9 @@ void ui_grid_resize(handle_T grid_handle, int width, int height, Error *error) } win_T *wp = get_win_by_grid_handle(grid_handle); - if (wp == NULL) { - api_set_error(error, kErrorTypeValidation, - "No window with the given handle"); + VALIDATE_INT((wp != NULL), "window handle", (int64_t)grid_handle, { return; - } + }); if (wp->w_floating) { if (width != wp->w_width || height != wp->w_height) { -- cgit From 6942528a54eacbcdcb5b40fa27f9e37ae9e80915 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sat, 25 Feb 2023 21:04:52 +0100 Subject: refactor(ui): ui_log() can now just be a function --- src/nvim/ui.c | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 1693595ce8..a2c6d9431c 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -64,31 +64,31 @@ static int pending_has_mouse = -1; static Array call_buf = ARRAY_DICT_INIT; #if MIN_LOG_LEVEL > LOGLVL_DBG -# define UI_LOG(funname) +# define ui_log(funname) #else static size_t uilog_seen = 0; -static char uilog_last_event[1024] = { 0 }; +static const char *uilog_last_event = NULL; +static void ui_log(const char *funname) +{ # ifndef EXITFREE -# define entered_free_all_mem false + if (entered_free_all_mem) { + return; // do nothing, we cannot log now + } # endif -# define UI_LOG(funname) \ - do { \ - if (entered_free_all_mem) { \ - /* do nothing, we cannot log now */ \ - } else if (strequal(uilog_last_event, STR(funname))) { \ - uilog_seen++; \ - } else { \ - if (uilog_seen > 0) { \ - logmsg(LOGLVL_DBG, "UI: ", NULL, -1, true, \ - "%s (+%zu times...)", uilog_last_event, uilog_seen); \ - } \ - logmsg(LOGLVL_DBG, "UI: ", NULL, -1, true, STR(funname)); \ - uilog_seen = 0; \ - xstrlcpy(uilog_last_event, STR(funname), sizeof(uilog_last_event)); \ - } \ - } while (0) + if (uilog_last_event == funname) { + uilog_seen++; + } else { + if (uilog_seen > 0) { + logmsg(LOGLVL_DBG, "UI: ", NULL, -1, true, + "%s (+%zu times...)", uilog_last_event, uilog_seen); + } + logmsg(LOGLVL_DBG, "UI: ", NULL, -1, true, "%s", funname); + uilog_seen = 0; + uilog_last_event = funname; + } +} #endif // UI_CALL invokes a function on all registered UI instances. @@ -105,7 +105,7 @@ static char uilog_last_event[1024] = { 0 }; } \ } \ if (any_call) { \ - UI_LOG(funname); \ + ui_log(STR(funname)); \ } \ } while (0) @@ -654,6 +654,8 @@ void ui_call_event(char *name, Array args) if (!handled) { UI_CALL(true, event, ui, name, args); } + + ui_log(name); } void ui_cb_update_ext(void) -- cgit From 659234c95a23307486a4b7496f3f4391a4bdbe58 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 26 Feb 2023 13:55:29 +0100 Subject: fix(build): fix invalid use of EXITFREE fixup 6942528 refactor(ui): ui_log() can now just be a function --- src/nvim/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index a2c6d9431c..73545441d3 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -71,7 +71,7 @@ static const char *uilog_last_event = NULL; static void ui_log(const char *funname) { -# ifndef EXITFREE +# ifdef EXITFREE if (entered_free_all_mem) { return; // do nothing, we cannot log now } -- cgit From 7f424e2b65779c59fc0cac3cc7508ba2ec07f200 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Thu, 23 Feb 2023 18:29:36 +0100 Subject: feat(api): more fields in nvim_list_uis Problem: nvim_list_uis does not report all ":help ui-option" fields. Solution: Store ":help ui-option" fields on the `UI` object and update ui_array. --- src/nvim/ui.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 73545441d3..6c95579b47 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -598,6 +598,15 @@ Array ui_array(void) PUT(info, "height", INTEGER_OBJ(ui->height)); PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb)); PUT(info, "override", BOOLEAN_OBJ(ui->override)); + + // TUI fields. + PUT(info, "term_name", STRING_OBJ(cstr_to_string(ui->term_name))); + PUT(info, "term_background", STRING_OBJ(cstr_to_string(ui->term_background))); + PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors)); + PUT(info, "stdin_fd", INTEGER_OBJ(ui->stdin_fd)); + PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty)); + PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty)); + for (UIExtension j = 0; j < kUIExtCount; j++) { if (ui_ext_names[j][0] != '_' || ui->ui_ext[j]) { PUT(info, ui_ext_names[j], BOOLEAN_OBJ(ui->ui_ext[j])); -- cgit From ce597235a26839826de88ecd8b949ec54c310fbd Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Mon, 27 Feb 2023 16:31:05 +0100 Subject: feat(ui): restore has('gui_running') Problem: has('gui_running') is still common in the wild and our answer has changed over time, causing frustration. https://github.com/vimpostor/vim-tpipeline/commit/95a6ccbe9f33bc42dd4cee45731d8bc3fbcd92d1 Solution: Use stdin_tty/stdout_tty to decide if a UI is (not) a GUI. --- src/nvim/ui.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 6c95579b47..ce1a57350a 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -134,6 +134,7 @@ void ui_free_all_mem(void) } #endif +/// Returns true if any `rgb=true` UI is attached. bool ui_rgb_attached(void) { if (!headless_mode && p_tgc) { @@ -147,6 +148,18 @@ bool ui_rgb_attached(void) return false; } +/// Returns true if a GUI is attached. +bool ui_gui_attached(void) +{ + for (size_t i = 0; i < ui_count; i++) { + bool tui = uis[i]->stdin_tty || uis[i]->stdout_tty; + if (!tui) { + return true; + } + } + return false; +} + /// Returns true if any UI requested `override=true`. bool ui_override(void) { @@ -599,11 +612,10 @@ Array ui_array(void) PUT(info, "rgb", BOOLEAN_OBJ(ui->rgb)); PUT(info, "override", BOOLEAN_OBJ(ui->override)); - // TUI fields. + // TUI fields. (`stdin_fd` is intentionally omitted.) PUT(info, "term_name", STRING_OBJ(cstr_to_string(ui->term_name))); PUT(info, "term_background", STRING_OBJ(cstr_to_string(ui->term_background))); PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors)); - PUT(info, "stdin_fd", INTEGER_OBJ(ui->stdin_fd)); PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty)); PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty)); -- cgit From 2ba224e1526681c1a0b1b2b095b1ef2b0874db48 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 26 Feb 2023 12:51:03 +0100 Subject: refactor(log): reduce compile time LOG_LEVEL granularity --- src/nvim/ui.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index ce1a57350a..45959b7b67 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -63,9 +63,7 @@ static int pending_has_mouse = -1; static Array call_buf = ARRAY_DICT_INIT; -#if MIN_LOG_LEVEL > LOGLVL_DBG -# define ui_log(funname) -#else +#ifdef NVIM_LOG_DEBUG static size_t uilog_seen = 0; static const char *uilog_last_event = NULL; @@ -89,6 +87,8 @@ static void ui_log(const char *funname) uilog_last_event = funname; } } +#else +# define ui_log(funname) #endif // UI_CALL invokes a function on all registered UI instances. -- cgit From 0d2fe7786537ef63d0d3ed1e94546eb3ee35a368 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 23 Apr 2023 19:02:23 +0200 Subject: refactor(time): refactor delay with input checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, there were three low-level delay entry points - os_delay(ms, ignoreinput=true): sleep for ms, only break on got_int - os_delay(ms, ignoreinput=false): sleep for ms, break on any key input os_microdelay(us, false): equivalent, but in μs (not directly called) - os_microdelay(us, true): sleep for μs, never break. The implementation of the latter two both used uv_cond_timedwait() This could have been for two reasons: 1. allow another thread to "interrupt" the wait 2. uv_cond_timedwait() has higher resolution than uv_sleep() However we (1) never used the first, even when TUI was a thread, and (2) nowhere in the codebase are we using μs resolution, it is always a ms multiplied with 1000. In addition, os_delay(ms, false) would completely block the thread for 100ms intervals and in between check for input. This is not how event handling is done alound here. Therefore: Replace the implementation of os_delay(ms, false) to use LOOP_PROCESS_EVENTS_UNTIL which does a proper epoll wait with a timeout, instead of the 100ms timer panic. Replace os_microdelay(us, false) with a direct wrapper of uv_sleep. --- src/nvim/ui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 45959b7b67..6d09b9f3a3 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -439,7 +439,7 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, MIN(clearcol, (int)grid->cols - 1)); ui_call_flush(); uint64_t wd = (uint64_t)labs(p_wd); - os_microdelay(wd * 1000U, true); + os_sleep(wd); pending_cursor_update = true; // restore the cursor later } } @@ -521,7 +521,7 @@ void ui_flush(void) ui_call_flush(); if (p_wd && (rdb_flags & RDB_FLUSH)) { - os_microdelay((uint64_t)labs(p_wd) * 1000U, true); + os_sleep((uint64_t)labs(p_wd)); } } -- cgit From e2fdd53d8c015913e8be4ff708fc3488558c8906 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 14 May 2023 18:45:56 +0200 Subject: refactor(map): avoid duplicated khash_t types for values This reduces the total number of khash_t instantiations from 22 to 8. Make the khash internal functions take the size of values as a runtime parameter. This is abstracted with typesafe Map containers which are still specialized for both key, value type. Introduce `Set(key)` type for when there is no value. Refactor shada.c to use Map/Set instead of khash directly. This requires `map_ref` operation to be more flexible. Return pointers to both key and value, plus an indicator for new_item. As a bonus, `map_key` is now redundant. Instead of Map(cstr_t, FileMarks), use a pointer map as the FileMarks struct is humongous. Make `event_strings` actually work like an intern pool instead of wtf it was doing before. --- src/nvim/ui.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 6d09b9f3a3..24f20af2f3 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -127,10 +127,10 @@ void ui_free_all_mem(void) kv_destroy(call_buf); UIEventCallback *event_cb; - map_foreach_value(&ui_event_cbs, event_cb, { + pmap_foreach_value(&ui_event_cbs, event_cb, { free_ui_event_callback(event_cb); }) - pmap_destroy(uint32_t)(&ui_event_cbs); + map_destroy(uint32_t, &ui_event_cbs); } #endif @@ -660,7 +660,7 @@ void ui_call_event(char *name, Array args) { UIEventCallback *event_cb; bool handled = false; - map_foreach_value(&ui_event_cbs, event_cb, { + pmap_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) { @@ -686,7 +686,7 @@ void ui_cb_update_ext(void) for (size_t i = 0; i < kUIGlobalCount; i++) { UIEventCallback *event_cb; - map_foreach_value(&ui_event_cbs, event_cb, { + pmap_foreach_value(&ui_event_cbs, event_cb, { if (event_cb->ext_widgets[i]) { ui_cb_ext[i] = true; break; @@ -710,9 +710,9 @@ void ui_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) event_cb->ext_widgets[kUICmdline] = true; } - UIEventCallback **item = (UIEventCallback **)pmap_ref(uint32_t)(&ui_event_cbs, ns_id, true); + ptr_t *item = pmap_put_ref(uint32_t)(&ui_event_cbs, ns_id, NULL, NULL); if (*item) { - free_ui_event_callback(*item); + free_ui_event_callback((UIEventCallback *)(*item)); } *item = event_cb; @@ -723,8 +723,8 @@ void ui_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) void ui_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); + UIEventCallback *item = pmap_del(uint32_t)(&ui_event_cbs, ns_id, NULL); + free_ui_event_callback(item); } ui_cb_update_ext(); ui_refresh(); -- cgit From cfd4fdfea4d0e68ea50ad412b88b5289ded6fd6f Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Tue, 23 May 2023 14:25:10 +0600 Subject: refactor(api): new helper macros Adds new API helper macros `CSTR_AS_OBJ()`, `STATIC_CSTR_AS_OBJ()`, and `STATIC_CSTR_TO_OBJ()`, which cleans up a lot of the current code. These macros will also be used extensively in the upcoming option refactor PRs because then API Objects will be used to get/set options. This PR also modifies pre-existing code to use old API helper macros like `CSTR_TO_OBJ()` to make them cleaner. --- src/nvim/ui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 24f20af2f3..8c31032492 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -613,8 +613,8 @@ Array ui_array(void) PUT(info, "override", BOOLEAN_OBJ(ui->override)); // TUI fields. (`stdin_fd` is intentionally omitted.) - PUT(info, "term_name", STRING_OBJ(cstr_to_string(ui->term_name))); - PUT(info, "term_background", STRING_OBJ(cstr_to_string(ui->term_background))); + PUT(info, "term_name", CSTR_TO_OBJ(ui->term_name)); + PUT(info, "term_background", CSTR_TO_OBJ(ui->term_background)); PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors)); PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty)); PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty)); -- cgit From 43d66c0ebbe43f40a1f76e1635ccef6181c01317 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Thu, 11 May 2023 10:48:48 +0800 Subject: fix(ui-ext): send title to newly-attached UI --- src/nvim/ui.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 8c31032492..87a0271f3d 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -15,7 +15,7 @@ #include "nvim/api/ui.h" #include "nvim/ascii.h" #include "nvim/autocmd.h" -#include "nvim/buffer_defs.h" +#include "nvim/buffer.h" #include "nvim/cursor_shape.h" #include "nvim/drawscreen.h" #include "nvim/ex_getln.h" @@ -348,6 +348,7 @@ void ui_attach_impl(UI *ui, uint64_t chanid) uis[ui_count++] = ui; ui_refresh_options(); + resettitle(); for (UIExtension i = kUIGlobalCount; (int)i < kUIExtCount; i++) { ui_set_ext_option(ui, i, ui->ui_ext[i]); -- cgit From b3d5138fd0066fda26ef7724a542ae45eb42fc84 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Wed, 7 Jun 2023 06:05:16 +0600 Subject: refactor(options): remove `getoption_T` and introduce `OptVal` (#23850) Removes the `getoption_T` struct and also introduces the `OptVal` struct to unify the methods of getting/setting different option value types. This is the first of many PRs to reduce code duplication in the Vim option code as well as to make options easier to maintain. It also increases the flexibility and extensibility of options. Which opens the door for things like Array and Dictionary options. --- src/nvim/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 87a0271f3d..7d8328d913 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -229,7 +229,7 @@ void ui_refresh(void) p_lz = save_p_lz; if (ext_widgets[kUIMessages]) { - set_option_value("cmdheight", 0L, NULL, 0); + set_option_value("cmdheight", NUMBER_OPTVAL(0), 0); command_height(); } ui_mode_info_set(); -- cgit From 5970157e1d22fd5e05ae5d3bd949f807fb7a744c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 17 May 2023 16:08:06 +0200 Subject: refactor(map): enhanced implementation, Clean Code™, etc etc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This involves two redesigns of the map.c implementations: 1. Change of macro style and code organization The old khash.h and map.c implementation used huge #define blocks with a lot of backslash line continuations. This instead uses the "implementation file" .c.h pattern. Such a file is meant to be included multiple times, with different macros set prior to inclusion as parameters. we already use this pattern e.g. for eval/typval_encode.c.h to implement different typval encoders reusing a similar structure. We can structure this code into two parts. one that only depends on key type and is enough to implement sets, and one which depends on both key and value to implement maps (as a wrapper around sets, with an added value[] array) 2. Separate the main hash buckets from the key / value arrays Change the hack buckets to only contain an index into separate key / value arrays This is a common pattern in modern, state of the art hashmap implementations. Even though this leads to one more allocated array, it is this often is a net reduction of memory consumption. Consider key+value consuming at least 12 bytes per pair. On average, we will have twice as many buckets per item. Thus old implementation: 2*12 = 24 bytes per item New implementation 1*12 + 2*4 = 20 bytes per item And the difference gets bigger with larger items. One might think we have pulled a fast one here, as wouldn't the average size of the new key/value arrays be 1.5 slots per items due to amortized grows? But remember, these arrays are fully dense, and thus the accessed memory, measured in _cache lines_, the unit which actually matters, will be the fully used memory but just rounded up to the nearest cache line boundary. This has some other interesting properties, such as an insert-only set/map will be fully ordered by insert only. Preserving this ordering in face of deletions is more tricky tho. As we currently don't use ordered maps, the "delete" operation maintains compactness of the item arrays in the simplest way by breaking the ordering. It would be possible to implement an order-preserving delete although at some cost, like allowing the items array to become non-dense until the next rehash. Finally, in face of these two major changes, all code used in khash.h has been integrated into map.c and friends. Given the heavy edits it makes no sense to "layer" the code into a vendored and a wrapper part. Rather, the layered cake follows the specialization depth: code shared for all maps, code specialized to a key type (and its equivalence relation), and finally code specialized to value+key type. --- src/nvim/ui.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 7d8328d913..ba16ba545f 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -127,7 +127,7 @@ void ui_free_all_mem(void) kv_destroy(call_buf); UIEventCallback *event_cb; - pmap_foreach_value(&ui_event_cbs, event_cb, { + map_foreach_value(&ui_event_cbs, event_cb, { free_ui_event_callback(event_cb); }) map_destroy(uint32_t, &ui_event_cbs); @@ -661,7 +661,7 @@ void ui_call_event(char *name, Array args) { UIEventCallback *event_cb; bool handled = false; - pmap_foreach_value(&ui_event_cbs, event_cb, { + 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) { @@ -687,7 +687,7 @@ void ui_cb_update_ext(void) for (size_t i = 0; i < kUIGlobalCount; i++) { UIEventCallback *event_cb; - pmap_foreach_value(&ui_event_cbs, event_cb, { + map_foreach_value(&ui_event_cbs, event_cb, { if (event_cb->ext_widgets[i]) { ui_cb_ext[i] = true; break; @@ -723,7 +723,7 @@ void ui_add_cb(uint32_t ns_id, LuaRef cb, bool *ext_widgets) void ui_remove_cb(uint32_t ns_id) { - if (pmap_has(uint32_t)(&ui_event_cbs, ns_id)) { + if (map_has(uint32_t, &ui_event_cbs, ns_id)) { UIEventCallback *item = pmap_del(uint32_t)(&ui_event_cbs, ns_id, NULL); free_ui_event_callback(item); } -- cgit From b85f1dafc7c0a19704135617454f1c66f41202c1 Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 27 Sep 2023 22:21:17 +0200 Subject: refactor(messages): fold msg_attr into msg problem: there are too many different functions in message.c solution: fold some of the functions into themselves --- src/nvim/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index ba16ba545f..b0d4a58b82 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -332,7 +332,7 @@ void vim_beep(unsigned val) // comes from. if (vim_strchr(p_debug, 'e') != NULL) { msg_source(HL_ATTR(HLF_W)); - msg_attr(_("Beep!"), HL_ATTR(HLF_W)); + msg(_("Beep!"), HL_ATTR(HLF_W)); } } -- cgit From af7d317f3ff31d5ac5d8724b5057a422e1451b54 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 26 Sep 2023 22:36:08 +0200 Subject: refactor: remove long long is 32-bits even on 64-bit windows which makes the type suboptimal for a codebase meant to be cross-platform. --- src/nvim/ui.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index b0d4a58b82..fc40d6fcfe 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -439,7 +439,7 @@ void ui_line(ScreenGrid *grid, int row, int startcol, int endcol, int clearcol, ui_call_grid_cursor_goto(grid->handle, row, MIN(clearcol, (int)grid->cols - 1)); ui_call_flush(); - uint64_t wd = (uint64_t)labs(p_wd); + uint64_t wd = (uint64_t)llabs(p_wd); os_sleep(wd); pending_cursor_update = true; // restore the cursor later } @@ -522,7 +522,7 @@ void ui_flush(void) ui_call_flush(); if (p_wd && (rdb_flags & RDB_FLUSH)) { - os_sleep((uint64_t)labs(p_wd)); + os_sleep((uint64_t)llabs(p_wd)); } } -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- src/nvim/ui.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index fc40d6fcfe..954d933d9c 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -30,6 +30,7 @@ #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" +#include "nvim/option_vars.h" #include "nvim/os/time.h" #include "nvim/strings.h" #include "nvim/ui.h" -- cgit From d7359a87425dc38efda4f74bd580bae9946abe31 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 1 Nov 2023 12:16:37 +0800 Subject: fix(startup): trigger UIEnter for the correct channel (#25860) --- src/nvim/ui.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 954d933d9c..90d475e7e7 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -337,6 +337,16 @@ void vim_beep(unsigned val) } } +/// Trigger UIEnter for all attached UIs. +/// Used on startup after VimEnter. +void do_autocmd_uienter_all(void) +{ + for (size_t i = 0; i < ui_count; i++) { + UIData *data = uis[i]->data; + do_autocmd_uienter(data->channel_id, true); + } +} + void ui_attach_impl(UI *ui, uint64_t chanid) { if (ui_count == MAX_UI_COUNT) { -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- src/nvim/ui.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 90d475e7e7..dc38c061b0 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -1,6 +1,3 @@ -// 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 #include #include -- cgit From 8d9789a0f3b748b75ac4ae1b8e43d27af40d49fe Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Tue, 7 Nov 2023 11:31:21 -0600 Subject: docs: deprecate the "term_background" UI field --- src/nvim/ui.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index dc38c061b0..3e5bfba315 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -623,7 +623,10 @@ Array ui_array(void) // TUI fields. (`stdin_fd` is intentionally omitted.) PUT(info, "term_name", CSTR_TO_OBJ(ui->term_name)); - PUT(info, "term_background", CSTR_TO_OBJ(ui->term_background)); + + // term_background is deprecated. Populate with an empty string + PUT(info, "term_background", CSTR_TO_OBJ("")); + PUT(info, "term_colors", INTEGER_OBJ(ui->term_colors)); PUT(info, "stdin_tty", BOOLEAN_OBJ(ui->stdin_tty)); PUT(info, "stdout_tty", BOOLEAN_OBJ(ui->stdout_tty)); -- cgit From 326d46f690b383846f136f2a25523cffe2882f27 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 16 Nov 2023 09:54:47 +0800 Subject: refactor: move some functions to winfloat.c (#26020) --- src/nvim/ui.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 3e5bfba315..a2791be583 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -35,6 +35,7 @@ #include "nvim/ui_compositor.h" #include "nvim/vim.h" #include "nvim/window.h" +#include "nvim/winfloat.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui.c.generated.h" -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- src/nvim/ui.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index a2791be583..3cc07b835e 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -10,7 +10,7 @@ #include "nvim/api/private/helpers.h" #include "nvim/api/private/validate.h" #include "nvim/api/ui.h" -#include "nvim/ascii.h" +#include "nvim/ascii_defs.h" #include "nvim/autocmd.h" #include "nvim/buffer.h" #include "nvim/cursor_shape.h" @@ -23,7 +23,7 @@ #include "nvim/highlight_defs.h" #include "nvim/log.h" #include "nvim/lua/executor.h" -#include "nvim/map.h" +#include "nvim/map_defs.h" #include "nvim/memory.h" #include "nvim/message.h" #include "nvim/option.h" @@ -33,7 +33,7 @@ #include "nvim/ui.h" #include "nvim/ui_client.h" #include "nvim/ui_compositor.h" -#include "nvim/vim.h" +#include "nvim/vim_defs.h" #include "nvim/window.h" #include "nvim/winfloat.h" -- cgit From a6cba103cebce535279db197f9efeb34e9d1171f Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 29 Nov 2023 20:32:40 +0800 Subject: refactor: move some constants out of vim_defs.h (#26298) --- src/nvim/ui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/ui.c') diff --git a/src/nvim/ui.c b/src/nvim/ui.c index 3cc07b835e..36f34bc75a 100644 --- a/src/nvim/ui.c +++ b/src/nvim/ui.c @@ -29,11 +29,11 @@ #include "nvim/option.h" #include "nvim/option_vars.h" #include "nvim/os/time.h" +#include "nvim/state_defs.h" #include "nvim/strings.h" #include "nvim/ui.h" #include "nvim/ui_client.h" #include "nvim/ui_compositor.h" -#include "nvim/vim_defs.h" #include "nvim/window.h" #include "nvim/winfloat.h" -- cgit