[libgnomekbd] Using the font name from gtk, listening to theme changes



commit bede9856e63a79322a6301ca4d341f947f5c9b02
Author: Sergey V. Udaltsov <svu gnome org>
Date:   Thu Mar 11 02:04:40 2010 +0000

    Using the font name from gtk, listening to theme changes
    
    https://bugzilla.gnome.org/show_bug.cgi?id=612371

 libgnomekbd/gkbd-indicator-config.c |   86 +++++++++++++++++++---------------
 libgnomekbd/gkbd-indicator-config.h |    9 +++-
 libgnomekbd/gkbd-status.c           |   46 +++++++++++++------
 3 files changed, 85 insertions(+), 56 deletions(-)
---
diff --git a/libgnomekbd/gkbd-indicator-config.c b/libgnomekbd/gkbd-indicator-config.c
index 89e6385..38acecc 100644
--- a/libgnomekbd/gkbd-indicator-config.c
+++ b/libgnomekbd/gkbd-indicator-config.c
@@ -38,6 +38,7 @@
  * GkbdIndicatorConfig
  */
 #define GKBD_INDICATOR_CONFIG_KEY_PREFIX  GKBD_CONFIG_KEY_PREFIX "/indicator"
+#define GTK_STYLE_PATH "*.GtkLabel"
 
 const gchar GKBD_INDICATOR_CONFIG_DIR[] = GKBD_INDICATOR_CONFIG_KEY_PREFIX;
 const gchar GKBD_INDICATOR_CONFIG_KEY_SHOW_FLAGS[] =
@@ -79,8 +80,7 @@ gkbd_indicator_config_free_enabled_plugins (GkbdIndicatorConfig *
 }
 
 static void
-gkbd_indicator_config_load_font_from_gconf (GkbdIndicatorConfig *
-					    ind_config)
+gkbd_indicator_config_load_font (GkbdIndicatorConfig * ind_config)
 {
 	GError *gerror = NULL;
 
@@ -111,18 +111,12 @@ gkbd_indicator_config_load_font_from_gconf (GkbdIndicatorConfig *
 	if (ind_config->font_family == NULL ||
 	    ind_config->font_family[0] == '\0') {
 		PangoFontDescription *fd;
-		gchar *sysfontname =
-		    gconf_client_get_string (ind_config->conf_client,
-					     SYSTEM_FONT_GCONF_ENTRY,
-					     &gerror);
-		if (gerror != NULL) {
-			g_warning ("Error reading configuration:%s\n",
-				   gerror->message);
-			sysfontname = g_strdup ("Sans 10");
-			g_error_free (gerror);
-			gerror = NULL;
-		}
-		fd = pango_font_description_from_string (sysfontname);
+		GtkStyle *style =
+		    gtk_rc_get_style_by_paths (gtk_settings_get_default (),
+					       GTK_STYLE_PATH,
+					       GTK_STYLE_PATH,
+					       GTK_TYPE_LABEL);
+		fd = style->font_desc;
 		if (fd != NULL) {
 			ind_config->font_family =
 			    g_strdup (pango_font_description_get_family
@@ -130,13 +124,18 @@ gkbd_indicator_config_load_font_from_gconf (GkbdIndicatorConfig *
 			ind_config->font_size =
 			    pango_font_description_get_size (fd) /
 			    PANGO_SCALE;
-			pango_font_description_free (fd);
 		}
-		g_free (sysfontname);
 	}
 	xkl_debug (150, "font: [%s], size %d\n", ind_config->font_family,
 		   ind_config->font_size);
 
+}
+
+static void
+gkbd_indicator_config_load_colors (GkbdIndicatorConfig * ind_config)
+{
+	GError *gerror = NULL;
+
 	ind_config->foreground_color =
 	    gconf_client_get_string (ind_config->conf_client,
 				     GKBD_INDICATOR_CONFIG_KEY_FOREGROUND_COLOR,
@@ -148,6 +147,26 @@ gkbd_indicator_config_load_font_from_gconf (GkbdIndicatorConfig *
 		gerror = NULL;
 	}
 
+	if (ind_config->foreground_color == NULL ||
+	    ind_config->foreground_color[0] == '\0') {
+		GtkStyle *style =
+		    gtk_rc_get_style_by_paths (gtk_settings_get_default (),
+					       GTK_STYLE_PATH,
+					       GTK_STYLE_PATH,
+					       GTK_TYPE_LABEL);
+		ind_config->foreground_color =
+		    g_strdup_printf ("%lg %lg %lg",
+				     ((double) style->
+				      fg[GTK_STATE_NORMAL].red) / 0x10000,
+				     ((double) style->
+				      fg[GTK_STATE_NORMAL].green) /
+				     0x10000,
+				     ((double) style->
+				      fg[GTK_STATE_NORMAL].blue) /
+				     0x10000);
+
+	}
+
 	ind_config->background_color =
 	    gconf_client_get_string (ind_config->conf_client,
 				     GKBD_INDICATOR_CONFIG_KEY_BACKGROUND_COLOR,
@@ -158,24 +177,16 @@ gkbd_indicator_config_load_font_from_gconf (GkbdIndicatorConfig *
 		g_error_free (gerror);
 		gerror = NULL;
 	}
+}
 
-	if (ind_config->foreground_color == NULL ||
-	    ind_config->foreground_color[0] == '\0') {
-		GtkSettings *settings = gtk_settings_get_default ();
-		GtkStyle *style = gtk_rc_get_style_by_paths (settings,
-							     "*.GtkLabel",
-							     "*.GtkLabel",
-							     GTK_TYPE_LABEL);
-		ind_config->foreground_color =
-		    g_strdup_printf ("%lg %lg %lg",
-				     ((double) style->fg[GTK_STATE_NORMAL].
-				      red) / 0x10000,
-				     ((double) style->fg[GTK_STATE_NORMAL].
-				      green) / 0x10000,
-				     ((double) style->fg[GTK_STATE_NORMAL].
-				      blue) / 0x10000);
-
-	}
+void
+gkbd_indicator_config_refresh_style (GkbdIndicatorConfig * ind_config)
+{
+	g_free (ind_config->font_family);
+	g_free (ind_config->foreground_color);
+	g_free (ind_config->background_color);
+	gkbd_indicator_config_load_font (ind_config);
+	gkbd_indicator_config_load_colors (ind_config);
 }
 
 char *
@@ -352,7 +363,8 @@ gkbd_indicator_config_load_from_gconf (GkbdIndicatorConfig * ind_config)
 		gerror = NULL;
 	}
 
-	gkbd_indicator_config_load_font_from_gconf (ind_config);
+	gkbd_indicator_config_load_font (ind_config);
+	gkbd_indicator_config_load_colors (ind_config);
 
 	gkbd_indicator_config_free_enabled_plugins (ind_config);
 	ind_config->enabled_plugins =
@@ -403,8 +415,7 @@ void
 gkbd_indicator_config_activate (GkbdIndicatorConfig * ind_config)
 {
 	xkl_engine_set_secondary_groups_mask (ind_config->engine,
-					      ind_config->
-					      secondary_groups_mask);
+					      ind_config->secondary_groups_mask);
 }
 
 void
@@ -423,6 +434,5 @@ void
 gkbd_indicator_config_stop_listen (GkbdIndicatorConfig * ind_config)
 {
 	gkbd_desktop_config_remove_listener (ind_config->conf_client,
-					     &ind_config->
-					     config_listener_id);
+					     &ind_config->config_listener_id);
 }
diff --git a/libgnomekbd/gkbd-indicator-config.h b/libgnomekbd/gkbd-indicator-config.h
index 9542d12..6675947 100644
--- a/libgnomekbd/gkbd-indicator-config.h
+++ b/libgnomekbd/gkbd-indicator-config.h
@@ -31,10 +31,10 @@ typedef struct _GkbdIndicatorConfig {
 	int secondary_groups_mask;
 	gboolean show_flags;
 
-	gchar * font_family;
+	gchar *font_family;
 	int font_size;
-	gchar * foreground_color;
-	gchar * background_color;
+	gchar *foreground_color;
+	gchar *background_color;
 
 	GSList *enabled_plugins;
 
@@ -63,6 +63,9 @@ extern void gkbd_indicator_config_load_from_gconf (GkbdIndicatorConfig
 extern void gkbd_indicator_config_save_to_gconf (GkbdIndicatorConfig *
 						 applet_config);
 
+extern void gkbd_indicator_config_refresh_style (GkbdIndicatorConfig *
+						 applet_config);
+
 extern gchar
     * gkbd_indicator_config_get_images_file (GkbdIndicatorConfig *
 					     applet_config,
diff --git a/libgnomekbd/gkbd-status.c b/libgnomekbd/gkbd-status.c
index cc978ba..2efb00f 100644
--- a/libgnomekbd/gkbd-status.c
+++ b/libgnomekbd/gkbd-status.c
@@ -218,14 +218,13 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
 	if (globals.ind_cfg.show_flags) {
 
 		image_filename =
-		    (char *) g_slist_nth_data (globals.ind_cfg.
-					       image_filenames, group);
+		    (char *) g_slist_nth_data (globals.
+					       ind_cfg.image_filenames,
+					       group);
 
 		image = gdk_pixbuf_new_from_file_at_size (image_filename,
-							  globals.
-							  current_size,
-							  globals.
-							  current_size,
+							  globals.current_size,
+							  globals.current_size,
 							  &gerror);
 
 		if (image == NULL) {
@@ -240,8 +239,7 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
 								    NULL ?
 								    "Unknown"
 								    :
-								    gerror->
-								    message);
+								    gerror->message);
 			g_signal_connect (G_OBJECT (dialog), "response",
 					  G_CALLBACK (gtk_widget_destroy),
 					  NULL);
@@ -281,7 +279,7 @@ gkbd_status_prepare_drawing (GkbdStatus * gki, int group)
 
 #if 0
 		char pngfilename[20];
-		g_sprintf(pngfilename, "label%d.png", group);
+		g_sprintf (pngfilename, "label%d.png", group);
 		cairo_surface_write_to_png (cs, pngfilename);
 #endif
 
@@ -522,8 +520,7 @@ gkbd_status_start_listen (void)
 static void
 gkbd_status_stop_listen (void)
 {
-	xkl_engine_stop_listen (globals.engine,
-				XKLL_TRACK_KEYBOARD_STATE);
+	xkl_engine_stop_listen (globals.engine, XKLL_TRACK_KEYBOARD_STATE);
 
 	gdk_window_remove_filter (NULL, (GdkFilterFunc)
 				  gkbd_status_filter_x_evt, NULL);
@@ -542,6 +539,14 @@ gkbd_status_size_changed (GkbdStatus * gki, gint size)
 }
 
 static void
+gkbd_status_theme_changed (GtkSettings * settings, GParamSpec * pspec,
+			   GkbdStatus * gki)
+{
+	gkbd_indicator_config_refresh_style (&globals.ind_cfg);
+	gkbd_status_reinit_ui (gki);
+}
+
+static void
 gkbd_status_init (GkbdStatus * gki)
 {
 	if (!g_slist_length (globals.widget_instances))
@@ -571,6 +576,19 @@ gkbd_status_init (GkbdStatus * gki)
 			  G_CALLBACK (gkbd_status_size_changed), NULL);
 	g_signal_connect (gki, "activate",
 			  G_CALLBACK (gkbd_status_activate), NULL);
+
+	g_signal_connect_after (gtk_settings_get_default (),
+				"notify::gtk-theme-name",
+				G_CALLBACK (gkbd_status_theme_changed),
+				gki);
+	g_signal_connect_after (gtk_settings_get_default (),
+				"notify::gtk-key-theme-name",
+				G_CALLBACK (gkbd_status_theme_changed),
+				gki);
+	g_signal_connect_after (gtk_settings_get_default (),
+				"notify::gtk-font-name",
+				G_CALLBACK (gkbd_status_theme_changed),
+				gki);
 }
 
 static void
@@ -614,15 +632,13 @@ gkbd_status_global_term (void)
 	if (g_signal_handler_is_connected
 	    (globals.engine, globals.state_changed_handler)) {
 		g_signal_handler_disconnect (globals.engine,
-					     globals.
-					     state_changed_handler);
+					     globals.state_changed_handler);
 		globals.state_changed_handler = 0;
 	}
 	if (g_signal_handler_is_connected
 	    (globals.engine, globals.config_changed_handler)) {
 		g_signal_handler_disconnect (globals.engine,
-					     globals.
-					     config_changed_handler);
+					     globals.config_changed_handler);
 		globals.config_changed_handler = 0;
 	}
 



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