summaryrefslogtreecommitdiff
path: root/gtk/gtkapplication.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2011-05-31 18:28:55 -0400
committerMatthias Clasen <mclasen@redhat.com>2011-05-31 18:28:55 -0400
commit75390b2d602ca73156190350b9b62a8f870c801d (patch)
treeb8f2ac896afc5db76b009509d36f35a8f1f6a11e /gtk/gtkapplication.c
parent5b4932adaa7a3eaf903024f6874049a8f68168df (diff)
downloadgtk+-75390b2d602ca73156190350b9b62a8f870c801d.tar.gz
Sort GtkApplication windows by most-recently-focused
Based on a patch by Matt Barnes, https://bugzilla.gnome.org/show_bug.cgi?id=624539
Diffstat (limited to 'gtk/gtkapplication.c')
-rw-r--r--gtk/gtkapplication.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index cf57bf28f5..d6287d9c9b 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -67,6 +67,25 @@ struct _GtkApplicationPrivate
GList *windows;
};
+static gboolean
+gtk_application_focus_in_event_cb (GtkWindow *window,
+ GdkEventFocus *event,
+ GtkApplication *application)
+{
+ GtkApplicationPrivate *priv = application->priv;
+ GList *link;
+
+ /* Keep the window list sorted by most-recently-focused. */
+ link = g_list_find (priv->windows, window);
+ if (link != NULL && link != priv->windows)
+ {
+ priv->windows = g_list_remove_link (priv->windows, link);
+ priv->windows = g_list_concat (link, priv->windows);
+ }
+
+ return FALSE;
+}
+
static void
gtk_application_startup (GApplication *application)
{
@@ -216,6 +235,10 @@ gtk_application_add_window (GtkApplication *application,
priv->windows = g_list_prepend (priv->windows, window);
gtk_window_set_application (window, application);
g_application_hold (G_APPLICATION (application));
+
+ g_signal_connect (window, "focus-in-event",
+ G_CALLBACK (gtk_application_focus_in_event_cb),
+ application);
}
}
@@ -240,13 +263,18 @@ gtk_application_remove_window (GtkApplication *application,
GtkWindow *window)
{
GtkApplicationPrivate *priv;
+ GList *link;
g_return_if_fail (GTK_IS_APPLICATION (application));
priv = application->priv;
- if (g_list_find (priv->windows, window))
+ link = g_list_find (priv->windows, window);
+ if (link)
{
- priv->windows = g_list_remove (priv->windows, window);
+ g_signal_handlers_disconnect_by_func (window,
+ gtk_application_focus_in_event_cb,
+ application);
+ priv->windows = g_list_remove_link (priv->windows, link);
g_application_release (G_APPLICATION (application));
gtk_window_set_application (window, NULL);
}
@@ -258,7 +286,13 @@ gtk_application_remove_window (GtkApplication *application,
*
* Gets a list of the #GtkWindow<!-- -->s associated with @application.
*
- * The list that is returned should not be modified in any way.
+ * The list is sorted by most recently focused window, such that the first
+ * element is the currently focused window. (Useful for choosing a parent
+ * for a transient window.)
+ *
+ * The list that is returned should not be modified in any way. It will
+ * only remain valid until the next focus change or window creation or
+ * deletion.
*
* Returns: (element-type GtkWindow) (transfer none): a #GList of #GtkWindow
*