[patch] default gtkrc files
- From: "Shawn T . Amundson" <amundson gimp org>
- To: gtk-devel-list redhat com
- Subject: [patch] default gtkrc files
- Date: Wed, 2 Dec 1998 19:43:12 -0800
I plan to apply this patch, but I figured it might be
useful to open this up for discussion first.
Basically:
gtk_init calls gtk_rc_init. gtk_rc_init will automatically
parse $sysconfdir/gtkrc and ~/.gtkrc by default. This can
be changed by using gtk_rc_set_default_files(GSList *files).
gtk_rc_get_default_files() can be used to get these files
if you want to append to the list (see testgtk example
below).
$sysconfdir is usually $prefix/etc and can be set with configure.
There is also a GTK_RC_FILES environment variable which can
be used to change the default files. This can be especially
useful for avoiding reading in $sysconfdir/gtkrc.
-Shawn
Index: gtk/Makefile.am
===================================================================
RCS file: /debian/home/gnomecvs/gtk+/gtk/Makefile.am,v
retrieving revision 1.65
diff -u -r1.65 Makefile.am
--- Makefile.am 1998/12/01 10:42:01 1.65
+++ Makefile.am 1998/12/03 03:27:43
@@ -343,6 +343,7 @@
-DG_LOG_DOMAIN=\"Gtk\" \
-DGTK_EXE_PREFIX=\"$(exec_prefix)\" \
-DGTK_DATA_PREFIX=\"$(prefix)\" \
+ -DGTK_SYSCONFDIR=\"$(sysconfdir)\" \
-I$(top_srcdir) \
@GTK_DEBUG_FLAGS@ \
@GTK_XIM_FLAGS@ \
Index: gtk/gtkrc.h
===================================================================
RCS file: /debian/home/gnomecvs/gtk+/gtk/gtkrc.h,v
retrieving revision 1.14
diff -u -r1.14 gtkrc.h
--- gtkrc.h 1998/11/28 07:42:17 1.14
+++ gtkrc.h 1998/12/03 03:27:43
@@ -56,6 +56,8 @@
};
void gtk_rc_init (void);
+void gtk_rc_set_default_files (GSList *files);
+GSList* gtk_rc_get_default_files (void);
void gtk_rc_parse (const gchar *filename);
void gtk_rc_parse_string (const gchar *rc_string);
gboolean gtk_rc_reparse_all (void);
Index: gtk/gtkrc.c
===================================================================
RCS file: /debian/home/gnomecvs/gtk+/gtk/gtkrc.c,v
retrieving revision 1.28
diff -u -r1.28 gtkrc.c
--- gtkrc.c 1998/11/30 19:06:38 1.28
+++ gtkrc.c 1998/12/03 03:27:49
@@ -95,6 +95,7 @@
static void gtk_rc_append_default_pixmap_path (void);
static void gtk_rc_append_default_module_path (void);
static void gtk_rc_append_pixmap_path (gchar *dir);
+static void gtk_rc_append_initial_default_files (void);
static const GScannerConfig gtk_rc_scanner_config =
@@ -179,6 +180,8 @@
static GSList *gtk_rc_sets_widget = NULL;
static GSList *gtk_rc_sets_widget_class = NULL;
static GSList *gtk_rc_sets_class = NULL;
+static GSList *gtk_rc_default_files = NULL;
+static gboolean gtk_rc_auto_parse = TRUE;
#define GTK_RC_MAX_PIXMAP_PATHS 128
static gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
@@ -303,15 +306,111 @@
g_free(path);
}
+static void
+gtk_rc_append_initial_default_files (void)
+{
+ gchar *var, *str;
+ gchar **files;
+ gint i;
+
+ var = getenv("GTK_RC_FILES");
+ if (var)
+ {
+ files = g_strsplit (var, ":", 256);
+ i=0;
+ while (files[i])
+ {
+ gtk_rc_default_files = g_slist_append (gtk_rc_default_files,
+ files[i]);
+ i++;
+ }
+ }
+ else
+ {
+ str = g_malloc (strlen(GTK_SYSCONFDIR) + strlen("/gtkrc"));
+ sprintf (str, "%s%s", GTK_SYSCONFDIR, "/gtkrc");
+ gtk_rc_default_files = g_slist_append (gtk_rc_default_files, str);
+
+ var = g_get_home_dir ();
+ str = g_malloc (strlen(var) + strlen("/.gtkrc"));
+ sprintf (str, "%s%s", var, "/.gtkrc");
+ printf("%s\n",str);
+ gtk_rc_default_files = g_slist_append (gtk_rc_default_files, str);
+ }
+}
+
void
+gtk_rc_set_default_files (GSList *files)
+{
+ GSList *tmp_list;
+
+ if (files == NULL)
+ {
+ tmp_list = gtk_rc_default_files;
+ while (tmp_list)
+ {
+ g_free (tmp_list->data);
+ tmp_list = tmp_list->next;
+ }
+ g_slist_free (gtk_rc_default_files);
+ gtk_rc_auto_parse = FALSE;
+ gtk_rc_default_files = NULL;
+ return;
+ }
+
+ tmp_list = files;
+ while (tmp_list)
+ {
+ gtk_rc_default_files = g_slist_append (gtk_rc_default_files,
+ g_strdup (tmp_list->data));
+ tmp_list = tmp_list->next;
+ }
+}
+
+GSList*
+gtk_rc_get_default_files (void)
+{
+ GSList *list = NULL;
+ GSList *tmp_list;
+
+ if (gtk_rc_auto_parse == TRUE && gtk_rc_default_files == NULL)
+ gtk_rc_append_initial_default_files ();
+
+ tmp_list = gtk_rc_default_files;
+ while (tmp_list)
+ {
+ list = g_slist_append (list, g_strdup (tmp_list->data));
+ tmp_list = tmp_list->next;
+ }
+
+ return list;
+}
+
+void
gtk_rc_init (void)
{
+ GSList *tmp_list;
+
rc_style_ht = g_hash_table_new ((GHashFunc) gtk_rc_style_hash,
(GCompareFunc) gtk_rc_style_compare);
pixmap_path[0] = NULL;
module_path[0] = NULL;
gtk_rc_append_default_pixmap_path();
gtk_rc_append_default_module_path();
+
+ if (gtk_rc_auto_parse == FALSE)
+ return;
+
+ if (gtk_rc_default_files == NULL)
+ gtk_rc_append_initial_default_files ();
+
+ tmp_list = gtk_rc_default_files;
+ while (tmp_list)
+ {
+ gtk_rc_parse ((gchar*) tmp_list->data);
+
+ tmp_list = tmp_list->next;
+ }
}
void
Index: gtk/testgtk.c
===================================================================
RCS file: /debian/home/gnomecvs/gtk+/gtk/testgtk.c,v
retrieving revision 1.144
diff -u -r1.144 testgtk.c
--- testgtk.c 1998/11/30 07:09:36 1.144
+++ testgtk.c 1998/12/03 03:28:06
@@ -8292,11 +8292,24 @@
main (int argc, char *argv[])
{
GtkBindingSet *binding_set;
+ GSList *rcfiles = NULL;
+ GSList *tmp_list;
srand (time (NULL));
gtk_set_locale ();
+ rcfiles = gtk_rc_get_default_files ();
+ rcfiles = g_slist_append (rcfiles, "testgtkrc");
+ gtk_rc_set_default_files (rcfiles);
+ tmp_list = rcfiles;
+ while (tmp_list)
+ {
+ g_free (tmp_list->data);
+ tmp_list = tmp_list->next;
+ }
+ g_slist_free (rcfiles);
+
gtk_init (&argc, &argv);
gdk_rgb_init ();
@@ -8309,8 +8322,6 @@
"debug_msg",
1,
GTK_TYPE_STRING, "GtkWidgetClass <ctrl><release>9 test");
-
- gtk_rc_parse ("testgtkrc");
create_main_window ();
--
Shawn T. Amundson
amundson@gimp.org http://www.gimp.org/~amundson
"The assumption that the universe looks the same in every
direction is clearly not true in reality." - Stephen Hawking
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]