]>
Dogcows Code - chaz/openbox/blob - plugin.c
e0067f22e808144750bb759d1954e573d0d8ea85
4 typedef void (*PluginStartup
)();
5 typedef void (*PluginShutdown
)();
11 PluginStartup startup
;
12 PluginShutdown shutdown
;
15 static gpointer
load_sym(GModule
*module, char *name
, char *symbol
)
18 if (!g_module_symbol(module, symbol
, &var
)) {
19 g_warning("Failed to load symbol '%s' from plugin '%s'",
26 static Plugin
*plugin_new(char *name
)
33 path
= g_build_filename(PLUGINDIR
, name
, NULL
);
34 p
->module = g_module_open(path
, 0);
37 if (p
->module == NULL
) {
38 path
= g_build_filename(g_get_home_dir(), ".openbox", "plugins", name
,
40 p
->module = g_module_open(path
, 0);
44 if (p
->module == NULL
) {
49 p
->startup
= (PluginStartup
)load_sym(p
->module, name
, "plugin_startup");
50 p
->shutdown
= (PluginShutdown
)load_sym(p
->module, name
, "plugin_shutdown");
52 if (p
->startup
== NULL
|| p
->shutdown
== NULL
) {
53 g_module_close(p
->module);
58 p
->name
= g_strdup(name
);
62 static void plugin_free(Plugin
*p
)
67 g_module_close(p
->module);
71 static GData
*plugins
= NULL
;
75 g_datalist_init(&plugins
);
78 void plugin_shutdown()
80 g_datalist_clear(&plugins
);
83 gboolean
plugin_open(char *name
)
87 if (g_datalist_get_data(&plugins
, name
) != NULL
) {
88 g_warning("plugin '%s' already loaded, can't load again", name
);
94 g_warning("failed to load plugin '%s'", name
);
97 /* XXX p->plugin_set_config(); */
99 g_datalist_set_data_full(&plugins
, name
, p
, (GDestroyNotify
) plugin_free
);
103 void plugin_close(char *name
)
105 g_datalist_remove_data(&plugins
, name
);
108 static void foreach_start(GQuark key
, Plugin
*p
, gpointer
*foo
)
113 void plugin_startall()
115 g_datalist_foreach(&plugins
, (GDataForeachFunc
)foreach_start
, NULL
);
118 void plugin_loadall()
124 path
= g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL
);
126 io
= g_io_channel_new_file(path
, "r", &err
);
130 path
= g_build_filename(RCDIR
, "pluginrc", NULL
);
132 io
= g_io_channel_new_file(path
, "r", &err
);
137 /* load the default plugins */
138 plugin_open("focus");
139 plugin_open("keyboard");
140 plugin_open("mouse");
141 plugin_open("placement");
142 plugin_open("resistance");
144 /* load the plugins in the rc file */
145 while (g_io_channel_read_line(io
, &name
, NULL
, NULL
, &err
) ==
146 G_IO_STATUS_NORMAL
) {
150 g_io_channel_unref(io
);
This page took 0.039151 seconds and 3 git commands to generate.