From c2ff76829f0db9ea32ca5c28c33357e856c1bad6 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Thu, 13 Feb 2020 14:29:33 -0800 Subject: [PATCH] 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. --- autoload/airline/util.vim | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/autoload/airline/util.vim b/autoload/airline/util.vim index d8e0e2ff..54539413 100644 --- a/autoload/airline/util.vim +++ b/autoload/airline/util.vim @@ -11,7 +11,7 @@ let s:spc = g:airline_symbols.space let s:nomodeline = (v:version > 703 || (v:version == 703 && has("patch438"))) ? '' : '' let s:has_strchars = exists('*strchars') let s:has_strcharpart = exists('*strcharpart') -let s:focusgained_ignored = 0 +let s:focusgained_ignore_time = 0 " TODO: Try to cache winwidth(0) function " 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 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 function! airline#util#try_focusgained() - let s:focusgained_ignored -= 1 - if s:focusgained_ignored < 0 - let s:focusgained_ignored = 0 - endif - return s:focusgained_ignored <= 0 + " Ignore lasts for at most one second and is cleared on the first + " focusgained. We use ignore to prevent system() calls from triggering + " FocusGained (which occurs 100% on win32 and seem to sometimes occur under + " tmux). + let dt = localtime() - s:focusgained_ignore_time + let s:focusgained_ignore_time = 0 + return dt >= 1 endfunction