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.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/nvim/ui.h') diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 996b3467a6..9034e7b764 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -69,6 +69,11 @@ struct ui_t { void (*inspect)(UI *ui, Dictionary *info); }; +typedef struct ui_event_callback { + LuaRef cb; + bool ext_widgets[kUIGlobalCount]; +} UIEventCallback; + #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui.h.generated.h" -- 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.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/nvim/ui.h') diff --git a/src/nvim/ui.h b/src/nvim/ui.h index 9034e7b764..c28393476e 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -6,9 +6,14 @@ #include #include "nvim/api/private/defs.h" +#include "nvim/event/multiqueue.h" #include "nvim/globals.h" #include "nvim/highlight_defs.h" +#include "nvim/macros.h" #include "nvim/memory.h" +#include "nvim/types.h" + +struct ui_t; typedef enum { kUICmdline = 0, @@ -74,11 +79,12 @@ typedef struct ui_event_callback { bool ext_widgets[kUIGlobalCount]; } UIEventCallback; +// uncrustify:off #ifdef INCLUDE_GENERATED_DECLARATIONS # include "ui.h.generated.h" - # include "ui_events_call.h.generated.h" #endif +// uncrustify:on EXTERN MultiQueue *resize_events; #endif // NVIM_UI_H -- 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.h | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) (limited to 'src/nvim/ui.h') diff --git a/src/nvim/ui.h b/src/nvim/ui.h index c28393476e..9140a9f1f3 100644 --- a/src/nvim/ui.h +++ b/src/nvim/ui.h @@ -52,6 +52,41 @@ enum { typedef int LineFlags; +typedef struct { + uint64_t channel_id; + +#define UI_BUF_SIZE 4096 ///< total buffer size for pending msgpack data. + /// guaranteed size available for each new event (so packing of simple events + /// and the header of grid_line will never fail) +#define EVENT_BUF_SIZE 256 + char buf[UI_BUF_SIZE]; ///< buffer of packed but not yet sent msgpack data + char *buf_wptr; ///< write head of buffer + const char *cur_event; ///< name of current event (might get multiple arglists) + Array call_buf; ///< buffer for constructing a single arg list (max 16 elements!) + + // state for write_cb, while packing a single arglist to msgpack. This + // might fail due to buffer overflow. + size_t pack_totlen; + bool buf_overflow; + char *temp_buf; + + // We start packing the two outermost msgpack arrays before knowing the total + // number of elements. Thus track the location where array size will need + // to be written in the msgpack buffer, once the specific array is finished. + char *nevents_pos; + char *ncalls_pos; + uint32_t nevents; ///< number of distinct events (top-level args to "redraw" + uint32_t ncalls; ///< number of calls made to the current event (plus one for the name!) + bool flushed_events; ///< events where sent to client without "flush" event + + int hl_id; // Current highlight for legacy put event. + Integer cursor_row, cursor_col; // Intended visible cursor position. + + // Position of legacy cursor, used both for drawing and visible user cursor. + Integer client_row, client_col; + bool wildmenu_active; +} UIData; + struct ui_t { bool rgb; bool override; ///< Force highest-requested UI capabilities. @@ -65,13 +100,9 @@ struct ui_t { double pum_col; double pum_height; double pum_width; - void *data; - -#ifdef INCLUDE_GENERATED_DECLARATIONS -# include "ui_events.generated.h" -#endif - void (*inspect)(UI *ui, Dictionary *info); + // TODO(bfredl): integrate into struct! + UIData data[1]; }; typedef struct ui_event_callback { -- cgit