I have a simple GTK application that has 11 small png images displayed on one screen of a GtkStack.
When I transition to another page (with one png image) using GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT, the transition is jerky, not smooth.
I’ve tried playing around with gtk_stack_set_transition_duration() and can see that the first few moments of the transition are jerky (no matter the total duration) and it smooths out by the end.
I am running on high-spec hardware, but the goal is to move to an embedded platform, so if there is a performance issue, I’ll want to determine that now rather than later.
Any advice on how to debug this transition is appreciated.
after the call to gtk_stack_set_visible_child_name() to give the transition time to complete without anything else going on. I’m surprised this caused an issue since the “other stuff going on” is occurring in a thread other than the UI thread. Insights or alternate solutions are appreciated.
Honestly, I’ve never experienced any jittering or lag with GtkStack even in a single-threaded GJS or PyGObject application.
I would be looking for something causing GtkWidget::draw to be triggered excessively, some recursive reaction to the panel switching or something else in that thread getting busy because of it.
After the transition call, I was running code for the new screen to do some (non-GTK) things. This in turn was triggering other GTK-mainloop actions, which caused the transition stutters. The timeout solution I previously posted would work, but timeouts are smelly. The following is more deterministic and yields buttery-smooth transitions. The only downside is that my “after transition” actions don’t start until the transition is complete, but that’s not a problem for my particular use case.
// Code is running on the gtk_main thread...
// Swap the views
gtk_stack_set_visible_child_full(...);
// Let it finish the transition so that it's nice and smooth
while (gtk_stack_get_transition_running(GTK_STACK(m_handle))) {
while (gtk_events_pending()) gtk_main_iteration();
}
Right, exactly – the new screen kicks off a more intensive loop in another thread.
However, that thread is still at the default priority, has various blocking mechanisms and delays, etc, so it’s not spiking the processor – but apparently it was enough to cause issues for the stack transition (which I imagine needs to redraw a lot to keep things smooth). Waiting for the transition to complete before starting that process fixed the issue.