Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Floating windows in TUI and Remote UI #6619

Merged
merged 1 commit into from Mar 2, 2019
Merged

Conversation

@bfredl
Copy link
Member

@bfredl bfredl commented Apr 29, 2017

From the drawer of very naive and crazy stuff (one does not simply mess with window positioning and expect stuff to work). Partially based on @dzhou121 external ui stuff (crazy/naiveness mine)

do this in a script:

fnew
call nvim_win_float_set_pos(0,5,10,20,5)
hi Floating guibg=#000044
set winhl=Normal:Floating
set nonumber
@justinmk justinmk added this to the 0.3 milestone Apr 29, 2017
@marvim marvim added the WIP label Apr 29, 2017
src/nvim/ex_cmds.lua Outdated Show resolved Hide resolved
@bfredl bfredl changed the title [WIP] (very WIP) Floating windows in TUI [WIP] Floating windows in TUI Apr 30, 2017
@johnzeng
Copy link

@johnzeng johnzeng commented Jun 5, 2017

hi, will this PR be merged? or, still wip?

@bfredl
Copy link
Member Author

@bfredl bfredl commented Jun 5, 2017

Is still WIP, many window commands can easily segfault, and the mouse is broken. Also we need a better redrawing strategy than "redraw the float everytime anything else is redrawn". Probabaly should use some buffering logic from #5686

@johnzeng
Copy link

@johnzeng johnzeng commented Jun 5, 2017

Good to know that. I am waiting for it.

@bfredl bfredl force-pushed the bfredl:floating branch from b108079 to b4cbf7a Jul 3, 2017
@bfredl bfredl force-pushed the bfredl:floating branch from b4cbf7a to 635f238 Aug 13, 2017
@bfredl
Copy link
Member Author

@bfredl bfredl commented Aug 13, 2017

Update: replaced fnew with api command:

Window nvim_open_floating_window(Buffer buffer,
                                 Integer x, Integer y, Integer w, Integer h,
                                 Integer mode, Boolean enter, Error *err)

mode supports anchor modes (will be relevant for UIs with different grid sizes in floats) as well making the window "unfocusable". It is still possible to make it current with api or number, but the user selecting it "by accident" with mouse or ctrl-Wctrl-W should be avoided.

Also added very basic mouse support.

@justinmk
Copy link
Member

@justinmk justinmk commented Aug 13, 2017

I'd suggest "new" as the standard verb for creating things. Also in API functions we always spell "window" as win.

nvim_new_floating_win
@bfredl
Copy link
Member Author

@bfredl bfredl commented Aug 13, 2017

new isn't verb though. The alternative would be add, but open signals something more heavy (as a window or channel is) than something you just add to a set like a line or a highlight. create might also work and is slightly more general (like nvim_create_namespace )

@justinmk
Copy link
Member

@justinmk justinmk commented Aug 13, 2017

new acts like a verb in many programming languages. It has wide recognition, it's short, strong, and familiar.

@bfredl
Copy link
Member Author

@bfredl bfredl commented Aug 13, 2017

My point was primarily about operation strength, not grammar. Opening/Creating a new window or buffer (or channel) is a lot heavier than adding a new line (we call it [o]pen only because [n] was taken for [n]ext) or highlight, or allocating a new object in "many programming languages". These are all different verbs for a reason. (and if we're discussing common languages, new string() vs string() in javascript is just madness, while in modern c++ well-typed pointers is preferred to new/delete)

@bfredl bfredl force-pushed the bfredl:floating branch from 635f238 to be01576 Sep 2, 2017
@bfredl
Copy link
Member Author

@bfredl bfredl commented Sep 2, 2017

Added nvim_add_buf(). Note it only adds a buffer to the buffer list, they are not opened/allocated until they are displayed in some window.

let b = nvim_add_buf("")
let w =  nvim_open_floating_window(b,5,10,20,5,0,0)
hi Floating guibg=#000044
call setwinvar(w, '&winhl', 'Normal:Floating')
call setwinvar(w, '&number', 0)
@wsdjeg
Copy link
Contributor

@wsdjeg wsdjeg commented Sep 2, 2017

This PR is awesome, and I have a question about the floating window, I just see the doc what dese Integer x, Integer y, Integer w, Integer h, base on? computer's screen or vim's screen?


Window nvim_open_floating_window(Buffer buffer,
Integer x, Integer y, Integer w, Integer h,
Integer mode, Boolean enter, Error *err)

This comment has been minimized.

@justinmk

justinmk Sep 2, 2017
Member

nvim_open_floating_win

@justinmk
Copy link
Member

@justinmk justinmk commented Sep 2, 2017

nvim_add_buf

Here "new" as the verb makes sense to me: nvim_new_buf(). We're creating an object. The buffer list is like a vtable (an implementation detail) so "add" isn't the characteristic operation.

@bfredl
Copy link
Member Author

@bfredl bfredl commented Sep 2, 2017

The buffer list most definitely not an implementation detail: it is well known and used vim functionality that a buffer can be "listed" without actually being "opened". The API functions current operation is only to add/return a number in the buffer list, but "add" might not be the best either, as it can return an existing buffer.

However, that is not necessarily the best operation, we could have a function that only creates a new (unnamed) buffer and fully allocates it (this special case might not need to make it temporarily displayed, as there is no swapfile, encoding errors, and probably we want no autocmds either) The current behavior makes sense in the "floating window" case given that it will immediately opened in a window anyway, at which point all the vim stuff happens.

src/nvim/buffer_defs.h Outdated Show resolved Hide resolved
src/nvim/buffer_defs.h Outdated Show resolved Hide resolved
src/nvim/screen.c Outdated Show resolved Hide resolved
@ZyX-I
Copy link
Contributor

@ZyX-I ZyX-I commented Sep 2, 2017

I have a suggestion: either make x and y Float and allow negative and fractional values, or add another argument which specifies what x and y are related to and what they actually mean. Neither makes sense for TUI, but GUI may open windows outside of the window.

Or do the other thing: open_floating_window already contains lots of arguments. Make that dict:

/// Open floating window
///
/// @param[in]  buffer  Buffer to display in that window.
/// @param[in]  position  Window position, pair of two integers which may be 
/// negative.
/// @param[in]  options  Additional options:
///                      Option | Type | Description
///                      ------ | ---- | -----------
///                      anchor | String | Make position be relative to the 
///                             |        | given anchor: "type-pos" where "type"
///                             |        | is one of "screen", "editor_area",
///                             |        | "wm_window" and "pos" is one of "NW",
///                             |        | "NE", "SW" or "SE"; additionally
///                             |        | "cursor" position is supported.
///                             |        |
///                             |        | Defaults to "cursor".
///                             |        |
///                             |        | TUI only supports "editor_area-…" and
///                             |        | "cursor".
///                      dimensions | pair of Integers | Dimensions in screen
///                                 |                  | cells, width x height.
///                                 |                  |
///                                 |                  | Defaults to either just
///                                 |                  | enough to show the
///                                 |                  | whole buffer contents
///                                 |                  | (not updated when
///                                 |                  | buffer contents
///                                 |                  | changes, call
///                                 |                  | `nvim_reconfigure_floating_window({dimensions: NIL})`
///                                 |                  | then), or just enough
///                                 |                  | to occupy all available
///                                 |                  | space, whichever is
///                                 |                  | lesser.
///                      standalone | Boolean | Make window standalone.
///                                 |         |
///                                 |         | Defaults to false, may be
///                                 |         | ignored in TUI.
///                      focusable | Boolean | Make window not focusable, and
///                                |         | also ignore mouse events.
///                                |         |
///                                |         | Defaults to false.
///                      position_type | String | Position type: either "cells"
///                                    |        | (position in display cells) or
///                                    |        | "pixels".
///                                    |        |
///                                    |        | Defaults to "cells" for
///                                    |        | "editor_area-*" and "cursor"
///                                    |        | anchors, "pixels" otherwise.
Window nvim_open_floating_window(Buffer buffer, ArrayOf(Integer) position,
                                 Dictionary options, Error *const err)

/// Reconfigure floating window
///
/// @param[in]  window  Window to reconfigure.
/// @param[in]  options  @see nvim_open_floating_window()
///                      Missing values mean “do not change option”, use NIL to 
///                      force defaults.
void nvim_reconfigure_floating_window(Window window, Dictionary options,
                                      Error *const err)
@justinmk
Copy link
Member

@justinmk justinmk commented Sep 2, 2017

The buffer list most definitely not an implementation detail: it is well known and used vim functionality

It's an irrelevant detail in the context of the API. When one creates a buffer one does not think "I want to add a buffer to the buffer list", only "I want a new buffer".

@bfredl bfredl force-pushed the bfredl:floating branch from be01576 to e8b9f15 Sep 2, 2017
@bfredl
Copy link
Member Author

@bfredl bfredl commented Sep 2, 2017

Again, the name describes what the function does right now, which was the simplest thing to implement. The relevant change would be to change what the function actually does (fully allocate a buffer), which will be more involved but probably worth it in the long run.

@bfredl bfredl force-pushed the bfredl:floating branch 2 times, most recently from df20643 to c702de6 Mar 1, 2019
@chemzqm
Copy link
Contributor

@chemzqm chemzqm commented Mar 2, 2019

I think a function for close preview window or close window without focus is needed.

I can close the preview window by wincmd c but it requries focus the preview window, the problem is when the user have selected region at this time the change of focused window break current selection.

@bfredl bfredl force-pushed the bfredl:floating branch 2 times, most recently from 211d9a2 to 3eb676d Mar 2, 2019
@bfredl
Copy link
Member Author

@bfredl bfredl commented Mar 2, 2019

:[winnr]close can be used, but it is not very convenient. We could add nvim_win_close([winid]) which works the same but with winid.

@bfredl bfredl force-pushed the bfredl:floating branch 7 times, most recently from 69b9ce8 to 71a5378 Mar 2, 2019
@bfredl bfredl changed the title [WIP] Floating windows in TUI and Remote UI [RFC] Floating windows in TUI and Remote UI Mar 2, 2019
@bfredl
Copy link
Member Author

@bfredl bfredl commented Mar 2, 2019

Working on the last issues, ci build is aalmost passing now. I plan to merge this today or tomorrow. It is usable enough as a MVP (as demonstrated by plugins adding support already). The API/functionality (and tests with them) can be expanded in follow-up PRs.

@marvim marvim added RFC and removed WIP labels Mar 2, 2019
@bfredl bfredl force-pushed the bfredl:floating branch 2 times, most recently from 3fcecb2 to 53d6a28 Mar 2, 2019
@bfredl bfredl modified the milestones: 0.6, 0.4 Mar 2, 2019
Co-Author: Dongdong Zhou <dzhou121@gmail.com>
@bfredl bfredl force-pushed the bfredl:floating branch from 53d6a28 to 9a1675b Mar 2, 2019
@bfredl bfredl merged commit 7a6da50 into neovim:master Mar 2, 2019
1 of 3 checks passed
1 of 3 checks passed
QuickBuild pr-6619: build finished with status failure
Details
continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
@justinmk justinmk removed the RFC label Mar 2, 2019
@bfredl
Copy link
Member Author

@bfredl bfredl commented Mar 2, 2019

Merged. Sorry for taking so long. I will lock this thread, as dealing with overlong github threads is a mess. Requests for additions/improvements (or bugs too minor to deserve their own issue) can be in #9421. Feel free to repeat stuff that is hidden somewhere in the middle of this thread and still are a concern.

@neovim neovim locked and limited conversation to collaborators Mar 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

You can’t perform that action at this time.