Fix native fullscreen rendering and resizing bugs by ychin · Pull Request #745 · macvim-dev/macvim

@ychin mentioned this pull request

Nov 1, 2018
Fix the issue where MacVim would occasionally draws corrupted image in
fullscreen (it would draw mostly black).

The easiest way to reproduce this is as follows:

1. Make a new MacVim window, enter fullscreen
2. Open a new tab or hit Cmd-= a few times
3. Switch to another fullscreen app or desktop, click around, then
   switch back
4. Observe most of the screen is black.

The reason this happens is that the MacVim resize code always tries to
resize the window to fit the content size (calculated from how many
lines / columns we have and whether other elements like tab bar are
visible).  This means the resize code
(resizeWindowToFitContentSize:keepOnScreen:) would make the window
smaller than the full size of screen. For some reason, when you switch
away from the space, macOS decides to resize the window back to screen
size again, causing a window resize event to happen. The resize event
invalidates the NSView, causing it to draw black.

This is also why fullscreen mode has black bars on top / bottom, which
is especially jarring when font size is large of `linespace` is high.

The fix is to treat guioptions 'k' to be on when in full screen mode,
since the option means we will always try to fit the Vim content inside
the window, rather than resize the window to fit the Vim content. This
way the fullscreen Vim window will take up the whole screen and won't
keep getting resized. This is also more similar to how native Gvim works
when maximized.

Close macvim-dev#496 (black bars)

Close macvim-dev#557, close macvim-dev#674 (full screen rendering issues)

A related issue is that MacVim (without CGLayer backing) doesn't
actually know how to redraw itself properly when invalidated, which is
the root cause of this bug. It receives Vim draw calls incrementally and
doesn't actually cache the rendered content, so it relies on the fact
that MacVim's NSWindow doesn't usually invalidates all the content which
allows it to draw incrementally without needing to perform a full
redraw. This is why non-native fullscreen requires CGLayer backing mode
as macOS's behavior in this mode (basically a borderless window) is that
it does clear the NSWindow's content when setWantsDisplay: is called.
This is also why Vim live window resizing is limited to cell size
instead of allowing smooth resize (to avoid having to trigger redraws).
These are issues that should be fixed later.
Previously when using native fullscreen mode, if you toggle fullscreen
off, the window will end up taking up the whole screen rather than
restoring back to the original size. Fix that.

The real issue is because when you resize MacVim's window (which the
fullscreen restore code does), then callback (windowDidResize) triggered
a complicated set of callbacks by calling setFrameSize:, which in turn
resizes Vim, which in turn calls windowDidResize again, which usually
does the right thing, but not always. Fix the window resize handler code
to always respect the new window size by calling
setFrameSizeKeepGUISize: instead which doesn't resize the window.
Fix issue where if the user double-clicks on the window border or corner
to resize MacVim (the macOS behavior is to resize the window all the way
to the screen's border), it results in an incomplete resize and also
takes a long time.

The code was spamming the Vim instance with live resize messages,
leading to slowdown and dropped messages. Fix it by rate limiting the
messages to one at a time, which speeds things up, and clean up when
live resize finishes to make sure things look right.

@ychin ychin deleted the rendering_fixes branch

November 2, 2018 05:33

ychin added a commit to ychin/macvim that referenced this pull request

Dec 5, 2018
Vim patch 8.1.560

Targets macOS 10.8+

Features:
- macOS Mojave (10.14) is now supported.
    - MacVim's UI now works with Dark Mode.
    - Fixed broken rendering and flickering under Mojave when using the
      default Core Text renderer. macvim-dev#757
- guioption 'k' is supported again. macvim-dev#731
    - This option prevents window from resizing when UI elements such as
      toolbars or tabs show or hide themselves.

Fixes:
- Fixed misc fullscreen and window resizing bugs and artifacts macvim-dev#745
- Dragging tabs to reorder now works properly macvim-dev#789
- Fixed timer callback handling in GUI macvim-dev#749
- Fixed native tabs (10.12+) interring with Vim tabs macvim-dev#788
- Fixed Japanese IME Ctrl-U/Ctrl-O handling macvim-dev#742
- Fixed MMShareFindPboard and Cmd-E/Cmd-G interactions macvim-dev#780
- Better handling of guifontwide font size macvim-dev#737
- Better python discovery in default vimrc macvim-dev#739

Known Issues:
- Scrolling performance is slightly worse under Mojave macvim-dev#796

Script interfaces have compatibility with these versions:
- Lua 5.3
- Perl 5.18
- Python2 2.7
- Python3 3.7
- Ruby 2.5

ychin added a commit that referenced this pull request

Dec 5, 2018
Vim patch 8.1.560

Targets macOS 10.8+

Features:
- macOS Mojave (10.14) is now supported.
    - MacVim's UI now works with Dark Mode.
    - Fixed broken rendering and flickering under Mojave when using the
      default Core Text renderer. #757
- guioption 'k' is supported again. #731
    - This option prevents window from resizing when UI elements such as
      toolbars or tabs show or hide themselves.

Fixes:
- Fixed misc fullscreen and window resizing bugs and artifacts #745
- Dragging tabs to reorder now works properly #789
- Fixed timer callback handling in GUI #749
- Fixed native tabs (10.12+) interring with Vim tabs #788
- Fixed Japanese IME Ctrl-U/Ctrl-O handling #742
- Fixed MMShareFindPboard and Cmd-E/Cmd-G interactions #780
- Better handling of guifontwide font size #737
- Better python discovery in default vimrc #739

Known Issues:
- Scrolling performance is slightly worse under Mojave #796

Script interfaces have compatibility with these versions:
- Lua 5.3
- Perl 5.18
- Python2 2.7
- Python3 3.7
- Ruby 2.5

@ychin ychin mentioned this pull request

Dec 20, 2018