[Xfce4-commits] <xfce4-cpugraph-plugin:master> Fix the resizing logic

Florian noreply at xfce.org
Sat Apr 17 16:16:29 CEST 2010


Updating branch refs/heads/master
         to 4690fcbad685a0cdda13c95a57714b6b0a58d5ee (commit)
       from 358c62c0c9abb7e4f74d5fa802a2a53a8303a520 (commit)

commit 4690fcbad685a0cdda13c95a57714b6b0a58d5ee
Author: Florian <frivoal at gmail.com>
Date:   Sun Feb 28 01:47:58 2010 +0900

    Fix the resizing logic
    
    The code that determined the size of the history was quite broken, most
    often resulting in someting that was larger than necessary, but also in
    some cases too small.

 panel-plugin/actions.c    |    4 +-
 panel-plugin/actions.h    |    2 +-
 panel-plugin/cpu.c        |   46 +++++++++++++++++++++++++-------------------
 panel-plugin/cpu.h        |    5 +--
 panel-plugin/properties.c |    4 +-
 panel-plugin/settings.c   |   10 ++++----
 6 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/panel-plugin/actions.c b/panel-plugin/actions.c
index 94e58e3..ed72b96 100644
--- a/panel-plugin/actions.c
+++ b/panel-plugin/actions.c
@@ -69,9 +69,9 @@ void FrameChange( GtkToggleButton * button, CPUGraph * base )
 	set_frame( base, gtk_toggle_button_get_active( button ) );
 }
 
-void WidthChange( GtkSpinButton * sb, CPUGraph *base)
+void SizeChange( GtkSpinButton * sb, CPUGraph *base)
 {
-	set_width( base, gtk_spin_button_get_value_as_int( sb ) );
+	set_size( base, gtk_spin_button_get_value_as_int( sb ) );
 }
 
 void TimeScaleChange( GtkToggleButton * button, CPUGraph * base )
diff --git a/panel-plugin/actions.h b/panel-plugin/actions.h
index 71c9db7..1e731ac 100644
--- a/panel-plugin/actions.h
+++ b/panel-plugin/actions.h
@@ -11,6 +11,6 @@ void DialogResponse( GtkWidget *dlg, int response, CPUGraph *base );
 void ApplyChanges( CPUGraph *base );
 void FrameChange( GtkToggleButton *button, CPUGraph *base );
 void ModeChange( GtkOptionMenu *om, CPUGraph *base );
-void WidthChange( GtkSpinButton *sb, CPUGraph *base );
+void SizeChange( GtkSpinButton *sb, CPUGraph *base );
 void TimeScaleChange( GtkToggleButton *button, CPUGraph *base );
 void UpdateChange( GtkOptionMenu *om, CPUGraph *base );
diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c
index 8e0201d..65fe5a1 100644
--- a/panel-plugin/cpu.c
+++ b/panel-plugin/cpu.c
@@ -85,7 +85,6 @@ CPUGraph * CreateControl( XfcePanelPlugin * plugin )
 	g_signal_connect_after( base->m_DrawArea, "expose-event", G_CALLBACK( DrawAreaExposeEvent ), base );
 
 	SetOrientation(plugin, orientation, base);
-	UserSetSize( base );
 
 	gtk_widget_show_all(ebox);
 
@@ -122,27 +121,38 @@ void UpdateTooltip( CPUGraph * base )
 gboolean SetSize( XfcePanelPlugin *plugin, int size, CPUGraph *base )
 {
 	gint i;
-	gtk_container_set_border_width( GTK_CONTAINER( base->m_FrameWidget ), size > 26 ? 2 : 0 );
+	gint frame_h, frame_v, bar_h, bar_v, history;
+
+	gtk_container_set_border_width( GTK_CONTAINER( base->m_FrameWidget ), MIN( size ,base->size ) > 26 ? 2 : 0 );
 
 	if( xfce_panel_plugin_get_orientation( plugin ) == GTK_ORIENTATION_HORIZONTAL )
 	{
-		gtk_widget_set_size_request( GTK_WIDGET( plugin ), base->m_Width, size );
-		for( i=0; i<base->nrCores; i++ )
-			gtk_widget_set_size_request( GTK_WIDGET(base->m_pBar[i]), BORDER, size );
+		frame_h = base->size;
+		frame_v = size;
+		bar_h = BORDER;
+		bar_v = size;
+	       	history = base->size;
 	}
 	else
 	{
-		gtk_widget_set_size_request( GTK_WIDGET( plugin ), size, base->m_Width );
-		for( i=0; i<base->nrCores; i++ )
-			gtk_widget_set_size_request( GTK_WIDGET( base->m_pBar[i] ), size, BORDER );
+		frame_h = size;
+		frame_v = base->size;
+		bar_h = size;
+		bar_v = BORDER;
+	       	history = size;
 	}
 
-	return TRUE;
-}
+	gtk_widget_set_size_request( GTK_WIDGET( base->m_FrameWidget ), frame_h, frame_v );
 
-void UserSetSize( CPUGraph * base )
-{
-	SetSize( base->plugin, xfce_panel_plugin_get_size( base->plugin ), base );
+	for( i=0; i<base->nrCores; i++ )
+		gtk_widget_set_size_request( GTK_WIDGET(base->m_pBar[i]), bar_h, bar_v );
+
+	base->m_History = (long *) g_realloc( base->m_History, history * sizeof( long ) );
+	if( history > base->m_Values )
+		memset( base->m_History + base->m_Values, 0, (history - base->m_Values) * sizeof( long ) );
+	base->m_Values = history;
+
+	return TRUE;
 }
 
 gboolean UpdateCPU( CPUGraph * base )
@@ -283,14 +293,10 @@ void set_update_rate( CPUGraph *base, int rate )
 	base->m_TimeoutID = g_timeout_add( update, (GtkFunction) UpdateCPU, base );
 }
 
-void set_width( CPUGraph *base, int width )
+void set_size( CPUGraph *base, int size )
 {
-	base->m_Width = width;
-	base->m_History = (long *) g_realloc( base->m_History, width * sizeof( long ) );
-	if( width > base->m_Values )
-		memset( base->m_History + base->m_Values, 0, (width - base->m_Values) * sizeof( long ) );
-	base->m_Values = width;
-	UserSetSize( base );
+	base->size = size;
+	SetSize( base->plugin, xfce_panel_plugin_get_size( base->plugin ), base );
 }
 
 void set_color_mode( CPUGraph *base, int color_mode )
diff --git a/panel-plugin/cpu.h b/panel-plugin/cpu.h
index 80686dd..6a8a2f3 100644
--- a/panel-plugin/cpu.h
+++ b/panel-plugin/cpu.h
@@ -37,7 +37,7 @@ typedef struct
 
 	int m_UpdateInterval; // Number of ms between updates.
 	gboolean m_TimeScale; // Wether to use non-linear time scale.
-	int m_Width; // The width of the plugin.
+	int size;
 	int m_Mode; // Eventual mode of the plugin.
 	int m_ColorMode;
 	gboolean m_Frame;
@@ -59,7 +59,6 @@ void Kill( XfcePanelPlugin *plugin, CPUGraph *base );
 void ReadSettings( XfcePanelPlugin *plugin, CPUGraph *base );
 void WriteSettings( XfcePanelPlugin *plugin, CPUGraph *base );
 gboolean SetSize( XfcePanelPlugin *plugin, int size, CPUGraph *base );
-void UserSetSize( CPUGraph *base );
 gboolean UpdateCPU( CPUGraph *base );
 void UpdateTooltip( CPUGraph *base );
 void DrawGraph( CPUGraph *base );
@@ -73,7 +72,7 @@ void set_command( CPUGraph *base, const gchar *command );
 void set_frame( CPUGraph *base, gboolean frame );
 void set_nonlinear_time( CPUGraph *base, gboolean nonlinear );
 void set_update_rate( CPUGraph *base, int rate );
-void set_width( CPUGraph *base, int width );
+void set_size( CPUGraph *base, int width );
 void set_color_mode( CPUGraph *base, int color_mode );
 void set_mode( CPUGraph *base, int mode );
 void set_color( CPUGraph *base, int number, GdkColor color );
diff --git a/panel-plugin/properties.c b/panel-plugin/properties.c
index 0871413..63ec061 100644
--- a/panel-plugin/properties.c
+++ b/panel-plugin/properties.c
@@ -171,10 +171,10 @@ static void SetupWidthOption( GtkBox *vbox, GtkSizeGroup *sg, XfcePanelPlugin *p
 		hbox = CreateOptionLine( vbox, sg, _("Height:") );
 
 	Size = gtk_spin_button_new_with_range( 10, 128, 1 );
-	gtk_spin_button_set_value( GTK_SPIN_BUTTON( Size ), base->m_Width );
+	gtk_spin_button_set_value( GTK_SPIN_BUTTON( Size ), base->size );
 	gtk_widget_show( Size );
 	gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( Size ), FALSE, FALSE, 0 );
-	g_signal_connect( Size, "value-changed", G_CALLBACK( WidthChange ), base );
+	g_signal_connect( Size, "value-changed", G_CALLBACK( SizeChange ), base );
 }
 
 static void SetupAssociateCommandOption( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base )
diff --git a/panel-plugin/settings.c b/panel-plugin/settings.c
index 45bfb42..49d0436 100644
--- a/panel-plugin/settings.c
+++ b/panel-plugin/settings.c
@@ -8,7 +8,7 @@ void ReadSettings( XfcePanelPlugin * plugin, CPUGraph * base )
 
 	int rate = 0;
 	gboolean nonlinear = FALSE;
-	int width = 70;
+	int size = 70;
 	int mode = 0;
 	int color_mode = 0;
 	gboolean frame = FALSE;
@@ -44,7 +44,7 @@ void ReadSettings( XfcePanelPlugin * plugin, CPUGraph * base )
 		{
 			rate =  xfce_rc_read_int_entry (rc, "UpdateInterval", rate );
 			nonlinear = xfce_rc_read_int_entry (rc, "TimeScale", nonlinear );
-			width = xfce_rc_read_int_entry( rc, "Width", width );
+			size = xfce_rc_read_int_entry( rc, "size", size );
 			mode = xfce_rc_read_int_entry( rc, "Mode", mode );
 			color_mode = xfce_rc_read_int_entry( rc, "ColorMode", color_mode );
 			frame = xfce_rc_read_int_entry( rc, "Frame", frame );
@@ -65,8 +65,8 @@ void ReadSettings( XfcePanelPlugin * plugin, CPUGraph * base )
 
 	set_update_rate( base, rate );
 	set_nonlinear_time( base, nonlinear );
-	set_width( base, width );
-	set_mode( base,  mode );
+	set_size( base, size );
+	set_mode( base, mode );
 	set_color_mode( base, color_mode );
 	set_frame( base, frame );
 	set_command( base, associated_command );
@@ -95,7 +95,7 @@ void WriteSettings( XfcePanelPlugin *plugin, CPUGraph *base )
 
 	xfce_rc_write_int_entry( rc, "TimeScale", base->m_TimeScale );
 
-	xfce_rc_write_int_entry( rc, "Width", base->m_Width );
+	xfce_rc_write_int_entry( rc, "Size", base->size );
 
 	xfce_rc_write_int_entry( rc, "Mode", base->m_Mode );
 



More information about the Xfce4-commits mailing list