]> Dogcows Code - chaz/openbox/blobdiff - openbox/plugin.c
new method for loading menu files etc
[chaz/openbox] / openbox / plugin.c
index 411eb6fbee5086a385f16174a365be9c08759be5..300cd82d478646d76a9d8660560b2b089fa16bf8 100644 (file)
@@ -6,16 +6,16 @@
 
 typedef struct {
     GModule *module;
-    char *name;
+    gchar *name;
+
+    gboolean started;
 
     PluginSetupConfig config;
     PluginStartup startup;
     PluginShutdown shutdown;
-    PluginCreate create;
-    PluginDestroy destroy;
 } Plugin;
 
-static gpointer load_sym(GModule *module, char *name, char *symbol,
+static gpointer load_sym(GModule *module, gchar *name, gchar *symbol,
                         gboolean allow_fail)
 {
     gpointer var;
@@ -28,12 +28,13 @@ static gpointer load_sym(GModule *module, char *name, char *symbol,
     return var;
 }
 
-static Plugin *plugin_new(char *name)
+static Plugin *plugin_new(gchar *name)
 {
     Plugin *p;
-    char *path;
+    gchar *path;
    
     p = g_new(Plugin, 1);
+    p->started = FALSE;
 
     path = g_build_filename(g_get_home_dir(), ".openbox", "plugins", name,
                             NULL);
@@ -58,9 +59,6 @@ static Plugin *plugin_new(char *name)
                                         FALSE);
     p->shutdown = (PluginShutdown)load_sym(p->module, name, "plugin_shutdown",
                                           FALSE);
-    p->create = (PluginCreate)load_sym(p->module, name, "plugin_create", TRUE);
-    p->destroy = (PluginDestroy)load_sym(p->module, name, "plugin_destroy",
-                                        TRUE);
 
     if (p->config == NULL || p->startup == NULL || p->shutdown == NULL) {
         g_module_close(p->module);
@@ -93,15 +91,12 @@ void plugin_shutdown()
     g_datalist_clear(&plugins);
 }
 
-gboolean plugin_open_full(char *name, gboolean reopen, ObParseInst *i)
+gboolean plugin_open(gchar *name, ObParseInst *i)
 {
     Plugin *p;
 
-    if (g_datalist_get_data(&plugins, name) != NULL) {
-       if (!reopen) 
-           g_warning("plugin '%s' already loaded, can't load again", name);
+    if (g_datalist_get_data(&plugins, name) != NULL)
         return TRUE;
-    }
 
     p = plugin_new(name);
     if (p == NULL) {
@@ -114,22 +109,12 @@ gboolean plugin_open_full(char *name, gboolean reopen, ObParseInst *i)
     return TRUE;
 }
 
-gboolean plugin_open(char *name, ObParseInst *i) {
-    return plugin_open_full(name, FALSE, i);
-}
-
-gboolean plugin_open_reopen(char *name, ObParseInst *i) {
-    return plugin_open_full(name, TRUE, i);
-}
-
-void plugin_close(char *name)
-{
-    g_datalist_remove_data(&plugins, name);
-}
-
 static void foreach_start(GQuark key, Plugin *p, gpointer *foo)
 {
-    p->startup();
+    if (!p->started) {
+        p->startup();
+        p->started = TRUE;
+    }
 }
 
 void plugin_startall()
@@ -137,11 +122,25 @@ void plugin_startall()
     g_datalist_foreach(&plugins, (GDataForeachFunc)foreach_start, NULL);
 }
 
+void plugin_start(gchar *name)
+{
+    Plugin *p;
+
+    if (!(p = g_datalist_get_data(&plugins, name))) {
+        g_warning("Tried to start plugin '%s' but it is not loaded", name);
+        return;
+    }
+    if (!p->started) {
+        p->startup();
+        p->started = TRUE;
+    }
+}
+
 void plugin_loadall(ObParseInst *i)
 {
     GIOChannel *io;
     GError *err;
-    char *path, *name;
+    gchar *path, *name;
 
     path = g_build_filename(g_get_home_dir(), ".openbox", "pluginrc", NULL);
     err = NULL;
@@ -158,10 +157,6 @@ void plugin_loadall(ObParseInst *i)
     if (io == NULL) {
         /* load the default plugins */
         plugin_open("placement", i);
-
-        /* XXX rm me when the parser loads me magically */
-        plugin_open("client_menu", i);
-        plugin_open("client_list_menu", i);
     } else {
         /* load the plugins in the rc file */
         while (g_io_channel_read_line(io, &name, NULL, NULL, &err) ==
@@ -174,41 +169,3 @@ void plugin_loadall(ObParseInst *i)
         g_io_channel_unref(io);
     }
 }
-
-void *plugin_create(char *name, void *data)
-{
-    Plugin *p = (Plugin *)g_datalist_get_data(&plugins, name);
-
-    if (p == NULL) {
-       g_warning("Unable to find plugin for create: %s", name);
-       return NULL;
-    }
-
-    if (p->create == NULL || p->destroy == NULL) {
-       g_critical("Unsupported create/destroy: %s", name);
-       return NULL;
-    }
-
-    return p->create(data);
-}
-
-void plugin_destroy(char *name, void *data)
-{
-    Plugin *p = (Plugin *)g_datalist_get_data(&plugins, name);
-
-    if (p == NULL) {
-       g_critical("Unable to find plugin for destroy: %s", name);
-       /* really shouldn't happen, but attempt to free something anyway? */
-       g_free(data);
-       return;
-    }
-
-    if (p->destroy == NULL || p->create == NULL) {
-       g_critical("Unsupported create/destroy: %s", name);
-       /* really, really shouldn't happen, but attempt to free anyway? */
-       g_free(data);
-       return;
-    }
-
-    p->destroy(data);
-}
This page took 0.027913 seconds and 4 git commands to generate.