Index: panel-plugin/settings.c =================================================================== --- panel-plugin/settings.c (revision 6468) +++ panel-plugin/settings.c (working copy) @@ -55,6 +55,8 @@ base->m_AssociateCommand = "xterm top"; base->m_ColorMode = 0; base->m_Mode = 0; + base->m_ShowBars = 1; + base->m_CPUMode = 0; // default to all cpu's if ((file = xfce_panel_plugin_lookup_rc_file (plugin)) != NULL) @@ -80,6 +82,12 @@ base->m_Frame = xfce_rc_read_int_entry (rc, "Frame", base->m_Frame); + base->m_ShowBars = + xfce_rc_read_int_entry (rc, "ShowBars", base->m_ShowBars); + + base->m_CPUMode = + xfce_rc_read_int_entry (rc, "CPUMode", base->m_CPUMode); + if (value = xfce_rc_read_entry (rc, "AssociateCommand", base->m_AssociateCommand)) { base->m_AssociateCommand = g_strdup(value); } @@ -158,6 +166,10 @@ xfce_rc_write_int_entry (rc, "Frame", base->m_Frame); + xfce_rc_write_int_entry (rc, "ShowBars", base->m_ShowBars); + + xfce_rc_write_int_entry (rc, "CPUMode", base->m_CPUMode); + xfce_rc_write_entry (rc, "AssociateCommand", base->m_AssociateCommand ? base->m_AssociateCommand : ""); xfce_rc_write_int_entry (rc, "ColorMode", base->m_ColorMode); Index: panel-plugin/cpu.c =================================================================== --- panel-plugin/cpu.c (revision 6468) +++ panel-plugin/cpu.c (working copy) @@ -48,6 +48,8 @@ ReadSettings (plugin, base); + ApplyChanges(base); + g_signal_connect (plugin, "free-data", G_CALLBACK (Kill), base); g_signal_connect (plugin, "save", G_CALLBACK (WriteSettings), base); @@ -129,16 +131,20 @@ gtk_progress_bar_set_orientation( GTK_PROGRESS_BAR(base->m_pBar[i]), barOrientation); - + gtk_box_pack_start( GTK_BOX(base->m_Box), base->m_pBar[i], FALSE, FALSE, 0); - - - gtk_widget_show(base->m_pBar[i]); + + + // show the status bars only if we need too. + if ( base->m_ShowBars && ( base->m_CPUMode == 0 || (base->m_CPUMode - 1 ) == i) ) { + gtk_widget_show(base->m_pBar[i]); + } + gtk_widget_show(base->m_pBar[i]); } /* <-- End of multicore stuff */ @@ -223,6 +229,10 @@ FALSE, FALSE, 1); + // show the status bars + if ( base->m_ShowBars && ( base->m_CPUMode == 0 || (base->m_CPUMode - 1 ) == i) ) { + gtk_widget_show(base->m_pBar[i]); + } /* We dont need anymore this reference */ g_object_unref(p_pBar[i]); } @@ -242,12 +252,28 @@ void UpdateTooltip (CPUGraph * base) { - char tooltip[32]; - int pos = snprintf (tooltip, 32, "Usage: %d%%", base->m_CPUUsage); + gchar *usage; + gchar *scaling = NULL; + gchar *tooltip; + + if ( base->m_CPUMode == 0 ) { + usage = g_strdup_printf("Usage: %d%%", base->m_CPUUsage); + } + else { + usage = g_strdup_printf("CPU %d usage: %d%%", base->m_CPUMode, base->m_CPUUsage); + } if( scaling_cur_freq ) - snprintf (tooltip+pos, 32-pos, " (%d MHz)", scaling_cur_freq/1000); + scaling = g_strdup_printf(" (%d MHz)", scaling_cur_freq/1000); + + tooltip = g_strconcat(usage, scaling, NULL); + gtk_tooltips_set_tip (GTK_TOOLTIPS (base->m_Tooltip), base->m_Box->parent, tooltip, NULL); + + g_free (usage); + if ( scaling ) + g_free (scaling); + g_free (tooltip); } /** @@ -299,23 +325,29 @@ gint i; cpuLoadData *data = cpuLoadMon_read(); - base->m_CPUUsage = data[0].value * 100.0; + if ( base->m_CPUMode > base->nrCores) { + base->m_CPUMode = 0; + } + base->m_CPUUsage = data[base->m_CPUMode].value * 100.0; for(i=0; inrCores; i++){ - gtk_progress_bar_set_fraction( - GTK_PROGRESS_BAR(base->m_pBar[i]), - (gdouble)data[i+1].value); + // only update the status bars if we need to + if ( base->m_ShowBars && ( base->m_CPUMode == 0 || (base->m_CPUMode - 1 ) == i) ) { + gtk_progress_bar_set_fraction( + GTK_PROGRESS_BAR(base->m_pBar[i]), + (gdouble)data[i+1].value); + } } + memmove (base->m_History + 1, base->m_History, (base->m_Values-1)*sizeof(float)); - base->m_History[0] = data[0].value; + base->m_History[0] = data[base->m_CPUMode].value; + /* Tooltip */ UpdateTooltip (base); - //fprintf(stderr, "update cpu %f\n", base->m_History[0]); - /* Draw the graph. */ gtk_widget_queue_draw (base->m_DrawArea); @@ -328,6 +360,11 @@ GtkWidget *da = base->m_DrawArea; int w, h; + if (xfce_panel_plugin_get_orientation (base->plugin) == + GTK_ORIENTATION_VERTICAL) + if (base->m_Values != base->m_DrawArea->allocation.width+1) + SetHistorySize (base, base->m_DrawArea->allocation.width+1); + w = da->allocation.width; h = da->allocation.height; @@ -380,6 +417,7 @@ ApplyChanges (CPUGraph * base) { int update; + int i; if (base->m_TimeoutID) g_source_remove (base->m_TimeoutID); @@ -399,10 +437,26 @@ } base->m_TimeoutID = g_timeout_add (update, (GtkFunction) UpdateCPU, base); + // re-show the status bars + for(i=0; inrCores; i++) { + + if ( base->m_ShowBars && ( base->m_CPUMode == 0 || (base->m_CPUMode - 1 ) == i) ) { + gtk_widget_show(base->m_pBar[i]); + } + else { + gtk_widget_hide(base->m_pBar[i]); + } + } + + UserSetSize (base); + if (xfce_panel_plugin_get_orientation (base->plugin) == + GTK_ORIENTATION_HORIZONTAL) + SetHistorySize (base, base->m_Width); + else + SetHistorySize (base, base->m_DrawArea->allocation.width+1); - fprintf(stderr, "m_Width %d\n", base->m_Width); - SetHistorySize (base, base->m_Width); + } void @@ -517,6 +571,7 @@ cpuLoadData *data = cpuLoadMon_read(); float usage = data[0].value; + base->m_History = (float *) realloc (base->m_History, size * sizeof (float)); @@ -568,6 +623,24 @@ } void +ShowBarChange (GtkToggleButton * button, CPUGraph * base) +{ + gint i; + + // set new value and reset the status bars + base->m_ShowBars = gtk_toggle_button_get_active (button); + + for(i=0; inrCores; i++) { + if ( base->m_ShowBars && ( base->m_CPUMode == 0 || (base->m_CPUMode - 1 ) == i) ) { + gtk_widget_show(base->m_pBar[i]); + } + else { + gtk_widget_hide(base->m_pBar[i]); + } + } +} + +void AssociateCommandChange (GtkEntry *entry, CPUGraph * base) { base->m_AssociateCommand = g_strdup (gtk_entry_get_text (entry)); @@ -589,6 +662,27 @@ } void +CPUOptionChange (GtkOptionMenu * om, CPUGraph * base) +{ + gint i; + // set the cpu mode value + + base->m_CPUMode = gtk_option_menu_get_history (om); + + // set the status bars based on the CPU mode value. + for(i=0; inrCores; i++) { + + if ( base->m_ShowBars && ( base->m_CPUMode == 0 || (base->m_CPUMode - 1 ) == i) ) { + gtk_widget_show(base->m_pBar[i]); + } + else { + gtk_widget_hide(base->m_pBar[i]); + } + } + +} + +void TimeScaleChange (GtkToggleButton * button, CPUGraph * base) { base->m_TimeScale = gtk_toggle_button_get_active (button); @@ -636,6 +730,6 @@ gtk_widget_set_sensitive (GTK_WIDGET (base->m_Options.m_FG3), TRUE); else gtk_widget_set_sensitive (GTK_WIDGET (base->m_Options.m_FG3), FALSE); + } } -} Index: panel-plugin/option.c =================================================================== --- panel-plugin/option.c (revision 6468) +++ panel-plugin/option.c (working copy) @@ -162,6 +162,28 @@ gtk_widget_show (GTK_WIDGET (vbox2)); gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8); + + /* Show Status Bars */ + + hbox = GTK_BOX (gtk_hbox_new (FALSE, BORDER)); + gtk_widget_show (GTK_WIDGET (hbox)); + gtk_box_pack_start (GTK_BOX (vbox), GTK_WIDGET (hbox), FALSE, FALSE, 0); + + op->m_ShowBars = gtk_check_button_new_with_mnemonic (_("Show Bars")); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (op->m_ShowBars), + base->m_ShowBars); + gtk_widget_show (op->m_ShowBars); + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (op->m_ShowBars), FALSE, + FALSE, 0); + g_signal_connect (op->m_ShowBars, "toggled", G_CALLBACK (ShowBarChange), + base); + gtk_size_group_add_widget (sg, op->m_ShowBars); + + vbox2 = GTK_BOX (gtk_vbox_new (FALSE, BORDER)); + gtk_widget_show (GTK_WIDGET (vbox2)); + gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8); + + /* Associate Command */ hbox = GTK_BOX (gtk_hbox_new (FALSE, BORDER)); @@ -366,6 +388,54 @@ g_signal_connect (op->m_ModeOption, "changed", G_CALLBACK (ColorModeChange), base); + + + + // CPU Selection Box + hbox = GTK_BOX (gtk_hbox_new (FALSE, BORDER)); + gtk_widget_show (GTK_WIDGET (hbox)); + gtk_box_pack_start (GTK_BOX (vbox2), GTK_WIDGET (hbox), FALSE, FALSE, 0); + + label = gtk_label_new (_("CPU:")); + gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5); + gtk_size_group_add_widget (sg, label); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (label), FALSE, FALSE, 0); + + op->m_CPUOption = gtk_option_menu_new (); + gtk_widget_show (op->m_CPUOption); + gtk_box_pack_start (GTK_BOX (hbox), op->m_CPUOption, FALSE, FALSE, 0); + + GtkWidget * menu = gtk_menu_new (); + gtk_option_menu_set_menu (GTK_OPTION_MENU (op->m_CPUOption), menu); + + GtkWidget * menuItem; + if ( base->nrCores > 1 ) { + menuItem = gtk_menu_item_new_with_label(_("All")); + gtk_widget_show (menuItem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuItem); + gint i; + for ( i=0; i < base->nrCores; i++ ) { + gchar * labelItem = g_strdup_printf(_("CPU %i"), i+1); + menuItem = gtk_menu_item_new_with_label(labelItem); + g_free ( labelItem); + gtk_widget_show (menuItem); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuItem); + } + gtk_widget_set_sensitive(op->m_CPUOption, TRUE); + + } + else { + // if only one cpu then we disable this selection + gtk_widget_set_sensitive(op->m_CPUOption, FALSE); + } + + gtk_option_menu_set_history (GTK_OPTION_MENU (op->m_CPUOption), base->m_CPUMode); + + g_signal_connect (op->m_CPUOption, "changed", G_CALLBACK (CPUOptionChange), + base); + + gtk_widget_show_all (GTK_WIDGET (hbox)); op->m_Notebook = gtk_notebook_new (); Index: panel-plugin/cpu.h =================================================================== --- panel-plugin/cpu.h (revision 6468) +++ panel-plugin/cpu.h (working copy) @@ -55,9 +55,12 @@ GtkWidget *m_UpdateMenu; GtkWidget *m_UpdateMenuItem; + GtkWidget *m_CPUOption; + GtkWidget *m_Width; GtkWidget *m_Height; GtkWidget *m_GraphFrame; + GtkWidget *m_ShowBars; GtkWidget *m_TimeScale; GtkWidget *m_AssociateCommand; @@ -102,6 +105,8 @@ int m_Mode; // Eventual mode of the plugin. int m_ColorMode; int m_Frame; + int m_ShowBars; // Show cpu bars + int m_CPUMode; // which cpu to show ar show all gchar * m_AssociateCommand; guint nrCores; // Number of cores (not including total cpu) @@ -120,6 +125,7 @@ int m_Orientation; + }CPUGraph; CPUGraph *CreateControl (XfcePanelPlugin *plugin); @@ -150,9 +156,11 @@ void ModeChange (GtkOptionMenu *om, CPUGraph *base); void ApplyChanges (CPUGraph *base); void FrameChange (GtkToggleButton *button, CPUGraph *base); +void ShowBarChange (GtkToggleButton *button, CPUGraph *base); void TimeScaleChange (GtkToggleButton *button, CPUGraph *base); void AssociateCommandChange(GtkEntry *entry, CPUGraph *base); void ColorModeChange (GtkOptionMenu *om, CPUGraph *base); gboolean LaunchCommand (GtkWidget *w, GdkEventButton *event, CPUGraph *base); +void CPUOptionChange (GtkOptionMenu *om, CPUGraph *base); #endif