Ignore FocusGained events for the current second

Fix #2062: restore g:airline_focuslost_inactive behaviour.

Only ignore focusgained events on Windows. If there are more problematic
platforms, we'll add them later.

Instead of ignoring the next x FocusGained events whenever we do call
system(), ignore them for the current second. That allows us to put a
hard limit on the duration of the ignore.

This seems like a much better solution than the previous one because it
also prevents ignore events from building up (s:focusgained_ignored was
often greater than 5).

Test (gvim 8.2.140 on Win10)
gvim.exe ~/.vim/bundle/airline/autoload/airline/extensions/branch.vim
:Gedit HEAD
check several parents and no regression of looping behaviour from #2053.

:let g:airline_focuslost_inactive = 1
:split
alt-tab several times and statusline is correctly dimmed and restored
each time.
This commit is contained in:
David Briscoe 2020-02-13 14:29:33 -08:00
parent 099dd92eeb
commit c2ff76829f
1 changed files with 13 additions and 7 deletions

View File

@ -11,7 +11,7 @@ let s:spc = g:airline_symbols.space
let s:nomodeline = (v:version > 703 || (v:version == 703 && has("patch438"))) ? '<nomodeline>' : '' let s:nomodeline = (v:version > 703 || (v:version == 703 && has("patch438"))) ? '<nomodeline>' : ''
let s:has_strchars = exists('*strchars') let s:has_strchars = exists('*strchars')
let s:has_strcharpart = exists('*strcharpart') let s:has_strcharpart = exists('*strcharpart')
let s:focusgained_ignored = 0 let s:focusgained_ignore_time = 0
" TODO: Try to cache winwidth(0) function " TODO: Try to cache winwidth(0) function
" e.g. store winwidth per window and access that, only update it, if the size " e.g. store winwidth per window and access that, only update it, if the size
@ -193,14 +193,20 @@ function! airline#util#stl_disabled(winnr)
endfunction endfunction
function! airline#util#ignore_next_focusgain() function! airline#util#ignore_next_focusgain()
let s:focusgained_ignored += 1 if has('win32')
" Setup an ignore for platforms that trigger FocusLost on calls to
" system(). macvim (gui and terminal) and Linux terminal vim do not.
let s:focusgained_ignore_time = localtime()
endif
endfunction endfunction
function! airline#util#try_focusgained() function! airline#util#try_focusgained()
let s:focusgained_ignored -= 1 " Ignore lasts for at most one second and is cleared on the first
if s:focusgained_ignored < 0 " focusgained. We use ignore to prevent system() calls from triggering
let s:focusgained_ignored = 0 " FocusGained (which occurs 100% on win32 and seem to sometimes occur under
endif " tmux).
return s:focusgained_ignored <= 0 let dt = localtime() - s:focusgained_ignore_time
let s:focusgained_ignore_time = 0
return dt >= 1
endfunction endfunction