aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/ui_bridge.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/ui_bridge.c')
-rw-r--r--src/nvim/ui_bridge.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/src/nvim/ui_bridge.c b/src/nvim/ui_bridge.c
index fd9d4671e3..25861abc1b 100644
--- a/src/nvim/ui_bridge.c
+++ b/src/nvim/ui_bridge.c
@@ -1,10 +1,13 @@
-// FIXME(tarruda): This module is very repetitive. It might be a good idea to
-// automatically generate it with a lua script during build
+// UI wrapper that sends requests to the UI thread.
+// Used by the built-in TUI and libnvim-based UIs.
+
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <limits.h>
+#include "nvim/log.h"
+#include "nvim/main.h"
#include "nvim/vim.h"
#include "nvim/ui.h"
#include "nvim/memory.h"
@@ -17,10 +20,30 @@
#define UI(b) (((UIBridgeData *)b)->ui)
-// Call a function in the UI thread
-#define UI_CALL(ui, name, argc, ...) \
- ((UIBridgeData *)ui)->scheduler( \
- event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui))
+#if MIN_LOG_LEVEL <= DEBUG_LOG_LEVEL
+static size_t uilog_seen = 0;
+static argv_callback uilog_event = NULL;
+#define UI_CALL(ui, name, argc, ...) \
+ do { \
+ if (uilog_event == ui_bridge_##name##_event) { \
+ uilog_seen++; \
+ } else { \
+ if (uilog_seen > 0) { \
+ DLOG("UI bridge: ...%zu times", uilog_seen); \
+ } \
+ DLOG("UI bridge: " STR(name)); \
+ uilog_seen = 0; \
+ uilog_event = ui_bridge_##name##_event; \
+ } \
+ ((UIBridgeData *)ui)->scheduler( \
+ event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui)); \
+ } while (0)
+#else
+// Schedule a function call on the UI bridge thread.
+#define UI_CALL(ui, name, argc, ...) \
+ ((UIBridgeData *)ui)->scheduler( \
+ event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui))
+#endif
#define INT2PTR(i) ((void *)(uintptr_t)i)
#define PTR2INT(p) ((int)(uintptr_t)p)
@@ -30,6 +53,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
UIBridgeData *rv = xcalloc(1, sizeof(UIBridgeData));
rv->ui = ui;
rv->bridge.rgb = ui->rgb;
+ rv->bridge.pum_external = ui->pum_external;
rv->bridge.stop = ui_bridge_stop;
rv->bridge.resize = ui_bridge_resize;
rv->bridge.clear = ui_bridge_clear;
@@ -71,7 +95,7 @@ UI *ui_bridge_attach(UI *ui, ui_main_fn ui_main, event_scheduler scheduler)
}
uv_mutex_unlock(&rv->mutex);
- ui_attach(&rv->bridge);
+ ui_attach_impl(&rv->bridge);
return &rv->bridge;
}
@@ -100,12 +124,12 @@ static void ui_bridge_stop(UI *b)
if (stopped) {
break;
}
- loop_poll_events(&loop, 10);
+ loop_poll_events(&main_loop, 10);
}
uv_thread_join(&bridge->ui_thread);
uv_mutex_destroy(&bridge->mutex);
uv_cond_destroy(&bridge->cond);
- ui_detach(b);
+ ui_detach_impl(b);
xfree(b);
}
static void ui_bridge_stop_event(void **argv)
@@ -215,16 +239,16 @@ static void ui_bridge_mode_change_event(void **argv)
}
static void ui_bridge_set_scroll_region(UI *b, int top, int bot, int left,
- int right)
+ int right)
{
UI_CALL(b, set_scroll_region, 5, b, INT2PTR(top), INT2PTR(bot),
- INT2PTR(left), INT2PTR(right));
+ INT2PTR(left), INT2PTR(right));
}
static void ui_bridge_set_scroll_region_event(void **argv)
{
UI *ui = UI(argv[0]);
ui->set_scroll_region(ui, PTR2INT(argv[1]), PTR2INT(argv[2]),
- PTR2INT(argv[3]), PTR2INT(argv[4]));
+ PTR2INT(argv[3]), PTR2INT(argv[4]));
}
static void ui_bridge_scroll(UI *b, int count)