[gtk+] application: Add unique IDs for GtkApplicationWindow



commit ff66d0d8e5817596cc7fd736abfebbf3dfd94fc5
Author: Christian Persch <chpe gnome org>
Date:   Fri Apr 20 19:29:11 2012 +0200

    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

 docs/reference/gtk/gtk3-sections.txt |    2 ++
 gtk/gtk.symbols                      |    2 ++
 gtk/gtkapplication.c                 |   34 ++++++++++++++++++++++++++++++++--
 gtk/gtkapplication.h                 |    4 ++++
 gtk/gtkapplicationprivate.h          |    3 ++-
 gtk/gtkapplicationwindow.c           |   29 ++++++++++++++++++++++++++++-
 gtk/gtkapplicationwindow.h           |    3 +++
 7 files changed, 73 insertions(+), 4 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 61b2849..88574b2 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -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
diff --git a/gtk/gtk.symbols b/gtk/gtk.symbols
index 504608b..b4f47ae 100644
--- a/gtk/gtk.symbols
+++ b/gtk/gtk.symbols
@@ -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
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 06403d3..8758fc3 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -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
@@ -874,6 +876,34 @@ gtk_application_get_windows (GtkApplication *application)
 }
 
 /**
+ * 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
  * @accelerator: accelerator string
diff --git a/gtk/gtkapplication.h b/gtk/gtkapplication.h
index 154a4f0..21cd389 100644
--- a/gtk/gtkapplication.h
+++ b/gtk/gtkapplication.h
@@ -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__ */
diff --git a/gtk/gtkapplicationprivate.h b/gtk/gtkapplicationprivate.h
index e838e88..a05752c 100644
--- a/gtk/gtkapplicationprivate.h
+++ b/gtk/gtkapplicationprivate.h
@@ -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);
diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c
index 495897e..ab98920 100644
--- a/gtk/gtkapplicationwindow.c
+++ b/gtk/gtkapplicationwindow.c
@@ -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;
+}
diff --git a/gtk/gtkapplicationwindow.h b/gtk/gtkapplicationwindow.h
index 22a013f..32fd068 100644
--- a/gtk/gtkapplicationwindow.h
+++ b/gtk/gtkapplicationwindow.h
@@ -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__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]