GtkTreeView doesn't draw header under certain conditions
The attached snippet was provided by a user who did some debugging, his conclusions were that this is a native GTK bug. I've gone ahead and verified the bug happens on my Fedora 30 box, and Ubuntu 18.04.
Steps to reproduce
- Compile and launch the snippet attached.
- Observe that only some of the GtkTreeView headers are drawn (all should be drawn)
- On GTK3.20+ this is an issue. GTK3.18 and below don't appear to be affected (more info below)
Current behavior
Only some GtkTreeViews draw their headers.
Expected outcome
All GtkTreeViews in the snippet should draw their headers.
Version information
Fedora 30, but is observable on all GTK >= 3.20
Additional information
The user who provided this information also left some clues as to what causes the bug:
- 'gtk_tree_view_draw' calls '_gtk_pixel_cache_draw'
- '_gtk_pixel_cache_draw' has two branches - 'if' and 'else'.
- For regular trees, 'if' branch is taken. It correctly uses 'cairo_save' / 'cairo_restore'.
- For bad trees, 'else' branch is taken. It forgets to save/restore.
- 'else' branch is taken because '_gtk_pixel_cache_create_surface_if_needed' has created a surface of type 'CAIRO_SURFACE_TYPE_IMAGE' instead of type 'CAIRO_SURFACE_TYPE_XLIB'.
- 'CAIRO_SURFACE_TYPE_IMAGE' is returned by 'cairo_surface_create_similar' because '_cairo_xlib_surface_create_similar' returns NULL.
- '_cairo_xlib_surface_create_similar' returns NULL because requested height == 0.
Summary: Buggy branch is taken in '_gtk_pixel_cache_draw' when Tree's content (non-header area) is 0 pixels high.