## Getting Started

Providers are ThunarxProviderPlugins loaded from shared libraries installed in `$libdir/thunarx-1/`. The shared libraries are linked against the `thunarx-1` 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

    #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-1
    -DXTHREADS -DXUSE_MTSAFE_API -I/opt/local/include/thunarx-1 -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-1
    -Wl,--rpath -Wl,/usr/local/lib -L/usr/local/lib -L/usr/X11R6/lib -L/opt/local/lib -lthunarx-1

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-1` 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-1
    /opt/local/lib/thunarx-1

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

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