From 4f5f246a958e66e04a5d62b3bf0d8986afb51c09 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 12 Dec 2014 16:25:11 -0300 Subject: ui: Add update_fg/update_bg methods It is necessary to notify the UI when the default background/foreground colors change in order to render correctly. --- src/nvim/msgpack_rpc/remote_ui.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/nvim/msgpack_rpc/remote_ui.c') diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index f980a77b4c..af7b82dfd4 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -67,6 +67,8 @@ Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, Array args, ui->put = remote_ui_put; ui->bell = remote_ui_bell; ui->visual_bell = remote_ui_visual_bell; + ui->update_fg = remote_ui_update_fg; + ui->update_bg = remote_ui_update_bg; ui->flush = remote_ui_flush; ui->suspend = remote_ui_suspend; pmap_put(uint64_t)(connected_uis, channel_id, ui); @@ -266,6 +268,20 @@ static void remote_ui_visual_bell(UI *ui) push_call(ui, "visual_bell", args); } +static void remote_ui_update_fg(UI *ui, int fg) +{ + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(fg)); + push_call(ui, "update_fg", args); +} + +static void remote_ui_update_bg(UI *ui, int bg) +{ + Array args = ARRAY_DICT_INIT; + ADD(args, INTEGER_OBJ(bg)); + push_call(ui, "update_bg", args); +} + static void remote_ui_flush(UI *ui) { UIData *data = ui->data; -- cgit From 9b30abcecbc2492910f0281f596679714d95a88c Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Sat, 13 Dec 2014 09:20:00 -0300 Subject: remote_ui: Move handler registration to remote_ui.c Also don't defer attach_ui handling --- src/nvim/msgpack_rpc/remote_ui.c | 45 +++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'src/nvim/msgpack_rpc/remote_ui.c') diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index af7b82dfd4..e27d4383c0 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -26,10 +26,32 @@ static PMap(uint64_t) *connected_uis = NULL; void remote_ui_init(void) { connected_uis = pmap_new(uint64_t)(); + // Add handler for "attach_ui" + String method = cstr_as_string("attach_ui"); + MsgpackRpcRequestHandler handler = {.fn = remote_ui_attach, .defer = false}; + msgpack_rpc_add_method_handler(method, handler); + method = cstr_as_string("detach_ui"); + handler.fn = remote_ui_detach; + msgpack_rpc_add_method_handler(method, handler); } -Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, Array args, - Error *error) +void remote_ui_disconnect(uint64_t channel_id) +{ + UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); + if (!ui) { + return; + } + UIData *data = ui->data; + // destroy pending screen updates + api_free_array(data->buffer); + pmap_del(uint64_t)(connected_uis, channel_id); + free(ui->data); + ui_detach(ui); + free(ui); +} + +static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, + Array args, Error *error) { if (pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(error, Exception, _("UI already attached for channel")); @@ -77,8 +99,8 @@ Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, Array args, return NIL; } -Object remote_ui_detach(uint64_t channel_id, uint64_t request_id, Array args, - Error *error) +static Object remote_ui_detach(uint64_t channel_id, uint64_t request_id, + Array args, Error *error) { if (!pmap_has(uint64_t)(connected_uis, channel_id)) { api_set_error(error, Exception, _("UI is not attached for channel")); @@ -88,21 +110,6 @@ Object remote_ui_detach(uint64_t channel_id, uint64_t request_id, Array args, return NIL; } -void remote_ui_disconnect(uint64_t channel_id) -{ - UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); - if (!ui) { - return; - } - UIData *data = ui->data; - // destroy pending screen updates - api_free_array(data->buffer); - pmap_del(uint64_t)(connected_uis, channel_id); - free(ui->data); - ui_detach(ui); - free(ui); -} - static void push_call(UI *ui, char *name, Array args) { Array call = ARRAY_DICT_INIT; -- cgit From 213c3c3e53459a77c77166cda85ba619e7eb2eb1 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Sat, 13 Dec 2014 12:58:06 -0300 Subject: ui: Fix ui resizing and change some method names --- src/nvim/msgpack_rpc/remote_ui.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'src/nvim/msgpack_rpc/remote_ui.c') diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index e27d4383c0..a0bc573698 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -27,12 +27,15 @@ void remote_ui_init(void) { connected_uis = pmap_new(uint64_t)(); // Add handler for "attach_ui" - String method = cstr_as_string("attach_ui"); + String method = cstr_as_string("ui_attach"); MsgpackRpcRequestHandler handler = {.fn = remote_ui_attach, .defer = false}; msgpack_rpc_add_method_handler(method, handler); - method = cstr_as_string("detach_ui"); + method = cstr_as_string("ui_detach"); handler.fn = remote_ui_detach; msgpack_rpc_add_method_handler(method, handler); + method = cstr_as_string("ui_try_resize"); + handler.fn = remote_ui_try_resize; + msgpack_rpc_add_method_handler(method, handler); } void remote_ui_disconnect(uint64_t channel_id) @@ -95,7 +98,6 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, ui->suspend = remote_ui_suspend; pmap_put(uint64_t)(connected_uis, channel_id, ui); ui_attach(ui); - return NIL; } @@ -110,6 +112,30 @@ static Object remote_ui_detach(uint64_t channel_id, uint64_t request_id, return NIL; } +static Object remote_ui_try_resize(uint64_t channel_id, uint64_t request_id, + Array args, Error *error) +{ + if (!pmap_has(uint64_t)(connected_uis, channel_id)) { + api_set_error(error, Exception, _("UI is not attached for channel")); + } + + if (args.size != 2 || args.items[0].type != kObjectTypeInteger + || args.items[1].type != kObjectTypeInteger + || args.items[0].data.integer <= 0 || args.items[1].data.integer <= 0) { + api_set_error(error, Validation, + _("Arguments must be a pair of positive integers " + "representing the remote screen width/height")); + return NIL; + } + + UI *ui = pmap_get(uint64_t)(connected_uis, channel_id); + ui->width = (int)args.items[0].data.integer; + ui->height = (int)args.items[1].data.integer; + ui_refresh(); + return NIL; +} + + static void push_call(UI *ui, char *name, Array args) { Array call = ARRAY_DICT_INIT; -- cgit From 0887c5446ee8ec6ea53ef69e5d02bd319e1bca1c Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Tue, 30 Dec 2014 08:24:22 -0300 Subject: ui: Merge standout and reverse into one attribute --- src/nvim/msgpack_rpc/remote_ui.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/nvim/msgpack_rpc/remote_ui.c') diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index a0bc573698..e1cb474530 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -249,10 +249,6 @@ static void remote_ui_highlight_set(UI *ui, HlAttrs attrs) PUT(hl, "bold", BOOLEAN_OBJ(true)); } - if (attrs.standout) { - PUT(hl, "standout", BOOLEAN_OBJ(true)); - } - if (attrs.underline) { PUT(hl, "underline", BOOLEAN_OBJ(true)); } -- cgit From 74c247f75baec5778296adf164831c5ffea0fb88 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Thu, 8 Jan 2015 11:23:45 -0300 Subject: ui: Add 'rgb' parameter to ui_attach When set to false, nvim will send cterm color numbers with `highlight_set`. --- src/nvim/msgpack_rpc/remote_ui.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/nvim/msgpack_rpc/remote_ui.c') diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index e1cb474530..6a638df61c 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -61,8 +61,9 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, return NIL; } - if (args.size != 2 || args.items[0].type != kObjectTypeInteger + if (args.size != 3 || args.items[0].type != kObjectTypeInteger || args.items[1].type != kObjectTypeInteger + || args.items[2].type != kObjectTypeBoolean || args.items[0].data.integer <= 0 || args.items[1].data.integer <= 0) { api_set_error(error, Validation, _("Arguments must be a pair of positive integers " @@ -75,6 +76,7 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, UI *ui = xcalloc(1, sizeof(UI)); ui->width = (int)args.items[0].data.integer; ui->height = (int)args.items[1].data.integer; + ui->rgb = args.items[2].data.boolean; ui->data = data; ui->resize = remote_ui_resize; ui->clear = remote_ui_clear; -- cgit From d992213678ecd14902ae74ff765e682fb76d5ad9 Mon Sep 17 00:00:00 2001 From: Thiago de Arruda Date: Fri, 9 Jan 2015 09:51:11 -0300 Subject: ui: Reimplement `:suspend` command for remote UIs. - Remove suspend method from the UI protocol - Handle `:suspend` by disconnecting the last channel that sent a request to nvim. --- src/nvim/msgpack_rpc/remote_ui.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/nvim/msgpack_rpc/remote_ui.c') diff --git a/src/nvim/msgpack_rpc/remote_ui.c b/src/nvim/msgpack_rpc/remote_ui.c index 6a638df61c..4db9c71ebb 100644 --- a/src/nvim/msgpack_rpc/remote_ui.c +++ b/src/nvim/msgpack_rpc/remote_ui.c @@ -97,7 +97,6 @@ static Object remote_ui_attach(uint64_t channel_id, uint64_t request_id, ui->update_fg = remote_ui_update_fg; ui->update_bg = remote_ui_update_bg; ui->flush = remote_ui_flush; - ui->suspend = remote_ui_suspend; pmap_put(uint64_t)(connected_uis, channel_id, ui); ui_attach(ui); return NIL; @@ -319,9 +318,3 @@ static void remote_ui_flush(UI *ui) channel_send_event(data->channel_id, "redraw", data->buffer); data->buffer = (Array)ARRAY_DICT_INIT; } - -static void remote_ui_suspend(UI *ui) -{ - UIData *data = ui->data; - remote_ui_disconnect(data->channel_id); -} -- cgit