Gtk sharp focus history?

194 views Asked by At

Is there an easy way to find out what the previously focus widget was?

Let's say I have two (or more) TextViews (A and B) and a ComboBoxEntry. Any change to the ComboBoxEntry modifies the current selection in A or B depending on the focused Widget (A or B). The problem is that the ComboBoxEntry grabs the focus so there is no way I can tell if I must apply the change to A or to B.

If I knew that last focused object it could work.

Now I can hardly imagine adding focus handlers to every single widget in my application just to be able to detect which one was the last focused before the ComboBoxEntry gets the focus.

Can anyone help?

Thanks.

1

There are 1 answers

0
Kristof On BEST ANSWER

In the end I did track focus changes accros my main window, but it turned out to be pretty simple :

On the top level window, override the OnSetFocus :

protected override void OnSetFocus(Widget focus)
{
    // Queue focus in a two entries queue (a simple array will do)
    // So this queue will always contain : Current Widget, last Widget.
}

Now, when my combobox with entry triggers OnChange, it spawns an event to both TextViews, which in turn read my Queue and determine which one was the focused element before they lost focus for the Combobox.