GNOME Bugzilla – Bug 624539
Keep track of last focused window
Last modified: 2011-05-31 22:29:43 UTC
Created attachment 166020 [details] [review] Keep track of last focused window Currently GtkApplication keeps track only of the first created window. If there are more than 1 window, we should keep track of the last one. Also, if the first one is destroyed, our reference is broken.
I was just going to file a very similar enhancement request, but I'll hijack this one. I'm starting to convert Evolution's EShell class from UniqueApp to GtkApplication. EShell has the exact same window-tracking concept as GtkApplication, except we keep the window list sorted by most-recently-focused using the same "focus-in-event" trick that Jonh's using in the patch here. But instead of explictly trying to keep track of a default window, you can just maintain the invariant that the first window in the list returned by gtk_application_get_windows() is the most recently focused window. This comes in handy when you need to quickly find a parent for a transient window. The most recently focused "tracked" window is usually a safe choice.
Created attachment 179689 [details] [review] Proposed patch
Review of attachment 179689 [details] [review]: Makes sense to me. Lets see if Ryan has any comments ::: gtk/gtkapplication.c @@ +267,3 @@ if (g_list_find (priv->windows, window)) { + if (GTK_IS_WINDOW (window)) Why is this check necessary ? @@ +290,1 @@ * The list that is returned should not be modified in any way. Should probably point out here that the list will only remain valid until the next focus change.
(In reply to comment #3) > ::: gtk/gtkapplication.c > @@ +267,3 @@ > if (g_list_find (priv->windows, window)) > { > + if (GTK_IS_WINDOW (window)) > > Why is this check necessary ? It may not be needed. I think that was for the case where the function is called from gtk_window_finalize(). Wasn't sure if it's safe to disconnect signal handlers on an instance already being finalized, but I might have just been overly paranoid.