Skip to content

PlasmaQuick::Dialog - Fix flickering issues when resizing (specially in krunner)

Eduardo Cruz requested to merge ecruz/plasma-framework:no_flickering into master

The goal is to fix the flickering issue with KRunner as reported in BUG 427672.

The bug report deals with 2 issues: the quick reordering of the results list (that will be fixed by milou!37 (merged)) and the quick rendering/flashing of frames with components in wrong positions. This MR deals with the latter.

In PlasmaQuick::Dialog we have the slots updateMinimumWidth, updateMinimumHeight, updateMaximumWidth, updateMaximumHeight connected to their corresponding signals on the underlying layout object.

Theses slots used to start a 0ms instantly-expired timer to condensate all four operations into one single execution of the method updateLayoutParameters(). It was seemingly done in an attempt to avoid flickering. However, it was apparently causing it instead of preventing it.

We had no guarantee that the timer's action will be the next event executed in the GUI thread event loop. By returning control of the GUI thread to the event loop, we are vulnerable to the event loop deciding that a frame update is more important than the expired timer's action, and that's what was happening: a frame was being rendered before that timer's action was executed, and the frame was rendered with incorrect layout parameters, causing KRunner to be displayed in crazy ways for a few milliseconds.

This code is old, 7 years ago. Maybe this timer mechanism was actually useful back then: there was a bug inside QT that caused flickering as reported in this QT bug report, but is is now already solved since QT 5.12.5.

I have deleted that timer and now I call updateLayoutParameters() instantly for each of the four slots. It is true that this method is now running 4 times, however that doesn't seem to be any problem at all. They run in the GUI thread, in the same pass of the event loop, so at the end of the loop's current pass we will reach our goal of having all layout parameters up-to-date before it gets a chance to decide to render the next frame.

This reference helped me to understand more of the frame rendering cycle: https://doc.qt.io/qt-5/qtquick-visualcanvas-scenegraph.html#threaded-render-loop-threaded

With this patch applied, the flickering situation in KRunner is MUCH better, but not completely fixed. Some kinds of flicker seem to be gone at all: for example we will never see the search textbox being rendered out of place, nor the quick repositioning of the results lists. But we sometimes still see some result being rendered in the location of the textbox when we press backspace successively. I'd say the problem is now 90% fixed, there must be other causes of flicker lurking across the stack but it doesn't seem to be in PlasmaQuick::Dialog.

CCBUG: 427672

Merge request reports