From 2e578194770653e84caf495eddc481f562118b44 Mon Sep 17 00:00:00 2001 From: Ryan Lortie Date: Fri, 17 Aug 2012 18:05:27 -0400 Subject: [PATCH] GtkApplication: add 'active-window' property --- gtk/gtk.symbols | 1 + gtk/gtkapplication.c | 43 ++++++++++++++++++++++++++++++++++++++++++- gtk/gtkapplication.h | 3 +++ 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols index 82f6f6f2a5..f0bffa4c69 100644 --- a/gtk/gtk.symbols +++ b/gtk/gtk.symbols @@ -246,6 +246,7 @@ gtk_application_window_get_type gtk_application_window_get_id gtk_application_window_new gtk_application_window_set_show_menubar +gtk_application_get_active_window gtk_arrow_get_type gtk_arrow_new gtk_arrow_placement_get_type diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c index efc1a8b486..0a233d993c 100644 --- a/gtk/gtkapplication.c +++ b/gtk/gtkapplication.c @@ -132,7 +132,8 @@ enum { PROP_ZERO, PROP_REGISTER_SESSION, PROP_APP_MENU, - PROP_MENUBAR + PROP_MENUBAR, + PROP_ACTIVE_WINDOW }; G_DEFINE_TYPE (GtkApplication, gtk_application, G_TYPE_APPLICATION) @@ -405,6 +406,8 @@ gtk_application_focus_in_event_cb (GtkWindow *window, priv->windows = g_list_concat (link, priv->windows); } + g_object_notify (G_OBJECT (application), "active-window"); + #ifdef GDK_WINDOWING_QUARTZ gtk_application_focus_changed (application, window); #endif @@ -529,6 +532,8 @@ gtk_application_window_added (GtkApplication *application, #ifdef GDK_WINDOWING_X11 gtk_application_window_added_x11 (application, window); #endif + + g_object_notify (G_OBJECT (application), "active-window"); } static void @@ -536,6 +541,9 @@ gtk_application_window_removed (GtkApplication *application, GtkWindow *window) { GtkApplicationPrivate *priv = application->priv; + gpointer old_active; + + old_active = priv->windows; #ifdef GDK_WINDOWING_X11 gtk_application_window_removed_x11 (application, window); @@ -548,6 +556,9 @@ gtk_application_window_removed (GtkApplication *application, g_application_release (G_APPLICATION (application)); priv->windows = g_list_remove (priv->windows, window); gtk_window_set_application (window, NULL); + + if (priv->windows != old_active) + g_object_notify (G_OBJECT (application), "active-window"); } static void @@ -755,6 +766,13 @@ gtk_application_class_init (GtkApplicationClass *class) P_("The GMenuModel for the menubar"), G_TYPE_MENU_MODEL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + g_object_class_install_property (object_class, PROP_ACTIVE_WINDOW, + g_param_spec_object ("active-window", + P_("Active window"), + P_("The window which most recently had focus"), + GTK_TYPE_WINDOW, + G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); } /** @@ -915,6 +933,29 @@ gtk_application_get_window_by_id (GtkApplication *application, return NULL; } +/** + * gtk_application_get_active_window: + * @application: a #GtkApplication + * + * Gets the "active" window for the application. + * + * The active window is the one that was most recently focused (within + * the application). This window may not have the focus at the moment + * if another application has it -- this is just the most + * recently-focused window within this application. + * + * Returns: (transfer none): the active window + * + * Since: 3.6 + **/ +GtkWindow * +gtk_application_get_active_window (GtkApplication *application) +{ + g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL); + + return application->priv->windows ? application->priv->windows->data : NULL; +} + /** * gtk_application_add_accelerator: * @application: a #GtkApplication diff --git a/gtk/gtkapplication.h b/gtk/gtkapplication.h index 21cd389ab3..d3545623fb 100644 --- a/gtk/gtkapplication.h +++ b/gtk/gtkapplication.h @@ -119,6 +119,9 @@ GDK_AVAILABLE_IN_3_6 GtkWindow * gtk_application_get_window_by_id (GtkApplication *application, guint id); +GDK_AVAILABLE_IN_3_6 +GtkWindow * gtk_application_get_active_window (GtkApplication *application); + G_END_DECLS #endif /* __GTK_APPLICATION_H__ */