After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 674409 - need a way to identify GtkApplicationWindows remotely
need a way to identify GtkApplicationWindows remotely
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: GtkApplication
unspecified
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2012-04-19 16:24 UTC by Christian Persch
Modified: 2012-05-03 15:46 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
application: Add unique IDs for GtkApplicationWindow (10.36 KB, patch)
2012-04-20 17:30 UTC, Christian Persch
reviewed Details | Review
application: Add unique IDs for GtkApplicationWindow (8.60 KB, patch)
2012-04-25 13:37 UTC, Christian Persch
reviewed Details | Review
application: Add unique IDs for GtkApplicationWindow (8.62 KB, patch)
2012-05-02 17:25 UTC, Christian Persch
none Details | Review
application: Add API to get the window's DBus object path (3.13 KB, patch)
2012-05-02 17:25 UTC, Christian Persch
rejected Details | Review

Description Christian Persch 2012-04-19 16:24:46 UTC
E.g. in gnome-terminal, I want to be able to refer to some specific GtkApplicationWindow remotely, to be able to open new tabs in some window, for example. 

GtkApplicationWindow exports its GActions on some dbus path, which it constructs from the application's dbus path, and a unique ID. 

There should be a way to retrieve that path as API on GtkApplicationWindow, or maybe just the unique ID part of it. And as convenience API, a function to get a GtkApplicationWindow by path/ID.
Comment 1 Allison Karlitskaya (desrt) 2012-04-19 20:42:09 UTC
So here's what I had in mind:

  uint64 ApplicationWindow.get_id();

  ApplicationWindow? Application.get_window_by_id(uint64);


For bonus points (since I don't think that it will help in your case, but would probably be rather useful in a lot of other situations) on the remote side, we then need a way to create (from the GtkApplication in remote mode) a GActionGroup corresponding to the remote window in order to invoke actions on it.

It may even make sense to just use the same get_window_by_id() function for this purpose (returning the real window on the primary instance and a proxy on the remote).
Comment 2 Christian Persch 2012-04-20 17:30:04 UTC
Created attachment 212444 [details] [review]
application: Add unique IDs for GtkApplicationWindow

This will allow to refer to specific GtkApplicationWindows remotely by ID.
Comment 3 Allison Karlitskaya (desrt) 2012-04-20 18:35:10 UTC
Review of attachment 212444 [details] [review]:

two (non-blocking) comments:

 - i'd have expected a hashtable in GtkApplication, but i guess the number of windows will generally be small...

 - the idea of having a property named "id" is an obvious natural expectation given the existence of a function named get_id() but it seems wrong somehow

both of those in mind, i have no opposition to the patch going into Gtk in its current form if you can get a sign-off from a Gtk maintainer.
Comment 4 Matthias Clasen 2012-04-25 04:21:05 UTC
Review of attachment 212444 [details] [review]:

::: gtk/gtkapplication.c
@@ +158,3 @@
   guint            menubar_id;
 
+  guint64          next_id;

Why is an uint not enough here ? 
There's no risk of having more than 2^32 windows in an application.
Seems an unmotivated change...

::: gtk/gtkapplicationwindow.c
@@ +832,3 @@
+  window->priv->id = object_id;
+
+  g_object_notify (G_OBJECT (window), "id");

I have to agree with Ryan: adding an 'id' property for this seems questionable.
Comment 5 Allison Karlitskaya (desrt) 2012-04-25 04:32:26 UTC
Review of attachment 212444 [details] [review]:

::: gtk/gtkapplication.c
@@ +158,3 @@
   guint            menubar_id;
 
+  guint64          next_id;

I think the idea was to guarantee that assigned ids would be unique for as long as the program was running with no risk of reuse.  It's theoretically possible that an extremely long-running app with a ridiculous amount of window showing/hiding could wrap a 32bit counter...
Comment 6 Matthias Clasen 2012-04-25 11:56:31 UTC
that sounds extremely unlikely
Comment 7 Christian Persch 2012-04-25 13:37:59 UTC
Created attachment 212781 [details] [review]
application: Add unique IDs for GtkApplicationWindow

Changes from guint64 to guint, and removes the object property.
Comment 8 Christian Persch 2012-04-25 13:41:12 UTC
(In reply to comment #5)
> +  guint64          next_id;
> 
> I think the idea was to guarantee that assigned ids would be unique for as long
> as the program was running with no risk of reuse.  It's theoretically possible
> that an extremely long-running app with a ridiculous amount of window
> showing/hiding could wrap a 32bit counter...

Given that signal connection IDs are globally unique and source IDs are unique for each GMainContext, both never reused, it seems that they would overflow long before the app window counter would overflow. So after discussion on IRC, I changed the patch to use guint for the ID.
Comment 9 Matthias Clasen 2012-04-26 03:22:48 UTC
Review of attachment 212781 [details] [review]:

::: gtk/gtkapplicationwindow.c
@@ +831,3 @@
+  window->priv->id = object_id;
+
+  g_object_notify (G_OBJECT (window), "id");

No need to notify anymore

@@ +852,3 @@
   window->priv->object_path = NULL;
+
+  g_object_notify (G_OBJECT (window), "id");

Here too

@@ +1103,3 @@
+ * @window: a #GtkApplicationWindow
+ * 
+ * Returns: the unique ID for @window, or <literal>0</literal> if the window

Please add some actual documentation here (even if it is basically just a repetition of the Returns: documentation.
Comment 10 Christian Persch 2012-05-02 17:25:44 UTC
Created attachment 213311 [details] [review]
application: Add unique IDs for GtkApplicationWindow

This will allow to refer to specific GtkApplicationWindows remotely by ID.
Comment 11 Christian Persch 2012-05-02 17:25:59 UTC
Created attachment 213312 [details] [review]
application: Add API to get the window's DBus object path

Now that GApplication exposes API to directly get its DBus object path,
add API to GtkApplicationWindow to retrieve the path where it exports
its action group.
Comment 12 Christian Persch 2012-05-03 15:39:46 UTC
Comment on attachment 213312 [details] [review]
application: Add API to get the window's DBus object path

desrt already veto'd this one on IRC until there's a concrete need for it :-)
Comment 13 Christian Persch 2012-05-03 15:46:46 UTC
Pushed attachment 213311 [details] [review] to master after being ok'd on IRC.