]> Pileus Git - ~andy/gtk/commitdiff
application: Add unique IDs for GtkApplicationWindow
authorChristian Persch <chpe@gnome.org>
Fri, 20 Apr 2012 17:29:11 +0000 (19:29 +0200)
committerChristian Persch <chpe@gnome.org>
Thu, 3 May 2012 15:45:46 +0000 (17:45 +0200)
This will allow to refer to specific GtkApplicationWindows remotely by ID.

https://bugzilla.gnome.org/show_bug.cgi?id=674409

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkapplication.c
gtk/gtkapplication.h
gtk/gtkapplicationprivate.h
gtk/gtkapplicationwindow.c
gtk/gtkapplicationwindow.h

index 61b2849c418416d496b51c7bf97d51db263314eb..88574b2d145c871f6fba41bd97df9892ed425111 100644 (file)
@@ -7020,6 +7020,7 @@ gtk_application_new
 gtk_application_add_window
 gtk_application_remove_window
 gtk_application_get_windows
+gtk_application_get_window_by_id
 
 <SUBSECTION>
 GtkApplicationInhibitFlags
@@ -7053,6 +7054,7 @@ GtkApplicationWindow
 gtk_application_window_new
 gtk_application_window_set_show_menubar
 gtk_application_window_get_show_menubar
+gtk_application_window_get_id
 
 <SUBSECTION Standard>
 GtkApplicationWindowClass
index 504608b2aa1d9752d9598d67a287341db079c8cf..b4f47ae1807d0a2dad381f6aa40faf78f0cc27c0 100644 (file)
@@ -231,6 +231,7 @@ gtk_application_get_app_menu
 gtk_application_get_menubar
 gtk_application_get_type
 gtk_application_get_windows
+gtk_application_get_window_by_id
 gtk_application_inhibit
 gtk_application_inhibit_flags_get_type
 gtk_application_is_inhibited
@@ -242,6 +243,7 @@ gtk_application_set_menubar
 gtk_application_uninhibit
 gtk_application_window_get_show_menubar
 gtk_application_window_get_type
+gtk_application_window_get_id
 gtk_application_window_new
 gtk_application_window_set_show_menubar
 gtk_arrow_get_type
index 06403d39ed518b3a924d4add03e5b742efeb4435..8758fc3b852eb4e2c59af330c3d9f9a20decc79f 100644 (file)
@@ -255,8 +255,8 @@ gtk_application_window_added_x11 (GtkApplication *application,
           guint window_id;
 
           window_id = application->priv->next_id++;
-          window_path = g_strdup_printf ("%s/window/%d", application->priv->object_path, window_id);
-          success = gtk_application_window_publish (app_window, application->priv->session_bus, window_path);
+          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, window_id);
           g_free (window_path);
         }
       while (!success);
@@ -501,6 +501,8 @@ gtk_application_init (GtkApplication *application)
   application->priv = G_TYPE_INSTANCE_GET_PRIVATE (application,
                                                    GTK_TYPE_APPLICATION,
                                                    GtkApplicationPrivate);
+
+  application->priv->next_id = 1;
 }
 
 static void
@@ -873,6 +875,34 @@ gtk_application_get_windows (GtkApplication *application)
   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:
  * @application: a #GtkApplication
index 154a4f004ec625c474dfdf478f37cf7adc6fdd7a..21cd389ab3b36aa2a806dd60675a1f3e6b1b0758 100644 (file)
@@ -115,6 +115,10 @@ GDK_AVAILABLE_IN_3_4
 gboolean         gtk_application_is_inhibited       (GtkApplication             *application,
                                                      GtkApplicationInhibitFlags  flags);
 
+GDK_AVAILABLE_IN_3_6
+GtkWindow *      gtk_application_get_window_by_id   (GtkApplication             *application,
+                                                     guint                       id);
+
 G_END_DECLS
 
 #endif /* __GTK_APPLICATION_H__ */
index e838e88cbcb54f80a1f358632d4b6373abaf4b85..a05752c7e9e2846dbe238653120d627dc89731be 100644 (file)
@@ -27,7 +27,8 @@
 G_GNUC_INTERNAL
 gboolean                gtk_application_window_publish                  (GtkApplicationWindow *window,
                                                                          GDBusConnection      *session,
-                                                                         const gchar          *object_path);
+                                                                         const gchar          *object_path,
+                                                                         guint                 object_id);
 
 G_GNUC_INTERNAL
 void                    gtk_application_window_unpublish                (GtkApplicationWindow *window);
index 495897efcc9bbedf55978f549e1f1c5cb68714a5..ab98920b4e8d30c5003c8dc996bd5f2d3697800b 100644 (file)
@@ -218,6 +218,8 @@ struct _GtkApplicationWindowPrivate
   GDBusConnection *session;
   gchar           *object_path;
   guint            export_id;
+
+  guint            id;
 };
 
 static void
@@ -809,11 +811,13 @@ gtk_application_window_real_unrealize (GtkWidget *widget)
 gboolean
 gtk_application_window_publish (GtkApplicationWindow *window,
                                 GDBusConnection      *session,
-                                const gchar          *object_path)
+                                const gchar          *object_path,
+                                guint                 object_id)
 {
   g_assert (window->priv->session == NULL);
   g_assert (window->priv->export_id == 0);
   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,
                                                                    G_ACTION_GROUP (window->priv->actions),
@@ -824,6 +828,7 @@ gtk_application_window_publish (GtkApplicationWindow *window,
 
   window->priv->session = session;
   window->priv->object_path = g_strdup (object_path);
+  window->priv->id = object_id;
 
   return TRUE;
 }
@@ -834,10 +839,12 @@ gtk_application_window_unpublish (GtkApplicationWindow *window)
   g_assert (window->priv->session != NULL);
   g_assert (window->priv->export_id != 0);
   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);
   window->priv->session = NULL;
   window->priv->export_id = 0;
+  window->priv->id = 0;
 
   g_free (window->priv->object_path);
   window->priv->object_path = NULL;
@@ -1086,3 +1093,23 @@ gtk_application_window_get_accel_group (GtkApplicationWindow *window)
 {
   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;
+}
index 22a013f8f1c63fe30a9687f328c5109b6e54fb4b..32fd068f9835c809e98ae6822b9cff8ea3eb8d1e 100644 (file)
@@ -67,6 +67,9 @@ void        gtk_application_window_set_show_menubar (GtkApplicationWindow *windo
 GDK_AVAILABLE_IN_3_4
 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
 
 #endif /* __GTK_APPLICATION_WINDOW_H__ */