![]() |
![]() |
![]() |
Thunar Extensions Reference Manual | ![]() |
---|
Providers are GTypeModules 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 GTypeModule
object, and must register all GTypes that the extension needs. 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 (GTypeModule *module) { 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] = g_type_module_register_type (module, 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 (GTypeModule *module) { 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 (module); } 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); }
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
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
<< Part II. Writing Extensions | Advanced topics >> |