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 675819 - document our intention with gtk_init() arguments
document our intention with gtk_init() arguments
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Documentation
unspecified
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2012-05-10 16:19 UTC by Allison Karlitskaya (desrt)
Modified: 2016-05-16 12:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Deprecate passing arguments to gtk_init() (2.81 KB, patch)
2014-05-13 02:46 UTC, Matthias Clasen
none Details | Review
Deprecate some commandline parsing API (3.65 KB, patch)
2014-05-13 02:55 UTC, Matthias Clasen
none Details | Review

Description Allison Karlitskaya (desrt) 2012-05-10 16:19:01 UTC
After talking with some people I have found that there is a substantial amount of confusion over the fact that gtk_init() takes the commandline arguments from main() but GtkApplication doesn't wire them through.

At some point we decided that libraries should use environment variables for behaviour customisation and commandline arguments should be reserved to applications.  There was even talk about changing the gtk_init() to take no arguments, but it was too late in the cycle to do that.

In any case, we've never made any formal communication of our intentions here, so we should determine precisely what they are and then document them.  Perhaps we should also come up with a concrete plan that GTK4 will have a gtk_init() that takes no arguments (or perhaps no gtk_init() at all).
Comment 1 Matthias Clasen 2012-05-10 16:48:31 UTC
Phasing out commandline args is pretty much universally agreed to, I think.
The devel is in the details - how do we get there ?
Comment 2 Colin Walters 2012-05-10 16:48:41 UTC
One major problematic issue with environment variables is the way they propagate to child processes too.  In some cases, that's what you want, in others, it may not be.

This matters because in e.g. some cases, applications can spawn other applications.  Imagine an application which set GIO_USE_VFS=local (see e.g. bug 665092 ) - it'd break any other application it might run via g_app_info_launch().

The most important thing is for libraries to provide API that affect only the current process, since we know for other reasons the traps involved in calling setenv() after you've started.

For developers, we might investigate a mode where the user controls inheritance of GLib environment variables.

For example:

$ env G_ENV_ONLY=G_SLICE=always-malloc myprog
$ env G_ENV=DISPLAY=:10,G_SLICE=always-malloc myprog

I'm not a fan at all of command line arguments generated by libraries.
Comment 3 Matthias Clasen 2012-05-10 16:52:57 UTC
Here is the list of options we are talking about:

GTK:

--gtk-module
--g-fatal-warnings
--gtk-debug
--gtk-no-debug

GDK:

--class
--name
--display
--gdk-debug
--gdk-no-debug
Comment 4 Matthias Clasen 2012-05-17 04:24:48 UTC
And, to wrap this up:

--gtk-module is covered by GTK_MODULES and a setting
--g-fatal-warnings is covered by G_DEBUG=fatal-warnings
--gtk-debug is covered by GTK_DEBUG
--gtk-no-debug is pretty useless

GDK:

--class
--name
--display covered by DISPLAY
--gdk-debug covered by GDK_DEBUG
--gdk-no-debug is useless
Comment 5 Matthias Clasen 2014-05-13 02:46:48 UTC
Created attachment 276426 [details] [review]
Deprecate passing arguments to gtk_init()

Issue a warning when G_ENABLE_DIAGNOSTIC=1 is set.
Comment 6 Matthias Clasen 2014-05-13 02:55:54 UTC
Created attachment 276427 [details] [review]
Deprecate some commandline parsing API

gtk_init_with_args and gtk_get_option_group are not useful
without commandline arguments, so deprecated them together
with commandline args.
Comment 7 Allison Karlitskaya (desrt) 2014-05-13 11:59:59 UTC
I sort of gave up on this: that's why we now have g_application_add_option_group: it is intended that this be used with gtk_get_option_group().
Comment 8 Matthias Clasen 2014-05-13 12:09:44 UTC
I dunno - giving up on not having commandline handling in GApplication is not the same as giving up on handling commandline options in the toolkit.
Comment 9 Allison Karlitskaya (desrt) 2014-05-13 12:43:29 UTC
I'm saying that I gave up on not having _toolkit_ commandline handling in GApplication, because app authors weren't happy about losing it.  Quite a lot of people were just wiring it back in again anyway, via local_command_line().

Colin's concerns about environment variable propagation are also valid and I've never been able to find a good counterargument for that.  As such, I think WONTFIX might be appropriate at this point.
Comment 10 Emmanuele Bassi (:ebassi) 2014-05-13 12:49:24 UTC
(In reply to comment #9)
> Quite a lot
> of people were just wiring it back in again anyway, via local_command_line().

why? to what end?
Comment 11 Matthias Clasen 2014-05-13 14:43:02 UTC
the counter argument to environment inheritance is dbus activation
Comment 12 Allison Karlitskaya (desrt) 2014-05-25 10:50:53 UTC
(In reply to comment #10)

> why? to what end?

I can't answer this, but before we added GOptionGroup support to GApplication there was quite a lot of this sort of thing around:

https://git.gnome.org/browse/gedit/tree/gedit/gedit-app.c?h=gnome-3-10#n697

If I had to guess, it's because a lot of the GTK options are still fairly useful...
Comment 13 Emmanuele Bassi (:ebassi) 2014-05-26 13:27:08 UTC
(In reply to comment #12)
> (In reply to comment #10)
> 
> > why? to what end?
> 
> I can't answer this, but before we added GOptionGroup support to GApplication
> there was quite a lot of this sort of thing around:
> 
> https://git.gnome.org/browse/gedit/tree/gedit/gedit-app.c?h=gnome-3-10#n697
> 
> If I had to guess, it's because a lot of the GTK options are still fairly
> useful...

quantifying "a lot":

 * GDK
  * --class
  * --display
  * --name

 * GTK
  * --gtk-modules
  * --g-fatal-warnings

the rest are conditionally compiled with the debug options, so applications cannot rely on them.

the GDK options are X11-isms, and are not really portable to other platforms or to other windowing systems; plus, they have to replicated in the environment (say for SSH sessions, if they even still work because of DBus), because otherwise other applications not using GTK will not work.

specifying GTK modules on the command line is a bit weird, and pretty much something that is not something that applications should change; it looks like a debug-only option, or an "unbreak my application by removing this broken module" switch.

passing arguments defined by the application is perfectly fine, but tool kit command line arguments are really something that should just not exist.
Comment 14 Emmanuele Bassi (:ebassi) 2014-05-26 13:29:31 UTC
the only one that I see some value in propagating is --g-fatal-warnings, which is a developer-only switch; I honestly don't know what would happen if you launched an app without it, then launched a second instance with it, tho; the remote instance would suddenly crash? but then, then remote instance was not launched under a debugging tool, so what would be the point of forcing a crash?
Comment 15 Allison Karlitskaya (desrt) 2016-05-16 12:48:35 UTC
This bug is sort of a zombie, I think.  With GApplication using GOptionContext and the gtk GOptionGroup being automatically added in cases of GtkApplication this is no longer anywhere as confusing as it was before.

I'd say that the only thing left to do here is to mention in the docs for gtk_init() that you don't need to call it if you are using GtkApplication -- and that note is already there.

This bug was fixed a long time ago.