Why is TopLevelWindowManager polling?


#1

TopLevelWindowManager polls with a 1731ms interval timer for the currently focused component to set the active TopLevelWindow, see TopLevelWindowManager::timerCallback.

This works but seems to be problematic on Ubuntu, at least for me.

The symptom: The initial TopLevelWindow of an application is inactive after application startup. It’s activated 1741ms after application startup resulting in a annoying visual delay.

The cause: It seems that the startTimer (10) call in TopLevelWindowManager::addWindow triggers the timer callback before the window has gained focus after adding it to the desktop. TopLevelWindowManager::timerCallback restarts the timer with 1731ms interval and in the next activation of the timer callback the window is set active, but late.

The question is, why is TopLevelWindowManager::timerCallback polling? Why isn’t the TopLevelWindowManager a FocusChangeListener and the work that the timer callback does now is done by the globalFocusChanged callback?

I’ll test now if it’s working with the proposed change, maybe I’ll find the reason for the polling.

Edit:
Using FocusChangeListener works on Ubuntu, but may be a too big change to solve this problem. Also I don’t know the reason for the polling behavior.

A much simpler solution is to change TopLevelWindowManager::timerCallback like this:

[code] void timerCallback()
{
if (getTimerInterval() < 1731)
startTimer (jmin (1731, getTimerInterval() * 2));
else
startTimer (1731);

    TopLevelWindow* active = 0;[/code]

Don’t let the timer interval jump from 10ms to 1731ms, but gradually increase it by doubling the interval each time the callback is called until it reaches an upper limit.


#2

That’s a good suggestion. Sorry, but I can’t remember exactly why it polls like that - I guess there was a problem in getting reliable callbacks to indicate when the focus has changed…