GNOME Bugzilla – Bug 674409
need a way to identify GtkApplicationWindows remotely
Last modified: 2012-05-03 15:46: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.
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).
Created attachment 212444 [details] [review] application: Add unique IDs for GtkApplicationWindow This will allow to refer to specific GtkApplicationWindows remotely by ID.
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.
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.
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...
that sounds extremely unlikely
Created attachment 212781 [details] [review] application: Add unique IDs for GtkApplicationWindow Changes from guint64 to guint, and removes the object property.
(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.
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.
Created attachment 213311 [details] [review] application: Add unique IDs for GtkApplicationWindow This will allow to refer to specific GtkApplicationWindows remotely by ID.
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 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 :-)
Pushed attachment 213311 [details] [review] to master after being ok'd on IRC.