What command line arguments does gtk_init filter out?

When you write a gtk application, one of the things you are recommended to do is pass a pointer to the command line arguments your program has received to gtk_init( ) or gtk_init_check( ).

These functions look for arguments that are meaningful to gtk, and remove them. Then your code can process the rest of the arguments as it sees fit.

I’m at the stage of trying to decide what arguments my program should call for.

But i don’t have any idea what arguments are meaningful to gtk so that i can arrange to avoid collisions in meaning.

So, is there some place i can get a list of the arguments that gtk finds meaningful?

Thanks in advance for any info.


First of all, you should be using GtkApplication and g_application_run() in newly-written GTK code; gtk_init() and gtk_init_check() belong to an earlier era.

Additionally, in GTK4, both gtk_init() and gtk_init_check() lost their arguments, and GTK does not use command line arguments any more. You probably want to use GtkApplication to minimise the porting differences when GTK4 is released.

This is one of the reasons why we dropped command line arguments from the library.

In general, you have two options:

  • parse your command line options before calling gtk_init() or before creating your GtkApplication instance, making sure you never call GTK API
  • use gtk_get_option_group() to retrieve the options from GTK, and then use g_option_context_add_group() to add them to your own options. GOption will warn if you’re trying to add multiple options with the same name, so you’ll get a chance to deal with conflicts while you’re developing your application.

There isn’t a place, mostly because the command line arguments depend on two factors:

  • build options used when compiling GTK itself—for instance, debugging arguments
  • platform-specific functionality

You could take any GTK-based application and run it with --help-all to show you all the command line options it takes, and the GTK-related ones would be in the GTK group; but, again, that depends on platform and build options.

Thanks very much Emmanuele, this answers my question completely. And this is absolutely fresh code, so i’ll see if i can manage to use GtkApplication.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.