The GTK documentation is divided in two major components:
In both cases, the contents are parsed, converted into DocBook format, and cross-linked in order to match types, functions, signals, and properties. From the DocBook output, we generate HTML, which can be used to read the documentation both offline and online.
In both cases, contributing to the GTK documentation requires modifying files tracked in the source control repository, and follows the same steps as any other code contribution as outlined in the GTK contribution guide. Please, refer to that document for any further question on the mechanics of contributing to GTK.
GTK uses gtk-doc to generate its documentation. Please, visit the gtk-doc website to read the project's documentation.
Whenever you need to add or modify the documentation of a type or a function, you will need to edit a gtk-doc
comment stanza, typically right above the type or function declaration. For instance:
/** * gtk_foo_set_bar: * @self: a #GtkFoo * @bar: a #GtkBar * * Sets the given #GtkBar instance on a #GtkFoo widget. */ void gtk_foo_set_bar (GtkFoo *self, GtkBar *bar) { ...
Or, for types:
/** * GtkFoo: * * A foo widget instance. * * The contents of this structure are private and should never * be accessed directly. */ struct _GtkFoo { GtkWidget parent_instance; };
Each public function and type in the GTK API reference must be listed in the sections.txt
file for the specific namespace to which it belongs: GDK, GSK, or GTK. For instance, if you add a function named gtk_foo_set_bar()
, you will need to:
docs/reference/gtk/gtk4-sections.txt
GtkFoo
typegtk_foo_set_bar
to the listNew classes require:
sections.txt
fileget_type
function added to the .types
filexinclude
element in the docs.xml
fileThe GTK documentation also contains a number of ‘freestanding’ chapters for which the source is in .md files in docs/reference/gtk.
Like the coding style, these rules try to formalize the existing documentation style; in general, you should only ever modify existing code that does not match the rules if you're already changing that code for unrelated reasons.
The input syntax for GTK documentation is markdown, in a flavor that is similar to what you see on gitlab or github. The markdown support for fragments that are extracted from sources is more limited than for freestanding chapters. As an exception, man pages for tools are currently maintained in docbook, since the conversion from markdown to docbook is losing too much of the expected formatting.
In addition to typical markdown formatting such as *emphasis* or _italics_, gtk-doc supports a few abbreviations for cross-references and formatting:
#ClassName
: Creates a link to the docs for a class
function()
: Creates a link to the docs for a function
%constant
: Generates suitable markup for enum values or constants
sections.txt
file; a title; and a short description. For instance:/** * SECTION:gtkshortcut * @Title: GtkShortcut * @Short_desc: A key shortcut * * ...
For classes, the title should be the name of the class. While it's possible to add section titles directly to the sections.txt
file, this is considered deprecated, and should not be done for newly written code.
Adds a shortcut to the shortcuts controller.
Or:
Checks whether the widget is set to be visible or not.
self
./** * GtkFoo::signal-name: * @arg1: ... * @arg2: ... * * ...
/** * GtkFoo:property-name: * * ...
/**c * GtkFoo|action-name: * @arg1: ... * @arg2: ... * * ...