Re: per-app .gtkrc



Tim Howe <vsync wego com> writes:

> A coworker and I wanted to create exceptions for certain apps from the
> global GTK theme, so I wrote this tweak.  Now the default behavior is
> to check for ~/.gtkrc.<appname> (appname = last component of
> argv[0]).  Failing that, it checks for the normal ~/.gtkrc.
> 
> Since I'm lazy, this is off the 1.2.8 tarball, not CVS.  I don't
> subscribe to this list, so CCing me on replies might be useful.

Err, and careless...  =)  This time I attached the patch.

-- 
Tim Howe
Associate Software Engineer
Wego Inc. -- wego.com

diff -ru gtk+-1.2.8/gtk/gtkmain.c gtk+-1.2.8.hacked/gtk/gtkmain.c
--- gtk+-1.2.8/gtk/gtkmain.c	Sun Feb  6 19:01:53 2000
+++ gtk+-1.2.8.hacked/gtk/gtkmain.c	Tue Aug 29 19:38:33 2000
@@ -182,6 +182,7 @@
   GSList *gtk_modules = NULL;
   GSList *slist;
   gchar *env_string = NULL;
+  gchar *appname = NULL;
 
   if (gtk_initialized)
     return TRUE;
@@ -233,6 +234,12 @@
     {
       gint i, j, k;
       
+      appname = rindex((*argv)[0], '/');
+      if (!appname)
+        appname = (*argv)[0];
+      else
+        appname++;
+
       for (i = 1; i < *argc;)
 	{
 	  if (strcmp ("--gtk-module", (*argv)[i]) == 0 ||
@@ -389,7 +396,7 @@
   gtk_type_init ();
   gtk_object_post_arg_parsing_init ();
   gtk_signal_init ();
-  gtk_rc_init ();
+  gtk_rc_init (appname);
   
   
   /* Register an exit function to make sure we are able to cleanup.
diff -ru gtk+-1.2.8/gtk/gtkrc.c gtk+-1.2.8.hacked/gtk/gtkrc.c
--- gtk+-1.2.8/gtk/gtkrc.c	Wed Oct 20 07:41:16 1999
+++ gtk+-1.2.8.hacked/gtk/gtkrc.c	Tue Aug 29 19:45:39 2000
@@ -211,6 +211,8 @@
 #define GTK_RC_MAX_MODULE_PATHS 128
 static gchar *module_path[GTK_RC_MAX_MODULE_PATHS];
 
+static gchar *gtk_rc_appname = NULL;
+
 /* A stack of directories for RC files we are parsing currently.
  * these are implicitely added to the end of PIXMAP_PATHS
  */
@@ -319,20 +321,34 @@
   if (var)
     {
       files = g_strsplit (var, ":", 128);
-      i=0;
-      while (files[i])
-	{
-	  gtk_rc_add_default_file (files[i]);
-	  i++;
-	}
+      for (i=0; files[i]; i++)
+        gtk_rc_add_default_file (files[i]);
       g_strfreev (files);
     }
   else
     {
+      struct stat buf;
+
       str = g_strdup_printf ("%s%s", GTK_SYSCONFDIR, "/gtk/gtkrc");
       gtk_rc_add_default_file (str);
       g_free (str);
 
+      /*
+       * This is somewhat quirky - first we check for an app-specific
+       * rc file, but if that fails, we fall back to the generic
+       * ~/.gtkrc.
+       */
+      if (gtk_rc_appname)
+        {
+          str = g_strdup_printf ("%s%s%s", g_get_home_dir (), "/.gtkrc.", gtk_rc_appname);
+          if (!stat (str, &buf))
+            {
+              gtk_rc_add_default_file (str);
+              g_free (str);
+              return;
+            }
+        }
+
       str = g_strdup_printf ("%s%s", g_get_home_dir (), "/.gtkrc");
       gtk_rc_add_default_file (str);
       g_free (str);
@@ -437,7 +453,7 @@
 }
 
 void
-gtk_rc_init (void)
+gtk_rc_init (const gchar *appname)
 {
   static gchar *locale_suffixes[3];
   static gint n_locale_suffixes = 0;
@@ -460,6 +476,9 @@
       gtk_rc_append_default_pixmap_path();
       gtk_rc_append_default_module_path();
       
+      if (appname)
+        gtk_rc_appname = g_strdup(appname);
+
       gtk_rc_add_initial_default_files ();
 
       if (strcmp (locale, "C") && strcmp (locale, "POSIX"))
diff -ru gtk+-1.2.8/gtk/gtkrc.h gtk+-1.2.8.hacked/gtk/gtkrc.h
--- gtk+-1.2.8/gtk/gtkrc.h	Sat Feb 12 22:59:50 2000
+++ gtk+-1.2.8.hacked/gtk/gtkrc.h	Tue Aug 29 19:10:26 2000
@@ -60,8 +60,8 @@
   gpointer        engine_data;
 };
 
-void	  gtk_rc_init			(void);
-void      gtk_rc_add_default_file    (const gchar *filename);
+void	  gtk_rc_init			(const gchar *appname);
+void      gtk_rc_add_default_file       (const gchar *filename);
 void      gtk_rc_set_default_files      (gchar **filenames);
 gchar**   gtk_rc_get_default_files      (void);
 void	  gtk_rc_parse			(const gchar *filename);





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]