macvim-dev / macvim

Vim - the text editor - for macOS
https://macvim.org
Vim License
7.47k stars 680 forks source link

MacVim does not enter full screen #1378

Closed mario-grgic closed 1 year ago

mario-grgic commented 1 year ago

Steps to reproduce

I am building MacVim from git source pretty regularly with huge features enabled on Catalina (macOS 10.15.7) with XCode 12.1 and Ventura (macOS 13.2.1) with XCode 14.1.

I have the following code in my .gvimrc that enters full screen in diff mode and equalizes the sizes of side by side windows:

au VimEnter,VimResized * :call MaximizeWindowInDiffMode()

function MaximizeWindowInDiffMode()
    " if the GUI was started in the diff mode, maximize the window
    if &diff
    color github

    " make all windows equal width
    execute "normal \<C-w>="

    " turn off transparency since colors look better
    set transparency=0

    " enter full screen
    if !&fu 
        set fu
    endif
    endif
endfunction

This used to work for over 15 years now, until it got broken very recently. It works fine in MacVim r176, patch level 1298:

VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Feb 19 2023 09:57:09)
macOS version - x86_64
Included patches: 1-1298
Huge version with MacVim GUI.  Features included (+) or not (-):
+acl               +find_in_path      +mouse_xterm       -tcl
+arabic            +float             +multi_byte        +termguicolors
+autocmd           +folding           +multi_lang        +terminal
+autochdir         -footer            -mzscheme          +terminfo
-autoservername    +fork()            +netbeans_intg     +termresponse
+balloon_eval      +fullscreen        +num64             +textobjects
+balloon_eval_term +gettext           +odbeditor         +textprop
+browse            -hangul_input      +packages          +timers
++builtin_terms    +iconv             +path_extra        +title
+byte_offset       +insert_expand     +perl              +toolbar
+channel           +ipv6              +persistent_undo   +transparency
+cindent           +job               +popupwin          +user_commands
+clientserver      +jumplist          +postscript        +vartabs
+clipboard         +keymap            +printer           +vertsplit
+cmdline_compl     +lambda            +profile           +vim9script
+cmdline_hist      +langmap           +python/dyn        +viminfo
+cmdline_info      +libcall           +python3/dyn       +virtualedit
+comments          +linebreak         +quickfix          +visual
+conceal           +lispindent        +reltime           +visualextra
+cryptv            +listcmds          +rightleft         +vreplace
+cscope            +localmap          +ruby              +wildignore
+cursorbind        +lua               +scrollbind        +wildmenu
+cursorshape       +menu              +signs             +windows
+dialog_con_gui    +mksession         +smartindent       +writebackup
+diff              +modify_fname      +sodium            -X11
+digraphs          +mouse             +sound             -xfontset
+dnd               +mouseshape        +spell             +xim
-ebcdic            +mouse_dec         +startuptime       -xpm
+emacs_tags        -mouse_gpm         +statusline        -xsmp
+eval              -mouse_jsbterm     -sun_workshop      -xterm_clipboard
+ex_extra          +mouse_netterm     +syntax            -xterm_save
+extra_search      +mouse_sgr         +tag_binary        
-farsi             -mouse_sysmouse    -tag_old_static    
+file_in_path      +mouse_urxvt       -tag_any_white     
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  system gvimrc file: "$VIM/gvimrc"
    user gvimrc file: "$HOME/.gvimrc"
2nd user gvimrc file: "~/.vim/gvimrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
    system menu file: "$VIMRUNTIME/menu.vim"
  fall-back for $VIM: "/Applications/MacVim.app/Contents/Resources/vim"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DFEAT_GUI_MACVIM -Wall -Wno-unknown-pragmas -pipe -DMACOS_X -DMACOS_X_DARWIN -g -O2 -I/usr/local/include -D_REENTRANT -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 
Linking: gcc -L/usr/local/lib -o Vim -lm -lncurses /usr/local/lib/libsodium.a -liconv /usr/local/lib/libintl.a -framework AppKit -L/usr/local/lib -llua -fstack-protector -L/System/Library/Perl/5.18/darwin-thread-multi-2level/CORE -lperl -lruby.2.6 -L/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib 

but stops working in patch level 1365.

Note that it works on Ventura but not on Catalina.

On Catalina you get erratic behavior where once in a while it will enter the full screen mode, but most of the time it will not.

Note that the function is always called (tested it with debug messages) and the fullscreen mode is set :set fu? prints fullscreen.

Of course you could solve this problem but not using VimEnter event at all and just entering full screen mode always in diff mode, but the full screen behaviour is quite jarring and not smooth.

Expected behaviour

MacVim should enter full screen mode.

Version of Vim and architecture

9.0.1365 x86_64

Environment

macOS 10.15.7 mac Terminal.app xterm-256color GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin19.6.0)

How MacVim was installed

Built form git

Logs and stack traces

No response

Vim configuration where issue is reproducable

No response

Issue has been tested with given configuration

Issue has been tested with no configuration

Other conditions

ychin commented 1 year ago

Huh, I'll need to test this in a VM because as you said it does work in macOS 13 Ventura. Just to be clear, set fu still works, just outside of VimEnter right? Or does set fu not work at all for you?

Also, are you using native or non-native full screen?

but the full screen behaviour is quite jarring and not smooth.

What do you mean by this by the way?

mario-grgic commented 1 year ago

Yes, set fu works ordinarily, just not from VIMEnter event (well only occasionally). I am using native full screen.

mario-grgic commented 1 year ago

but the full screen behaviour is quite jarring and not smooth.

What do you mean by this by the way?

If you run set fu directly in .gvimrc, the OS seems to run its own window opening animation (i.e. window growing from small rectangle to final window size), which is then interrupted by full screen animation somewhere in the middle. The full screen animation is also not rendering all frames, only the final few frames are rendered and it looks jarring.

If you run set fu from VimEnter event, both animations are run smoothly and fully in order , first window opening animation, followed full screen animation. This takes longer too but is smoother and less jarring.

ychin commented 1 year ago

Alright found the bug. It was introduced when merging from upstream and resolving merge conflicts. It's a little annoying because it relies on the specifics of the compiler in order to show up (the code was reading the wrong C union value if you were curious), so I'm glad you somehow found the case that did expose the bug. The full repro was actually just set diff followed by set fu, no need for VimEnter autocmds.

The fix should be merged shortly.

mario-grgic commented 1 year ago

I can confirm this is fixed.

Thank you for finding and fixing it so quickly. That is a very subtle bug.