Gtk3 view flickers when GtkHeaderBar isn't shown or is drawn via Server-Side-Decorations.
Hey!
Repro code can be found here: https://github.com/jpnurmi/oh-my-corners
Gtk3 windows flicker when using gtk_widget_queue_draw() to update the window. The flickering becomes a lot more apparent when swiping up and down with 2 fingers in the view, although the issue also sometimes occurs when the cursor enters or leaves the window. Swiping up and down in other windows also causes the flicker to happen.
This only happens on X11 systems. I tested this on Fedora 37 running Gnome, but others have reported the same issue on recent Ubuntu versions. People who are affected by the issue are NVIDIA/INTEL users, using both nouveau and the proprietary NVIDIA drivers, though it seems that AMD users are unaffected.
In the repro code, when commenting out gtk_widget_show(GTK_WIDGET(header_bar));
the flickering only occurs in the top left and top right corner. For some reason the screen recording shows the entire window flickering even though I could only see the top left and right corners flicker.
Screencast_from_2023-02-17_09-04-38
When we don't let GTK create a headerbar for us and use SSD by removing the following piece of code:
GtkWidget* header_bar = gtk_header_bar_new();
gtk_widget_show(GTK_WIDGET(header_bar));
gtk_window_set_titlebar(GTK_WINDOW(window), GTK_WIDGET(header_bar));
the flickering occurs on the entire window. It's worth noting that that bigger the window is, the more it flickers and the longer those black frames are present.
Screencast_from_2023-02-17_09-05-32
I was able to remove all kinds of flickering by forcing Vsync on my device (https://askubuntu.com/questions/1066722/intel-screen-tearing-ubuntu-18-04), although at a massive performance cost.
Edit: After some further testing, this also happens when GTK draws a HeaderBar itself and doesn't hide it. Some food for thought: Since the flickering only ever happens when scrolling or entering and leaving the window, maybe the Gdk window listens to pointer events at a much faster rate than what the current refresh rate it, leading to multiple overlapping draw calls?