Skip to content

Fix popup window flickering on content-only updates#19559

Closed
mattn wants to merge 7 commits intovim:masterfrom
mattn:fix-popup-flicker
Closed

Fix popup window flickering on content-only updates#19559
mattn wants to merge 7 commits intovim:masterfrom
mattn:fix-popup-flicker

Conversation

@mattn
Copy link
Member

@mattn mattn commented Mar 3, 2026

When popup_setoptions() is called to update only firstline (e.g. scrolling via a timer), windows behind the popup flicker because a full popup mask refresh and UPD_NOT_VALID redraw are triggered every time, even though the popup's position and size haven't changed.

This patch distinguishes content-only changes (firstline, highlights) from structural ones (zindex, popup_flags, blend). For content-only changes, skip the mask refresh and popup_adjust_position(), and use UPD_VALID instead of UPD_NOT_VALID so only the popup itself is redrawn.

" Reproducer
let s:id = popup_create(range(1, 50)->map({i, v -> $"line {v}"}), {
  \ 'pos': 'center', 'minwidth': 60, 'maxheight': 10, 'border': [],
  \ })
let s:n = 1
function! s:scroll(timer) abort
  let s:n = s:n % 50 + 1
  call popup_setoptions(s:id, {'firstline': s:n})
endfunction
call timer_start(500, function('s:scroll'), {'repeat': -1})

#19510 (comment)

@mattn
Copy link
Member Author

mattn commented Mar 3, 2026

	Found errors in Test_popup_firstline():
	command line..script /home/runner/work/vim/vim/src/testdir/runtest.vim[636]..function RunTheTest[63]..Test_popup_firstline line 30: Expected 11 but got 10
	command line..script /home/runner/work/vim/vim/src/testdir/runtest.vim[636]..function RunTheTest[63]..Test_popup_firstline line 36: Expected 10 but got 9
	command line..script /home/runner/work/vim/vim/src/testdir/runtest.vim[636]..function RunTheTest[63]..Test_popup_firstline line 41: Expected 10 but got 9

Test is failing but I can judge whether the problem is depend on firstline or not.

Also, `opacity: 100` (fully opaque) now clears the `POPF_OPACITY` flag so the popup behaves exactly like a normal popup without opacity. The transparency rendering path is only used for `opacity: 1-99`.
@mattn
Copy link
Member Author

mattn commented Mar 3, 2026

Also, opacity: 100 (fully opaque) now clears the POPF_OPACITY flag so the popup behaves exactly like a normal popup without opacity. The transparency rendering path is only used for opacity: 1-99.

mattn added 5 commits March 3, 2026 22:45
During screen redraw, background window drawing would output characters
to the terminal for cells covered by popup windows. When the output
buffer flushed between background and popup drawing, the raw background
briefly appeared before the popup was redrawn, causing visible flicker
during mouse wheel scrolling.

Fix this in two ways:

1. In the skip_for_popup block in screen_line(), only call screen_char()
   during popup drawing (screen_zindex > 0). During background drawing
   (screen_zindex == 0), update the screen buffer but suppress terminal
   output. Set redraw_this = FALSE to prevent redundant drawing.

2. For opacity popups (which skip popup_mask), add a separate
   popup_opacity_mask array that tracks cells under opacity popups.
   Check this mask in screen_char() and screen_char_2() to suppress
   terminal output during background drawing. This covers all output
   paths including screen_fill().
- Always call popup_adjust_position() in popup_setoptions() so that
  border, close, padding changes are properly applied (restores
  original behavior).
- Use lightweight redraw (w_redr_type) for content-only changes
  (firstline, highlights) to avoid flickering.
- Remove popup_opacity_mask: master's patch v9.2.0104 already handles
  background suppression for opaque popups via screen_opacity_popup,
  and popup_opacity_mask was incorrectly blocking terminal output for
  transparent popup cells.
@mattn
Copy link
Member Author

mattn commented Mar 4, 2026

What this pull request fixes

  • Reduces the redraw area when changes are confined to the popup window
  • Prevents flickering of the popup window during background scrolling

See #19510

@chrisbra chrisbra closed this in 4d0c57e Mar 5, 2026
@chrisbra
Copy link
Member

chrisbra commented Mar 5, 2026

thanks

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.

2 participants