From cfed9a4123afe3184c3914b6123869f2a52be250 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Fri, 15 Mar 2019 18:23:37 +0100 Subject: api: add nvim_win_get_config() --- src/nvim/api/window.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 157f73c9fa..8a03d7acef 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -472,6 +472,61 @@ void nvim_win_config(Window window, Integer width, Integer height, } } +/// Return window configuration. +/// +/// Return a dictionary containing the same options that can be given to +/// |nvim_open_win()|. +/// +/// @param window Window handle +/// @param[out] err Error details, if any +/// @return Window configuration +Dictionary nvim_win_get_config(Window window, Error *err) + FUNC_API_SINCE(6) +{ + Dictionary rv = ARRAY_DICT_INIT; + + win_T *wp = find_window_by_handle(window, err); + if (!wp) { + return rv; + } + + PUT(rv, "height", INTEGER_OBJ(wp->w_height)); + PUT(rv, "width", INTEGER_OBJ(wp->w_width)); + PUT(rv, "focusable", BOOLEAN_OBJ(wp->w_float_config.focusable)); + PUT(rv, "external", BOOLEAN_OBJ(wp->w_float_config.external)); + PUT(rv, "anchor", STRING_OBJ(cstr_to_string( + float_anchor_str[wp->w_float_config.anchor]))); + + if (wp->w_float_config.relative == kFloatRelativeWindow) { + PUT(rv, "win", INTEGER_OBJ(wp->w_float_config.window)); + } + + if (wp->w_float_config.external) { + return rv; + } + + PUT(rv, "row", FLOAT_OBJ(wp->w_float_config.row)); + PUT(rv, "col", FLOAT_OBJ(wp->w_float_config.col)); + + if (wp->w_floating) { + switch (wp->w_float_config.relative) { + case kFloatRelativeEditor: + PUT(rv, "relative", STRING_OBJ(cstr_to_string("editor"))); + break; + case kFloatRelativeWindow: + PUT(rv, "relative", STRING_OBJ(cstr_to_string("win"))); + break; + case kFloatRelativeCursor: + PUT(rv, "relative", STRING_OBJ(cstr_to_string("cursor"))); + break; + } + } else { + PUT(rv, "relative", STRING_OBJ(cstr_to_string(""))); + } + + return rv; +} + /// Close a window. /// /// This is equivalent to |:close| with count except that it takes a window id. -- cgit From 98391cd6abb4079ffd79bbc31ed949fd6f2d1a31 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Wed, 13 Mar 2019 20:09:00 +0100 Subject: api: refactor FloatAnchor usage --- src/nvim/api/window.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 8a03d7acef..b3acbe90cb 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -495,7 +495,7 @@ Dictionary nvim_win_get_config(Window window, Error *err) PUT(rv, "focusable", BOOLEAN_OBJ(wp->w_float_config.focusable)); PUT(rv, "external", BOOLEAN_OBJ(wp->w_float_config.external)); PUT(rv, "anchor", STRING_OBJ(cstr_to_string( - float_anchor_str[wp->w_float_config.anchor]))); + float_anchor_str[wp->w_float_config.anchor]))); if (wp->w_float_config.relative == kFloatRelativeWindow) { PUT(rv, "win", INTEGER_OBJ(wp->w_float_config.window)); -- cgit From 3c88bbecb8dc2bf1fb426cce08af232640bfd44d Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Thu, 14 Mar 2019 16:37:45 +0100 Subject: api: nvim_win_config() -> nvim_win_set_config() --- src/nvim/api/window.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index b3acbe90cb..f8bcaddb36 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -444,8 +444,8 @@ Boolean nvim_win_is_valid(Window window) /// When reconfiguring a floating window, absent option keys will not be /// changed. The following restriction apply: `row`, `col` and `relative` /// must be reconfigured together. Only changing a subset of these is an error. -void nvim_win_config(Window window, Integer width, Integer height, - Dictionary options, Error *err) +void nvim_win_set_config(Window window, Integer width, Integer height, + Dictionary options, Error *err) FUNC_API_SINCE(6) { win_T *win = find_window_by_handle(window, err); -- cgit From 96edbe7b1d6144f3cf9b720d61182ee31858b478 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Fri, 15 Mar 2019 18:03:12 +0100 Subject: api: add width/height to FloatConfig --- src/nvim/api/window.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index f8bcaddb36..ba505af87e 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -439,13 +439,12 @@ Boolean nvim_win_is_valid(Window window) /// types). /// /// See documentation at |nvim_open_win()|, for the meaning of parameters. Pass -/// in -1 for 'witdh' and 'height' to keep exiting size. +/// in 0 for 'witdh' and 'height' to keep exiting size. /// /// When reconfiguring a floating window, absent option keys will not be /// changed. The following restriction apply: `row`, `col` and `relative` /// must be reconfigured together. Only changing a subset of these is an error. -void nvim_win_set_config(Window window, Integer width, Integer height, - Dictionary options, Error *err) +void nvim_win_set_config(Window window, Dictionary options, Error *err) FUNC_API_SINCE(6) { win_T *win = find_window_by_handle(window, err); @@ -453,21 +452,21 @@ void nvim_win_set_config(Window window, Integer width, Integer height, return; } bool new_float = !win->w_floating; - width = width > 0 ? width: win->w_width; - height = height > 0 ? height : win->w_height; // reuse old values, if not overriden FloatConfig config = new_float ? FLOAT_CONFIG_INIT : win->w_float_config; if (!parse_float_config(options, &config, !new_float, err)) { return; } + config.height = config.height > 0 ? config.height : win->w_height; + config.width = config.width > 0 ? config.width : win->w_width; if (new_float) { - if (!win_new_float(win, (int)width, (int)height, config, err)) { + if (!win_new_float(win, config, err)) { return; } redraw_later(NOT_VALID); } else { - win_config_float(win, (int)width, (int)height, config); + win_config_float(win, config); win->w_pos_changed = true; } } @@ -490,8 +489,8 @@ Dictionary nvim_win_get_config(Window window, Error *err) return rv; } - PUT(rv, "height", INTEGER_OBJ(wp->w_height)); - PUT(rv, "width", INTEGER_OBJ(wp->w_width)); + PUT(rv, "width", INTEGER_OBJ(wp->w_float_config.width)); + PUT(rv, "height", INTEGER_OBJ(wp->w_float_config.height)); PUT(rv, "focusable", BOOLEAN_OBJ(wp->w_float_config.focusable)); PUT(rv, "external", BOOLEAN_OBJ(wp->w_float_config.external)); PUT(rv, "anchor", STRING_OBJ(cstr_to_string( -- cgit From 27c4b6b9bd90fbc3a41945f87ec944bd0ced8228 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Fri, 15 Mar 2019 18:18:56 +0100 Subject: api: update doc --- src/nvim/api/window.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index ba505af87e..dd63dbbb4a 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -439,11 +439,15 @@ Boolean nvim_win_is_valid(Window window) /// types). /// /// See documentation at |nvim_open_win()|, for the meaning of parameters. Pass -/// in 0 for 'witdh' and 'height' to keep exiting size. +/// in 0 for `width` and `height` to keep existing size. /// /// When reconfiguring a floating window, absent option keys will not be /// changed. The following restriction apply: `row`, `col` and `relative` /// must be reconfigured together. Only changing a subset of these is an error. +/// +/// @param window Window handle +/// @param options Dictionary of options +/// @param[out] err Error details, if any void nvim_win_set_config(Window window, Dictionary options, Error *err) FUNC_API_SINCE(6) { @@ -476,6 +480,8 @@ void nvim_win_set_config(Window window, Dictionary options, Error *err) /// Return a dictionary containing the same options that can be given to /// |nvim_open_win()|. /// +/// `relative` will be empty for normal windows. +/// /// @param window Window handle /// @param[out] err Error details, if any /// @return Window configuration -- cgit From 86992a7bb1fbf7f4eb2632a473ae3dbe5221d50f Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 16 Mar 2019 13:57:50 +0100 Subject: api: numerous small fixes --- src/nvim/api/window.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index dd63dbbb4a..9e53a7bf14 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -438,17 +438,16 @@ Boolean nvim_win_is_valid(Window window) /// floating and external windows (including changing a split window to these /// types). /// -/// See documentation at |nvim_open_win()|, for the meaning of parameters. Pass -/// in 0 for `width` and `height` to keep existing size. +/// See documentation at |nvim_open_win()|, for the meaning of parameters. /// /// When reconfiguring a floating window, absent option keys will not be /// changed. The following restriction apply: `row`, `col` and `relative` /// must be reconfigured together. Only changing a subset of these is an error. /// /// @param window Window handle -/// @param options Dictionary of options +/// @param config Dictionary of window configuration /// @param[out] err Error details, if any -void nvim_win_set_config(Window window, Dictionary options, Error *err) +void nvim_win_set_config(Window window, Dictionary config, Error *err) FUNC_API_SINCE(6) { win_T *win = find_window_by_handle(window, err); @@ -457,34 +456,34 @@ void nvim_win_set_config(Window window, Dictionary options, Error *err) } bool new_float = !win->w_floating; // reuse old values, if not overriden - FloatConfig config = new_float ? FLOAT_CONFIG_INIT : win->w_float_config; + FloatConfig fconfig = new_float ? FLOAT_CONFIG_INIT : win->w_float_config; - if (!parse_float_config(options, &config, !new_float, err)) { + if (!parse_float_config(config, &fconfig, !new_float, err)) { return; } - config.height = config.height > 0 ? config.height : win->w_height; - config.width = config.width > 0 ? config.width : win->w_width; + fconfig.height = fconfig.height > 0 ? fconfig.height : win->w_height; + fconfig.width = fconfig.width > 0 ? fconfig.width : win->w_width; if (new_float) { - if (!win_new_float(win, config, err)) { + if (!win_new_float(win, fconfig, err)) { return; } redraw_later(NOT_VALID); } else { - win_config_float(win, config); + win_config_float(win, fconfig); win->w_pos_changed = true; } } /// Return window configuration. /// -/// Return a dictionary containing the same options that can be given to +/// Return a dictionary containing the same config that can be given to /// |nvim_open_win()|. /// -/// `relative` will be empty for normal windows. +/// `relative` will be an empty string for normal windows. /// -/// @param window Window handle +/// @param window Window handle /// @param[out] err Error details, if any -/// @return Window configuration +/// @return Window configuration Dictionary nvim_win_get_config(Window window, Error *err) FUNC_API_SINCE(6) { -- cgit From 073ab7cda83ca2f804b02e10bc6be17a02c4d3c9 Mon Sep 17 00:00:00 2001 From: Marco Hinz Date: Sat, 16 Mar 2019 15:34:16 +0100 Subject: api: refactor FloatRelative usage --- src/nvim/api/window.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'src/nvim/api/window.c') diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 9e53a7bf14..2204170aab 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -512,21 +512,9 @@ Dictionary nvim_win_get_config(Window window, Error *err) PUT(rv, "row", FLOAT_OBJ(wp->w_float_config.row)); PUT(rv, "col", FLOAT_OBJ(wp->w_float_config.col)); - if (wp->w_floating) { - switch (wp->w_float_config.relative) { - case kFloatRelativeEditor: - PUT(rv, "relative", STRING_OBJ(cstr_to_string("editor"))); - break; - case kFloatRelativeWindow: - PUT(rv, "relative", STRING_OBJ(cstr_to_string("win"))); - break; - case kFloatRelativeCursor: - PUT(rv, "relative", STRING_OBJ(cstr_to_string("cursor"))); - break; - } - } else { - PUT(rv, "relative", STRING_OBJ(cstr_to_string(""))); - } + const char *rel = + wp->w_floating ? float_relative_str[wp->w_float_config.relative] : ""; + PUT(rv, "relative", STRING_OBJ(cstr_to_string(rel))); return rv; } -- cgit