mirror of
https://github.com/neovim/neovim.git
synced 2025-10-08 19:06:31 +00:00
@@ -1003,35 +1003,35 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err)
|
||||
/// Exactly one of `external` and `relative` must be specified.
|
||||
///
|
||||
/// @param buffer handle of buffer to be displayed in the window
|
||||
/// @param enter whether the window should be entered (made the current window)
|
||||
/// @param width width of window (in character cells)
|
||||
/// @param height height of window (in character cells)
|
||||
/// @param options dict of options for configuring window positioning
|
||||
/// accepts the following keys:
|
||||
/// @param enter whether the window should be entered (made the current window)
|
||||
/// @param config dictionary for the window configuration accepts these keys:
|
||||
///
|
||||
/// `relative`: If set, the window becomes a floating window. The window
|
||||
/// will be placed with row,col coordinates relative one of the
|
||||
/// following:
|
||||
/// "editor" the global editor grid
|
||||
/// "win" a window. Use 'win' option below to specify window id,
|
||||
/// or current window will be used by default.
|
||||
/// "win" a window. Use `win` to specify a window id,
|
||||
/// or the current window will be used by default.
|
||||
/// "cursor" the cursor position in current window.
|
||||
/// `anchor`: the corner of the float that the row,col position defines
|
||||
/// `win`: When using relative='win', window id of the window where the
|
||||
/// position is defined.
|
||||
/// `anchor`: The corner of the float that the row,col position defines:
|
||||
/// "NW" north-west (default)
|
||||
/// "NE" north-east
|
||||
/// "SW" south-west
|
||||
/// "SE" south-east
|
||||
/// `focusable`: Whether window can be focused by wincmds and
|
||||
/// mouse events. Defaults to true. Even if set to false, the window
|
||||
/// can still be entered using |nvim_set_current_win()| API call.
|
||||
/// `row`: row position. Screen cell height are used as unit. Can be
|
||||
/// `height`: window height (in character cells). Minimum of 1.
|
||||
/// `width`: window width (in character cells). Minimum of 2.
|
||||
/// `row`: row position. Screen cell height are used as unit. Can be
|
||||
/// floating point.
|
||||
/// `col`: column position. Screen cell width is used as unit. Can be
|
||||
/// floating point.
|
||||
/// `win`: when using relative='win', window id of the window where the
|
||||
/// position is defined.
|
||||
/// `external` GUI should display the window as an external
|
||||
/// top-level window. Currently accepts no other positioning options
|
||||
/// together with this.
|
||||
/// `focusable`: Whether window can be focused by wincmds and
|
||||
/// mouse events. Defaults to true. Even if set to false, the window
|
||||
/// can still be entered using |nvim_set_current_win()| API call.
|
||||
/// `external`: GUI should display the window as an external
|
||||
/// top-level window. Currently accepts no other positioning
|
||||
/// configuration together with this.
|
||||
///
|
||||
/// With editor positioning row=0, col=0 refers to the top-left corner of the
|
||||
/// screen-grid and row=Lines-1, Columns-1 refers to the bottom-right corner.
|
||||
@@ -1047,16 +1047,15 @@ Buffer nvim_create_buf(Boolean listed, Boolean scratch, Error *err)
|
||||
///
|
||||
/// @param[out] err Error details, if any
|
||||
/// @return the window handle or 0 when error
|
||||
Window nvim_open_win(Buffer buffer, Boolean enter,
|
||||
Integer width, Integer height,
|
||||
Dictionary options, Error *err)
|
||||
Window nvim_open_win(Buffer buffer, Boolean enter, Dictionary config,
|
||||
Error *err)
|
||||
FUNC_API_SINCE(6)
|
||||
{
|
||||
FloatConfig config = FLOAT_CONFIG_INIT;
|
||||
if (!parse_float_config(options, &config, false, err)) {
|
||||
FloatConfig fconfig = FLOAT_CONFIG_INIT;
|
||||
if (!parse_float_config(config, &fconfig, false, err)) {
|
||||
return 0;
|
||||
}
|
||||
win_T *wp = win_new_float(NULL, (int)width, (int)height, config, err);
|
||||
win_T *wp = win_new_float(NULL, fconfig, err);
|
||||
if (!wp) {
|
||||
return 0;
|
||||
}
|
||||
|
@@ -438,14 +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 -1 for 'witdh' and 'height' to keep exiting 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.
|
||||
void nvim_win_config(Window window, Integer width, Integer height,
|
||||
Dictionary options, Error *err)
|
||||
///
|
||||
/// @param window Window handle
|
||||
/// @param config Dictionary of window configuration
|
||||
/// @param[out] err Error details, if any
|
||||
void nvim_win_set_config(Window window, Dictionary config, Error *err)
|
||||
FUNC_API_SINCE(6)
|
||||
{
|
||||
win_T *win = find_window_by_handle(window, err);
|
||||
@@ -453,25 +455,70 @@ void nvim_win_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;
|
||||
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;
|
||||
}
|
||||
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, (int)width, (int)height, config, err)) {
|
||||
if (!win_new_float(win, fconfig, err)) {
|
||||
return;
|
||||
}
|
||||
redraw_later(NOT_VALID);
|
||||
} else {
|
||||
win_config_float(win, (int)width, (int)height, config);
|
||||
win_config_float(win, fconfig);
|
||||
win->w_pos_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Return window configuration.
|
||||
///
|
||||
/// Return a dictionary containing the same config that can be given to
|
||||
/// |nvim_open_win()|.
|
||||
///
|
||||
/// `relative` will be an empty string for normal windows.
|
||||
///
|
||||
/// @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, "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(
|
||||
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));
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/// Close a window.
|
||||
///
|
||||
/// This is equivalent to |:close| with count except that it takes a window id.
|
||||
|
Reference in New Issue
Block a user