Fix bugs of plugin support.
authorHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Sat, 7 Aug 2010 13:06:19 +0000 (21:06 +0800)
committerHong Jen Yee (PCMan) <pcman.tw@gmail.com>
Sat, 7 Aug 2010 13:06:19 +0000 (21:06 +0800)
configure.ac
src/lxappearance.c
src/plugin.c

index fb47f14..ded5cbd 100644 (file)
@@ -29,7 +29,7 @@ PKG_CHECK_MODULES(XLIB, "x11")
 AC_SUBST(XLIB_CFLAGS)
 AC_SUBST(XLIB_LIBS)
 
-gtk_modules="gtk+-2.0 >= 2.12.0"
+gtk_modules="gtk+-2.0 >= 2.12.0 gthread-2.0"
 PKG_CHECK_MODULES(GTK, [$gtk_modules])
 AC_SUBST(GTK_CFLAGS)
 AC_SUBST(GTK_LIBS)
index 0ce3607..286034e 100644 (file)
@@ -370,6 +370,7 @@ int main(int argc, char** argv)
     textdomain ( GETTEXT_PACKAGE );
 #endif
 
+    g_thread_init(NULL);
     /* initialize GTK+ and parse the command line arguments */
     if( G_UNLIKELY( ! gtk_init_with_args( &argc, &argv, "", option_entries, GETTEXT_PACKAGE, &err ) ) )
     {
@@ -401,12 +402,11 @@ int main(int argc, char** argv)
     icon_theme_init(b);
     cursor_theme_init(b);
     other_init(b);
-
-    plugins_init(b);
-
     /* the page for window manager plugins */
     app.wm_page = GTK_WIDGET(gtk_builder_get_object(b, "wm_page"));
 
+    plugins_init(b);
+
     g_signal_connect(app.dlg, "response", G_CALLBACK(on_dlg_response), NULL);
 
     gtk_window_present(GTK_WINDOW(app.dlg));
index 10a3ea6..9042b1f 100644 (file)
@@ -48,27 +48,32 @@ void plugins_init(GtkBuilder* builder)
         return;
     while(name = g_dir_read_name(dir))
     {
-        char* file = g_build_filename(PLUGIN_DIR, name, NULL);
-        GModule* mod = g_module_open(file, G_MODULE_BIND_LOCAL);
-        if(mod)
+        if(g_str_has_suffix(name, ".so"))
         {
-            PluginLoadFunc load;
-            gboolean loaded = FALSE;
-            if(g_module_symbol(mod, "plugin_load", &load))
-                loaded = load(&app, builder);
-            if(loaded)
+            char* file = g_build_filename(PLUGIN_DIR, name, NULL);
+            GModule* mod = g_module_open(file, 0);
+            g_free(file);
+            if(mod)
             {
-                Plugin* plugin = g_slice_new0(Plugin);
-                plugin->module = mod;
-                plugin->load = load;
-                g_module_symbol(mod, "plugin_unload", &plugin->unload);
-                plugins = g_slist_prepend(plugins, plugin);
-                g_debug("plugin: %s loadad", file);
+                PluginLoadFunc load;
+                gboolean loaded = FALSE;
+                g_debug("module: %s", g_module_name(mod));
+                if(g_module_symbol(mod, "plugin_load", &load))
+                    loaded = load(&app, builder);
+                if(loaded)
+                {
+                    Plugin* plugin = g_slice_new0(Plugin);
+                    plugin->module = mod;
+                    plugin->load = load;
+                    g_module_symbol(mod, "plugin_unload", &plugin->unload);
+                    plugins = g_slist_prepend(plugins, plugin);
+                }
+                else
+                    g_module_close(mod);
             }
             else
-                g_module_close(mod);
+                g_debug("open failed: %s\n%s", name, g_module_error());
         }
-        g_free(file);
     }
     g_dir_close(dir);
 }
@@ -79,6 +84,8 @@ void plugins_finalize()
     for(l = plugins; l; l=l->next)
     {
         Plugin* plugin = (Plugin*)l->data;
+        if(plugin->unload)
+            plugin->unload(&app);
         g_module_close(plugin->module);
         g_slice_free(Plugin, plugin);
     }