]> Dogcows Code - chaz/openbox/blobdiff - openbox/plugin.c
add helper functions for manipulating the focus_order list.
[chaz/openbox] / openbox / plugin.c
index 247d490a5faa03fe5b1c090f8cc6a6f33a2aae52..c3e21ec49c81fcf29a60ab7d963d36c5653e0cf1 100644 (file)
@@ -1,6 +1,7 @@
 #include <glib.h>
 #include <gmodule.h>
 
+typedef void (*PluginSetupConfig)();
 typedef void (*PluginStartup)();
 typedef void (*PluginShutdown)();
 
@@ -8,6 +9,7 @@ typedef struct {
     GModule *module;
     char *name;
 
+    PluginSetupConfig config;
     PluginStartup startup;
     PluginShutdown shutdown;
 } Plugin;
@@ -30,26 +32,29 @@ static Plugin *plugin_new(char *name)
    
     p = g_new(Plugin, 1);
 
-    path = g_build_filename(PLUGINDIR, name, NULL);
+    path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
+                            NULL);
     p->module = g_module_open(path, 0);
     g_free(path);
 
     if (p->module == NULL) {
-       path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
-                               NULL);
-       p->module = g_module_open(path, 0);
-       g_free(path);
+        path = g_build_filename(PLUGINDIR, name, NULL);
+        p->module = g_module_open(path, 0);
+        g_free(path);
     }
 
     if (p->module == NULL) {
+        g_warning(g_module_error());
         g_free(p);
         return NULL;
     }
 
-    p->startup = load_sym(p->module, name, "plugin_startup");
-    p->shutdown = load_sym(p->module, name, "plugin_shutdown");
+    p->config = (PluginSetupConfig)load_sym(p->module, name,
+                                            "plugin_setup_config");
+    p->startup = (PluginStartup)load_sym(p->module, name, "plugin_startup");
+    p->shutdown = (PluginShutdown)load_sym(p->module, name, "plugin_shutdown");
 
-    if (p->startup == NULL || p->shutdown == NULL) {
+    if (p->config == NULL || p->startup == NULL || p->shutdown == NULL) {
         g_module_close(p->module);
         g_free(p);
         return NULL;
@@ -94,9 +99,9 @@ gboolean plugin_open(char *name)
         g_warning("failed to load plugin '%s'", name);
         return FALSE;
     }
+    p->config();
 
-    g_datalist_set_data_full(&plugins, name, p,  (GDestroyNotify) plugin_free);
-    p->startup();
+    g_datalist_set_data_full(&plugins, name, p, (GDestroyNotify) plugin_free);
     return TRUE;
 }
 
@@ -104,3 +109,50 @@ void plugin_close(char *name)
 {
     g_datalist_remove_data(&plugins, name);
 }
+
+static void foreach_start(GQuark key, Plugin *p, gpointer *foo)
+{
+    p->startup();
+}
+
+void plugin_startall()
+{
+    g_datalist_foreach(&plugins, (GDataForeachFunc)foreach_start, NULL);
+}
+
+void plugin_loadall()
+{
+    GIOChannel *io;
+    GError *err;
+    char *path, *name;
+
+    path = g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL);
+    err = NULL;
+    io = g_io_channel_new_file(path, "r", &err);
+    g_free(path);
+
+    if (io == NULL) {
+        path = g_build_filename(RCDIR, "pluginrc", NULL);
+        err = NULL;
+        io = g_io_channel_new_file(path, "r", &err);
+        g_free(path);
+    }
+
+    if (io == NULL) {
+        /* load the default plugins */
+        plugin_open("keyboard");
+        plugin_open("mouse");
+        plugin_open("placement");
+        plugin_open("resistance");
+    } else {
+        /* load the plugins in the rc file */
+        while (g_io_channel_read_line(io, &name, NULL, NULL, &err) ==
+               G_IO_STATUS_NORMAL) {
+            g_strstrip(name);
+            if (name[0] != '\0' && name[0] != '#')
+                plugin_open(name);
+            g_free(name);
+        }
+        g_io_channel_unref(io);
+    }
+}
This page took 0.02655 seconds and 4 git commands to generate.