application: Add unique IDs for GtkApplicationWindow

This will allow to refer to specific GtkApplicationWindows remotely by ID.

https://bugzilla.gnome.org/show_bug.cgi?id=674409
This commit is contained in:
Christian Persch 2012-04-20 19:29:11 +02:00
parent 824776cb02
commit ff66d0d8e5
7 changed files with 73 additions and 4 deletions

View File

@ -7020,6 +7020,7 @@ gtk_application_new
gtk_application_add_window gtk_application_add_window
gtk_application_remove_window gtk_application_remove_window
gtk_application_get_windows gtk_application_get_windows
gtk_application_get_window_by_id
<SUBSECTION> <SUBSECTION>
GtkApplicationInhibitFlags GtkApplicationInhibitFlags
@ -7053,6 +7054,7 @@ GtkApplicationWindow
gtk_application_window_new gtk_application_window_new
gtk_application_window_set_show_menubar gtk_application_window_set_show_menubar
gtk_application_window_get_show_menubar gtk_application_window_get_show_menubar
gtk_application_window_get_id
<SUBSECTION Standard> <SUBSECTION Standard>
GtkApplicationWindowClass GtkApplicationWindowClass

View File

@ -231,6 +231,7 @@ gtk_application_get_app_menu
gtk_application_get_menubar gtk_application_get_menubar
gtk_application_get_type gtk_application_get_type
gtk_application_get_windows gtk_application_get_windows
gtk_application_get_window_by_id
gtk_application_inhibit gtk_application_inhibit
gtk_application_inhibit_flags_get_type gtk_application_inhibit_flags_get_type
gtk_application_is_inhibited gtk_application_is_inhibited
@ -242,6 +243,7 @@ gtk_application_set_menubar
gtk_application_uninhibit gtk_application_uninhibit
gtk_application_window_get_show_menubar gtk_application_window_get_show_menubar
gtk_application_window_get_type gtk_application_window_get_type
gtk_application_window_get_id
gtk_application_window_new gtk_application_window_new
gtk_application_window_set_show_menubar gtk_application_window_set_show_menubar
gtk_arrow_get_type gtk_arrow_get_type

View File

@ -255,8 +255,8 @@ gtk_application_window_added_x11 (GtkApplication *application,
guint window_id; guint window_id;
window_id = application->priv->next_id++; window_id = application->priv->next_id++;
window_path = g_strdup_printf ("%s/window/%d", application->priv->object_path, window_id); window_path = g_strdup_printf ("%s/window/%u", application->priv->object_path, window_id);
success = gtk_application_window_publish (app_window, application->priv->session_bus, window_path); success = gtk_application_window_publish (app_window, application->priv->session_bus, window_path, window_id);
g_free (window_path); g_free (window_path);
} }
while (!success); while (!success);
@ -501,6 +501,8 @@ gtk_application_init (GtkApplication *application)
application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application, application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
GTK_TYPE_APPLICATION, GTK_TYPE_APPLICATION,
GtkApplicationPrivate); GtkApplicationPrivate);
application->priv->next_id = 1;
} }
static void static void
@ -873,6 +875,34 @@ gtk_application_get_windows (GtkApplication *application)
return application->priv->windows; return application->priv->windows;
} }
/**
* gtk_application_get_window_by_id:
* @application: a #GtkApplication
* @id: an identifier number
*
* Returns: (transfer none): the #GtkApplicationWindow with ID @id, or
* %NULL if there is no window with this ID
*
* Since: 3.6
*/
GtkWindow *
gtk_application_get_window_by_id (GtkApplication *application,
guint id)
{
GList *l;
g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
for (l = application->priv->windows; l != NULL; l = l->next)
{
if (GTK_IS_APPLICATION_WINDOW (l->data) &&
gtk_application_window_get_id (GTK_APPLICATION_WINDOW (l->data)) == id)
return l->data;
}
return NULL;
}
/** /**
* gtk_application_add_accelerator: * gtk_application_add_accelerator:
* @application: a #GtkApplication * @application: a #GtkApplication

View File

@ -115,6 +115,10 @@ GDK_AVAILABLE_IN_3_4
gboolean gtk_application_is_inhibited (GtkApplication *application, gboolean gtk_application_is_inhibited (GtkApplication *application,
GtkApplicationInhibitFlags flags); GtkApplicationInhibitFlags flags);
GDK_AVAILABLE_IN_3_6
GtkWindow * gtk_application_get_window_by_id (GtkApplication *application,
guint id);
G_END_DECLS G_END_DECLS
#endif /* __GTK_APPLICATION_H__ */ #endif /* __GTK_APPLICATION_H__ */

View File

@ -27,7 +27,8 @@
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean gtk_application_window_publish (GtkApplicationWindow *window, gboolean gtk_application_window_publish (GtkApplicationWindow *window,
GDBusConnection *session, GDBusConnection *session,
const gchar *object_path); const gchar *object_path,
guint object_id);
G_GNUC_INTERNAL G_GNUC_INTERNAL
void gtk_application_window_unpublish (GtkApplicationWindow *window); void gtk_application_window_unpublish (GtkApplicationWindow *window);

View File

@ -218,6 +218,8 @@ struct _GtkApplicationWindowPrivate
GDBusConnection *session; GDBusConnection *session;
gchar *object_path; gchar *object_path;
guint export_id; guint export_id;
guint id;
}; };
static void static void
@ -809,11 +811,13 @@ gtk_application_window_real_unrealize (GtkWidget *widget)
gboolean gboolean
gtk_application_window_publish (GtkApplicationWindow *window, gtk_application_window_publish (GtkApplicationWindow *window,
GDBusConnection *session, GDBusConnection *session,
const gchar *object_path) const gchar *object_path,
guint object_id)
{ {
g_assert (window->priv->session == NULL); g_assert (window->priv->session == NULL);
g_assert (window->priv->export_id == 0); g_assert (window->priv->export_id == 0);
g_assert (window->priv->object_path == NULL); g_assert (window->priv->object_path == NULL);
g_assert (window->priv->id == 0);
window->priv->export_id = g_dbus_connection_export_action_group (session, object_path, window->priv->export_id = g_dbus_connection_export_action_group (session, object_path,
G_ACTION_GROUP (window->priv->actions), G_ACTION_GROUP (window->priv->actions),
@ -824,6 +828,7 @@ gtk_application_window_publish (GtkApplicationWindow *window,
window->priv->session = session; window->priv->session = session;
window->priv->object_path = g_strdup (object_path); window->priv->object_path = g_strdup (object_path);
window->priv->id = object_id;
return TRUE; return TRUE;
} }
@ -834,10 +839,12 @@ gtk_application_window_unpublish (GtkApplicationWindow *window)
g_assert (window->priv->session != NULL); g_assert (window->priv->session != NULL);
g_assert (window->priv->export_id != 0); g_assert (window->priv->export_id != 0);
g_assert (window->priv->object_path != NULL); g_assert (window->priv->object_path != NULL);
g_assert (window->priv->id != 0);
g_dbus_connection_unexport_action_group (window->priv->session, window->priv->export_id); g_dbus_connection_unexport_action_group (window->priv->session, window->priv->export_id);
window->priv->session = NULL; window->priv->session = NULL;
window->priv->export_id = 0; window->priv->export_id = 0;
window->priv->id = 0;
g_free (window->priv->object_path); g_free (window->priv->object_path);
window->priv->object_path = NULL; window->priv->object_path = NULL;
@ -1086,3 +1093,23 @@ gtk_application_window_get_accel_group (GtkApplicationWindow *window)
{ {
return window->priv->accels; return window->priv->accels;
} }
/**
* gtk_application_window_get_id:
* @window: a #GtkApplicationWindow
*
* Returns the unique ID of the window. If the window has not yet been added to
* a #GtkApplication, returns <literal>0</literal>.
*
* Returns: the unique ID for @window, or <literal>0</literal> if the window
* has not yet been added to a #GtkApplication
*
* Since: 3.6
*/
guint
gtk_application_window_get_id (GtkApplicationWindow *window)
{
g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (window), 0);
return window->priv->id;
}

View File

@ -67,6 +67,9 @@ void gtk_application_window_set_show_menubar (GtkApplicationWindow *windo
GDK_AVAILABLE_IN_3_4 GDK_AVAILABLE_IN_3_4
gboolean gtk_application_window_get_show_menubar (GtkApplicationWindow *window); gboolean gtk_application_window_get_show_menubar (GtkApplicationWindow *window);
GDK_AVAILABLE_IN_3_6
guint gtk_application_window_get_id (GtkApplicationWindow *window);
G_END_DECLS G_END_DECLS
#endif /* __GTK_APPLICATION_WINDOW_H__ */ #endif /* __GTK_APPLICATION_WINDOW_H__ */