## Getting Started

Providers are ThunarxProviderPlugins loaded from shared libraries installed in `$libdir/thunarx-2/`. The shared libraries are linked against the `thunarx-2` library.

The extensions must provide three public functions, `thunar_extension_initialize()`, `thunar_extension_shutdown()` and `thunar_extension_list_types()`.

`thunar_extension_initialize()` is passed a ThunarxProviderPlugin object, and is responsible to register all GTypes required by the extension. `thunar_extension_shutdown()` should perform any extension-specific shutdown required prior to unloading the extension. `thunar_extension_list_types()` returns an array of GTypes that represent the types of the providers exported by the extension. Thunar will instantiate objects of those types when needed.

Example 1. Basic Structure of an extension

    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

    #include <gmodule.h>
    #include <thunarx/thunarx.h>

    static GType type_list[1];

    static void
    foo_extension_register_type (ThunarxProviderPlugin *plugin)
    {
      static const GTypeInfo info =
      {
        sizeof (FooExtensionClass),
        NULL,
        NULL,
        (GClassInitFunc) foo_extension_class_init,
        NULL,
        NULL,
        sizeof (FooExtension),
        0,
        (GInstanceInitFunc) foo_extension_init,
        NULL,
      };

      type_list[0] = thunarx_provider_plugin_register_type (plugin,
                                                            G_TYPE_OBJECT,
                                                            "FooExtension",
                                                            &info, 0);

      /* implement the desired provider interfaces */
    }

    static GType
    foo_extension_get_type (void)
    {
      return type_list[0];
    }

    G_MODULE_EXPORT void
    thunar_extension_initialize (ThunarxProviderPlugin *plugin)
    {
      const gchar *mismatch;

      /* verify the versions */
      mismatch = thunarx_check_version (THUNARX_MAJOR_VERSION,
                                        THUNARX_MINOR_VERSION,
                                        THUNARX_MICRO_VERSION);
      if (G_UNLIKELY (mismatch != NULL))
        {
          g_warning ("Version mismatch: %s", mismatch);
          return;
        }

      foo_extension_register_type (plugin);
    }

    G_MODULE_EXPORT void
    thunar_extension_shutdown (void)
    {
      /* any extension-specific shutdown */
    }

    G_MODULE_EXPORT void
    thunar_extension_list_types (const GType **types,
                                 gint         *n_types)
    {
      *types = type_list;
      *n_types = G_N_ELEMENTS (type_list);
    }

You should check the TexOpenTerminal extension, which is included in the Thunar distribution in the `examples/tex-open-terminal` directory, for a more complete example of how to write a Thunar extension.

### Compiling Thunar Extensions

To compile a Thunar extension, you need to tell the compiler where to find the `thunarx` header files and library. This is done with the `pkg-config` utility.

The following interactive shell session demonstrates how `pkg-config` is used (the actual output on your system will be different):

    $ pkg-config --cflags thunarx-2
    -DXTHREADS -DXUSE_MTSAFE_API -I/opt/local/include/thunarx-2 -I/usr/local/include/atk-1.0 \
    -I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include -I/usr/X11R6/include/gtk-2.0 \
    -I/usr/X11R6/lib/gtk-2.0/include -I/usr/X11R6/include -I/usr/X11R6/include/pango-1.0 \
    -I/usr/local/include/freetype2 -I/usr/local/include
    $ pkg-config --libs thunarx-2
    -Wl,--rpath -Wl,/usr/local/lib -L/usr/local/lib -L/usr/X11R6/lib -L/opt/local/lib -lthunarx-2

The easiest way to compile an extension is to use the backticks feature of the shell. If you enclose a command in backticks (not single quotes), then its output will be substituted into the command line before execution. So to compile an extension, you would type the following:

    $ gcc -shared -fPIC -DPIC `pkg-config --cflags --libs thunarx-2` foo.c -o foo.so

### Installing Thunar Extensions

To determine the directory where extensions must be installed on your local system, you can use the following command (as mentioned above, the output will be different on your system):

    $ pkg-config --variable=extensionsdir thunarx-2
    /opt/local/lib/thunarx-2

For example, to install the extension `foo.so` on your system, you would type the following:

    $ install -d `pkg-config --variable=extensionsdir thunarx-2`
    $ install -c -m 0755 foo.so `pkg-config --variable=extensionsdir thunarx-2`/foo.so