Skip to content

Conversation

justinmk
Copy link
Member

@justinmk justinmk commented Mar 2, 2017

It's not ideal but seems to work quite well. Only enabled for the "built-in UI" (TUI) since we haven't seen reports of the resize issue for GUIs.

Fixing the root issue is still a priority but it will take time and there are more important things to do in the near term.

References #3929 #4884 #5692 #6157

src/nvim/main.c Outdated
@@ -429,6 +429,7 @@ int main(int argc, char **argv)
// Stop reading from input stream, the UI layer will take over now.
input_stop();
ui_builtin_start();
do_cmdline_cmd("au VimResized * call timer_start(100, {-> execute('mode')})");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for lambda

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brcolow Thanks for working on it :)

@JelteF
Copy link
Contributor

JelteF commented Mar 2, 2017

For me this doesn't fix the resize issue

@justinmk
Copy link
Member Author

justinmk commented Mar 2, 2017

@JelteF Could you try these variations (just enter them in the nvim command line, then do a resize):

au VimResized * call timer_start(300, {-> execute('mode')})

au VimResized * call timer_start(100, {-> execute('refresh!|mode')})

@JelteF
Copy link
Contributor

JelteF commented Mar 2, 2017

@justinmk The first one still doesn't work and the second one gives an error:

Error detected while processing function <lambda>8:                                                                   
line    1:                                                                                                            
E492: Not an editor command: refresh!|mode      

However, I tried to increase the timer of the first one a bit more, to 1000, and that worked great. You can still have a short visual glitch, but then it corrects it.

@justinmk
Copy link
Member Author

justinmk commented Mar 2, 2017

Oops it should be redraw.

Does 500 work?

@tweekmonster
Copy link
Contributor

Wouldn't you want to cancel any previous timers? Fast resizing might leave us with :mode spam making the screen flicker like the timer was never used.

@JelteF
Copy link
Contributor

JelteF commented Mar 2, 2017

Nope, but 800 works for both. One thing I noticed was that when you resize while typing a : command (ex-mode?), the screen is fully cleared except for the line with the : command.

@tweekmonster that sounds reasonable.

@tweekmonster
Copy link
Contributor

VimResized			After the Vim window was resized, thus 'lines'
				and/or 'columns' changed.  Not when starting
				up though.

Actually, if VimResized is fired when lines and columns are changed, wouldn't it mean that this hack doesn't work and it's just going by the same old randomness of the original issue? I was testing it with au VimResized * echomsg 'fixed' reltimestr(reltime()) and this seems to be the case.

Don't know if this is useful for narrowing down the issue:

diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index b98e59e..cd88c0c 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -7327,6 +7327,7 @@ int number_width(win_T *wp)
 void screen_resize(int width, int height)
 {
   static int busy = FALSE;
+  ILOG("Screen resize.  Updating: %d, Busy: %d", updating_screen, busy);
 
   // Avoid recursiveness, can happen when setting the window size causes
   // another window-changed signal.

It seems that updating_screen > 1 or busy > 1 is when the TUI has problems. Ignoring both of them resizes nvim correctly each time, but eventually segfaults (which isn't surprising).

@justinmk
Copy link
Member Author

justinmk commented Mar 2, 2017

The root cause has to do with the input queue timing. I looked at it in November, didn't go further yet.

@choco
Copy link
Contributor

choco commented Mar 5, 2017

Tested the fix above and even though it works when splitting the tmux pane, when I destroy the same split pane neovim doesn't resize itself most of the times. Changing the timing doesn't seem to change this from happening, but lower timing influences the first part of the issue (when splitting)

@Tranquility
Copy link
Contributor

I also realized that :redraw does not help. I have the problem every time a destroy a horizontal tmux pane. But the resize works correctly if a use a vertical tmux pane. Therefore the only way to redraw and for me right now is creating and directly destroying a vertical tmux pane.

@justinmk justinmk changed the title startup: Hack around TUI resize bug. ui: Fix TUI resize bug. Mar 5, 2017
@justinmk justinmk force-pushed the tui-resize-hack branch 2 times, most recently from ccc38d9 to 68367d4 Compare March 5, 2017 18:18
src/nvim/ui.c Outdated
if (updating_screen) {
loop_schedule(&main_loop, event_create(1, ui_refresh_event, 0));
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block could be moved before the declarations and loop_schedule(...) could be replaced with ui_schedule_refresh().

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if block could be moved before the declarations

Good point. The current placement was due to me trying different things. If it gets here, it usually happens a dozen or so times. So, I was testing the width and height to double check that it wasn't from multiple SIGWINCH events.

and loop_schedule(...) could be replaced with ui_schedule_refresh().

@justinmk
Copy link
Member Author

justinmk commented Mar 5, 2017

Any airline users seeing an improvement from this?

@choco
Copy link
Contributor

choco commented Mar 5, 2017

This doesn't solve the #4884 issue for me, with or without airline. But at least it works sometimes ( 1 out of 10 times? ), before it never worked.

@tweekmonster
Copy link
Contributor

tweekmonster commented Mar 5, 2017

@justinmk I didn't notice anything different in regard to airline.

@choco Are you using the most recent changes from this PR? It sounds like you're describing the original code using timers.

I used to have the problem mentioned in that issue, but I can no longer reproduce it. This PR makes it impossible for a resize to be ignored, so if you're still having issues it must mean that nvim isn't noticing the terminal is resizing.

justinmk and others added 2 commits March 5, 2017 22:17
You cannot escape clint...
statusline still disappears in some cases, but this change is a net
improvement.

References neovim#3929 neovim#5692 neovim#4884 neovim#6157
@justinmk justinmk changed the title ui: Fix TUI resize bug. ui: Ameliorate TUI resize bug. Mar 5, 2017
@justinmk justinmk merged commit e32ec03 into neovim:master Mar 5, 2017
@justinmk justinmk deleted the tui-resize-hack branch March 5, 2017 22:24
@choco
Copy link
Contributor

choco commented Mar 6, 2017

Yep, still having it unfortunately :( But I noticed that removing lazyredraw from my vimrc seems to fix the issue after this change. Is there any way to ignore the lazyredraw value in these resizing situations?

@JelteF
Copy link
Contributor

JelteF commented Mar 6, 2017

This seems to fix the issue for me.

justinmk added a commit to justinmk/neovim that referenced this pull request Mar 11, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request May 1, 2017
FEATURES:
    bc4a2e1 help, man.vim: "outline" (TOC) feature neovim#5169
    58422f1 'guicursor' works in the TUI (and sends info to UIs) neovim#6423
    129f107 api: nvim_get_mode() neovim#6247
    0b59f98 api/ui: externalize tabline neovim#6583
    bc6d868 'listchars': `Whitespace` highlight group neovim#6367
    6afa7d6 writefile() obeys 'fsync' option neovim#6427
    c60e409 eval.c refactor (also improves some error messages) neovim#5119
    9d200cd getcompletion("cmdline") neovim#6376
    2ea7bfc terminal: Support extra arguments in 'shell'. neovim#4504
    bf51102 DirChanged autocmd neovim#5928 neovim#6262
    1743df8 'cpoptions': "_" flag to toggle `cw` behaviour neovim#6235
    22337b1 CTRL-R omits trailing ^M when pasting to cmdline neovim#6137
    0e44916 :edit allows unescaped spaces in filename neovim#6119
    abdbfd2 eval: Add id() function and make printf("%p") useful neovim#6095
    bdfa147 findfile(), :find, gf work in :terminal. neovim#6009
    2f38ed1 providers: Disable if `g:loaded_*` exists.
    b5560a6 setpos() can set lowercase marks in other buffers neovim#5753
    7c513d6 Throttle :! output, pulse "..." message. neovim#5396
    d2e8c76 v:exiting neovim#5651

    :terminal improvements neovim#6185 neovim#6142
      - cursor keeps position after leaving insert-mode.
      - 4ceec30 Follows output only if cursor is at end of buffer.
      - e7bbd35 new option: 'scrollback'
      - fedb844 quasi-support for undo and 'modifiable'
      - b45ddf7 disables 'list' by default
      - disables 'relativenumber' by default

    :help now contains full API documentation at `:help api`.

    man.vim saw numerous improvements.

    Windows support:
      - Windows is no longer "experimental", it is fully supported.
      - Windows package includes a GUI, curl.exe and other utilities.

    "Vim 8" features: partials, lambdas, packages.

FIXES:
    12fc1de ops: fix i<c-r> with multi-byte text neovim#6524
    dd391bf Windows: system() and friends neovim#6497
    13352c0 Windows: os_get_hostname() neovim#6413
    16babc6 tui: Less-noisy mouse seqs neovim#6411
    3a9dd13 (vim bug) folding edge-cases  neovim#6207
    f6946c6 job-control: set CLOEXEC on pty processes. neovim#5986
    d1afd43 rplugin: Call s:LoadRemotePlugins() on startup.
    1215084 backtick-expansion works with `shell=fish` neovim#6224
    e32ec03 tui: Improved behavior after resize. neovim#6202
    86c2adc edit.c: CTRL-SPC: Insert previously-inserted text. neovim#6090
    c318d8e b:changedtick now follows VimL rules neovim#6112
    34e24cb terminal: Initialize colors in reverse order neovim#6160
    e889917 undo: Don't set b_u_curhead in ex_undojoin() neovim#5869
    d25649f undo: :earlier, g-: Set b_u_seq_cur correctly. (neovim#6016)
    043d8ba 'Visual-mode put from @. register' neovim#5782
    42c922b open_buffer(): Do `BufEnter` for directories.
    50d0d89 inccommand: Preview :sub commands only after delimiter neovim#5932
    1420e10 CheckHealth improvements neovim#5519
    c8d5e92 jobstart(): Return -1 if cmd is not executable. neovim#5671

CHANGES:
    NVIM_TUI_ENABLE_CURSOR_SHAPE was removed. Use 'guicursor' instead.
        See https://github.com/neovim/neovim/wiki/Following-HEAD#20170402

    81525dc 'mouse=a' is no longer the default. (This will probably
                 change again after it is improved.) neovim#6022

    0c1f783 defaults: 'showcmd', 'belloff', 'ruler' neovim#6087
    eb0e94f api: {get,set}_option update local options as appropriate neovim#6405
    bdcb2a3 "Reading from stdin..." message was removed. neovim#6298
@justinmk justinmk mentioned this pull request May 1, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request May 1, 2017
FEATURES:
    bc4a2e1 help, man.vim: "outline" (TOC) feature neovim#5169
    58422f1 'guicursor' works in the TUI (and sends info to UIs) neovim#6423
    129f107 api: nvim_get_mode() neovim#6247
    0b59f98 api/ui: externalize tabline neovim#6583
    bc6d868 'listchars': `Whitespace` highlight group neovim#6367
    6afa7d6 writefile() obeys 'fsync' option neovim#6427
    c60e409 eval.c refactor (also improves some error messages) neovim#5119
    9d200cd getcompletion("cmdline") neovim#6376
    2ea7bfc terminal: Support extra arguments in 'shell'. neovim#4504
    bf51102 DirChanged autocmd neovim#5928 neovim#6262
    1743df8 'cpoptions': "_" flag to toggle `cw` behaviour neovim#6235
    22337b1 CTRL-R omits trailing ^M when pasting to cmdline neovim#6137
    0e44916 :edit allows unescaped spaces in filename neovim#6119
    abdbfd2 eval: Add id() function and make printf("%p") useful neovim#6095
    bdfa147 findfile(), :find, gf work in :terminal. neovim#6009
    2f38ed1 providers: Disable if `g:loaded_*` exists.
    b5560a6 setpos() can set lowercase marks in other buffers neovim#5753
    7c513d6 Throttle :! output, pulse "..." message. neovim#5396
    d2e8c76 v:exiting neovim#5651

    :terminal improvements neovim#6185 neovim#6142
      - cursor keeps position after leaving insert-mode.
      - 4ceec30 Follows output only if cursor is at end of buffer.
      - e7bbd35 new option: 'scrollback'
      - fedb844 quasi-support for undo and 'modifiable'
      - b45ddf7 disables 'list' by default
      - disables 'relativenumber' by default

    :help now contains full API documentation at `:help api`.

    man.vim saw numerous improvements.

    Windows support:
      - Windows is no longer "experimental", it is fully supported.
      - Windows package includes a GUI, curl.exe and other utilities.

    "Vim 8" features: partials, lambdas.

SECURITY FIXES:
    CVE-2017-5953 CVE-2017-6349 CVE-2017-6350 neovim#6485

CHANGES:
    NVIM_TUI_ENABLE_CURSOR_SHAPE was removed. Use 'guicursor' instead.
        See https://github.com/neovim/neovim/wiki/Following-HEAD#20170402

    81525dc 'mouse=a' is no longer the default. (This will probably
                 change again after it is improved.) neovim#6022

    0c1f783 defaults: 'showcmd', 'belloff', 'ruler' neovim#6087
    eb0e94f api: {get,set}_option update local options as appropriate neovim#6405
    bdcb2a3 "Reading from stdin..." message was removed. neovim#6298

FIXES:
    12fc1de ops: fix i<c-r> with multi-byte text neovim#6524
    dd391bf Windows: system() and friends neovim#6497
    13352c0 Windows: os_get_hostname() neovim#6413
    16babc6 tui: Less-noisy mouse seqs neovim#6411
    3a9dd13 (vim bug) folding edge-cases  neovim#6207
    f6946c6 job-control: set CLOEXEC on pty processes. neovim#5986
    d1afd43 rplugin: Call s:LoadRemotePlugins() on startup.
    1215084 backtick-expansion works with `shell=fish` neovim#6224
    e32ec03 tui: Improved behavior after resize. neovim#6202
    86c2adc edit.c: CTRL-SPC: Insert previously-inserted text. neovim#6090
    c318d8e b:changedtick now follows VimL rules neovim#6112
    34e24cb terminal: Initialize colors in reverse order neovim#6160
    e889917 undo: Don't set b_u_curhead in ex_undojoin() neovim#5869
    d25649f undo: :earlier, g-: Set b_u_seq_cur correctly. (neovim#6016)
    043d8ba 'Visual-mode put from @. register' neovim#5782
    42c922b open_buffer(): Do `BufEnter` for directories.
    50d0d89 inccommand: Preview :sub commands only after delimiter neovim#5932
    1420e10 CheckHealth improvements neovim#5519
    c8d5e92 jobstart(): Return -1 if cmd is not executable. neovim#5671
justinmk added a commit to justinmk/neovim that referenced this pull request May 1, 2017
FEATURES:
    bc4a2e1 help, man.vim: "outline" (TOC) feature neovim#5169
    58422f1 'guicursor' works in the TUI (and sends info to UIs) neovim#6423
    129f107 api: nvim_get_mode() neovim#6247
    0b59f98 api/ui: externalize tabline neovim#6583
    bc6d868 'listchars': `Whitespace` highlight group neovim#6367
    6afa7d6 writefile() obeys 'fsync' option neovim#6427
    c60e409 eval.c refactor (also improves some error messages) neovim#5119
    9d200cd getcompletion("cmdline") neovim#6376
    2ea7bfc terminal: Support extra arguments in 'shell'. neovim#4504
    bf51102 DirChanged autocmd neovim#5928 neovim#6262
    1743df8 'cpoptions': "_" flag to toggle `cw` behaviour neovim#6235
    22337b1 CTRL-R omits trailing ^M when pasting to cmdline neovim#6137
    0e44916 :edit allows unescaped spaces in filename neovim#6119
    abdbfd2 eval: Add id() function and make printf("%p") useful neovim#6095
    bdfa147 findfile(), :find, gf work in :terminal. neovim#6009
    2f38ed1 providers: Disable if `g:loaded_*` exists.
    b5560a6 setpos() can set lowercase marks in other buffers neovim#5753
    7c513d6 Throttle :! output, pulse "..." message. neovim#5396
    d2e8c76 v:exiting neovim#5651

    :terminal improvements neovim#6185 neovim#6142
      - cursor keeps position after leaving insert-mode.
      - 4ceec30 Follows output only if cursor is at end of buffer.
      - e7bbd35 new option: 'scrollback'
      - fedb844 quasi-support for undo and 'modifiable'
      - b45ddf7 disables 'list' by default
      - disables 'relativenumber' by default

    :help now contains full API documentation at `:help api`.

    man.vim saw numerous improvements.

    Windows support:
      - Windows is no longer "experimental", it is fully supported.
      - Windows package includes a GUI, curl.exe and other utilities.

    "Vim 8" features: partials, lambdas.

SECURITY FIXES:
    CVE-2017-5953 CVE-2017-6349 CVE-2017-6350 neovim#6485

CHANGES:
    NVIM_TUI_ENABLE_CURSOR_SHAPE was removed. Use 'guicursor' instead.
        See https://github.com/neovim/neovim/wiki/Following-HEAD#20170402

    81525dc 'mouse=a' is no longer the default. (This will probably
                 change again after it is improved.) neovim#6022

    0c1f783 defaults: 'showcmd', 'belloff', 'ruler' neovim#6087
    eb0e94f api: {get,set}_option update local options as appropriate neovim#6405
    bdcb2a3 "Reading from stdin..." message was removed. neovim#6298

FIXES:
    12fc1de ops: fix i<c-r> with multi-byte text neovim#6524
    dd391bf Windows: system() and friends neovim#6497
    13352c0 Windows: os_get_hostname() neovim#6413
    16babc6 tui: Less-noisy mouse seqs neovim#6411
    3a9dd13 (vim bug) folding edge-cases  neovim#6207
    f6946c6 job-control: set CLOEXEC on pty processes. neovim#5986
    d1afd43 rplugin: Call s:LoadRemotePlugins() on startup.
    1215084 backtick-expansion works with `shell=fish` neovim#6224
    e32ec03 tui: Improved behavior after resize. neovim#6202
    86c2adc edit.c: CTRL-SPC: Insert previously-inserted text. neovim#6090
    c318d8e b:changedtick now follows VimL rules neovim#6112
    34e24cb terminal: Initialize colors in reverse order neovim#6160
    e889917 undo: Don't set b_u_curhead in ex_undojoin() neovim#5869
    d25649f undo: :earlier, g-: Set b_u_seq_cur correctly. (neovim#6016)
    043d8ba 'Visual-mode put from @. register' neovim#5782
    42c922b open_buffer(): Do `BufEnter` for directories.
    50d0d89 inccommand: Preview :sub commands only after delimiter neovim#5932
    1420e10 CheckHealth improvements neovim#5519
    c8d5e92 jobstart(): Return -1 if cmd is not executable. neovim#5671
justinmk added a commit to justinmk/neovim that referenced this pull request Aug 14, 2017
justinmk added a commit to justinmk/neovim that referenced this pull request Aug 14, 2017
Could also try `do_redraw = true` instead of save/restore `p_lz`, but
the nice thing about save/restore of `p_lz` is that it is "atomic".
The semantics of `do_redraw` are not clear to me.

Closes neovim#4884
References neovim#6202
References neovim#6202 (comment)
References neovim#3929 neovim#5692 neovim#6157
References neovim#5866
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants