[Xfce4-commits] <xfce4-cpugraph-plugin:master> Add an option allowing to set the bar color.

Landry Breuil noreply at xfce.org
Sun Jun 24 16:40:01 CEST 2012


Updating branch refs/heads/master
         to fb8f36e68b72fe1694c9c6d28ce7699a06568674 (commit)
       from 7a29f3435734fa83cc3b18eae52ca2a28c5b853c (commit)

commit fb8f36e68b72fe1694c9c6d28ce7699a06568674
Author: Sabi <adeymo at gmail.com>
Date:   Sun Jun 24 16:38:20 2012 +0200

    Add an option allowing to set the bar color.
    
    Adds a 'Bars color:' string to translations.

 panel-plugin/cpu.c        |   19 +++++++++++++++++++
 panel-plugin/cpu.h        |    4 ++--
 panel-plugin/properties.c |   18 ++++++++++++++++++
 panel-plugin/settings.c   |   11 +++++++++++
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c
index 719dd4f..8958259 100644
--- a/panel-plugin/cpu.c
+++ b/panel-plugin/cpu.c
@@ -172,6 +172,11 @@ static void create_bars( CPUGraph *base )
 	for( i=0; i< n; i++ )
 	{
 		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]);
+
 		gtk_box_pack_end( GTK_BOX(base->box), base->bars[i], FALSE, FALSE, 0 );
 		gtk_widget_show( base->bars[i] );
 	}
@@ -505,12 +510,26 @@ void set_mode( CPUGraph *base, guint mode )
 
 void set_color( CPUGraph *base, guint number, GdkColor color )
 {
+	guint i, n;
+
 	base->colors[number] = color;
 	if( number == 0 )
 	{
 		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 )
+	{
+		n = nb_bars( base );
+
+		for( i=0; i< n; i++ )
+		{
+			/* 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]);
+		}
+	}
 }
 
 void set_tracked_core( CPUGraph *base, guint core )
diff --git a/panel-plugin/cpu.h b/panel-plugin/cpu.h
index e7083b2..527c229 100644
--- a/panel-plugin/cpu.h
+++ b/panel-plugin/cpu.h
@@ -42,7 +42,7 @@ typedef struct
 	GtkWidget *draw_area;
 	GtkWidget *box;
 	GtkWidget **bars;
-	GtkWidget *color_buttons[4];
+	GtkWidget *color_buttons[5];
 	GtkWidget *tooltip_text;
 
 	/* Settings */
@@ -57,7 +57,7 @@ typedef struct
 	gchar  *command;
 	gboolean in_terminal;
 	gboolean startup_notification;
-	GdkColor colors[4];
+	GdkColor colors[5];
 	guint tracked_core;
 
 	/* Runtime data */
diff --git a/panel-plugin/properties.c b/panel-plugin/properties.c
index 257bdda..f83c611 100644
--- a/panel-plugin/properties.c
+++ b/panel-plugin/properties.c
@@ -53,7 +53,9 @@ static void change_color_0( GtkColorButton *button, CPUGraph *base );
 static void change_color_1( GtkColorButton * button, CPUGraph * base );
 static void change_color_2( GtkColorButton *button, CPUGraph *base );
 static void change_color_3( GtkColorButton *button, CPUGraph *base );
+static void change_color_4( GtkColorButton *button, CPUGraph *base );
 static void select_active_colors( CPUGraph * base );
+static void select_active_barscolors( CPUGraph * base );
 static void change_mode( GtkComboBox *om, CPUGraph *base );
 static void change_color_mode( GtkComboBox *om, CPUGraph *base );
 static void response_cb( GtkWidget *dlg, gint response, CPUGraph *base );
@@ -109,6 +111,8 @@ void create_options( XfcePanelPlugin *plugin, CPUGraph *base )
 	select_active_colors( base );
 	setup_mode_option( vbox2, sg, base );
 	setup_color_mode_option( vbox2, sg, base );
+	setup_color_option( vbox2, sg, base, 4, _("Bars color:"), G_CALLBACK( change_color_4 ) );
+	select_active_barscolors( base );
 
 	Notebook = gtk_notebook_new();
 	gtk_container_set_border_width( GTK_CONTAINER( Notebook ), BORDER - 2 );
@@ -324,6 +328,11 @@ static void change_color_0( GtkColorButton * button, CPUGraph * base )
 	change_color( button, base, 0);
 }
 
+static void change_color_4( GtkColorButton * button, CPUGraph * base )
+{
+	change_color( button, base, 4);
+}
+
 static void select_active_colors( CPUGraph * base )
 {
 	if( base->color_mode != 0 || base->mode == 1 || base->mode == 3 )
@@ -337,6 +346,14 @@ static void select_active_colors( CPUGraph * base )
 		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[3] ), FALSE );
 }
 
+static void select_active_barscolors( CPUGraph * base )
+{
+	if( base->has_bars )
+		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[4] ), TRUE );
+	else
+		gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[4] ), FALSE );
+}
+
 static void change_mode( GtkComboBox * combo, CPUGraph * base )
 {
 	set_mode( base, gtk_combo_box_get_active( combo ) );
@@ -369,6 +386,7 @@ static void change_border( GtkToggleButton * button, CPUGraph * base )
 static void change_bars( GtkToggleButton * button, CPUGraph * base )
 {
 	set_bars( base, gtk_toggle_button_get_active( button ) );
+	select_active_barscolors( base );
 }
 
 static void change_size( GtkSpinButton * sb, CPUGraph *base)
diff --git a/panel-plugin/settings.c b/panel-plugin/settings.c
index 7331154..4123140 100644
--- a/panel-plugin/settings.c
+++ b/panel-plugin/settings.c
@@ -61,6 +61,7 @@ void read_settings( XfcePanelPlugin * plugin, CPUGraph * base )
 	GdkColor foreground2;
 	GdkColor foreground3;
 	GdkColor background;
+	GdkColor barscolor;
 	guint size;
 	const gchar  *associated_command;
 	gboolean in_terminal;
@@ -82,6 +83,11 @@ void read_settings( XfcePanelPlugin * plugin, CPUGraph * base )
 	background.green = 65535;
 	background.blue = 65535;
 
+	/* gold yellow */
+	barscolor.red = 65535;
+	barscolor.green = 47872;
+	barscolor.blue = 0;
+
 	size = xfce_panel_plugin_get_size( plugin );
 	default_command( &associated_command, &in_terminal, &startup_notification );
 
@@ -113,6 +119,8 @@ 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 )) )
+				gdk_color_parse( value, &barscolor );
 
 			xfce_rc_close( rc );
 		}
@@ -134,6 +142,7 @@ void read_settings( XfcePanelPlugin * plugin, CPUGraph * base )
 	set_color( base, 2, foreground2 );
 	set_color( base, 3, foreground3 );
 	set_color( base, 0, background );
+	set_color( base, 4, barscolor );
 }
 
 void write_settings( XfcePanelPlugin *plugin, CPUGraph *base )
@@ -172,5 +181,7 @@ void write_settings( XfcePanelPlugin *plugin, CPUGraph *base )
 	xfce_rc_write_entry( rc, "Background", value );
 	g_snprintf( value, 8, "#%02X%02X%02X", base->colors[3].red >> 8, base->colors[3].green >> 8, base->colors[3].blue >> 8 );
 	xfce_rc_write_entry( rc, "Foreground3", value );
+	g_snprintf( value, 8, "#%02X%02X%02X", base->colors[4].red >> 8, base->colors[4].green >> 8, base->colors[4].blue >> 8 );
+	xfce_rc_write_entry( rc, "BarsColor", value );
 	xfce_rc_close( rc );
 }


More information about the Xfce4-commits mailing list