XSetting for font



The attached patch implements an xsetting/GtkSetting for the default
font. This seemed a more elegant way of setting the default font in the
control center than editing ~/.gtkrc-2.0. May I commit? 

-- Zaphod





? gtk-font-name.patch
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.2982
diff -u -r1.2982 ChangeLog
--- ChangeLog	2002/02/09 22:12:01	1.2982
+++ ChangeLog	2002/02/10 05:44:53
@@ -1,3 +1,19 @@
+2002-02-09  Richard Hestilow  <hestilow ximian com>
+
+	* gdk/x11/gdkevents-x11.c (settings_map): Add XSetting Gtk/FontName.
+	
+	* gtk/gtkrc.c (_GtkRcContext): Add field font_name.
+	(gtk_rc_settings_changed): Check if gtk-font-name changed.
+	(gtk_rc_context_get): Set context->font_name, and register a
+	settings listener for gtk-font-name.
+	(gtk_rc_reparse_all_for_settings): Reload gtk-font-name.
+
+	* gtk/gtksettings.c (gtk_settings_class_init): Register
+	gtk-font-name as a setting, with "Sans 10" as a default.
+
+	* gtk/gtkstyle.c (gtk_style_init): Initalize style->font_desc
+	from gtk-font-name, instead of hardcoding Sans 10.
+
 2002-02-09  Matthias Clasen  <matthias local>
 
 	* gtk/gtknotebook.c (gtk_notebook_set_focus_child): Avoid segfault
Index: gdk/x11/gdkevents-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkevents-x11.c,v
retrieving revision 1.66
diff -u -r1.66 gdkevents-x11.c
--- gdk/x11/gdkevents-x11.c	2002/02/04 15:13:26	1.66
+++ gdk/x11/gdkevents-x11.c	2002/02/10 05:45:51
@@ -2053,7 +2053,8 @@
   { "Net/CursorBlink", "gtk-cursor-blink" },
   { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
   { "Net/ThemeName", "gtk-theme-name" },
-  { "Gtk/KeyThemeName", "gtk-key-theme-name" }
+  { "Gtk/KeyThemeName", "gtk-key-theme-name" },
+  { "Gtk/FontName", "gtk-font-name"}
 };
 
 static void
Index: gtk/gtkrc.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkrc.c,v
retrieving revision 1.116
diff -u -r1.116 gtkrc.c
--- gtk/gtkrc.c	2002/02/09 00:19:29	1.116
+++ gtk/gtkrc.c	2002/02/10 05:46:19
@@ -95,6 +95,7 @@
 
   gchar *theme_name;
   gchar *key_theme_name;
+  gchar *font_name;
   
   gchar *pixmap_path[GTK_RC_MAX_PIXMAP_PATHS];
 
@@ -532,22 +533,27 @@
 {
   gchar *new_theme_name;
   gchar *new_key_theme_name;
+  gchar *new_font_name;
 
   g_object_get (settings,
 		"gtk-theme-name", &new_theme_name,
 		"gtk-key-theme-name", &new_key_theme_name,
+		"gtk-font-name", &new_font_name,
 		NULL);
 
   if ((new_theme_name != context->theme_name && 
        !(new_theme_name && context->theme_name && strcmp (new_theme_name, context->theme_name) == 0)) ||
       (new_key_theme_name != context->key_theme_name &&
-       !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)))
+       !(new_key_theme_name && context->key_theme_name && strcmp (new_key_theme_name, context->key_theme_name) == 0)) ||
+      (new_font_name != context->font_name &&
+       !(new_font_name && context->font_name && strcmp (new_font_name, context->font_name) == 0)))
     {
       gtk_rc_reparse_all_for_settings (settings, TRUE);
     }
 
   g_free (new_theme_name);
   g_free (new_key_theme_name);
+  g_free (new_font_name);
 }
 
 static GtkRcContext *
@@ -567,6 +573,7 @@
       g_object_get (settings,
 		    "gtk-theme-name", &context->theme_name,
 		    "gtk-key-theme-name", &context->key_theme_name,
+		    "gtk-font-name", &context->font_name,
 		    NULL);
 
       g_signal_connect (settings,
@@ -577,6 +584,11 @@
 			"notify::gtk-key-theme-name",
 			G_CALLBACK (gtk_rc_settings_changed),
 			context);
+      g_signal_connect (settings,
+			"notify::gtk-font-name",
+			G_CALLBACK (gtk_rc_settings_changed),
+			context);
+
       
       context->pixmap_path[0] = NULL;
 
@@ -1362,9 +1374,12 @@
 
       g_free (context->theme_name);
       g_free (context->key_theme_name);
+      g_free (context->font_name);
+
       g_object_get (context->settings,
 		    "gtk-theme-name", &context->theme_name,
 		    "gtk-key-theme-name", &context->key_theme_name,
+		    "gtk-font-name", &context->font_name,
 		    NULL);
 
       if (context->theme_name && context->theme_name[0])
Index: gtk/gtksettings.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtksettings.c,v
retrieving revision 1.24
diff -u -r1.24 gtksettings.c
--- gtk/gtksettings.c	2002/01/31 20:14:18	1.24
+++ gtk/gtksettings.c	2002/02/10 05:46:30
@@ -30,7 +30,8 @@
   PROP_THEME_NAME,
   PROP_KEY_THEME_NAME,
   PROP_MENU_BAR_ACCEL,
-  PROP_DND_DRAG_THRESHOLD
+  PROP_DND_DRAG_THRESHOLD,
+  PROP_FONT_NAME
 };
 
 
@@ -208,7 +209,16 @@
                                                                G_PARAM_READWRITE),
 					     NULL);
   g_assert (result == PROP_DND_DRAG_THRESHOLD);
-  
+
+  result = settings_install_property_parser (class,
+                                             g_param_spec_string ("gtk-font-name",
+								   _("Font Name"),
+								   _("Name of default font to use"),
+								  "Sans 10",
+								  G_PARAM_READWRITE),
+                                             NULL);
+  g_assert (result == PROP_FONT_NAME);
+ 
 }
 
 static void
Index: gtk/gtkstyle.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstyle.c,v
retrieving revision 1.105
diff -u -r1.105 gtkstyle.c
--- gtk/gtkstyle.c	2002/02/04 15:43:09	1.105
+++ gtk/gtkstyle.c	2002/02/10 05:48:01
@@ -448,8 +448,12 @@
 gtk_style_init (GtkStyle *style)
 {
   gint i;
-  
-  style->font_desc = pango_font_description_from_string ("Sans 10");
+  GtkSettings *settings = gtk_settings_get_default ();
+  gchar *font_name;
+
+  g_object_get (settings, "gtk-font-name", &font_name, NULL);
+  style->font_desc = pango_font_description_from_string (font_name);
+  g_free (font_name);
 
   style->attach_count = 0;
   style->colormap = NULL;


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