GNOME Bugzilla – Bug 624280
Incompatible with GOptionContext
Last modified: 2011-12-17 05:07:10 UTC
Created attachment 165830 [details] Use case It seems to be impossible to mix GOptionContext and GtkApplication in an application, because both modify argc and argv. I've attached a typical use case, where the cmd line args are processed by GOptionContext - it needs to be the first, to catch thinks like --help, etc - and then I create a GtkApplication. In the second instance, nothing is passed to the first one, because argv was modified by GOptionContext.
If gtk_application_new doesn't exit if it's the second instance, we could work around this problem easily. app = gtk_application_try_new (...); if (g_application_is_remote (app)) send_actions ()... else register_actions()... continue_everything()...
Created attachment 165899 [details] [review] Proposed patch With this new function, gtk_application_new_without_quit(), users have an alternative approach for automatic activation in GtkApplication. It will allow users to manually invoke actions on the remote instance and exit. I'm not good at names, I agree the suffix "_without_quit" is weird. Also, I've tried by best at writing the documentation. Suggestions are welcome!
Created attachment 165900 [details] Use case #2 This is a bit modified version of my use case. It's using the new API and works fine. Now, I'm able to use GOptionContext and GtkApplication at the same app.
the way to create a remote application proxy should be: GtkApplication *gtk_application_try_new_remote (...) also, the various GVariant usage should be reduced to a convenience function, like: GVariant *variant_from_argv (const int argc, const char *argv[]) gboolean variant_to_argv (GVariant *variant, int *argc, char ***argv); where this convenience function should live, I honestly don't know. maybe with GVariant itself - might be worth to ask Ryan.
FWIW, I'm doing this in vinagre: ... app = g_initable_new (GTK_TYPE_APPLICATION, NULL, &error, "application-id", "org.gnome.Vinagre", "argv", g_variant_new_bytestring_array ((const gchar * const*)argv, argc), "default-quit", FALSE, NULL); if (!app) g_error ("%s", error->message); if (g_application_is_remote (G_APPLICATION (app))) { vinagre_options_invoke_remote_instance (app, &optionstate); return 0; } ... Once a new constructor land in gtk, I'll use it.
These things have all changed considerably in the GtkApplication rewrite. I'm tempted to close this as obsolete, but I'll move it to GApplication instead, since Ryan was considering adding some kind of easy option context suppport there.
In bug #643650, Matthias mentioned that "there is currently no good way to do 'split handling' with GOption. Either --help only works for local options, or it only gives you docs for the remote options...", so that's maybe something that this could fix.
*** This bug has been marked as a duplicate of bug 634990 ***