]> Pileus Git - ~andy/gtk/blobdiff - gtk/gtkmodules.c
css: Don't query type for regions
[~andy/gtk] / gtk / gtkmodules.c
index 97944f13b0eec8f8fe6743e0e243aa0ae836153d..5fa2abf8a13ffd35a42526ff3da7fa6c830730bf 100644 (file)
@@ -18,7 +18,7 @@
  * Boston, MA 02111-1307, USA.
  */
 
-#include <config.h>
+#include "config.h"
 
 #include <string.h>
 
 #include "gtksettings.h"
 #include "gtkdebug.h"
 #include "gtkprivate.h" /* GTK_LIBDIR */
-#include "gtkintl.h" 
-#include "gtkalias.h"
+#include "gtkmainprivate.h"
+#include "gtkintl.h"
 
 #include <gmodule.h>
-#include <pango/pango-utils.h> /* For pango_split_file_list */
 
 typedef struct _GtkModuleInfo GtkModuleInfo;
 struct _GtkModuleInfo
@@ -67,15 +66,15 @@ get_module_path (void)
 
   home_dir = g_get_home_dir();
   if (home_dir)
-    home_gtk_dir = g_build_filename (home_dir, ".gtk-2.0", NULL);
+    home_gtk_dir = g_build_filename (home_dir, ".gtk-3.0", NULL);
 
   module_path_env = g_getenv ("GTK_PATH");
   exe_prefix = g_getenv ("GTK_EXE_PREFIX");
 
   if (exe_prefix)
-    default_dir = g_build_filename (exe_prefix, "lib", "gtk-2.0", NULL);
+    default_dir = g_build_filename (exe_prefix, "lib", "gtk-3.0", NULL);
   else
-    default_dir = g_build_filename (GTK_LIBDIR, "gtk-2.0", NULL);
+    default_dir = g_build_filename (GTK_LIBDIR, "gtk-3.0", NULL);
 
   if (module_path_env && home_gtk_dir)
     module_path = g_build_path (G_SEARCHPATH_SEPARATOR_S,
@@ -238,7 +237,16 @@ find_module (const gchar *name)
     }
 
   module = g_module_open (module_name, G_MODULE_BIND_LOCAL | G_MODULE_BIND_LAZY);
-  g_free(module_name);
+
+  if (_gtk_module_has_mixed_deps (module))
+    {
+      g_warning ("GTK+ module %s cannot be loaded.\n"
+                 "GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.", module_name);
+      g_module_close (module);
+      module = NULL;
+    }
+
+  g_free (module_name);
 
   return module;
 }
@@ -255,6 +263,7 @@ load_module (GSList      *module_list,
             const gchar *name)
 {
   GtkModuleInitFunc modinit_func;
+  gpointer modinit_func_ptr;
   GtkModuleInfo *info = NULL;
   GModule *module = NULL;
   GSList *l;
@@ -265,7 +274,7 @@ load_module (GSList      *module_list,
       for (l = gtk_modules; l; l = l->next)
        {
          info = l->data;
-         if (g_slist_find_custom (info->names, name, 
+         if (g_slist_find_custom (info->names, name,
                                   (GCompareFunc)strcmp))
            {
              info->ref_count++;
@@ -274,20 +283,31 @@ load_module (GSList      *module_list,
            }
        }
 
-      if (!success) 
+      if (!success)
        {
          module = find_module (name);
 
          if (module)
            {
-             if (!g_module_symbol (module, "gtk_module_init", (gpointer *) &modinit_func) ||
-                 !modinit_func)
+             if (g_module_symbol (module, "gtk_module_init", &modinit_func_ptr))
+               modinit_func = modinit_func_ptr;
+             else
+               modinit_func = NULL;
+
+             if (!modinit_func)
                g_module_close (module);
              else
                {
+                 GSList *temp;
+
                  success = TRUE;
-                 info = (GtkModuleInfo *) g_slist_find_custom (gtk_modules, module,
-                                                               (GCompareFunc)cmp_module);
+                 info = NULL;
+
+                 temp = g_slist_find_custom (gtk_modules, module,
+                       (GCompareFunc)cmp_module);
+                 if (temp != NULL)
+                       info = temp->data;
+
                  if (!info)
                    {
                      info = g_new0 (GtkModuleInfo, 1);
@@ -302,7 +322,7 @@ load_module (GSList      *module_list,
                      gtk_modules = g_slist_append (gtk_modules, info);
                      
                      /* display_init == NULL indicates a non-multihead aware module.
-                      * For these, we delay the call to init_func until first display is 
+                      * For these, we delay the call to init_func until first display is
                       * opened, see default_display_notify_cb().
                       * For multihead aware modules, we call init_func immediately,
                       * and also call display_init_func on all opened displays.
@@ -343,8 +363,13 @@ load_module (GSList      *module_list,
        }
     }
   else
-    g_message ("Failed to load module \"%s\": %s", name, g_module_error ());
-  
+    {
+      const gchar *error = g_module_error ();
+
+      g_message ("Failed to load module \"%s\"%s%s",
+                 name, error ? ": " : "", error ? error : "");
+    }
+
   return module_list;
 }
 
@@ -359,7 +384,7 @@ gtk_module_info_unref (GtkModuleInfo *info)
   if (info->ref_count == 0) 
     {
       GTK_NOTE (MODULES, 
-               g_print ("Unloading module: %s", g_module_name (info->module)));
+               g_print ("Unloading module: %s\n", g_module_name (info->module)));
 
       gtk_modules = g_slist_remove (gtk_modules, info);
       g_module_close (info->module);
@@ -377,7 +402,7 @@ load_modules (const char *module_str)
   GSList *module_list = NULL;
   gint i;
 
-  GTK_NOTE (MODULES, g_print ("Loading module list: %s", module_str));
+  GTK_NOTE (MODULES, g_print ("Loading module list: %s\n", module_str));
 
   module_names = pango_split_file_list (module_str);
   for (i = 0; module_names[i]; i++) 
@@ -499,6 +524,7 @@ _gtk_modules_init (gint        *argc,
     }
 
   display_manager = gdk_display_manager_get ();
+  default_display_opened = gdk_display_get_default () != NULL;
   g_signal_connect (display_manager, "notify::default-display",
                    G_CALLBACK (default_display_notify_cb), 
                    NULL);
@@ -506,11 +532,13 @@ _gtk_modules_init (gint        *argc,
                    G_CALLBACK (display_opened_cb), 
                    NULL);
 
-  /* Modules specified in the GTK_MODULES environment variable
-   * or on the command line are always loaded, so we'll just leak 
-   * the refcounts.
-   */
-  g_slist_free (load_modules (gtk_modules_args));
+  if (gtk_modules_args) {
+    /* Modules specified in the GTK_MODULES environment variable
+     * or on the command line are always loaded, so we'll just leak 
+     * the refcounts.
+     */
+    g_slist_free (load_modules (gtk_modules_args));
+  }
 }
 
 static void
@@ -532,6 +560,8 @@ _gtk_modules_settings_changed (GtkSettings *settings,
 {
   GSList *new_modules = NULL;
 
+  GTK_NOTE (MODULES, g_print ("gtk-modules setting changed to: %s\n", modules));
+
   /* load/ref before unreffing existing */
   if (modules && modules[0])
     new_modules = load_modules (modules);