4 typedef void (*PluginSetupConfig)();
5 typedef void (*PluginStartup)();
6 typedef void (*PluginShutdown)();
12 PluginSetupConfig config;
13 PluginStartup startup;
14 PluginShutdown shutdown;
17 static gpointer load_sym(GModule *module, char *name, char *symbol)
20 if (!g_module_symbol(module, symbol, &var)) {
21 g_warning("Failed to load symbol '%s' from plugin '%s'",
28 static Plugin *plugin_new(char *name)
35 path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
37 p->module = g_module_open(path, 0);
40 if (p->module == NULL) {
41 path = g_build_filename(PLUGINDIR, name, NULL);
42 p->module = g_module_open(path, 0);
46 if (p->module == NULL) {
47 g_warning(g_module_error());
52 p->config = (PluginSetupConfig)load_sym(p->module, name,
53 "plugin_setup_config");
54 p->startup = (PluginStartup)load_sym(p->module, name, "plugin_startup");
55 p->shutdown = (PluginShutdown)load_sym(p->module, name, "plugin_shutdown");
57 if (p->config == NULL || p->startup == NULL || p->shutdown == NULL) {
58 g_module_close(p->module);
63 p->name = g_strdup(name);
67 static void plugin_free(Plugin *p)
72 g_module_close(p->module);
76 static GData *plugins = NULL;
80 g_datalist_init(&plugins);
83 void plugin_shutdown()
85 g_datalist_clear(&plugins);
88 gboolean plugin_open(char *name)
92 if (g_datalist_get_data(&plugins, name) != NULL) {
93 g_warning("plugin '%s' already loaded, can't load again", name);
99 g_warning("failed to load plugin '%s'", name);
104 g_datalist_set_data_full(&plugins, name, p, (GDestroyNotify) plugin_free);
108 void plugin_close(char *name)
110 g_datalist_remove_data(&plugins, name);
113 static void foreach_start(GQuark key, Plugin *p, gpointer *foo)
118 void plugin_startall()
120 g_datalist_foreach(&plugins, (GDataForeachFunc)foreach_start, NULL);
123 void plugin_loadall()
129 path = g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL);
131 io = g_io_channel_new_file(path, "r", &err);
135 path = g_build_filename(RCDIR, "pluginrc", NULL);
137 io = g_io_channel_new_file(path, "r", &err);
142 /* load the default plugins */
143 plugin_open("keyboard");
144 plugin_open("mouse");
145 plugin_open("placement");
146 plugin_open("resistance");
148 /* load the plugins in the rc file */
149 while (g_io_channel_read_line(io, &name, NULL, NULL, &err) ==
150 G_IO_STATUS_NORMAL) {
152 if (name[0] != '\0' && name[0] != '#')
156 g_io_channel_unref(io);