]>
Dogcows Code - chaz/openbox/blob - openbox/plugin.c
b8d9be4beb4cb9f983fefd3e8af346e840b2c592
1 #include "plugins/interface.h"
2 #include "parser/parse.h"
11 PluginSetupConfig config
;
12 PluginStartup startup
;
13 PluginShutdown shutdown
;
16 static gpointer
load_sym(GModule
*module, char *name
, char *symbol
,
20 if (!g_module_symbol(module, symbol
, &var
)) {
22 g_warning("Failed to load symbol '%s' from plugin '%s'",
29 static Plugin
*plugin_new(char *name
)
36 path
= g_build_filename(g_get_home_dir(), ".openbox", "plugins", name
,
38 p
->module = g_module_open(path
, 0);
41 if (p
->module == NULL
) {
42 path
= g_build_filename(PLUGINDIR
, name
, NULL
);
43 p
->module = g_module_open(path
, 0);
47 if (p
->module == NULL
) {
48 g_warning(g_module_error());
53 p
->config
= (PluginSetupConfig
)load_sym(p
->module, name
,
54 "plugin_setup_config", FALSE
);
55 p
->startup
= (PluginStartup
)load_sym(p
->module, name
, "plugin_startup",
57 p
->shutdown
= (PluginShutdown
)load_sym(p
->module, name
, "plugin_shutdown",
60 if (p
->config
== NULL
|| p
->startup
== NULL
|| p
->shutdown
== NULL
) {
61 g_module_close(p
->module);
66 p
->name
= g_strdup(name
);
70 static void plugin_free(Plugin
*p
)
75 g_module_close(p
->module);
79 static GData
*plugins
= NULL
;
83 g_datalist_init(&plugins
);
86 void plugin_shutdown()
88 g_datalist_clear(&plugins
);
91 gboolean
plugin_open_full(char *name
, gboolean reopen
, ObParseInst
*i
)
95 if (g_datalist_get_data(&plugins
, name
) != NULL
) {
97 g_warning("plugin '%s' already loaded, can't load again", name
);
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 gboolean
plugin_open(char *name
, ObParseInst
*i
) {
113 return plugin_open_full(name
, FALSE
, i
);
116 gboolean
plugin_open_reopen(char *name
, ObParseInst
*i
) {
117 return plugin_open_full(name
, TRUE
, i
);
120 void plugin_close(char *name
)
122 g_datalist_remove_data(&plugins
, name
);
125 static void foreach_start(GQuark key
, Plugin
*p
, gpointer
*foo
)
130 void plugin_startall()
132 g_datalist_foreach(&plugins
, (GDataForeachFunc
)foreach_start
, NULL
);
135 void plugin_loadall(ObParseInst
*i
)
141 path
= g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL
);
143 io
= g_io_channel_new_file(path
, "r", &err
);
147 path
= g_build_filename(RCDIR
, "pluginrc", NULL
);
149 io
= g_io_channel_new_file(path
, "r", &err
);
154 /* load the default plugins */
155 plugin_open("placement", i
);
157 /* XXX rm me when the parser loads me magically */
158 plugin_open("client_menu", i
);
159 plugin_open("client_list_menu", 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
);
This page took 0.038719 seconds and 4 git commands to generate.