• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

gdk/H03-May-2022-4,4473,819

gsk/H03-May-2022-1,3431,159

gtk/H03-May-2022-9,5237,658

README.mdH A D01-Nov-20216.7 KiB221169

meson.buildH A D01-Nov-2021328 1510

README.md

1# How to contribute to GTK's documentation
2
3The GTK documentation is divided in two major components:
4
5 - the API reference, which is generated from special comments in the GTK
6   source code
7 - static pages that provide an overview of specific sections of the API
8
9In both cases, the contents are parsed as markdown and cross-linked in order
10to match types, functions, signals, and properties. Ultimatively, we generate
11HTML, which can be used to read the documentation both offline and online.
12
13Contributing to the GTK documentation requires modifying files tracked in the
14source control repository, and follows the same steps as any other code
15contribution as outlined in the GTK [contribution guide][contributing].
16Please, refer to that document for any further question on the mechanics
17of contributing to GTK.
18
19GTK uses [gi-docgen][gidocgen] to generate its documentation. Please, visit
20the gi-docgen website to read the project's documentation.
21
22[contributing]: ../../CONTRIBUTING.md
23[gi-docgen]: https://gitlab.gnome.org/ebassi/gi-docgen
24
25## Contributing to the API reference
26
27Whenever you need to add or modify the documentation of a type or a
28function, you will need to edit a comment stanza, typically right
29above the type or function declaration. For instance:
30
31```c
32/**
33 * gtk_foo_set_bar:
34 * @self: a foo widget
35 * @bar: (nullable): the bar to set
36 *
37 * Sets the given `GtkBar` instance on a foo widget.
38 *
39 * Returns: `TRUE` if the bar was set
40 */
41gboolean
42gtk_foo_set_bar (GtkFoo *self,
43                 GtkBar *bar)
44{
45  ...
46```
47
48Or, for types:
49
50```c
51/**
52 * GtkFoo:
53 *
54 * A foo widget instance.
55 */
56struct _GtkFoo
57{
58  /*< private >*/
59  GtkWidget parent_instance;
60};
61```
62
63The GTK documentation also contains a number of 'freestanding' chapters
64for which the source is in .md files in docs/reference/gtk.
65
66## Style guide
67
68Like the [coding style][coding], these rules try to formalize the existing
69documentation style; in general, you should only ever modify existing code
70that does not match the rules if you're already changing that code for
71unrelated reasons.
72
73[coding]: ../CODING-STYLE.md
74
75### Syntax
76
77The input syntax for GTK documentation is Markdown, in a flavor that is
78similar to what you see on GitLab or GitHub. The markdown support for
79fragments that are extracted from sources is identical to the one for
80freestanding chapters. As an exception, man pages for tools are currently
81maintained in docbook, since the conversion from markdown to docbook is
82losing too much of the expected formatting.
83
84In addition to typical markdown formatting such as \*emphasis\* or \_italics\_,
85the GTK documentation supports additional link formats, like:
86
87`[class@Namespace.ClassName]`
88 : Creates a link to the docs for a class
89
90`[method@Namespace.Method.name]`
91 : Creates a link to the docs for a method in a class
92
93`[func@Namespace.function]`
94 : Creates a link to the docs for a global function
95
96For more information on the available link formats, see the gi-docgen
97documentation.
98
99Every doc comment should start with a single-sentence paragraph that
100can serve as a summary of sorts (it will often be placed next to a
101link pointing to the full documentation for the symbol/class/etc).
102The summary should not include links.
103
104### Introspection annotations
105
106The purpose of the annotations for function arguments, properties, signals,
107etc., is to describe the API in a machine readable way. The annotations
108are consumed by language bindings and by the documentation tools.
109
110For more information about the annotations used by GTK, you should refer to
111the [GObject Introspection documentation][gi-annotations].
112
113[gi-annotations]: https://gi.readthedocs.io/en/latest/annotations/giannotations.html
114
115### Type description
116
117Each type should be annotated with a description of what the type does.
118
119For classes, the description should contain an overview of the type;
120what it does; typical use cases; and idiomatic examples of its use.
121
122For widget classes, the description should also contain:
123
124  - special XML elements and attributes parsed by the class, in case of a
125    custom GtkBuildable implementation
126  - the CSS element name to be used by selectors
127  - the CSS selector hierarchy for children, in case of a composite widget
128  - the accessible role of the class
129
130Each section in a type description can have a heading; it's preferred to use
131second and third level headings only.
132
133### Functions
134
135 - The argument names must match in the declaration, definition, and
136   documentation stanza.
137 - The description should refer to the function as the subject, e.g.:
138
139```
140Adds a shortcut to the shortcuts controller.
141```
142
143   Or:
144
145```
146Checks whether the widget is set to be visible or not.
147```
148
149### Methods
150
151 - Methods are special functions whose first argument is always the instance
152   of a certain class. The instance argument for newly written code should be
153   called `self`.
154 - If a method is a setter or a getter for an object property, you should
155   add an `(attributes org.gtk.Method.set_property=property-name)` or a
156   an `(attributes org.gtk.Method.get_property=property-name)` annotation
157   to the method's identifier
158 - If a method changes one or more properties as side effect, link those
159   properties in the method's description
160 - If a method is a signal emitter, you should use the
161   `(attributes org.gtk.Method.signal=signal-name)` annotation in
162   the method's identifier
163
164### Arguments and return values
165
166 - Arguments should be descriptive, but short
167 - There is no need to mention the type of the argument
168 - Always annotate nullability, direction, and ownership transfer
169
170### Signals
171
172 - While GObject can introspect argument and return types for signals,
173   you should *always* document them with an explicit documentation stanza.
174 - The syntax for signal stanzas is similar to functions:
175
176```c
177/**
178 * GtkFoo::signal-name:
179 * @arg1: ...
180 * @arg2: ...
181 *
182 * ...
183```
184
185### Properties
186
187 - While GObject properties contain text that can be extracted
188   programmatically in order to build their documentation, you should
189   *always* document them with an explicit documentation stanza. The text
190   associated to the property is short and meant to be used when
191   programmatically building user interfaces, and not for documentation
192   purposes.
193 - Always note if setting a property has side effects, like causing another
194   property to change state.
195 - If the property has public accessors you should annotate it with
196   the `(attributes org.gtk.Property.set=setter_function)` and
197   `(attributes org.gtk.Property.get=getter_function)` attributes
198 - The syntax for property documentation is:
199
200```c
201/**
202 * GtkFoo:property-name:
203 *
204 * ...
205```
206
207### Actions
208
209 - Actions are new in GTK 4, and describe an action associated to
210   a widget class
211 - The syntax for action documentation is:
212
213```
214/**c
215 * GtkFoo|action-name:
216 * @arg1: ...
217 * @arg2: ...
218 *
219 * ...
220```
221