1 #include "plugins/interface.h"
2 #include "parser/parse.h"
13 PluginSetupConfig config;
14 PluginStartup startup;
15 PluginShutdown shutdown;
18 static gpointer load_sym(GModule *module, gchar *name, gchar *symbol,
22 if (!g_module_symbol(module, symbol, &var)) {
24 g_warning("Failed to load symbol '%s' from plugin '%s'",
31 static Plugin *plugin_new(gchar *name)
39 path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
41 p->module = g_module_open(path, 0);
44 if (p->module == NULL) {
45 path = g_build_filename(PLUGINDIR, name, NULL);
46 p->module = g_module_open(path, 0);
50 if (p->module == NULL) {
51 g_warning(g_module_error());
56 p->config = (PluginSetupConfig)load_sym(p->module, name,
57 "plugin_setup_config", FALSE);
58 p->startup = (PluginStartup)load_sym(p->module, name, "plugin_startup",
60 p->shutdown = (PluginShutdown)load_sym(p->module, name, "plugin_shutdown",
63 if (p->config == NULL || p->startup == NULL || p->shutdown == NULL) {
64 g_module_close(p->module);
69 p->name = g_strdup(name);
73 static void plugin_free(Plugin *p)
78 g_module_close(p->module);
82 static GData *plugins = NULL;
86 g_datalist_init(&plugins);
89 void plugin_shutdown()
91 g_datalist_clear(&plugins);
94 gboolean plugin_open(gchar *name, ObParseInst *i)
98 if (g_datalist_get_data(&plugins, name) != NULL)
101 p = plugin_new(name);
103 g_warning("failed to load plugin '%s'", name);
108 g_datalist_set_data_full(&plugins, name, p, (GDestroyNotify) plugin_free);
112 static void foreach_start(GQuark key, Plugin *p, gpointer *foo)
120 void plugin_startall()
122 g_datalist_foreach(&plugins, (GDataForeachFunc)foreach_start, NULL);
125 void plugin_start(gchar *name)
129 if (!(p = g_datalist_get_data(&plugins, name))) {
130 g_warning("Tried to start plugin '%s' but it is not loaded", name);
139 void plugin_loadall(ObParseInst *i)
145 path = g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL);
147 io = g_io_channel_new_file(path, "r", &err);
151 path = g_build_filename(RCDIR, "pluginrc", NULL);
153 io = g_io_channel_new_file(path, "r", &err);
158 /* load the default plugins */
159 plugin_open("placement", i);
161 /* load the plugins in the rc file */
162 while (g_io_channel_read_line(io, &name, NULL, NULL, &err) ==
163 G_IO_STATUS_NORMAL) {
165 if (name[0] != '\0' && name[0] != '#')
166 plugin_open(name, i);
169 g_io_channel_unref(io);