[Xfce4-commits] <xfce4-cpugraph-plugin:master> Only set the barcolor if a color was actually specified (bug #9081)

Landry Breuil noreply at xfce.org
Wed Jul 4 16:20:01 CEST 2012


Updating branch refs/heads/master
         to 8149080cd9798f17821b75a6cd532b3ae2a82bf9 (commit)
       from 1b4295c483adf48e2e1479cf836552223c7f5220 (commit)

commit 8149080cd9798f17821b75a6cd532b3ae2a82bf9
Author: Landry Breuil <landry at xfce.org>
Date:   Wed Jul 4 16:15:20 2012 +0200

    Only set the barcolor if a color was actually specified (bug #9081)
    
    - instead of trying to detect the theme color, default to not set the bar color.
    - only save the bar color if it was actually set
    - make the ui default to gold yellow (this doesnt mean it's applied,
      the user needs to validate it)

 panel-plugin/cpu.c        |   12 +++++++-----
 panel-plugin/cpu.h        |    1 +
 panel-plugin/properties.c |    1 +
 panel-plugin/settings.c   |   17 ++++++++---------
 4 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c
index c454124..927bb1e 100644
--- a/panel-plugin/cpu.c
+++ b/panel-plugin/cpu.c
@@ -120,6 +120,7 @@ static CPUGraph * create_gui( XfcePanelPlugin * plugin )
 	g_signal_connect_after( base->draw_area, "expose-event", G_CALLBACK( draw_area_cb ), base );
 
 	base->has_bars = FALSE;
+	base->has_barcolor = FALSE;
 	base->bars = NULL;
 
 #ifdef HAS_PANEL_49
@@ -173,10 +174,11 @@ static void create_bars( CPUGraph *base )
 	{
 		base->bars[i] = GTK_WIDGET(gtk_progress_bar_new());
 		/* Set bar colors */
-		gtk_widget_modify_bg(base->bars[i], GTK_STATE_PRELIGHT, &base->colors[4]);
-		gtk_widget_modify_bg(base->bars[i], GTK_STATE_SELECTED, &base->colors[4]);
-		gtk_widget_modify_base(base->bars[i], GTK_STATE_SELECTED, &base->colors[4]);
-
+		if (base->has_barcolor) {
+			gtk_widget_modify_bg(base->bars[i], GTK_STATE_PRELIGHT, &base->colors[4]);
+			gtk_widget_modify_bg(base->bars[i], GTK_STATE_SELECTED, &base->colors[4]);
+			gtk_widget_modify_base(base->bars[i], GTK_STATE_SELECTED, &base->colors[4]);
+		}
 		gtk_box_pack_end( GTK_BOX(base->box), base->bars[i], FALSE, FALSE, 0 );
 		gtk_widget_show( base->bars[i] );
 	}
@@ -517,7 +519,7 @@ void set_color( CPUGraph *base, guint number, GdkColor color )
 		gtk_widget_modify_bg( base->draw_area, GTK_STATE_INSENSITIVE, &base->colors[0] );
 		gtk_widget_modify_bg( base->draw_area, GTK_STATE_NORMAL, &base->colors[0] );
 	}
-	if( number == 4 && base->has_bars )
+	if( number == 4 && base->has_bars && base->has_barcolor )
 	{
 		n = nb_bars( base );
 
diff --git a/panel-plugin/cpu.h b/panel-plugin/cpu.h
index 527c229..fcd9d85 100644
--- a/panel-plugin/cpu.h
+++ b/panel-plugin/cpu.h
@@ -54,6 +54,7 @@ typedef struct
 	gboolean has_frame;
 	gboolean has_border;
 	gboolean has_bars;
+	gboolean has_barcolor;
 	gchar  *command;
 	gboolean in_terminal;
 	gboolean startup_notification;
diff --git a/panel-plugin/properties.c b/panel-plugin/properties.c
index f83c611..53fe0ff 100644
--- a/panel-plugin/properties.c
+++ b/panel-plugin/properties.c
@@ -330,6 +330,7 @@ static void change_color_0( GtkColorButton * button, CPUGraph * base )
 
 static void change_color_4( GtkColorButton * button, CPUGraph * base )
 {
+	base->has_barcolor = TRUE;
 	change_color( button, base, 4);
 }
 
diff --git a/panel-plugin/settings.c b/panel-plugin/settings.c
index bec6585..8679f2d 100644
--- a/panel-plugin/settings.c
+++ b/panel-plugin/settings.c
@@ -62,8 +62,6 @@ void read_settings( XfcePanelPlugin * plugin, CPUGraph * base )
 	GdkColor foreground3;
 	GdkColor background;
 	GdkColor barscolor;
-	GtkWidget* bar;
-	GtkStyle* barstyle;
 	guint size;
 	const gchar  *associated_command;
 	gboolean in_terminal;
@@ -85,11 +83,9 @@ void read_settings( XfcePanelPlugin * plugin, CPUGraph * base )
 	background.green = 65535;
 	background.blue = 65535;
 
-	/* use color from theme for default bar color */
-	bar = gtk_progress_bar_new();
-	barstyle = gtk_widget_get_style(bar);
-	barscolor = barstyle->bg[GTK_STATE_SELECTED];
-	gtk_widget_destroy(bar);
+	barscolor.red = 65535;
+	barscolor.green = 47872;
+	barscolor.blue = 0;
 
 	size = xfce_panel_plugin_get_size( plugin );
 	default_command( &associated_command, &in_terminal, &startup_notification );
@@ -122,8 +118,10 @@ void read_settings( XfcePanelPlugin * plugin, CPUGraph * base )
 				gdk_color_parse( value, &foreground3 );
 			if( (value = xfce_rc_read_entry( rc, "Background", NULL )) )
 				gdk_color_parse( value, &background );
-			if( (value = xfce_rc_read_entry( rc, "BarsColor", NULL )) )
+			if( (value = xfce_rc_read_entry( rc, "BarsColor", NULL )) ) {
 				gdk_color_parse( value, &barscolor );
+				base->has_barcolor = TRUE;
+			}
 
 			xfce_rc_close( rc );
 		}
@@ -179,6 +177,7 @@ void write_settings( XfcePanelPlugin *plugin, CPUGraph *base )
 	xfce_rc_write_entry( rc, "Foreground2", gdk_color_to_string(&(base->colors[2])) );
 	xfce_rc_write_entry( rc, "Foreground3", gdk_color_to_string(&(base->colors[3])) );
 	xfce_rc_write_entry( rc, "Background", gdk_color_to_string(&(base->colors[0])) );
-	xfce_rc_write_entry( rc, "BarsColor", gdk_color_to_string(&(base->colors[4])) );
+	if (base->has_barcolor)
+		xfce_rc_write_entry( rc, "BarsColor", gdk_color_to_string(&(base->colors[4])) );
 	xfce_rc_close( rc );
 }


More information about the Xfce4-commits mailing list