Difference between idle_add(...) and timeout_add(0, ...) with scroll_to_cell

I have code that invokes scroll_to_cell to center a selection after a particular action, but the scrolling did not occur. It did not occur whether I called scroll_to_cell directly or in idle_add. I discovered yesterday that the scrolling did occur when I called scroll_to_cell in timeout_add with a time of 0. I would have thought that timeout_add with a time of 0 would be the same as idle_add.

To add to the mystery, there is another situation in which the same TreeView needs to scroll. scroll_to_cell in idle_add was working in that situation, but when I switched to timeout_add it stopped working. I solved both problems by calling scroll_to_cell twice, first in timeout_add and then in idle_add.

This surprising hack solves my problem, but I am curious to know whether anyone has any insight into why idle_add(…) and timeout_add(0, …) produce different results – and why scroll_to_cell is working only with one of them.

Idle sources installed in the main loop with g_idle_add() have a priority of G_PRIORITY_DEFAULT_IDLE. Timeout source installed with g_timeout_add() have a priority of G_PRIORITY_DEFAULT. The default priority is higher than the default idle priority, so timeout sources will be scheduled first.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.