summaryrefslogtreecommitdiff
path: root/docs/reference/gtk/running.sgml
blob: 044ab553565c66d2d432c3745656197e75c2c1d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
<?xml version="1.0"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
               "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [
]>
<refentry id="gtk-running">
<refmeta>
<refentrytitle>Running GTK Applications</refentrytitle>
<manvolnum>3</manvolnum>
<refmiscinfo>GTK Library</refmiscinfo>
</refmeta>

<refnamediv>
<refname>Running GTK Applications</refname>
<refpurpose>
How to run and debug your GTK application
</refpurpose>
</refnamediv>

<refsect1>
<title>Running and debugging GTK Applications</title>

<refsect2>
<title>Environment variables</title>

<para>
GTK inspects a number of environment variables in addition to standard
variables like <envar>LANG</envar>, <envar>PATH</envar>, <envar>HOME</envar>
or <envar>DISPLAY</envar>; mostly to determine paths to look for certain
files. The <link linkend="x11-envar">X11</link>,
<link linkend="win32-envar">Windows</link> and
<link linkend="broadway-envar">Broadway</link> GDK backends use some
additional environment variables.
</para>

<formalpara id="GTK-Debug-Options">
  <title><envar>GTK_DEBUG</envar></title>

  <para>
  Unless GTK has been configured with <option>--enable-debug=no</option>,
  this variable can be set to a list of debug options, which cause GTK
  to print out different types of debugging information.
  <variablelist>
    <varlistentry>
      <term>actions</term>
      <listitem><para>Actions and menu models</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>builder</term>
      <listitem><para>GtkBuilder support</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>geometry</term>
      <listitem><para>Size allocation</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>icontheme</term>
      <listitem><para>Icon themes</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>keybindings</term>
      <listitem><para>Keybindings</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>modules</term>
      <listitem><para>Loading of modules</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>printing</term>
      <listitem><para>Printing support</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>size-request</term>
      <listitem><para>Size requests</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>text</term>
      <listitem><para>Text widget internals</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>tree</term>
      <listitem><para>Tree widget internals</para></listitem>
    </varlistentry>
  </variablelist>
  A number of keys are influencing behavior instead of just logging:
  <variablelist>
    <varlistentry>
      <term>interactive</term>
      <listitem><para>Open the <link linkend="interactive-debugging">interactive debugger</link></para></listitem>
    </varlistentry>
    <varlistentry>
      <term>no-css-cache</term>
      <listitem><para>Bypass caching for CSS style properties</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>touchscreen</term>
      <listitem><para>Pretend the pointer is a touchscreen device</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>baselines</term>
      <listitem><para>Show baselines</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>updates</term>
      <listitem><para>Visual feedback about window updates</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>resize</term>
      <listitem><para>Highlight resizing widgets</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>layout</term>
      <listitem><para>Show layout borders</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>snapshot</term>
      <listitem><para>Include debug render nodes in the generated snapshots</para></listitem>
    </varlistentry>
  </variablelist>
  The special value <literal>all</literal> can be used to turn on all
  debug options. The special value <literal>help</literal> can be used
  to obtain a list of all supported debug options.
  </para>
</formalpara>

<formalpara id="gtk-path">
  <title><envar>GTK_PATH</envar></title>

  <para>
    Specifies a list of directories to search when GTK is looking for
    dynamically loaded objects such as input method
    modules and print backends. If the path to
    the dynamically loaded object is given as an absolute path name,
    then GTK loads it directly.
    Otherwise, GTK goes in turn through the directories in <envar>GTK_PATH</envar>,
    followed by the directory <filename>.gtk-4.0</filename> in the user's
    home directory, followed by the system default directory,
    which is <filename><replaceable>libdir</replaceable>/gtk-4.0/modules</filename>.
    (If <envar>GTK_EXE_PREFIX</envar> is defined, <replaceable>libdir</replaceable> is
    <filename>$GTK_EXE_PREFIX/lib</filename>. Otherwise it is the libdir
    specified when GTK was configured, usually
    <filename>/usr/lib</filename>, or
    <filename>/usr/local/lib</filename>.)
    For each directory in this list, GTK actually looks in a
    subdirectory
    <filename><replaceable>directory</replaceable>/<replaceable>version</replaceable>/<replaceable>host</replaceable>/<replaceable>type</replaceable></filename>
    Where <replaceable>version</replaceable> is derived from the
    version of GTK (use <literal>pkg-config
    --variable=gtk_binary_version gtk4</literal> to determine this from a
    script), <replaceable>host</replaceable> is the architecture on
    which GTK was built. (use <literal>pkg-config
    --variable=gtk_host gtk4</literal> to determine this from a
    script), and <replaceable>type</replaceable> is a directory
    specific to the type of modules; currently it can be
    <literal>modules</literal>, <literal>engines</literal>,
    <literal>immodules</literal>, <literal>filesystems</literal> or
    <literal>printbackends</literal>, corresponding to the types of
    modules mentioned above. Either <replaceable>version</replaceable>,
    <replaceable>host</replaceable>, or both may be omitted. GTK looks
    first in the most specific directory, then in directories with
    fewer components.
    The components of GTK_PATH are separated by the ':' character on
    Linux and Unix, and the ';' character on Windows.
  </para>
  <warning>
    Note that this environment variable is read by GTK 2.x and GTK 3.x too,
    which makes it unsuitable for setting it system-wide (or session-wide),
    since doing so will cause applications using different GTK versions
    to see incompatible modules.
  </warning>
</formalpara>

<formalpara>
  <title><envar>GTK_IM_MODULE</envar></title>

  <para>
    Specifies an IM module to use in preference to the one determined
    from the locale. If this isn't set and you are running on the system
    that enables <literal>XSETTINGS</literal> and has a value in
    <literal>Gtk/IMModule</literal>, that will be used for the default
    IM module.
    This also can be a colon-separated list of input-methods, which
    GTK will try in turn until it finds one available on the system.
  </para>
</formalpara>

<formalpara>
  <title><envar>GTK_EXE_PREFIX</envar></title>

  <para>
    If set, GTK uses <filename>$GTK_EXE_PREFIX/lib</filename> instead of
    the libdir configured when GTK was compiled.
  </para>
</formalpara>

<formalpara>
  <title><envar>GTK_DATA_PREFIX</envar></title>

  <para>
    If set, makes GTK use <filename>$GTK_DATA_PREFIX</filename>
    instead of the prefix configured when GTK was compiled.
  </para>
</formalpara>

<formalpara>
  <title><envar>GTK_THEME</envar></title>

  <para>
    If set, makes GTK use the named theme instead of the theme
    that is specified by the gtk-theme-name setting. This is intended
    mainly for easy debugging of theme issues.
  </para>
  <para>
    It is also possible to specify a theme variant to load, by appending
    the variant name with a colon, like this: `GTK_THEME=Adwaita:dark`.
  </para>
</formalpara>

<para>
The following environment variables are used by GdkPixbuf, GDK or
Pango, not by GTK itself, but we list them here for completeness
nevertheless.
</para>

<formalpara>
  <title><envar>GDK_PIXBUF_MODULE_FILE</envar></title>

  <para>
    Specifies the file listing the GdkPixbuf loader modules to load.
    This environment variable overrides the default value
    <filename><replaceable>libdir</replaceable>/gtk-4.0/4.0.0/loaders.cache</filename>
    (<replaceable>libdir</replaceable> is the sysconfdir specified when
    GTK was configured, usually <filename>/usr/local/lib</filename>.)
  </para>
  <para>
    The <filename>loaders.cache</filename> file is generated by the
    <command>gdk-pixbuf-query-loaders</command> utility.
  </para>
 </formalpara>

<formalpara id="GDK-Debug-Options">
  <title><envar>GDK_DEBUG</envar></title>

  <para>
  If GTK has been configured with <option>--enable-debug=yes</option>,
  this variable can be set to a list of debug options, which cause GDK
  to print out different types of debugging information.
  <variablelist>
    <varlistentry>
      <term>cursor</term>
      <listitem><para>Information about cursor objects (only win32)</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>eventloop</term>
      <listitem><para>Information about event loop operation (mostly Quartz)</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>misc</term>
      <listitem><para>Miscellaneous information</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>frames</term>
      <listitem><para>Information about the frame clock</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>settings</term>
      <listitem><para>Information about xsettings</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>selection</term>
      <listitem><para>Information about selections</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>clipboard</term>
      <listitem><para>Information about clipboards</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>dnd</term>
      <listitem><para>Information about drag-and-drop</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>opengl</term>
      <listitem><para>Information about OpenGL</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>vulkan</term>
      <listitem><para>Information about Vulkan</para></listitem>
    </varlistentry>
  </variablelist>
  A number of options affect behavior instead of logging:
  <variablelist>
    <varlistentry>
      <term>nograbs</term>
      <listitem><para>Turn off all pointer and keyboard grabs</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>gl-disable</term>
      <listitem><para>Disable OpenGL support</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>gl-software</term>
      <listitem><para>Force OpenGL software rendering</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>gl-texture-rect</term>
      <listitem><para>Use the OpenGL texture rectangle extension, if available</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>gl-legacy</term>
      <listitem><para>Use a legacy OpenGL context</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>gl-gles</term>
      <listitem><para>Use a GLES OpenGL context</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>vulkan-disable</term>
      <listitem><para>Disable Vulkan support</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>vulkan-validate</term>
      <listitem><para>Load the Vulkan validation layer, if available</para></listitem>
    </varlistentry>
  </variablelist>
  The special value <literal>all</literal> can be used to turn on all
  debug options. The special value <literal>help</literal> can be used
  to obtain a list of all supported debug options.
  </para>
</formalpara>

<formalpara id="GSK-Debug-Options">
  <title><envar>GSK_DEBUG</envar></title>

  <para>
  If GTK has been configured with <option>--enable-debug=yes</option>,
  this variable can be set to a list of debug options, which cause GSK
  to print out different types of debugging information.
  <variablelist>
    <varlistentry>
      <term>renderer</term>
      <listitem><para>General renderer information</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>cairo</term>
      <listitem><para>cairo renderer information</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>opengl</term>
      <listitem><para>OpenGL renderer information</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>shaders</term>
      <listitem><para>Shaders</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>ssurface</term>
      <listitem><para>Surfaces</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>vulkan</term>
      <listitem><para>Vulkan renderer information</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>fallback</term>
      <listitem><para>Information about fallbacks</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>glyphcache</term>
      <listitem><para>Information about glyph caching</para></listitem>
    </varlistentry>
  </variablelist>
  A number of options affect behavior instead of logging:
  <variablelist>
    <varlistentry>
      <term>diff</term>
      <listitem><para>Show differences</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>geometry</term>
      <listitem><para>Show borders</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>full-redraw</term>
      <listitem><para>Force full redraws for every frame</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>sync</term>
      <listitem><para>Sync after each frame</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>vulkan-staging-image</term>
      <listitem><para>Use a staging image for Vulkan texture upload</para></listitem>
    </varlistentry>
    <varlistentry>
      <term>vulkan-staging-buffer</term>
      <listitem><para>Use a staging buffer for Vulkan texture upload</para></listitem>
    </varlistentry>
  </variablelist>
  The special value <literal>all</literal> can be used to turn on all
  debug options. The special value <literal>help</literal> can be used
  to obtain a list of all supported debug options.
  </para>
</formalpara>

<formalpara>
  <title><envar>GDK_BACKEND</envar></title>

  <para>
    If set, selects the GDK backend to use. Selecting a backend requires that
    GTK is compiled with support for that backend. The following backends can
    be selected, provided they are included in the GDK libraries you are using:
    <variablelist>

      <varlistentry>
        <term>quartz</term>
        <listitem><para>Selects the native Quartz backend</para></listitem>
      </varlistentry>

      <varlistentry>
        <term>win32</term>
        <listitem><para>Selects the native backend for Microsoft Windows</para></listitem>
      </varlistentry>

      <varlistentry>
        <term>x11</term>
        <listitem><para>Selects the native backend for connecting to X11 servers.</para></listitem>
      </varlistentry>

      <varlistentry>
        <term>broadway</term>
        <listitem><para>Selects the Broadway backend for display in web browsers</para></listitem>
      </varlistentry>

      <varlistentry>
        <term>wayland</term>
        <listitem><para>Selects the Wayland backend for connecting to Wayland display servers</para></listitem>
      </varlistentry>

    </variablelist>
    Since 3.10, this environment variable can contain a comma-separated list
    of backend names, which are tried in order. The list may also contain
    a *, which means: try all remaining backends. The special value "help" can
    be used to make GDK print out a list of all available backends.
    For more information about selecting backends, see the gdk_display_manager_get() function.
  </para>
</formalpara>

<formalpara>
  <title><envar>GDK_VULKAN_DEVICE</envar></title>

  <para>
    This variable can be set to the index of a Vulkan device to override the
    default selection of the device that is used for Vulkan rendering.
    The special value <literal>list</literal> can be used to obtain a list
    of all Vulkan devices.
  </para>
</formalpara>

<formalpara>
  <title><envar>GSK_RENDERER</envar></title>

  <para>
    If set, selects the GSK renderer to use. The following renderers can
    be selected, provided they are included in the GTK library you are using
    and the GDK backend supports them:
    <variablelist>

      <varlistentry>
        <term>help</term>
        <listitem><para>Prints information about available options</para></listitem>
      </varlistentry>

      <varlistentry>
        <term>broadway</term>
        <listitem><para>Selects the Broadway-backend specific renderer</para></listitem>
      </varlistentry>

      <varlistentry>
        <term>cairo</term>
        <listitem><para>Selects the fallback Cairo renderer</para></listitem>
      </varlistentry>

      <varlistentry>
        <term>gl</term>
        <listitem><para>Selects the default OpenGL renderer</para></listitem>
      </varlistentry>

      <varlistentry>
        <term>vulkan</term>
        <listitem><para>Selects the Vulkan renderer</para></listitem>
      </varlistentry>

    </variablelist>
  </para>
</formalpara>

<formalpara>
  <title><envar>GTK_CSD</envar></title>

  <para>
    The default value of this environment variable is 1. If changed to 0, this
    disables the default use of client-side decorations on GTK windows, thus
    making the window manager responsible for drawing the decorations of
    windows that do not have a custom titlebar widget.
  </para>
  <para>
    CSD is always used for windows with a custom titlebar widget set, as the WM
    should not draw another titlebar or other decorations around the custom one.
  </para>
</formalpara>

<formalpara>
  <title><envar>XDG_DATA_HOME</envar>, <envar>XDG_DATA_DIRS</envar></title>

  <para>
    GTK uses these environment variables to locate icon themes
    and MIME information. For more information, see
    <ulink url="https://freedesktop.org/Standards/icon-theme-spec">Icon Theme Specification</ulink>,
    the <ulink url="https://freedesktop.org/Standards/shared-mime-info-spec">Shared MIME-info Database</ulink>
    and the <ulink url="https://freedesktop.org/Standards/basedir-spec">Base Directory Specification</ulink>.
  </para>
</formalpara>

<formalpara>
  <title><envar>DESKTOP_STARTUP_ID</envar></title>

  <para>
    GTK uses this environment variable to provide startup notification
    according to the <ulink url="https://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup Notification Spec</ulink>.
    Following the specification, GTK unsets this variable after reading
    it (to keep it from leaking to child processes). So, if you need its
    value for your own purposes, you have to read it before calling
    gtk_init().
  </para>
</formalpara>

</refsect2>

<refsect2 id="interactive-debugging">
<title>Interactive debugging</title>

  <inlinegraphic fileref="inspector.png" format="PNG"></inlinegraphic>

  <para>
    GTK includes an interactive debugger, called the GTK Inspector, which
    lets you explore the widget tree of any GTK application at runtime, as
    well as tweak the theme and trigger visual debugging aids. You can
    easily try out changes at runtime before putting them into the code.
  </para>
  <para>
    Note that the GTK inspector can only show GTK internals. It can not
    understand the application-specific logic of a GTK application. Also,
    the fact that the GTK inspector is running in the application process
    limits what it can do. It is meant as a complement to full-blown debuggers
    and system tracing facilities such as DTrace, not as a replacement.
  </para>
  <para>
    To enable the GTK inspector, you can use the Control-Shift-I or
    Control-Shift-D keyboard shortcuts, or set the
    <envar>GTK_DEBUG=interactive</envar> environment variable.
  </para>
  <para>
    There are a few more environment variables that can be set to influence
    how the inspector renders its UI. <envar>GTK_INSPECTOR_DISPLAY</envar> and
    <envar>GTK_INSPECTOR_RENDERER</envar> determine the GDK display and
    the GSK renderer that the inspector is using.
  </para>

  <para>
    In some situations, it may be inappropriate to give users access to the
    GTK inspector. The keyboard shortcuts can be disabled with the
    `enable-inspector-keybinding` key in the `org.gtk.Settings.Debug`
    GSettings schema.
  </para>

</refsect2>

<refsect2 id="profiling">
  <title>Profiling</title>

  <para>
    GTK supports profiling with sysprof. It exports timing information
    about frameclock phases and various characteristics of GskRenders
    in a format that can be displayed by sysprof or GNOME Builder.
  </para>
  <para>
    A simple way to capture data is to set the <envar>GTK_TRACE</envar>
    environment variable. When it is set, GTK will write profiling
    data to a file called
    <filename>gtk.<replaceable>PID</replaceable>.syscap</filename>.
  </para>
  <para>
    When launching the application from sysprof, it will set the
    <envar>SYSPROF_TRACE_FD</envar> environment variable to point
    GTK at a file descriptor to write profiling data to.
  </para>
  <para>
    When GtkApplication registers with D-Bus, it exports the
    <literal>org.gnome.Sysprof2.Profiler</literal> interface
    that lets sysprof request profiling data at runtime.
  </para>
</refsect2>

</refsect1>

</refentry>