This is an automated email from the git hooks/post-receive script. a n d r e p u s h e d a c o m m i t t o b r a n c h m a s t e r in repository panel-plugins/xfce4-cpugraph-plugin.
commit 5c535d2ad2e21e692e6305645d339418032ae336 Author: Andre Miranda <andre...@xfce.org> Date: Sat Jun 1 18:04:27 2019 -0300 Fix indentation --- Makefile.am | 2 +- icons/Makefile.am | 14 +- panel-plugin/Makefile.am | 41 +-- panel-plugin/cpu.c | 816 +++++++++++++++++++++++++--------------------- panel-plugin/cpu.h | 87 ++--- panel-plugin/mode.c | 311 +++++++++--------- panel-plugin/mode.h | 8 +- panel-plugin/os.c | 474 ++++++++++++++------------- panel-plugin/os.h | 10 +- panel-plugin/properties.c | 624 ++++++++++++++++++++--------------- panel-plugin/properties.h | 2 +- panel-plugin/settings.c | 311 +++++++++--------- panel-plugin/settings.h | 4 +- 13 files changed, 1450 insertions(+), 1254 deletions(-) diff --git a/Makefile.am b/Makefile.am index e9182ec..1a3e5c0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,7 +20,7 @@ ChangeLog: Makefile dist-hook: ChangeLog EXTRA_DIST = \ - README \ + README \ intltool-extract.in \ intltool-merge.in \ intltool-update.in diff --git a/icons/Makefile.am b/icons/Makefile.am index 80cf5d5..3857a44 100644 --- a/icons/Makefile.am +++ b/icons/Makefile.am @@ -3,13 +3,13 @@ SUBDIRS = 16x16 22x22 48x48 gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor install-data-hook: - @-if test -z "$(DESTDIR)"; then \ - echo "Updating Gtk icon cache."; \ - $(gtk_update_icon_cache); \ - else \ + @-if test -z "$(DESTDIR)"; then \ + echo "Updating Gtk icon cache."; \ + $(gtk_update_icon_cache); \ + else \ echo "*** Icon cache not updated. Remember to run:"; \ - echo "***"; \ - echo "*** $(gtk_update_icon_cache)"; \ - echo "***"; \ + echo "***"; \ + echo "*** $(gtk_update_icon_cache)"; \ + echo "***"; \ fi diff --git a/panel-plugin/Makefile.am b/panel-plugin/Makefile.am index a129fc1..a2b437e 100644 --- a/panel-plugin/Makefile.am +++ b/panel-plugin/Makefile.am @@ -1,34 +1,35 @@ plugindir = $(libdir)/xfce4/panel/plugins plugin_LTLIBRARIES = libcpugraph.la -libcpugraph_la_CFLAGS = \ - -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ - @LIBXFCE4UI_CFLAGS@ \ +libcpugraph_la_CFLAGS = \ + -DPACKAGE_LOCALE_DIR=\"$(localedir)\" \ + @LIBXFCE4UI_CFLAGS@ \ @LIBXFCE4PANEL_CFLAGS@ -libcpugraph_la_LIBADD = \ - @LIBXFCE4UI_LIBS@ \ +libcpugraph_la_LIBADD = \ + @LIBXFCE4UI_LIBS@ \ @LIBXFCE4PANEL_LIBS@ -libcpugraph_la_SOURCES = \ - mode.c \ - mode.h \ - cpu.c \ - cpu.h \ - os.c \ - os.h \ - properties.c \ - properties.h \ - settings.c \ +libcpugraph_la_SOURCES = \ + mode.c \ + mode.h \ + cpu.c \ + cpu.h \ + os.c \ + os.h \ + properties.c \ + properties.h \ + settings.c \ settings.h -libcpugraph_la_LDFLAGS = \ - -avoid-version \ - -module \ - -no-undefined \ - -export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \ +libcpugraph_la_LDFLAGS = \ + -avoid-version \ + -module \ + -no-undefined \ + -export-symbols-regex '^xfce_panel_module_(preinit|init|construct)' \ $(PLATFORM_LDFLAGS) +# # .desktop file # desktop_in_files = cpugraph.desktop.in diff --git a/panel-plugin/cpu.c b/panel-plugin/cpu.c index d8496e9..915f228 100644 --- a/panel-plugin/cpu.c +++ b/panel-plugin/cpu.c @@ -32,491 +32,549 @@ # define _(String) gettext (String) #endif -static void cpugraph_construct( XfcePanelPlugin *plugin ); -static CPUGraph *create_gui( XfcePanelPlugin *plugin ); -static void create_bars( CPUGraph *base ); -static guint init_cpu_data( CpuData **data ); -static void shutdown( XfcePanelPlugin *plugin, CPUGraph *base ); -static void delete_bars( CPUGraph *base ); -static gboolean size_cb( XfcePanelPlugin *plugin, guint size, CPUGraph *base ); -static void about_cb( XfcePanelPlugin *plugin, CPUGraph *base ); -static void set_bars_size( CPUGraph *base, gint size, GtkOrientation orientation ); -static void mode_cb( XfcePanelPlugin *plugin, XfcePanelPluginMode mode, CPUGraph *base ); -static void set_bars_orientation( CPUGraph *base, GtkOrientation orientation); -static gboolean update_cb( CPUGraph *base ); -static void update_tooltip( CPUGraph *base ); -static gboolean tooltip_cb( GtkWidget *widget, gint x, gint y, gboolean keyboard, GtkTooltip * tooltip, CPUGraph *base); -static void draw_area_cb( GtkWidget *w, cairo_t *cr, gpointer data ); -static gboolean command_cb( GtkWidget *w, GdkEventButton *event, CPUGraph *base ); - -XFCE_PANEL_PLUGIN_REGISTER( cpugraph_construct ); - -static void cpugraph_construct( XfcePanelPlugin *plugin ) +static void cpugraph_construct (XfcePanelPlugin *plugin); +static CPUGraph *create_gui (XfcePanelPlugin *plugin); +static void create_bars (CPUGraph *base); +static guint init_cpu_data (CpuData **data); +static void shutdown (XfcePanelPlugin *plugin, + CPUGraph *base); +static void delete_bars (CPUGraph *base); +static gboolean size_cb (XfcePanelPlugin *plugin, + guint size, + CPUGraph *base); +static void about_cb (XfcePanelPlugin *plugin, + CPUGraph *base); +static void set_bars_size (CPUGraph *base, + gint size, + GtkOrientation orientation); +static void mode_cb (XfcePanelPlugin *plugin, + XfcePanelPluginMode mode, + CPUGraph *base); +static void set_bars_orientation (CPUGraph *base, + GtkOrientation orientation); +static gboolean update_cb (CPUGraph *base); +static void update_tooltip (CPUGraph *base); +static gboolean tooltip_cb (GtkWidget *widget, + gint x, + gint y, + gboolean keyboard, + GtkTooltip *tooltip, + CPUGraph *base); +static void draw_area_cb (GtkWidget *w, + cairo_t *cr, + gpointer data); +static gboolean command_cb (GtkWidget *w, + GdkEventButton *event, + CPUGraph *base); + +XFCE_PANEL_PLUGIN_REGISTER (cpugraph_construct); + +static void +cpugraph_construct (XfcePanelPlugin *plugin) { - CPUGraph *base; + CPUGraph *base; - xfce_textdomain( GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8" ); + xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8"); - base = create_gui( plugin ); - read_settings( plugin, base ); - xfce_panel_plugin_menu_show_configure( plugin ); + base = create_gui (plugin); + read_settings (plugin, base); + xfce_panel_plugin_menu_show_configure (plugin); - xfce_panel_plugin_menu_show_about( plugin ); + xfce_panel_plugin_menu_show_about (plugin); - g_signal_connect( plugin, "about", G_CALLBACK (about_cb), base ); - g_signal_connect( plugin, "free-data", G_CALLBACK( shutdown ), base ); - g_signal_connect( plugin, "save", G_CALLBACK( write_settings ), base ); - g_signal_connect( plugin, "configure-plugin", G_CALLBACK( create_options ), base ); - g_signal_connect( plugin, "size-changed", G_CALLBACK( size_cb ), base ); - g_signal_connect( plugin, "mode-changed", G_CALLBACK( mode_cb ), base ); + g_signal_connect (plugin, "about", G_CALLBACK (about_cb), base); + g_signal_connect (plugin, "free-data", G_CALLBACK (shutdown), base); + g_signal_connect (plugin, "save", G_CALLBACK (write_settings), base); + g_signal_connect (plugin, "configure-plugin", G_CALLBACK (create_options), base); + g_signal_connect (plugin, "size-changed", G_CALLBACK (size_cb), base); + g_signal_connect (plugin, "mode-changed", G_CALLBACK (mode_cb), base); } -static CPUGraph * create_gui( XfcePanelPlugin * plugin ) +static CPUGraph * +create_gui (XfcePanelPlugin *plugin) { - GtkWidget *frame, *ebox; - GtkOrientation orientation; - CPUGraph *base = g_new0( CPUGraph, 1 ); + GtkWidget *frame, *ebox; + GtkOrientation orientation; + CPUGraph *base = g_new0 (CPUGraph, 1); - orientation = xfce_panel_plugin_get_orientation(plugin); - if( (base->nr_cores = init_cpu_data( &base->cpu_data )) == 0) - fprintf(stderr,"Cannot init cpu data !\n"); + orientation = xfce_panel_plugin_get_orientation (plugin); + if ((base->nr_cores = init_cpu_data (&base->cpu_data)) == 0) + fprintf (stderr,"Cannot init cpu data !\n"); - base->plugin = plugin; + base->plugin = plugin; - ebox = gtk_event_box_new(); - gtk_event_box_set_visible_window(GTK_EVENT_BOX(ebox), FALSE); - gtk_event_box_set_above_child(GTK_EVENT_BOX(ebox), TRUE); - gtk_container_add( GTK_CONTAINER( plugin ), ebox ); - xfce_panel_plugin_add_action_widget( plugin, ebox ); - g_signal_connect( ebox, "button-press-event", G_CALLBACK( command_cb ), base ); + ebox = gtk_event_box_new (); + gtk_event_box_set_visible_window (GTK_EVENT_BOX (ebox), FALSE); + gtk_event_box_set_above_child (GTK_EVENT_BOX (ebox), TRUE); + gtk_container_add (GTK_CONTAINER (plugin), ebox); + xfce_panel_plugin_add_action_widget (plugin, ebox); + g_signal_connect (ebox, "button-press-event", G_CALLBACK (command_cb), base); - base->box = gtk_box_new(orientation, 0); - gtk_container_add(GTK_CONTAINER(ebox), base->box); - gtk_widget_set_has_tooltip( base->box, TRUE); - g_signal_connect( base->box, "query-tooltip", G_CALLBACK( tooltip_cb ), base ); + base->box = gtk_box_new (orientation, 0); + gtk_container_add (GTK_CONTAINER (ebox), base->box); + gtk_widget_set_has_tooltip (base->box, TRUE); + g_signal_connect (base->box, "query-tooltip", G_CALLBACK (tooltip_cb), base); - base->frame_widget = frame = gtk_frame_new( NULL ); - gtk_box_pack_end( GTK_BOX(base->box), frame, TRUE, TRUE, 0); + base->frame_widget = frame = gtk_frame_new (NULL); + gtk_box_pack_end (GTK_BOX (base->box), frame, TRUE, TRUE, 0); - base->draw_area = gtk_drawing_area_new(); - gtk_container_add( GTK_CONTAINER( frame ), GTK_WIDGET( base->draw_area ) ); - g_signal_connect_after( base->draw_area, "draw", G_CALLBACK( draw_area_cb ), base ); + base->draw_area = gtk_drawing_area_new (); + gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (base->draw_area)); + g_signal_connect_after (base->draw_area, "draw", G_CALLBACK (draw_area_cb), base); - base->has_bars = FALSE; - base->has_barcolor = FALSE; - base->bars = NULL; + base->has_bars = FALSE; + base->has_barcolor = FALSE; + base->bars = NULL; - mode_cb(plugin, orientation, base); - gtk_widget_show_all(ebox); + mode_cb (plugin, orientation, base); + gtk_widget_show_all (ebox); - base->tooltip_text = gtk_label_new( NULL ); - g_object_ref( base->tooltip_text ); + base->tooltip_text = gtk_label_new (NULL); + g_object_ref (base->tooltip_text); - return base; + return base; } static void -about_cb( XfcePanelPlugin *plugin, CPUGraph *base ) +about_cb (XfcePanelPlugin *plugin, CPUGraph *base) { - GdkPixbuf *icon; - const gchar *auth[] = { - "Alexander Nordfelth <alex.nordfe...@telia.com>", "gatopeich <gatoguan...@yahoo.com>", - "lidiriel <lidir...@coriolys.org>","Angelo Miguel Arrifano <mik...@gmail.com>", - "Florian Rivoal <friv...@gmail.com>","Peter Tribble <peter.trib...@gmail.com>", NULL}; - icon = xfce_panel_pixbuf_from_source("xfce4-cpugraph-plugin", NULL, 32); - gtk_show_about_dialog(NULL, - "logo", icon, - "license", xfce_get_license_text (XFCE_LICENSE_TEXT_GPL), - "version", PACKAGE_VERSION, - "program-name", PACKAGE_NAME, - "comments", _("Graphical representation of the CPU load"), - "website", "https://goodies.xfce.org/projects/panel-plugins/xfce4-cpugraph-plugin", - "copyright", _("Copyright (c) 2003-2019\n"), - "authors", auth, NULL); - - if(icon) - g_object_unref(G_OBJECT(icon)); + GdkPixbuf *icon; + const gchar *auth[] = { + "Alexander Nordfelth <alex.nordfe...@telia.com>", "gatopeich <gatoguan...@yahoo.com>", + "lidiriel <lidir...@coriolys.org>","Angelo Miguel Arrifano <mik...@gmail.com>", + "Florian Rivoal <friv...@gmail.com>","Peter Tribble <peter.trib...@gmail.com>", NULL}; + icon = xfce_panel_pixbuf_from_source ("xfce4-cpugraph-plugin", NULL, 32); + gtk_show_about_dialog (NULL, + "logo", icon, + "license", xfce_get_license_text (XFCE_LICENSE_TEXT_GPL), + "version", PACKAGE_VERSION, + "program-name", PACKAGE_NAME, + "comments", _("Graphical representation of the CPU load"), + "website", "https://goodies.xfce.org/projects/panel-plugins/xfce4-cpugraph-plugin", + "copyright", _("Copyright (c) 2003-2019\n"), + "authors", auth, NULL); + + if (icon) + g_object_unref (G_OBJECT (icon)); } -static guint nb_bars( CPUGraph * base ) +static guint +nb_bars (CPUGraph *base) { - return base->tracked_core == 0 ? base->nr_cores : 1; + return base->tracked_core == 0 ? base->nr_cores : 1; } -static void create_bars( CPUGraph *base ) + +static void +create_bars (CPUGraph *base) { - guint i; - guint n; - n = nb_bars( base ); - base->bars = (GtkWidget **) g_malloc( sizeof( GtkWidget * ) * n ); - - for( i=0; i< n; i++ ) - { - base->bars[i] = GTK_WIDGET(gtk_progress_bar_new()); - /* Set bar colors */ - if (base->has_barcolor) { - gtk_widget_override_background_color(base->bars[i], GTK_STATE_PRELIGHT, &base->colors[4]); - gtk_widget_override_background_color(base->bars[i], GTK_STATE_SELECTED, &base->colors[4]); - gtk_widget_override_color(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] ); - } + guint i; + guint n; + n = nb_bars (base); + base->bars = (GtkWidget **) g_malloc (sizeof (GtkWidget *) * n); + + for (i = 0; i < n; i++) + { + base->bars[i] = GTK_WIDGET (gtk_progress_bar_new ()); + /* Set bar colors */ + if (base->has_barcolor) { + gtk_widget_override_background_color (base->bars[i], GTK_STATE_PRELIGHT, &base->colors[4]); + gtk_widget_override_background_color (base->bars[i], GTK_STATE_SELECTED, &base->colors[4]); + gtk_widget_override_color (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]); + } } -guint init_cpu_data( CpuData **data ) +guint +init_cpu_data (CpuData **data) { - guint cpuNr; + guint cpuNr; - cpuNr = detect_cpu_number(); - if( cpuNr == 0 ) - return 0; + cpuNr = detect_cpu_number (); + if (cpuNr == 0) + return 0; - *data = (CpuData *) g_malloc0( (cpuNr+1) * sizeof( CpuData ) ); + *data = (CpuData *) g_malloc0 ((cpuNr+1) * sizeof (CpuData)); - return cpuNr; + return cpuNr; } -static void shutdown( XfcePanelPlugin * plugin, CPUGraph * base ) +static void +shutdown (XfcePanelPlugin *plugin, CPUGraph *base) { - g_free( base->cpu_data ); - delete_bars( base ); - gtk_widget_destroy(base->box); - gtk_widget_destroy(base->tooltip_text); - if( base->timeout_id ) - g_source_remove( base->timeout_id ); - g_free( base->history ); - g_free( base->command ); - g_free( base ); + g_free (base->cpu_data); + delete_bars (base); + gtk_widget_destroy (base->box); + gtk_widget_destroy (base->tooltip_text); + if (base->timeout_id) + g_source_remove (base->timeout_id); + g_free (base->history); + g_free (base->command); + g_free (base); } -static void delete_bars( CPUGraph *base ) +static void +delete_bars (CPUGraph *base) { - guint i; - guint n; - if( base->bars ) - { - n = nb_bars( base ); - for( i=0; i < n; i++ ) - { - gtk_widget_hide( base->bars[i] ); - gtk_widget_destroy( base->bars[i] ); - } - g_free( base->bars ); - base->bars = NULL; - } + guint i; + guint n; + if (base->bars) + { + n = nb_bars (base); + for (i = 0; i < n; i++) + { + gtk_widget_hide (base->bars[i]); + gtk_widget_destroy (base->bars[i]); + } + g_free (base->bars); + base->bars = NULL; + } } -static gboolean size_cb( XfcePanelPlugin *plugin, guint size, CPUGraph *base ) +static gboolean +size_cb (XfcePanelPlugin *plugin, guint size, CPUGraph *base) { - gint frame_h, frame_v, history; - GtkOrientation orientation; - - orientation = xfce_panel_plugin_get_orientation( plugin ); - - if( orientation == GTK_ORIENTATION_HORIZONTAL ) - { - frame_h = base->size; - frame_v = size; - history = base->size; - } - else - { - frame_h = size; - frame_v = base->size; - history = size; - } - - gtk_widget_set_size_request( GTK_WIDGET( base->frame_widget ), frame_h, frame_v ); - - base->history = (guint *) g_realloc( base->history, history * sizeof( guint ) ); - if( history > base->history_size ) - memset( base->history + base->history_size, 0, (history - base->history_size) * sizeof( guint ) ); - base->history_size = history; - - if( base->has_bars ) - set_bars_size( base, size, orientation ); - set_border( base, base->has_border ); - - return TRUE; + gint frame_h, frame_v, history; + GtkOrientation orientation; + + orientation = xfce_panel_plugin_get_orientation (plugin); + + if (orientation == GTK_ORIENTATION_HORIZONTAL) + { + frame_h = base->size; + frame_v = size; + history = base->size; + } + else + { + frame_h = size; + frame_v = base->size; + history = size; + } + + gtk_widget_set_size_request (GTK_WIDGET (base->frame_widget), frame_h, frame_v); + + base->history = (guint *) g_realloc (base->history, history * sizeof (guint)); + if (history > base->history_size) + memset (base->history + base->history_size, 0, (history - base->history_size) * sizeof (guint)); + base->history_size = history; + + if (base->has_bars) + set_bars_size (base, size, orientation); + set_border (base, base->has_border); + + return TRUE; } -static void set_bars_size( CPUGraph *base, gint size, GtkOrientation orientation ) +static void +set_bars_size (CPUGraph *base, gint size, GtkOrientation orientation) { - guint i; - guint n; - gint h, v; - if( orientation == GTK_ORIENTATION_HORIZONTAL ) - { - h = 8; - v = -1; - } - else - { - h = -1; - v = 8; - } - n = nb_bars( base ); - for( i=0; i < n ; i++ ) - gtk_widget_set_size_request( GTK_WIDGET(base->bars[i]), h, v ); + guint i; + guint n; + gint h, v; + + if (orientation == GTK_ORIENTATION_HORIZONTAL) + { + h = 8; + v = -1; + } + else + { + h = -1; + v = 8; + } + + n = nb_bars (base); + for (i = 0; i < n ; i++) + gtk_widget_set_size_request (GTK_WIDGET (base->bars[i]), h, v); } -static void mode_cb( XfcePanelPlugin * plugin, XfcePanelPluginMode mode, CPUGraph *base ) +static void +mode_cb (XfcePanelPlugin *plugin, XfcePanelPluginMode mode, CPUGraph *base) { - GtkOrientation orientation = (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL) ? - GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; + GtkOrientation orientation = (mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL) ? + GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL; - gtk_orientable_set_orientation( GTK_ORIENTABLE( base->box ), xfce_panel_plugin_get_orientation (plugin)); + gtk_orientable_set_orientation (GTK_ORIENTABLE (base->box), + xfce_panel_plugin_get_orientation (plugin)); - if( base->has_bars ) - set_bars_orientation( base, orientation ); + if (base->has_bars) + set_bars_orientation (base, orientation); - size_cb( plugin, xfce_panel_plugin_get_size( base->plugin ), base); + size_cb (plugin, xfce_panel_plugin_get_size (base->plugin), base); } -static void set_bars_orientation( CPUGraph *base, GtkOrientation orientation) +static void +set_bars_orientation (CPUGraph *base, GtkOrientation orientation) { - guint i, n; - - /* the received orientation refers to the panel's, so we need to invert it for the bars */ - orientation = (orientation == GTK_ORIENTATION_HORIZONTAL) ? - GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL; - - n = nb_bars( base ); - for( i=0; i < n; i++ ) { - gtk_orientable_set_orientation( GTK_ORIENTABLE( base->bars[i] ), orientation ); - gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR (base->bars[i]), - orientation == GTK_ORIENTATION_VERTICAL); - } + guint i, n; + + /* the received orientation refers to the panel's, so we need to invert it for the bars */ + orientation = (orientation == GTK_ORIENTATION_HORIZONTAL) ? + GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL; + + n = nb_bars (base); + for (i = 0; i < n; i++) + { + gtk_orientable_set_orientation (GTK_ORIENTABLE (base->bars[i]), orientation); + gtk_progress_bar_set_inverted (GTK_PROGRESS_BAR (base->bars[i]), + orientation == GTK_ORIENTATION_VERTICAL); + } } -static gboolean update_cb( CPUGraph * base ) +static gboolean +update_cb (CPUGraph *base) { - gint i, a, b, factor; - - if( !read_cpu_data( base->cpu_data, base->nr_cores ) ) - return TRUE; - - if( base->tracked_core > base->nr_cores ) - base->cpu_data[0].load = 0; - else if( base->tracked_core != 0 ) - base->cpu_data[0].load = base->cpu_data[base->tracked_core].load; - - if( base->has_bars ) - { - if( base->tracked_core != 0 || base->nr_cores == 1 ) - { - gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(base->bars[0]), - (gdouble)base->cpu_data[0].load / CPU_SCALE - ); - } - else - { - for( i=0; i<base->nr_cores; i++ ) - gtk_progress_bar_set_fraction( GTK_PROGRESS_BAR(base->bars[i]), - (gdouble)base->cpu_data[i+1].load / CPU_SCALE - ); - } - } - - if( base->non_linear ) - { - i = base->history_size - 1; - while( i > 0 ) - { - a = base->history[i], b = base->history[i-1]; - if( a < b ) a++; - factor = (i*2); - base->history[i--] = (a * (factor-1) + b) / factor; - } - } else { - memmove( base->history + 1 , base->history , (base->history_size - 1) * sizeof( guint ) ); - } - base->history[0] = base->cpu_data[0].load; - - update_tooltip( base ); - gtk_widget_queue_draw( base->draw_area ); - - return TRUE; + gint i, a, b, factor; + + if (!read_cpu_data (base->cpu_data, base->nr_cores)) + return TRUE; + + if (base->tracked_core > base->nr_cores) + base->cpu_data[0].load = 0; + else if (base->tracked_core != 0) + base->cpu_data[0].load = base->cpu_data[base->tracked_core].load; + + if (base->has_bars) + { + if (base->tracked_core != 0 || base->nr_cores == 1) + { + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (base->bars[0]), + (gdouble) base->cpu_data[0].load / CPU_SCALE); + } + else + { + for (i = 0; i < base->nr_cores; i++) + gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (base->bars[i]), + (gdouble) base->cpu_data[i+1].load / CPU_SCALE); + } + } + + if (base->non_linear) + { + i = base->history_size - 1; + while (i > 0) + { + a = base->history[i], b = base->history[i-1]; + if (a < b) a++; + factor = (i * 2); + base->history[i--] = (a * (factor-1) + b) / factor; + } + } + else { + memmove (base->history + 1 , base->history , (base->history_size - 1) * sizeof (guint)); + } + base->history[0] = base->cpu_data[0].load; + + update_tooltip (base); + gtk_widget_queue_draw (base->draw_area); + + return TRUE; } -static void update_tooltip( CPUGraph * base ) +static void +update_tooltip (CPUGraph *base) { - gchar tooltip[32]; - g_snprintf( tooltip, 32, _("Usage: %u%%"), (guint)base->cpu_data[0].load*100/CPU_SCALE ); - gtk_label_set_text( GTK_LABEL(base->tooltip_text), tooltip ); + gchar tooltip[32]; + g_snprintf (tooltip, 32, _("Usage: %u%%"), (guint) base->cpu_data[0].load * 100 / CPU_SCALE); + gtk_label_set_text (GTK_LABEL (base->tooltip_text), tooltip); } -static gboolean tooltip_cb( GtkWidget *widget, gint x, gint y, gboolean keyboard, GtkTooltip * tooltip, CPUGraph *base) +static gboolean +tooltip_cb (GtkWidget *widget, gint x, gint y, gboolean keyboard, GtkTooltip *tooltip, CPUGraph *base) { - gtk_tooltip_set_custom( tooltip, base->tooltip_text ); - return TRUE; + gtk_tooltip_set_custom (tooltip, base->tooltip_text); + return TRUE; } -static void draw_area_cb( GtkWidget * widget, cairo_t * cr, gpointer data ) +static void +draw_area_cb (GtkWidget *widget, cairo_t *cr, gpointer data) { - CPUGraph *base = (CPUGraph *) data; - GtkAllocation alloc; - gint w, h; - - gtk_widget_get_allocation( base->draw_area, &alloc ); - w = alloc.width; - h = alloc.height; - - gdk_cairo_set_source_rgba(cr, &base->colors[0]); - cairo_rectangle(cr, 0, 0, w, h); - cairo_fill(cr); - - switch( base->mode ) - { - case 0: - draw_graph_normal( base, cr, w, h ); - break; - case 1: - draw_graph_LED( base, cr, w, h ); - break; - case 2: - draw_graph_no_history( base, cr, w, h ); - break; - case 3: - draw_graph_grid(base, cr, w, h); - break; - } + CPUGraph *base = (CPUGraph *) data; + GtkAllocation alloc; + gint w, h; + + gtk_widget_get_allocation (base->draw_area, &alloc); + w = alloc.width; + h = alloc.height; + + gdk_cairo_set_source_rgba (cr, &base->colors[0]); + cairo_rectangle (cr, 0, 0, w, h); + cairo_fill (cr); + + switch (base->mode) + { + case 0: + draw_graph_normal (base, cr, w, h); + break; + case 1: + draw_graph_LED (base, cr, w, h); + break; + case 2: + draw_graph_no_history (base, cr, w, h); + break; + case 3: + draw_graph_grid (base, cr, w, h); + break; + } } -static gboolean command_cb( GtkWidget *w,GdkEventButton *event, CPUGraph *base ) +static gboolean +command_cb (GtkWidget *w, GdkEventButton *event, CPUGraph *base) { - if( event->button == 1 && base->command ) - { - xfce_spawn_command_line_on_screen( gdk_screen_get_default(), base->command, base->in_terminal, base->startup_notification, NULL ); - } - return FALSE; + if (event->button == 1 && base->command) + { + xfce_spawn_command_line_on_screen (gdk_screen_get_default (), + base->command, base->in_terminal, + base->startup_notification, NULL); + } + return FALSE; } -void set_startup_notification( CPUGraph *base, gboolean startup_notification ) +void +set_startup_notification (CPUGraph *base, gboolean startup_notification) { - base->startup_notification = startup_notification; + base->startup_notification = startup_notification; } -void set_in_terminal( CPUGraph *base, gboolean in_terminal ) +void +set_in_terminal (CPUGraph *base, gboolean in_terminal) { - base->in_terminal = in_terminal; + base->in_terminal = in_terminal; } -void set_command( CPUGraph *base, const gchar *command ) +void +set_command (CPUGraph *base, const gchar *command) { - g_free( base->command ); - base->command = g_strdup( command ); + g_free (base->command); + base->command = g_strdup (command); } -void set_bars( CPUGraph * base, gboolean bars) +void +set_bars (CPUGraph *base, gboolean bars) { - GtkOrientation orientation; - if( base->has_bars != bars ) - { - base->has_bars = bars; - if(bars) - { - orientation = xfce_panel_plugin_get_orientation( base->plugin ); - create_bars( base ); - set_bars_orientation( base, orientation ); - set_bars_size( base, xfce_panel_plugin_get_size( base->plugin ), orientation ); - } - else - delete_bars( base ); - } + GtkOrientation orientation; + + if (base->has_bars != bars) + { + base->has_bars = bars; + if (bars) + { + orientation = xfce_panel_plugin_get_orientation (base->plugin); + create_bars (base); + set_bars_orientation (base, orientation); + set_bars_size (base, xfce_panel_plugin_get_size (base->plugin), orientation); + } + else + delete_bars (base); + } } -void set_border( CPUGraph *base, gboolean border ) +void +set_border (CPUGraph *base, gboolean border) { - int border_width = (xfce_panel_plugin_get_size( base->plugin ) > 26 ? 2 : 1); - base->has_border = border; - if (!base->has_border) - border_width = 0; - gtk_container_set_border_width( GTK_CONTAINER( base->box ), border_width); + int border_width = (xfce_panel_plugin_get_size (base->plugin) > 26 ? 2 : 1); + base->has_border = border; + if (!base->has_border) + border_width = 0; + gtk_container_set_border_width (GTK_CONTAINER (base->box), border_width); } -void set_frame( CPUGraph *base, gboolean frame ) +void +set_frame (CPUGraph *base, gboolean frame) { - base->has_frame = frame; - gtk_frame_set_shadow_type( GTK_FRAME( base->frame_widget ), base->has_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE ); + base->has_frame = frame; + gtk_frame_set_shadow_type (GTK_FRAME (base->frame_widget), base->has_frame ? GTK_SHADOW_IN : GTK_SHADOW_NONE); } -void set_nonlinear_time( CPUGraph *base, gboolean nonlinear ) +void +set_nonlinear_time (CPUGraph *base, gboolean nonlinear) { - base->non_linear = nonlinear; + base->non_linear = nonlinear; } -void set_update_rate( CPUGraph *base, guint rate ) +void +set_update_rate (CPUGraph *base, guint rate) { - guint update; - - base->update_interval = rate; - - if( base->timeout_id ) - g_source_remove( base->timeout_id ); - switch( base->update_interval ) - { - case 0: - update = 250; - break; - case 1: - update = 500; - break; - case 2: - update = 750; - break; - default: - update = 1000; - } - base->timeout_id = g_timeout_add( update, (GSourceFunc) update_cb, base ); + guint update; + + base->update_interval = rate; + + if (base->timeout_id) + g_source_remove (base->timeout_id); + + switch (base->update_interval) + { + case 0: + update = 250; + break; + case 1: + update = 500; + break; + case 2: + update = 750; + break; + default: + update = 1000; + } + base->timeout_id = g_timeout_add (update, (GSourceFunc) update_cb, base); } -void set_size( CPUGraph *base, guint size ) +void +set_size (CPUGraph *base, guint size) { - base->size = size; - size_cb( base->plugin, xfce_panel_plugin_get_size( base->plugin ), base ); + base->size = size; + size_cb (base->plugin, xfce_panel_plugin_get_size (base->plugin), base); } -void set_color_mode( CPUGraph *base, guint color_mode ) +void +set_color_mode (CPUGraph *base, guint color_mode) { - base->color_mode = color_mode; + base->color_mode = color_mode; } -void set_mode( CPUGraph *base, guint mode ) +void +set_mode (CPUGraph *base, guint mode) { - base->mode = mode; + base->mode = mode; } -void set_color( CPUGraph *base, guint number, GdkRGBA color ) +void +set_color (CPUGraph *base, guint number, GdkRGBA color) { - guint i, n; - - base->colors[number] = color; - if( number == 0 ) - { - gtk_widget_override_background_color( base->draw_area, GTK_STATE_INSENSITIVE, &base->colors[0] ); - gtk_widget_override_background_color( base->draw_area, GTK_STATE_NORMAL, &base->colors[0] ); - } - if( number == 4 && base->has_bars && base->has_barcolor ) - { - n = nb_bars( base ); - - for( i=0; i< n; i++ ) - { - /* Set bar colors */ - gtk_widget_override_background_color(base->bars[i], GTK_STATE_PRELIGHT, &base->colors[4]); - gtk_widget_override_background_color(base->bars[i], GTK_STATE_SELECTED, &base->colors[4]); - gtk_widget_override_color(base->bars[i], GTK_STATE_SELECTED, &base->colors[4]); - } - } + guint i, n; + + base->colors[number] = color; + + if (number == 0) + { + gtk_widget_override_background_color (base->draw_area, GTK_STATE_INSENSITIVE, &base->colors[0]); + gtk_widget_override_background_color (base->draw_area, GTK_STATE_NORMAL, &base->colors[0]); + } + + if (number == 4 && base->has_bars && base->has_barcolor) + { + n = nb_bars (base); + + for (i = 0; i < n; i++) + { + /* Set bar colors */ + gtk_widget_override_background_color (base->bars[i], GTK_STATE_PRELIGHT, &base->colors[4]); + gtk_widget_override_background_color (base->bars[i], GTK_STATE_SELECTED, &base->colors[4]); + gtk_widget_override_color (base->bars[i], GTK_STATE_SELECTED, &base->colors[4]); + } + } } -void set_tracked_core( CPUGraph *base, guint core ) +void +set_tracked_core (CPUGraph *base, guint core) { - gboolean has_bars = base->has_bars; - if( has_bars) - set_bars( base, FALSE ); - base->tracked_core = core; - if( has_bars) - set_bars( base, TRUE ); + gboolean has_bars = base->has_bars; + if (has_bars) + set_bars (base, FALSE); + base->tracked_core = core; + if (has_bars) + set_bars (base, TRUE); } diff --git a/panel-plugin/cpu.h b/panel-plugin/cpu.h index 77bab3f..c49a751 100644 --- a/panel-plugin/cpu.h +++ b/panel-plugin/cpu.h @@ -32,54 +32,55 @@ #include "os.h" -#define BORDER 8 +#define BORDER 8 typedef struct { - /* GUI components */ - XfcePanelPlugin *plugin; - GtkWidget *frame_widget; - GtkWidget *draw_area; - GtkWidget *box; - GtkWidget **bars; - GtkWidget *color_buttons[5]; - GtkWidget *tooltip_text; + /* GUI components */ + XfcePanelPlugin *plugin; + GtkWidget *frame_widget; + GtkWidget *draw_area; + GtkWidget *box; + GtkWidget **bars; + GtkWidget *color_buttons[5]; + GtkWidget *tooltip_text; - /* Settings */ - guint update_interval; /* Number of ms between updates. */ - gboolean non_linear; - guint size; - guint mode; - guint color_mode; - gboolean has_frame; - gboolean has_border; - gboolean has_bars; - gboolean has_barcolor; - gchar *command; - gboolean in_terminal; - gboolean startup_notification; - GdkRGBA colors[5]; - guint tracked_core; + /* Settings */ + guint update_interval; /* Number of ms between updates. */ + gboolean non_linear; + guint size; + guint mode; + guint color_mode; + gboolean has_frame; + gboolean has_border; + gboolean has_bars; + gboolean has_barcolor; + gchar *command; + gboolean in_terminal; + gboolean startup_notification; + GdkRGBA colors[5]; + guint tracked_core; - /* Runtime data */ - guint nr_cores; - guint timeout_id; - guint *history; - gssize history_size; - CpuData *cpu_data; + /* Runtime data */ + guint nr_cores; + guint timeout_id; + guint *history; + gssize history_size; + CpuData *cpu_data; } CPUGraph; -void set_startup_notification( CPUGraph *base, gboolean startup_notification ); -void set_in_terminal( CPUGraph *base, gboolean in_terminal ); -void set_command( CPUGraph *base, const gchar *command ); -void set_bars( CPUGraph * base, gboolean bars); -void set_border( CPUGraph *base, gboolean border); -void set_frame( CPUGraph *base, gboolean frame ); -void set_nonlinear_time( CPUGraph *base, gboolean nonlinear ); -void set_update_rate( CPUGraph *base, guint rate ); -void set_size( CPUGraph *base, guint width ); -void set_color_mode( CPUGraph *base, guint color_mode ); -void set_mode( CPUGraph *base, guint mode ); -void set_color( CPUGraph *base, guint number, GdkRGBA color ); -void set_tracked_core( CPUGraph *base, guint core ); +void set_startup_notification (CPUGraph *base, gboolean startup_notification); +void set_in_terminal (CPUGraph *base, gboolean in_terminal); +void set_command (CPUGraph *base, const gchar *command); +void set_bars (CPUGraph * base, gboolean bars); +void set_border (CPUGraph *base, gboolean border); +void set_frame (CPUGraph *base, gboolean frame); +void set_nonlinear_time (CPUGraph *base, gboolean nonlinear); +void set_update_rate (CPUGraph *base, guint rate); +void set_size (CPUGraph *base, guint width); +void set_color_mode (CPUGraph *base, guint color_mode); +void set_mode (CPUGraph *base, guint mode); +void set_color (CPUGraph *base, guint number, GdkRGBA color); +void set_tracked_core (CPUGraph *base, guint core); + #endif /* !_XFCE_CPU_H_ */ diff --git a/panel-plugin/mode.c b/panel-plugin/mode.c index f3751f5..e079af9 100644 --- a/panel-plugin/mode.c +++ b/panel-plugin/mode.c @@ -25,170 +25,183 @@ #include <cairo/cairo.h> #include "mode.h" -static gdouble _lerp( gdouble t, gdouble a, gdouble b ) +typedef struct { - return (gdouble) (a + t * (b - a)); -} + gint x; + gint y; +} point; -static void mix_colors( gdouble ratio, GdkRGBA *color1, GdkRGBA *color2, cairo_t *target ) +static gdouble +_lerp (gdouble t, gdouble a, gdouble b) { - GdkRGBA color; - color.red = _lerp (ratio, color1->red, color2->red); - color.green = _lerp (ratio, color1->green, color2->green); - color.blue = _lerp (ratio, color1->blue, color2->blue); - color.alpha = 1.0; - gdk_cairo_set_source_rgba( target, &color ); + return (gdouble) (a + t * (b - a)); } -void draw_graph_normal( CPUGraph *base, cairo_t *cr, gint w, gint h ) +static void +mix_colors (gdouble ratio, GdkRGBA *color1, GdkRGBA *color2, cairo_t *target) { - gint x, y; - gint usage; - gdouble t; - gint tmp; - - if( base->color_mode == 0 ) - gdk_cairo_set_source_rgba( cr, &base->colors[1] ); - - for( x = 0; x < w; x++ ) - { - usage = h * base->history[w - 1- x] / CPU_SCALE; - - if( usage == 0 ) continue; - - if( base->color_mode == 0 ) - { - /* draw line */ - cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE ); - cairo_move_to( cr, x, h - usage ); - cairo_line_to( cr, x, h - 1 ); - cairo_stroke( cr ); - } - else - { - tmp = 0; - for( y = h-1; y >= h - usage; y--, tmp++ ) - { - t = (base->color_mode == 1) ? - (tmp / (gdouble) (h)) : - (tmp / (gdouble) (usage)); - mix_colors( t, &base->colors[1], &base->colors[2], cr ); - /* draw point */ - cairo_set_line_cap( cr, CAIRO_LINE_CAP_ROUND ); - cairo_move_to( cr, x, y ); - cairo_close_path (cr); - cairo_stroke( cr ); - } - } - } + GdkRGBA color; + color.red = _lerp (ratio, color1->red, color2->red); + color.green = _lerp (ratio, color1->green, color2->green); + color.blue = _lerp (ratio, color1->blue, color2->blue); + color.alpha = 1.0; + gdk_cairo_set_source_rgba (target, &color); } -void draw_graph_LED( CPUGraph *base, cairo_t *cr, gint w, gint h ) +void +draw_graph_normal (CPUGraph *base, cairo_t *cr, gint w, gint h) { - gint nrx = (w + 1) / 3; - gint nry = (h + 1) / 2; - gint x, y; - gint idx; - gint limit; - - for( x = 0; x * 3 < w; x++ ) - { - idx = nrx-x; - limit = nry - nry * base->history[idx]/CPU_SCALE; - for( y = 0; y * 2 < h; y++ ) - { - if( base->color_mode != 0 && y < limit ) - { - gdouble t = (base->color_mode == 1) ? - (y / (gdouble)nry) : - (y / (gdouble)limit); - mix_colors( t, &base->colors[3], &base->colors[2], cr ); - } - else - { - gdk_cairo_set_source_rgba( cr, y >= limit ? &base->colors[1] : &base->colors[2] ); - } - /* draw rectangle */ - cairo_rectangle( cr, x * 3, y * 2, 2, 1 ); - cairo_fill( cr ); - } - } + gint x, y; + gint usage; + gdouble t; + gint tmp; + + if (base->color_mode == 0) + gdk_cairo_set_source_rgba (cr, &base->colors[1]); + + for (x = 0; x < w; x++) + { + usage = h * base->history[w - 1- x] / CPU_SCALE; + + if (usage == 0) + continue; + + if (base->color_mode == 0) + { + /* draw line */ + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + cairo_move_to (cr, x, h - usage); + cairo_line_to (cr, x, h - 1); + cairo_stroke (cr); + } + else + { + tmp = 0; + for (y = h - 1; y >= h - usage; y--, tmp++) + { + t = (base->color_mode == 1) ? + (tmp / (gdouble) (h)) : + (tmp / (gdouble) (usage)); + mix_colors (t, &base->colors[1], &base->colors[2], cr); + /* draw point */ + cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND); + cairo_move_to (cr, x, y); + cairo_close_path (cr); + cairo_stroke (cr); + } + } + } } -void draw_graph_no_history( CPUGraph *base, cairo_t *cr, gint w, gint h ) +void +draw_graph_LED (CPUGraph *base, cairo_t *cr, gint w, gint h) { - gint y; - gint usage = h * base->history[0] / CPU_SCALE; - gint tmp = 0; - gdouble t; - - if( base->color_mode == 0 ) - { - gdk_cairo_set_source_rgba( cr, &base->colors[1] ); - cairo_rectangle( cr, 0, h - usage, w, usage ); - cairo_fill( cr ); - } - else - { - for( y = h-1; y > h - 1 - usage; y-- ) - { - t = (base->color_mode == 1) ? - (tmp / (gdouble) (h)) : - (tmp / (gdouble) (usage)); - mix_colors( t, &base->colors[1], &base->colors[2], cr ); - tmp++; - /* draw line */ - cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE ); - cairo_move_to( cr, 0, y ); - cairo_line_to( cr, w -1, y ); - cairo_stroke( cr ); - } - } + gint nrx = (w + 1) / 3; + gint nry = (h + 1) / 2; + gint x, y; + gint idx; + gint limit; + + for (x = 0; x * 3 < w; x++) + { + idx = nrx - x; + limit = nry - nry * base->history[idx] / CPU_SCALE; + + for (y = 0; y * 2 < h; y++) + { + if (base->color_mode != 0 && y < limit) + { + gdouble t = (base->color_mode == 1) ? + (y / (gdouble) nry) : + (y / (gdouble) limit); + mix_colors (t, &base->colors[3], &base->colors[2], cr); + } + else + { + gdk_cairo_set_source_rgba (cr, y >= limit ? &base->colors[1] : &base->colors[2]); + } + + /* draw rectangle */ + cairo_rectangle (cr, x * 3, y * 2, 2, 1); + cairo_fill (cr); + } + } } -typedef struct +void +draw_graph_no_history (CPUGraph *base, cairo_t *cr, gint w, gint h) { - gint x; - gint y; -} point; + gint y; + gint usage = h * base->history[0] / CPU_SCALE; + gint tmp = 0; + gdouble t; + + if (base->color_mode == 0) + { + gdk_cairo_set_source_rgba (cr, &base->colors[1]); + cairo_rectangle (cr, 0, h - usage, w, usage); + cairo_fill (cr); + } + else + { + for (y = h - 1; y > h - 1 - usage; y--) + { + t = (base->color_mode == 1) ? + (tmp / (gdouble) (h)) : + (tmp / (gdouble) (usage)); + mix_colors (t, &base->colors[1], &base->colors[2], cr); + tmp++; + + /* draw line */ + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + cairo_move_to (cr, 0, y); + cairo_line_to (cr, w -1, y); + cairo_stroke (cr); + } + } +} -void draw_graph_grid( CPUGraph *base, cairo_t *cr, gint w, gint h ) +void +draw_graph_grid (CPUGraph *base, cairo_t *cr, gint w, gint h) { - gint x, y; - gint usage; - point last, current; - last.x = 0; - last.y = h; - - gdk_cairo_set_source_rgba( cr, &base->colors[1] ); - cairo_set_line_cap( cr, CAIRO_LINE_CAP_SQUARE ); - cairo_set_line_width( cr, 1 ); - - for( x = 0; x * 6 < w; x++ ) - { - /* draw line */ - cairo_move_to( cr, x * 6 + 0.5, 0.5 ); - cairo_line_to( cr, x * 6 + 0.5, h - 1 + 0.5 ); - cairo_stroke( cr ); - } - for( y = 0; y * 4 < h; y++ ) - { - /* draw line */ - cairo_move_to( cr, 0.5, y * 4 + 0.5 ); - cairo_line_to( cr, w - 1 + 0.5, y * 4 + 0.5 ); - cairo_stroke( cr ); - } - - gdk_cairo_set_source_rgba( cr, &base->colors[2] ); - for( x = 0; x < w; x++ ) - { - usage = h * base->history[w - 1- x] / CPU_SCALE; - current.x = x; - current.y = h - usage; - /* draw line */ - cairo_move_to( cr, current.x + 0.5, current.y + 0.5 ); - cairo_line_to( cr, last.x + 0.5, last.y + 0.5 ); - cairo_stroke( cr ); - last = current; - } + gint x, y; + gint usage; + point last, current; + last.x = 0; + last.y = h; + + gdk_cairo_set_source_rgba (cr, &base->colors[1]); + cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); + cairo_set_line_width (cr, 1); + + for (x = 0; x * 6 < w; x++) + { + /* draw line */ + cairo_move_to (cr, x * 6 + 0.5, 0.5); + cairo_line_to (cr, x * 6 + 0.5, h - 1 + 0.5); + cairo_stroke (cr); + } + + for (y = 0; y * 4 < h; y++) + { + /* draw line */ + cairo_move_to (cr, 0.5, y * 4 + 0.5); + cairo_line_to (cr, w - 1 + 0.5, y * 4 + 0.5); + cairo_stroke (cr); + } + + gdk_cairo_set_source_rgba (cr, &base->colors[2]); + + for (x = 0; x < w; x++) + { + usage = h * base->history[w - 1 - x] / CPU_SCALE; + current.x = x; + current.y = h - usage; + + /* draw line */ + cairo_move_to (cr, current.x + 0.5, current.y + 0.5); + cairo_line_to (cr, last.x + 0.5, last.y + 0.5); + cairo_stroke (cr); + last = current; + } } diff --git a/panel-plugin/mode.h b/panel-plugin/mode.h index 7354cd1..f56e8be 100644 --- a/panel-plugin/mode.h +++ b/panel-plugin/mode.h @@ -26,9 +26,9 @@ #include "cpu.h" -void draw_graph_normal( CPUGraph *base, cairo_t *cr, gint w, gint h ); -void draw_graph_LED( CPUGraph *base, cairo_t *cr, gint w, gint h ); -void draw_graph_no_history( CPUGraph *base, cairo_t *cr, gint w, gint h ); -void draw_graph_grid( CPUGraph *base, cairo_t *cr, gint w, gint h ); +void draw_graph_normal (CPUGraph *base, cairo_t *cr, gint w, gint h); +void draw_graph_LED (CPUGraph *base, cairo_t *cr, gint w, gint h); +void draw_graph_no_history (CPUGraph *base, cairo_t *cr, gint w, gint h); +void draw_graph_grid (CPUGraph *base, cairo_t *cr, gint w, gint h); #endif /* !_XFCE_MODE_H_ */ diff --git a/panel-plugin/os.c b/panel-plugin/os.c index 87e0322..f71f8b5 100644 --- a/panel-plugin/os.c +++ b/panel-plugin/os.c @@ -68,265 +68,299 @@ static kstat_ctl_t *kc; #endif #if defined (__linux__) || defined (__FreeBSD_kernel__) -guint detect_cpu_number() +guint +detect_cpu_number () { - guint nb_lines= 0; - FILE *fstat = NULL; - gchar cpuStr[PROCMAXLNLEN]; + guint nb_lines= 0; + FILE *fstat = NULL; + gchar cpuStr[PROCMAXLNLEN]; - if( !(fstat = fopen( PROC_STAT, "r" )) ) - return 0; + if (!(fstat = fopen (PROC_STAT, "r"))) + return 0; - while( fgets( cpuStr, PROCMAXLNLEN, fstat ) ) - { - if( strncmp( cpuStr, "cpu", 3 ) == 0 ) - nb_lines++; - else - break; - } + while (fgets (cpuStr, PROCMAXLNLEN, fstat)) + { + if (strncmp (cpuStr, "cpu", 3) == 0) + nb_lines++; + else + break; + } - fclose( fstat ); + fclose (fstat); - return nb_lines > 1 ? nb_lines - 1 : 0; + return nb_lines > 1 ? nb_lines - 1 : 0; } -gboolean read_cpu_data( CpuData *data, guint nb_cpu ) +gboolean +read_cpu_data (CpuData *data, guint nb_cpu) { - FILE *fStat; - gchar cpuStr[PROCMAXLNLEN]; - gulong user, nice, system, idle, used, total, iowait, irq, softirq; - guint line; - - if( !(fStat = fopen( PROC_STAT, "r" )) ) - return FALSE; - - for( line = 0; line < nb_cpu + 1; line++ ) - { - if( !fgets( cpuStr, PROCMAXLNLEN, fStat ) || - strncmp( cpuStr, "cpu", 3 ) != 0 - ) - { - fclose( fStat ); - return FALSE; - } - if( sscanf( cpuStr, "%*s %lu %lu %lu %lu %lu %lu %lu", &user, &nice, &system, &idle, &iowait, &irq, &softirq ) < 7 ) - iowait = irq = softirq = 0; - used = user + nice + system + irq + softirq; - total = used + idle + iowait; - if( (total - data[line].previous_total) != 0 ) - { - data[line].load = CPU_SCALE * (used - data[line].previous_used) / - (total - data[line].previous_total); - } - else - { - data[line].load = 0; - } - data[line].previous_used = used; - data[line].previous_total = total; - } - - fclose( fStat ); - - return TRUE; + FILE *fStat; + gchar cpuStr[PROCMAXLNLEN]; + gulong user, nice, system, idle, used, total, iowait, irq, softirq; + guint line; + + if (!(fStat = fopen (PROC_STAT, "r"))) + return FALSE; + + for (line = 0; line < nb_cpu + 1; line++) + { + if (!fgets (cpuStr, PROCMAXLNLEN, fStat) || + strncmp (cpuStr, "cpu", 3) != 0) + { + fclose (fStat); + return FALSE; + } + + if (sscanf (cpuStr, "%*s %lu %lu %lu %lu %lu %lu %lu", &user, &nice, &system, &idle, &iowait, &irq, &softirq) < 7) + iowait = irq = softirq = 0; + + used = user + nice + system + irq + softirq; + total = used + idle + iowait; + + if ((total - data[line].previous_total) != 0) + { + data[line].load = CPU_SCALE * (used - data[line].previous_used) / + (total - data[line].previous_total); + } + else + { + data[line].load = 0; + } + data[line].previous_used = used; + data[line].previous_total = total; + } + + fclose (fStat); + + return TRUE; } #elif defined (__FreeBSD__) -guint detect_cpu_number() +guint +detect_cpu_number () { - static gint mib[] = {CTL_HW, HW_NCPU}; - gint ncpu; - gsize len = sizeof( gint ); - if( sysctl( mib, 2, &ncpu, &len, NULL, 0 ) < 0 ) - return 0; - else - return ncpu; + static gint mib[] = {CTL_HW, HW_NCPU}; + gint ncpu; + gsize len = sizeof (gint); + + if (sysctl (mib, 2, &ncpu, &len, NULL, 0) < 0) + return 0; + else + return ncpu; } -gboolean read_cpu_data( CpuData *data, guint nb_cpu) +gboolean +read_cpu_data (CpuData *data, guint nb_cpu) { - glong used, total; - glong *cp_time; - glong *cp_time1; - gint i; - unsigned int max_cpu; - gsize len = sizeof(max_cpu); - - data[0].load = 0; - if (sysctlbyname("kern.smp.maxid", &max_cpu, &len, NULL, 0) < 0) - return FALSE; - - max_cpu++; /* max_cpu is 0-based */ - if (max_cpu < nb_cpu) - return FALSE; /* should not happen */ - len = sizeof(glong) * max_cpu * CPUSTATES; - cp_time = (glong *) g_malloc(len); - - if (sysctlbyname( "kern.cp_times", cp_time, &len, NULL, 0 ) < 0) { - g_free(cp_time); - return FALSE; - } - for (i = 1; i <= nb_cpu; i++ ) - { - cp_time1 = &cp_time[CPUSTATES * (i - 1)]; - used = cp_time1[CP_USER] + cp_time1[CP_NICE] + cp_time1[CP_SYS] + cp_time1[CP_INTR]; - total = used + cp_time1[CP_IDLE]; - if( (total - data[i].previous_total) != 0 ) - data[i].load = (CPU_SCALE * (used - data[i].previous_used))/(total - data[i].previous_total); - else - data[i].load = 0; - - data[i].previous_used = used; - data[i].previous_total = total; - data[0].load += data[i].load; - } - data[0].load /= nb_cpu; - g_free(cp_time); - return TRUE; + glong used, total; + glong *cp_time; + glong *cp_time1; + gint i; + unsigned int max_cpu; + gsize len = sizeof (max_cpu); + + data[0].load = 0; + if (sysctlbyname ("kern.smp.maxid", &max_cpu, &len, NULL, 0) < 0) + return FALSE; + + max_cpu++; /* max_cpu is 0-based */ + if (max_cpu < nb_cpu) + return FALSE; /* should not happen */ + len = sizeof (glong) * max_cpu * CPUSTATES; + cp_time = (glong *) g_malloc (len); + + if (sysctlbyname ("kern.cp_times", cp_time, &len, NULL, 0) < 0) { + g_free (cp_time); + return FALSE; + } + + for (i = 1; i <= nb_cpu; i++) + { + cp_time1 = &cp_time[CPUSTATES * (i - 1)]; + used = cp_time1[CP_USER] + cp_time1[CP_NICE] + cp_time1[CP_SYS] + cp_time1[CP_INTR]; + total = used + cp_time1[CP_IDLE]; + + if ((total - data[i].previous_total) != 0) + data[i].load = (CPU_SCALE * (used - data[i].previous_used)) / + (total - data[i].previous_total); + else + data[i].load = 0; + + data[i].previous_used = used; + data[i].previous_total = total; + data[0].load += data[i].load; + } + + data[0].load /= nb_cpu; + g_free (cp_time); + return TRUE; } #elif defined (__NetBSD__) -guint detect_cpu_number() +guint +detect_cpu_number () { - static gint mib[] = {CTL_HW, HW_NCPU}; - gint ncpu; - gsize len = sizeof( gint ); - if( sysctl( mib, 2, &ncpu, &len, NULL, 0 ) < 0 ) - return 0; - else - return ncpu; + static gint mib[] = {CTL_HW, HW_NCPU}; + gint ncpu; + gsize len = sizeof (gint); + + if (sysctl (mib, 2, &ncpu, &len, NULL, 0) < 0) + return 0; + else + return ncpu; } -gboolean read_cpu_data( CpuData *data, guint nb_cpu) +gboolean +read_cpu_data (CpuData *data, guint nb_cpu) { - guint64 used, total; - guint64 cp_time[CPUSTATES * nb_cpu]; - guint64 *cp_time1; - gint i; - gsize len = nb_cpu * CPUSTATES * sizeof( guint64 ); - gint mib[] = {CTL_KERN, KERN_CP_TIME}; - if( sysctl( mib, 2, &cp_time, &len, NULL, 0 ) < 0 ) - return FALSE; - - data[0].load = 0; - for( i = 1 ; i <= nb_cpu ; i++ ) - { - cp_time1 = cp_time + CPUSTATE * (i - 1); - used = cp_time1[CP_USER] + cp_time1[CP_NICE] + cp_time1[CP_SYS] + cp_time1[CP_INTR]; - total = used + cp_time1[CP_IDLE]; - - if( total - data[i].previous_total != 0 ) - data[i].load = (CPU_SCALE * (used - data[i].previous_used))/(total - data[i].previous_total); - else - data[i].load = 0; - data[i].previous_used = used; - data[i].previous_total = total; - data[0].load += data[i].load; - } - data[0].load /= nb_cpu; - return TRUE; + guint64 used, total; + guint64 cp_time[CPUSTATES * nb_cpu]; + guint64 *cp_time1; + gint i; + gsize len = nb_cpu * CPUSTATES * sizeof (guint64); + gint mib[] = {CTL_KERN, KERN_CP_TIME}; + + if (sysctl (mib, 2, &cp_time, &len, NULL, 0) < 0) + return FALSE; + + data[0].load = 0; + for (i = 1; i <= nb_cpu; i++) + { + cp_time1 = cp_time + CPUSTATE * (i - 1); + used = cp_time1[CP_USER] + cp_time1[CP_NICE] + cp_time1[CP_SYS] + cp_time1[CP_INTR]; + total = used + cp_time1[CP_IDLE]; + + if (total - data[i].previous_total != 0) + data[i].load = (CPU_SCALE * (used - data[i].previous_used)) / + (total - data[i].previous_total); + else + data[i].load = 0; + + data[i].previous_used = used; + data[i].previous_total = total; + data[0].load += data[i].load; + } + + data[0].load /= nb_cpu; + return TRUE; } #elif defined (__OpenBSD__) -guint detect_cpu_number() +guint +detect_cpu_number () { - static gint mib[] = {CTL_HW, HW_NCPU}; - gint ncpu; - gsize len = sizeof( gint ); - if( sysctl( mib, 2, &ncpu, &len, NULL, 0 ) < 0 ) - return 0; - else - return ncpu; + static gint mib[] = {CTL_HW, HW_NCPU}; + gint ncpu; + gsize len = sizeof (gint); + + if (sysctl (mib, 2, &ncpu, &len, NULL, 0) < 0) + return 0; + else + return ncpu; } -gboolean read_cpu_data( CpuData *data, guint nb_cpu) +gboolean +read_cpu_data (CpuData *data, guint nb_cpu) { - guint64 used, total; - guint64 cp_time[CPUSTATES]; - gint i; - data[0].load = 0; - for( i = 1 ; i <= nb_cpu ; i++ ) - { - gsize len = CPUSTATES * sizeof( guint64 ); - gint mib[] = {CTL_KERN, KERN_CPTIME2, i - 1}; - if( sysctl( mib, 3, &cp_time, &len, NULL, 0 ) < 0 ) - return FALSE; - - used = cp_time[CP_USER] + cp_time[CP_NICE] + cp_time[CP_SYS] + cp_time[CP_INTR]; - total = used + cp_time[CP_IDLE]; - - if( total - data[i].previous_total != 0 ) - data[i].load = (CPU_SCALE * (used - data[i].previous_used))/(total - data[i].previous_total); - else - data[i].load = 0; - data[i].previous_used = used; - data[i].previous_total = total; - data[0].load += data[i].load; - } - data[0].load /= nb_cpu; - return TRUE; + guint64 used, total; + guint64 cp_time[CPUSTATES]; + gint i; + data[0].load = 0; + + for (i = 1; i <= nb_cpu; i++) + { + gsize len = CPUSTATES * sizeof (guint64); + gint mib[] = {CTL_KERN, KERN_CPTIME2, i - 1}; + + if (sysctl (mib, 3, &cp_time, &len, NULL, 0) < 0) + return FALSE; + + used = cp_time[CP_USER] + cp_time[CP_NICE] + cp_time[CP_SYS] + cp_time[CP_INTR]; + total = used + cp_time[CP_IDLE]; + + if (total - data[i].previous_total != 0) + data[i].load = (CPU_SCALE * (used - data[i].previous_used)) / + (total - data[i].previous_total); + else + data[i].load = 0; + + data[i].previous_used = used; + data[i].previous_total = total; + data[0].load += data[i].load; + } + + data[0].load /= nb_cpu; + return TRUE; } #elif defined (__sun__) -static void init_stats() +static void +init_stats () { - kc = kstat_open(); + kc = kstat_open (); } -guint detect_cpu_number() +guint +detect_cpu_number () { - kstat_t *ksp; - kstat_named_t *knp; - - if( !kc ) - init_stats(); - - if( !(ksp = kstat_lookup( kc, "unix", 0, "system_misc" )) ) - return 0; - else - kstat_read( kc, ksp, NULL ); - knp = kstat_data_lookup( ksp, "ncpus" ); - return knp->value.ui32; + kstat_t *ksp; + kstat_named_t *knp; + + if (!kc) + init_stats (); + + if (!(ksp = kstat_lookup (kc, "unix", 0, "system_misc"))) + return 0; + + kstat_read (kc, ksp, NULL); + knp = kstat_data_lookup (ksp, "ncpus"); + + return knp->value.ui32; } -gboolean read_cpu_data( CpuData *data, guint nb_cpu ) +gboolean +read_cpu_data (CpuData *data, guint nb_cpu) { - kstat_t *ksp; - kstat_named_t *knp; - guint64 used, total; - gint i; - data[0].load = 0; - - if( !kc ) - init_stats(); - - i = 1; - for( ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next ) - { - if( !g_strcmp0( ksp->ks_module, "cpu" ) && !g_strcmp0( ksp->ks_name, "sys" ) ) - { - kstat_read( kc, ksp, NULL ); - knp = kstat_data_lookup( ksp, "cpu_nsec_user" ); - used = knp->value.ul; - knp = kstat_data_lookup( ksp, "cpu_nsec_intr" ); - used += knp->value.ul; - knp = kstat_data_lookup( ksp, "cpu_nsec_kernel" ); - used += knp->value.ul; - knp = kstat_data_lookup( ksp, "cpu_nsec_idle" ); - total = used + knp->value.ul; - if( total - data[i].previous_total != 0 ) - data[i].load = (CPU_SCALE * (used - data[i].previous_used))/(total - data[i].previous_total); - else - data[i].load = 0; - data[i].previous_used = used; - data[i].previous_total = total; - data[0].load += data[i].load; - i++; - } - } - - data[0].load /= nb_cpu; - return TRUE; + kstat_t *ksp; + kstat_named_t *knp; + guint64 used, total; + gint i; + data[0].load = 0; + + if (!kc) + init_stats (); + + i = 1; + + for (ksp = kc->kc_chain; ksp != NULL; ksp = ksp->ks_next) + { + if (!g_strcmp0 (ksp->ks_module, "cpu") && !g_strcmp0 (ksp->ks_name, "sys")) + { + kstat_read (kc, ksp, NULL); + knp = kstat_data_lookup (ksp, "cpu_nsec_user"); + used = knp->value.ul; + knp = kstat_data_lookup (ksp, "cpu_nsec_intr"); + used += knp->value.ul; + knp = kstat_data_lookup (ksp, "cpu_nsec_kernel"); + used += knp->value.ul; + knp = kstat_data_lookup (ksp, "cpu_nsec_idle"); + total = used + knp->value.ul; + + if (total - data[i].previous_total != 0) + data[i].load = (CPU_SCALE * (used - data[i].previous_used)) / + (total - data[i].previous_total); + else + data[i].load = 0; + + data[i].previous_used = used; + data[i].previous_total = total; + data[0].load += data[i].load; + i++; + } + } + + data[0].load /= nb_cpu; + return TRUE; } #else #error "Your OS is not supported." diff --git a/panel-plugin/os.h b/panel-plugin/os.h index 423bc26..76eb454 100644 --- a/panel-plugin/os.h +++ b/panel-plugin/os.h @@ -30,12 +30,12 @@ typedef struct { - guint load; - guint64 previous_used; - guint64 previous_total; + guint load; + guint64 previous_used; + guint64 previous_total; } CpuData; -guint detect_cpu_number(); -gboolean read_cpu_data( CpuData *data, guint nb_cpu ); +guint detect_cpu_number (); +gboolean read_cpu_data (CpuData *data, guint nb_cpu); #endif /* !_XFCE_OS_H */ diff --git a/panel-plugin/properties.c b/panel-plugin/properties.c index 809f6ac..8873dcb 100644 --- a/panel-plugin/properties.c +++ b/panel-plugin/properties.c @@ -33,381 +33,467 @@ # define _(String) gettext (String) #endif -static GtkBox *create_tab(); -static GtkBox *create_option_line( GtkBox *tab, GtkSizeGroup *sg, const gchar *name ); -static void create_check_box( GtkBox *tab, GtkSizeGroup *sg, const gchar *name, gboolean init, void (callback)( GtkToggleButton *, CPUGraph *), void *cb_data ); -static void create_drop_down( GtkBox *tab, GtkSizeGroup *sg, const gchar * name, const gchar **items, gsize nb_items, guint init, void (callback)( GtkComboBox *, CPUGraph * ), void * cb_data); - -static void setup_update_interval_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ); -static void setup_tracked_core_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ); -static void setup_size_option( GtkBox *vbox, GtkSizeGroup *sg, XfcePanelPlugin *plugin, CPUGraph *base ); -static void setup_command_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ); -static void setup_color_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base, guint number, const gchar *name, GCallback cb ); -static void setup_mode_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ); -static void setup_color_mode_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ); - -static void change_in_terminal( GtkToggleButton *button, CPUGraph *base ); -static void change_startup_notification( GtkToggleButton *button, CPUGraph *base ); -static void change_command( GtkEntry *entry, CPUGraph *base ); -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 ); -static void change_frame( GtkToggleButton *button, CPUGraph *base ); -static void change_border( GtkToggleButton *button, CPUGraph *base ); -static void change_bars( GtkToggleButton * button, CPUGraph * base ); -static void change_size( GtkSpinButton *sb, CPUGraph *base ); -static void change_time_scale( GtkToggleButton *button, CPUGraph *base ); -static void change_update( GtkComboBox *om, CPUGraph *base ); -static void change_core( GtkComboBox * combo, CPUGraph * base ); - -void create_options( XfcePanelPlugin *plugin, CPUGraph *base ) -{ - GtkWidget *dlg, *header, *content; - GtkBox *vbox, *vbox2; - GtkWidget *label; - GtkSizeGroup *sg; - GtkWidget *Notebook; - - xfce_panel_plugin_block_menu( plugin ); - - dlg = xfce_titled_dialog_new_with_buttons( _("CPU Graph Properties"), - GTK_WINDOW( gtk_widget_get_toplevel( GTK_WIDGET( plugin ) ) ), - GTK_DIALOG_DESTROY_WITH_PARENT, - "_Close", - GTK_RESPONSE_OK, - NULL - ); - - g_signal_connect( dlg, "response", G_CALLBACK( response_cb ), base ); - - gtk_window_set_icon_name( GTK_WINDOW (dlg), "xfce4-cpugraph-plugin" ); - - sg = gtk_size_group_new( GTK_SIZE_GROUP_HORIZONTAL ); - - vbox = create_tab(); - setup_update_interval_option( vbox, sg, base ); - setup_tracked_core_option( vbox, sg, base ); - setup_size_option( vbox, sg, plugin, base ); - create_check_box( vbox, sg, _("Use non-linear time-scale"), base->non_linear, change_time_scale, base ); - create_check_box( vbox, sg, _("Show frame"), base->has_frame, change_frame, base ); - create_check_box( vbox, sg, _("Show border"), base->has_border, change_border, base ); - create_check_box( vbox, sg, ngettext( "Show current usage bar", "Show current usage bars", base->nr_cores ), base->has_bars, change_bars, base ); - setup_command_option( vbox, sg, base ); - create_check_box( vbox, sg, _("Run in terminal"), base->in_terminal, change_in_terminal, base ); - create_check_box( vbox, sg, _("Use startup notification"), base->startup_notification, change_startup_notification, base ); - - vbox2 = create_tab(); - setup_color_option( vbox2, sg, base, 1, _("Color 1:"), G_CALLBACK( change_color_1 ) ); - setup_color_option( vbox2, sg, base, 2, _("Color 2:"), G_CALLBACK( change_color_2 ) ); - setup_color_option( vbox2, sg, base, 3, _("Color 3:"), G_CALLBACK( change_color_3 ) ); - setup_color_option( vbox2, sg, base, 0, _("Background:"), G_CALLBACK( change_color_0 ) ); - 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 ); - label = gtk_label_new( _("Appearance") ); - gtk_notebook_append_page( GTK_NOTEBOOK( Notebook ), GTK_WIDGET( vbox2 ), GTK_WIDGET( label ) ); - label = gtk_label_new( _("Advanced") ); - gtk_notebook_append_page( GTK_NOTEBOOK( Notebook ), GTK_WIDGET( vbox ), GTK_WIDGET( label ) ); - gtk_widget_show( Notebook ); - - content = gtk_dialog_get_content_area( GTK_DIALOG( dlg ) ); - gtk_container_add( GTK_CONTAINER( content ), Notebook ); - - gtk_widget_show( dlg ); -} - -static GtkBox *create_tab() -{ - GtkBox *tab; - tab = GTK_BOX( gtk_box_new( GTK_ORIENTATION_VERTICAL, BORDER ) ); - gtk_container_set_border_width( GTK_CONTAINER( tab ), BORDER ); - gtk_widget_show( GTK_WIDGET( tab ) ); - return tab; -} - -static GtkBox *create_option_line( GtkBox *tab, GtkSizeGroup *sg, const gchar *name ) -{ - GtkBox *line; - GtkWidget *label; - - line = GTK_BOX( gtk_box_new( GTK_ORIENTATION_HORIZONTAL, BORDER ) ); - gtk_widget_show( GTK_WIDGET( line ) ); - gtk_box_pack_start( GTK_BOX( tab ), GTK_WIDGET( line ), FALSE, FALSE, 0 ); +static GtkBox *create_tab (); +static GtkBox *create_option_line (GtkBox *tab, + GtkSizeGroup *sg, + const gchar *name); +static void create_check_box (GtkBox *tab, + GtkSizeGroup *sg, + const gchar *name, + gboolean init, + void (callback)(GtkToggleButton *, CPUGraph *), + void *cb_data); +static void create_drop_down (GtkBox *tab, + GtkSizeGroup *sg, + const gchar *name, + const gchar **items, + gsize nb_items, + guint init, + void (callback)(GtkComboBox *, CPUGraph *), + void *cb_data); + +static void setup_update_interval_option (GtkBox *vbox, + GtkSizeGroup *sg, + CPUGraph *base); +static void setup_tracked_core_option (GtkBox *vbox, + GtkSizeGroup *sg, + CPUGraph *base); +static void setup_size_option (GtkBox *vbox, + GtkSizeGroup *sg, + XfcePanelPlugin *plugin, + CPUGraph *base); +static void setup_command_option (GtkBox *vbox, + GtkSizeGroup *sg, + CPUGraph *base); +static void setup_color_option (GtkBox *vbox, + GtkSizeGroup *sg, + CPUGraph *base, + guint number, + const gchar *name, + GCallback cb); +static void setup_mode_option (GtkBox *vbox, + GtkSizeGroup *sg, + CPUGraph *base); +static void setup_color_mode_option (GtkBox *vbox, + GtkSizeGroup *sg, + CPUGraph *base); + +static void change_in_terminal (GtkToggleButton *button, + CPUGraph *base); +static void change_startup_notification (GtkToggleButton *button, + CPUGraph *base); +static void change_command (GtkEntry *entry, + CPUGraph *base); +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); +static void change_frame (GtkToggleButton *button, + CPUGraph *base); +static void change_border (GtkToggleButton *button, + CPUGraph *base); +static void change_bars (GtkToggleButton *button, + CPUGraph *base); +static void change_size (GtkSpinButton *sb, + CPUGraph *base); +static void change_time_scale (GtkToggleButton *button, + CPUGraph *base); +static void change_update (GtkComboBox *om, + CPUGraph *base); +static void change_core (GtkComboBox *combo, + CPUGraph *base); + +void +create_options (XfcePanelPlugin *plugin, CPUGraph *base) +{ + GtkWidget *dlg, *header, *content; + GtkBox *vbox, *vbox2; + GtkWidget *label; + GtkSizeGroup *sg; + GtkWidget *notebook; + + xfce_panel_plugin_block_menu (plugin); + + dlg = xfce_titled_dialog_new_with_buttons (_("CPU Graph Properties"), + GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (plugin))), + GTK_DIALOG_DESTROY_WITH_PARENT, + "_Close", + GTK_RESPONSE_OK, + NULL); + + g_signal_connect (dlg, "response", G_CALLBACK (response_cb), base); + + gtk_window_set_icon_name (GTK_WINDOW (dlg), "xfce4-cpugraph-plugin"); + + sg = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); + + vbox = create_tab (); + setup_update_interval_option (vbox, sg, base); + setup_tracked_core_option (vbox, sg, base); + setup_size_option (vbox, sg, plugin, base); + create_check_box (vbox, sg, _("Use non-linear time-scale"), base->non_linear, change_time_scale, base); + create_check_box (vbox, sg, _("Show frame"), base->has_frame, change_frame, base); + create_check_box (vbox, sg, _("Show border"), base->has_border, change_border, base); + create_check_box (vbox, sg, ngettext ("Show current usage bar", "Show current usage bars", base->nr_cores), base->has_bars, change_bars, base); + setup_command_option (vbox, sg, base); + create_check_box (vbox, sg, _("Run in terminal"), base->in_terminal, change_in_terminal, base); + create_check_box (vbox, sg, _("Use startup notification"), base->startup_notification, change_startup_notification, base); + + vbox2 = create_tab (); + setup_color_option (vbox2, sg, base, 1, _("Color 1:"), G_CALLBACK (change_color_1)); + setup_color_option (vbox2, sg, base, 2, _("Color 2:"), G_CALLBACK (change_color_2)); + setup_color_option (vbox2, sg, base, 3, _("Color 3:"), G_CALLBACK (change_color_3)); + setup_color_option (vbox2, sg, base, 0, _("Background:"), G_CALLBACK (change_color_0)); + 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); + label = gtk_label_new (_("Appearance")); + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), GTK_WIDGET (vbox2), GTK_WIDGET (label)); + label = gtk_label_new (_("Advanced")); + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), GTK_WIDGET (vbox), GTK_WIDGET (label)); + gtk_widget_show (notebook); + + content = gtk_dialog_get_content_area (GTK_DIALOG (dlg)); + gtk_container_add (GTK_CONTAINER (content), notebook); + + gtk_widget_show (dlg); +} + +static GtkBox * +create_tab () +{ + GtkBox *tab; + tab = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, BORDER)); + gtk_container_set_border_width (GTK_CONTAINER (tab), BORDER); + gtk_widget_show (GTK_WIDGET (tab)); + return tab; +} + +static GtkBox * +create_option_line (GtkBox *tab, GtkSizeGroup *sg, const gchar *name) +{ + GtkBox *line; + GtkWidget *label; + + line = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, BORDER)); + gtk_widget_show (GTK_WIDGET (line)); + gtk_box_pack_start (GTK_BOX (tab), GTK_WIDGET (line), FALSE, FALSE, 0); + + if (name) + { + label = gtk_label_new (name); + gtk_label_set_xalign (GTK_LABEL (label), 0.0); + gtk_label_set_yalign (GTK_LABEL (label), 0.5); + gtk_size_group_add_widget (sg, label); + gtk_widget_show (label); + gtk_box_pack_start (GTK_BOX (line), GTK_WIDGET (label), FALSE, FALSE, 0); + } - if( name ) - { - label = gtk_label_new( name ); - gtk_label_set_xalign( GTK_LABEL( label ), 0.0 ); - gtk_label_set_yalign( GTK_LABEL( label ), 0.5 ); - gtk_size_group_add_widget( sg, label ); - gtk_widget_show( label ); - gtk_box_pack_start( GTK_BOX( line ), GTK_WIDGET( label ), FALSE, FALSE, 0 ); - } - - return line; + return line; } -static void create_check_box( GtkBox *tab, GtkSizeGroup *sg, const gchar *name, gboolean init, void (callback)( GtkToggleButton *, CPUGraph *), void *cb_data ) +static void +create_check_box (GtkBox *tab, GtkSizeGroup *sg, const gchar *name, gboolean init, + void (callback)(GtkToggleButton *, CPUGraph *), void *cb_data) { - GtkBox *hbox; - GtkWidget * checkBox; + GtkBox *hbox; + GtkWidget *checkbox; - hbox = create_option_line( tab, sg, NULL ); + hbox = create_option_line (tab, sg, NULL); - checkBox = gtk_check_button_new_with_mnemonic( name ); - gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( checkBox ), init ); - gtk_widget_show( checkBox ); - gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( checkBox ), FALSE, FALSE, 0 ); - g_signal_connect( checkBox, "toggled", G_CALLBACK( callback ), cb_data ); + checkbox = gtk_check_button_new_with_mnemonic (name); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (checkbox), init); + gtk_widget_show (checkbox); + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (checkbox), FALSE, FALSE, 0); + g_signal_connect (checkbox, "toggled", G_CALLBACK (callback), cb_data); } -static void create_drop_down( GtkBox *tab, GtkSizeGroup *sg, const gchar * name, const gchar ** items, gsize nb_items, guint init, void (callback)( GtkComboBox *, CPUGraph * ), void * cb_data) +static void +create_drop_down (GtkBox *tab, GtkSizeGroup *sg, const gchar *name, + const gchar **items, gsize nb_items, guint init, + void (callback)(GtkComboBox *, CPUGraph *), void * cb_data) { - GtkBox *hbox; - GtkWidget *combo; - gint i; + GtkBox *hbox; + GtkWidget *combo; + gint i; - hbox = create_option_line( tab, sg, name ); + hbox = create_option_line (tab, sg, name); - combo = gtk_combo_box_text_new(); - for( i = 0; i < nb_items; i++ ) - { - gtk_combo_box_text_append( GTK_COMBO_BOX_TEXT( combo ), NULL, items[i] ); - } - gtk_combo_box_set_active( GTK_COMBO_BOX( combo), init ); - gtk_box_pack_start( GTK_BOX( hbox ), combo, FALSE, FALSE, 0 ); - gtk_widget_show( combo ); + combo = gtk_combo_box_text_new (); + for (i = 0; i < nb_items; i++) + { + gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (combo), NULL, items[i]); + } + gtk_combo_box_set_active (GTK_COMBO_BOX (combo), init); + gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0); + gtk_widget_show (combo); - g_signal_connect( combo, "changed", G_CALLBACK( callback ), cb_data ); + g_signal_connect (combo, "changed", G_CALLBACK (callback), cb_data); } -static void setup_update_interval_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ) +static void +setup_update_interval_option (GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base) { - const gchar *items[] = { _("Fastest (~250ms)"), - _("Fast (~500ms)"), - _("Normal (~750ms)"), - _("Slow (~1s)") - }; - gsize nb_items = sizeof( items ) / sizeof( gchar* ); + const gchar *items[] = { _("Fastest (~250ms)"), + _("Fast (~500ms)"), + _("Normal (~750ms)"), + _("Slow (~1s)") + }; + gsize nb_items = sizeof (items) / sizeof (gchar*); - create_drop_down( vbox, sg, _("Update Interval:"), items, nb_items, base->update_interval, change_update, base); + create_drop_down (vbox, sg, _("Update Interval:"), items, nb_items, base->update_interval, change_update, base); } -static void setup_tracked_core_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ) +static void +setup_tracked_core_option (GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base) { - gsize nb_items = base->nr_cores + 1; - gchar *items[ nb_items ]; - guint i; - items[0] = _("All"); - for( i = 1; i < nb_items; i++ ) - { - items[i] = g_strdup_printf( "%u", i ); - } - create_drop_down( vbox, sg, _("Tracked Core:"), (const gchar **)items, nb_items, base->tracked_core, change_core, base); - for( i = 1; i < nb_items; i++ ) - g_free( items[i] ); + gsize nb_items = base->nr_cores + 1; + gchar *items[ nb_items ]; + guint i; + items[0] = _("All"); + + for (i = 1; i < nb_items; i++) + { + items[i] = g_strdup_printf ("%u", i); + } + + create_drop_down (vbox, sg, _("Tracked Core:"), (const gchar **) items, nb_items, base->tracked_core, change_core, base); + for (i = 1; i < nb_items; i++) + g_free (items[i]); } -static void setup_size_option( GtkBox *vbox, GtkSizeGroup *sg, XfcePanelPlugin *plugin, CPUGraph *base ) +static void +setup_size_option (GtkBox *vbox, GtkSizeGroup *sg, XfcePanelPlugin *plugin, CPUGraph *base) { - GtkBox *hbox; - GtkWidget *Size; + GtkBox *hbox; + GtkWidget *size; - if( xfce_panel_plugin_get_orientation( plugin ) == GTK_ORIENTATION_HORIZONTAL ) - hbox = create_option_line( vbox, sg, _("Width:") ); - else - hbox = create_option_line( vbox, sg, _("Height:") ); + if (xfce_panel_plugin_get_orientation (plugin) == GTK_ORIENTATION_HORIZONTAL) + hbox = create_option_line (vbox, sg, _("Width:")); + else + hbox = create_option_line (vbox, sg, _("Height:")); - Size = gtk_spin_button_new_with_range( 10, 128, 1 ); - 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( change_size ), base ); + size = gtk_spin_button_new_with_range (10, 128, 1); + 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 (change_size), base); } -static void setup_command_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ) +static void +setup_command_option (GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base) { - GtkBox *hbox; - GtkWidget *AssociateCommand; + GtkBox *hbox; + GtkWidget *associatecommand; - hbox = create_option_line( vbox, sg, _("Associated command:") ); + hbox = create_option_line (vbox, sg, _("Associated command:")); - AssociateCommand = gtk_entry_new(); - gtk_entry_set_text( GTK_ENTRY(AssociateCommand), base->command ); - gtk_widget_show( AssociateCommand ); - gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( AssociateCommand ), FALSE, FALSE, 0 ); - g_signal_connect( AssociateCommand, "changed", G_CALLBACK( change_command ), base ); + associatecommand = gtk_entry_new (); + gtk_entry_set_text (GTK_ENTRY (associatecommand), base->command); + gtk_widget_show (associatecommand); + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (associatecommand), FALSE, FALSE, 0); + g_signal_connect (associatecommand, "changed", G_CALLBACK (change_command), base); } -static void setup_color_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base, guint number, const gchar * name, GCallback cb ) +static void +setup_color_option (GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base, + guint number, const gchar * name, GCallback cb) { - GtkBox *hbox; + GtkBox *hbox; - hbox = create_option_line( vbox, sg, name ); + hbox = create_option_line (vbox, sg, name); - base->color_buttons[number] = gtk_color_button_new_with_rgba( &base->colors[number] ); - gtk_widget_show( GTK_WIDGET( base->color_buttons[number] ) ); - gtk_box_pack_start( GTK_BOX( hbox ), GTK_WIDGET( base->color_buttons[number] ), FALSE, FALSE, 0 ); + base->color_buttons[number] = gtk_color_button_new_with_rgba (&base->colors[number]); + gtk_widget_show (GTK_WIDGET (base->color_buttons[number])); + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (base->color_buttons[number]), FALSE, FALSE, 0); - g_signal_connect( base->color_buttons[number], "color-set", cb, base ); + g_signal_connect (base->color_buttons[number], "color-set", cb, base); } -static void setup_mode_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ) +static void +setup_mode_option (GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base) { - const gchar *items[] = { _("Normal"), - _("LED"), - _("No history"), - _("Grid") - }; - gsize nb_items = sizeof( items ) / sizeof( gchar* ); + const gchar *items[] = { _("Normal"), + _("LED"), + _("No history"), + _("Grid") + }; + gsize nb_items = sizeof (items) / sizeof (gchar*); - create_drop_down( vbox, sg, _("Mode:"), items, nb_items, base->mode, change_mode, base); + create_drop_down (vbox, sg, _("Mode:"), items, nb_items, base->mode, change_mode, base); } -static void setup_color_mode_option( GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base ) +static void +setup_color_mode_option (GtkBox *vbox, GtkSizeGroup *sg, CPUGraph *base) { - const gchar *items[] = { _("Solid"), - _("Gradient"), - _("Fire"), - }; - gsize nb_items = sizeof( items ) / sizeof( gchar* ); + const gchar *items[] = { _("Solid"), + _("Gradient"), + _("Fire"), + }; + gsize nb_items = sizeof (items) / sizeof (gchar*); - create_drop_down( vbox, sg, _("Color mode: "), items, nb_items, base->color_mode, change_color_mode, base); + create_drop_down (vbox, sg, _("Color mode: "), items, nb_items, base->color_mode, change_color_mode, base); } -static void change_in_terminal( GtkToggleButton *button, CPUGraph *base ) +static void +change_in_terminal (GtkToggleButton *button, CPUGraph *base) { - set_in_terminal( base, gtk_toggle_button_get_active( button ) ); + set_in_terminal (base, gtk_toggle_button_get_active (button)); } -static void change_startup_notification( GtkToggleButton *button, CPUGraph *base ) +static void +change_startup_notification (GtkToggleButton *button, CPUGraph *base) { - set_startup_notification( base, gtk_toggle_button_get_active( button ) ); + set_startup_notification (base, gtk_toggle_button_get_active (button)); } -static void change_command( GtkEntry *entry, CPUGraph * base ) +static void +change_command (GtkEntry *entry, CPUGraph *base) { - set_command( base, gtk_entry_get_text( entry ) ); + set_command (base, gtk_entry_get_text (entry)); } -static void change_color( GtkColorButton * button, CPUGraph * base, guint number) +static void +change_color (GtkColorButton *button, CPUGraph *base, guint number) { - GdkRGBA color; - gtk_color_chooser_get_rgba( GTK_COLOR_CHOOSER( button ), &color ); - set_color( base, number, color ); + GdkRGBA color; + gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER (button), &color); + set_color (base, number, color); } -static void change_color_1( GtkColorButton * button, CPUGraph * base ) +static void +change_color_1 (GtkColorButton *button, CPUGraph *base) { - change_color( button, base, 1); + change_color (button, base, 1); } -static void change_color_2( GtkColorButton * button, CPUGraph * base ) +static void +change_color_2 (GtkColorButton *button, CPUGraph *base) { - change_color( button, base, 2); + change_color (button, base, 2); } -static void change_color_3( GtkColorButton * button, CPUGraph * base ) +static void +change_color_3 (GtkColorButton *button, CPUGraph *base) { - change_color( button, base, 3); + change_color (button, base, 3); } -static void change_color_0( GtkColorButton * button, CPUGraph * base ) +static void +change_color_0 (GtkColorButton *button, CPUGraph *base) { - change_color( button, base, 0); + change_color (button, base, 0); } -static void change_color_4( GtkColorButton * button, CPUGraph * base ) +static void +change_color_4 (GtkColorButton *button, CPUGraph *base) { - base->has_barcolor = TRUE; - change_color( button, base, 4); + base->has_barcolor = TRUE; + change_color (button, base, 4); } -static void select_active_colors( CPUGraph * base ) +static void +select_active_colors (CPUGraph *base) { - if( base->color_mode != 0 || base->mode == 1 || base->mode == 3 ) - gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[2] ), TRUE ); - else - gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[2] ), FALSE ); + if (base->color_mode != 0 || base->mode == 1 || base->mode == 3) + gtk_widget_set_sensitive (GTK_WIDGET (base->color_buttons[2]), TRUE); + else + gtk_widget_set_sensitive (GTK_WIDGET (base->color_buttons[2]), FALSE); - if( base->color_mode != 0 && base->mode == 1 ) - gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[3] ), TRUE ); - else - gtk_widget_set_sensitive( GTK_WIDGET( base->color_buttons[3] ), FALSE ); + if (base->color_mode != 0 && base->mode == 1) + gtk_widget_set_sensitive (GTK_WIDGET (base->color_buttons[3]), TRUE); + else + gtk_widget_set_sensitive (GTK_WIDGET (base->color_buttons[3]), FALSE); } -static void select_active_barscolors( CPUGraph * base ) +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 ); + 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 ) +static void +change_mode (GtkComboBox *combo, CPUGraph *base) { - set_mode( base, gtk_combo_box_get_active( combo ) ); - select_active_colors( base ); + set_mode (base, gtk_combo_box_get_active (combo)); + select_active_colors (base); } -static void change_color_mode( GtkComboBox * combo, CPUGraph * base ) +static void +change_color_mode (GtkComboBox *combo, CPUGraph *base) { - set_color_mode( base, gtk_combo_box_get_active( combo ) ); - select_active_colors( base ); + set_color_mode (base, gtk_combo_box_get_active (combo)); + select_active_colors (base); } -static void response_cb( GtkWidget *dlg, gint response, CPUGraph *base ) +static void +response_cb (GtkWidget *dlg, gint response, CPUGraph *base) { - gtk_widget_destroy( dlg ); - xfce_panel_plugin_unblock_menu( base->plugin ); - write_settings( base->plugin, base ); + gtk_widget_destroy (dlg); + xfce_panel_plugin_unblock_menu (base->plugin); + write_settings (base->plugin, base); } -static void change_frame( GtkToggleButton * button, CPUGraph * base ) +static void +change_frame (GtkToggleButton *button, CPUGraph *base) { - set_frame( base, gtk_toggle_button_get_active( button ) ); + set_frame (base, gtk_toggle_button_get_active (button)); } -static void change_border( GtkToggleButton * button, CPUGraph * base ) +static void +change_border (GtkToggleButton *button, CPUGraph *base) { - set_border( base, gtk_toggle_button_get_active( button ) ); + set_border (base, gtk_toggle_button_get_active (button)); } -static void change_bars( 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 ); + set_bars (base, gtk_toggle_button_get_active (button)); + select_active_barscolors (base); } -static void change_size( GtkSpinButton * sb, CPUGraph *base) +static void +change_size (GtkSpinButton *sb, CPUGraph *base) { - set_size( base, gtk_spin_button_get_value_as_int( sb ) ); + set_size (base, gtk_spin_button_get_value_as_int (sb)); } -static void change_time_scale( GtkToggleButton * button, CPUGraph * base ) +static void change_time_scale (GtkToggleButton *button, CPUGraph *base) { - set_nonlinear_time( base, gtk_toggle_button_get_active( button ) ); + set_nonlinear_time (base, gtk_toggle_button_get_active (button)); } -static void change_update( GtkComboBox * combo, CPUGraph * base ) +static void change_update (GtkComboBox *combo, CPUGraph *base) { - set_update_rate( base, gtk_combo_box_get_active( combo ) ); + set_update_rate (base, gtk_combo_box_get_active (combo)); } -static void change_core( GtkComboBox * combo, CPUGraph * base ) +static void change_core (GtkComboBox *combo, CPUGraph *base) { - set_tracked_core( base, gtk_combo_box_get_active( combo ) ); + set_tracked_core (base, gtk_combo_box_get_active (combo)); } diff --git a/panel-plugin/properties.h b/panel-plugin/properties.h index 5a2d6a1..b253ebb 100644 --- a/panel-plugin/properties.h +++ b/panel-plugin/properties.h @@ -26,6 +26,6 @@ #include "cpu.h" -void create_options( XfcePanelPlugin *plugin, CPUGraph *base ); +void create_options (XfcePanelPlugin *plugin, CPUGraph *base); #endif /* !_XFCE_PROPERTIES_H_ */ diff --git a/panel-plugin/settings.c b/panel-plugin/settings.c index 2676edf..76375ff 100644 --- a/panel-plugin/settings.c +++ b/panel-plugin/settings.c @@ -24,165 +24,168 @@ #include "settings.h" #include <libxfce4ui/libxfce4ui.h> -static void default_command( const gchar ** command, gboolean * in_terminal, gboolean * startup_notification ) +static void +default_command (const gchar **command, gboolean *in_terminal, gboolean *startup_notification) { - gchar * s = g_find_program_in_path( "xfce4-taskmanager"); - if( s != NULL ) - { - g_free( s ); - *command = "xfce4-taskmanager"; - *in_terminal = FALSE; - *startup_notification = TRUE; - } - else - { - *command = "top"; - *in_terminal = TRUE; - *startup_notification = FALSE; - } + gchar *s = g_find_program_in_path ("xfce4-taskmanager"); + if (s != NULL) + { + g_free (s); + *command = "xfce4-taskmanager"; + *in_terminal = FALSE; + *startup_notification = TRUE; + } + else + { + *command = "top"; + *in_terminal = TRUE; + *startup_notification = FALSE; + } } -void read_settings( XfcePanelPlugin * plugin, CPUGraph * base ) +void +read_settings (XfcePanelPlugin *plugin, CPUGraph *base) { - const char *value; - char *file; - XfceRc *rc; - - guint rate = 0; - gboolean nonlinear = FALSE; - guint mode = 0; - guint color_mode = 0; - gboolean frame = TRUE; - gboolean border = TRUE; - gboolean bars = TRUE; - guint tracked_core = 0; - - GdkRGBA foreground1; - GdkRGBA foreground2; - GdkRGBA foreground3; - GdkRGBA background; - GdkRGBA barscolor; - guint size; - const gchar *associated_command; - gboolean in_terminal; - gboolean startup_notification; - - foreground1.red = 0.0; - foreground1.green = 1.0; - foreground1.blue = 0.0; - foreground1.alpha = 1.0; - - foreground2.red = 1.0; - foreground2.green = 0.0; - foreground2.blue = 0.0; - foreground2.alpha = 1.0; - - foreground3.red = 0.0; - foreground3.green = 0.0; - foreground3.blue = 1.0; - foreground3.alpha = 1.0; - - background.red = 1.0; - background.green = 1.0; - background.blue = 1.0; - background.alpha = 1.0; - - barscolor.red = 1.0; - barscolor.green = 0.73048; - barscolor.blue = 0.0; - barscolor.alpha = 1.0; - - size = xfce_panel_plugin_get_size( plugin ); - default_command( &associated_command, &in_terminal, &startup_notification ); - - if( (file = xfce_panel_plugin_lookup_rc_file( plugin )) != NULL ) - { - rc = xfce_rc_simple_open( file, TRUE ); - g_free( file ); - - if( rc ) - { - rate = xfce_rc_read_int_entry (rc, "UpdateInterval", rate ); - nonlinear = xfce_rc_read_int_entry (rc, "TimeScale", nonlinear ); - 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 ); - associated_command = g_strdup(xfce_rc_read_entry( rc, "Command", associated_command )); - in_terminal = xfce_rc_read_int_entry( rc, "InTerminal", in_terminal ); - startup_notification = xfce_rc_read_int_entry( rc, "StartupNotification", startup_notification ); - border = xfce_rc_read_int_entry( rc, "Border", border ); - bars = xfce_rc_read_int_entry( rc, "Bars", bars ); - tracked_core = xfce_rc_read_int_entry( rc, "TrackedCore", tracked_core ); - - if( (value = xfce_rc_read_entry( rc, "Foreground1", NULL )) ) - gdk_rgba_parse( &foreground1, value ); - if( (value = xfce_rc_read_entry( rc, "Foreground2", NULL )) ) - gdk_rgba_parse( &foreground2, value ); - if( (value = xfce_rc_read_entry( rc, "Foreground3", NULL )) ) - gdk_rgba_parse( &foreground3, value ); - if( (value = xfce_rc_read_entry( rc, "Background", NULL )) ) - gdk_rgba_parse( &background, value ); - if( (value = xfce_rc_read_entry( rc, "BarsColor", NULL )) ) { - gdk_rgba_parse( &barscolor, value ); - base->has_barcolor = TRUE; - } - - xfce_rc_close( rc ); - } - } - - set_update_rate( base, rate ); - set_nonlinear_time( base, nonlinear ); - set_size( base, size ); - set_mode( base, mode ); - set_color_mode( base, color_mode ); - set_frame( base, frame ); - set_command( base, associated_command ); - set_in_terminal( base, in_terminal); - set_startup_notification( base, startup_notification ); - set_border( base, border); - set_tracked_core( base, tracked_core ); - set_bars( base, bars); - set_color( base, 1, foreground1 ); - set_color( base, 2, foreground2 ); - set_color( base, 3, foreground3 ); - set_color( base, 0, background ); - set_color( base, 4, barscolor ); + const char *value; + char *file; + XfceRc *rc; + + guint rate = 0; + gboolean nonlinear = FALSE; + guint mode = 0; + guint color_mode = 0; + gboolean frame = TRUE; + gboolean border = TRUE; + gboolean bars = TRUE; + guint tracked_core = 0; + + GdkRGBA foreground1; + GdkRGBA foreground2; + GdkRGBA foreground3; + GdkRGBA background; + GdkRGBA barscolor; + guint size; + const gchar *associated_command; + gboolean in_terminal; + gboolean startup_notification; + + foreground1.red = 0.0; + foreground1.green = 1.0; + foreground1.blue = 0.0; + foreground1.alpha = 1.0; + + foreground2.red = 1.0; + foreground2.green = 0.0; + foreground2.blue = 0.0; + foreground2.alpha = 1.0; + + foreground3.red = 0.0; + foreground3.green = 0.0; + foreground3.blue = 1.0; + foreground3.alpha = 1.0; + + background.red = 1.0; + background.green = 1.0; + background.blue = 1.0; + background.alpha = 1.0; + + barscolor.red = 1.0; + barscolor.green = 0.73048; + barscolor.blue = 0.0; + barscolor.alpha = 1.0; + + size = xfce_panel_plugin_get_size (plugin); + default_command (&associated_command, &in_terminal, &startup_notification); + + if ((file = xfce_panel_plugin_lookup_rc_file (plugin)) != NULL) + { + rc = xfce_rc_simple_open (file, TRUE); + g_free (file); + + if (rc) + { + rate = xfce_rc_read_int_entry (rc, "UpdateInterval", rate); + nonlinear = xfce_rc_read_int_entry (rc, "TimeScale", nonlinear); + 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); + associated_command = g_strdup (xfce_rc_read_entry (rc, "Command", associated_command)); + in_terminal = xfce_rc_read_int_entry (rc, "InTerminal", in_terminal); + startup_notification = xfce_rc_read_int_entry (rc, "StartupNotification", startup_notification); + border = xfce_rc_read_int_entry (rc, "Border", border); + bars = xfce_rc_read_int_entry (rc, "Bars", bars); + tracked_core = xfce_rc_read_int_entry (rc, "TrackedCore", tracked_core); + + if ((value = xfce_rc_read_entry (rc, "Foreground1", NULL))) + gdk_rgba_parse (&foreground1, value); + if ((value = xfce_rc_read_entry (rc, "Foreground2", NULL))) + gdk_rgba_parse (&foreground2, value); + if ((value = xfce_rc_read_entry (rc, "Foreground3", NULL))) + gdk_rgba_parse (&foreground3, value); + if ((value = xfce_rc_read_entry (rc, "Background", NULL))) + gdk_rgba_parse (&background, value); + if ((value = xfce_rc_read_entry (rc, "BarsColor", NULL))) { + gdk_rgba_parse (&barscolor, value); + base->has_barcolor = TRUE; + } + + xfce_rc_close (rc); + } + } + + set_update_rate (base, rate); + set_nonlinear_time (base, nonlinear); + set_size (base, size); + set_mode (base, mode); + set_color_mode (base, color_mode); + set_frame (base, frame); + set_command (base, associated_command); + set_in_terminal (base, in_terminal); + set_startup_notification (base, startup_notification); + set_border (base, border); + set_tracked_core (base, tracked_core); + set_bars (base, bars); + set_color (base, 1, foreground1); + 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 ) +void +write_settings (XfcePanelPlugin *plugin, CPUGraph *base) { - XfceRc *rc; - char *file; - - if( !(file = xfce_panel_plugin_save_location( plugin, TRUE )) ) - return; - - rc = xfce_rc_simple_open( file, FALSE ); - g_free( file ); - - if( !rc ) - return; - - xfce_rc_write_int_entry( rc, "UpdateInterval", base->update_interval ); - xfce_rc_write_int_entry( rc, "TimeScale", base->non_linear ); - xfce_rc_write_int_entry( rc, "Size", base->size ); - xfce_rc_write_int_entry( rc, "Mode", base->mode ); - xfce_rc_write_int_entry( rc, "Frame", base->has_frame ); - xfce_rc_write_int_entry( rc, "Border", base->has_border ); - xfce_rc_write_int_entry( rc, "Bars", base->has_bars ); - xfce_rc_write_int_entry( rc, "TrackedCore", base->tracked_core ); - xfce_rc_write_entry( rc, "Command", base->command ? base->command : "" ); - xfce_rc_write_int_entry( rc, "InTerminal", base->in_terminal ); - xfce_rc_write_int_entry( rc, "StartupNotification", base->startup_notification ); - xfce_rc_write_int_entry( rc, "ColorMode", base->color_mode ); - - xfce_rc_write_entry( rc, "Foreground1", gdk_rgba_to_string(&(base->colors[1])) ); - xfce_rc_write_entry( rc, "Foreground2", gdk_rgba_to_string(&(base->colors[2])) ); - xfce_rc_write_entry( rc, "Foreground3", gdk_rgba_to_string(&(base->colors[3])) ); - xfce_rc_write_entry( rc, "Background", gdk_rgba_to_string(&(base->colors[0])) ); - if (base->has_barcolor) - xfce_rc_write_entry( rc, "BarsColor", gdk_rgba_to_string(&(base->colors[4])) ); - xfce_rc_close( rc ); + XfceRc *rc; + char *file; + + if (!(file = xfce_panel_plugin_save_location (plugin, TRUE))) + return; + + rc = xfce_rc_simple_open (file, FALSE); + g_free (file); + + if (!rc) + return; + + xfce_rc_write_int_entry (rc, "UpdateInterval", base->update_interval); + xfce_rc_write_int_entry (rc, "TimeScale", base->non_linear); + xfce_rc_write_int_entry (rc, "Size", base->size); + xfce_rc_write_int_entry (rc, "Mode", base->mode); + xfce_rc_write_int_entry (rc, "Frame", base->has_frame); + xfce_rc_write_int_entry (rc, "Border", base->has_border); + xfce_rc_write_int_entry (rc, "Bars", base->has_bars); + xfce_rc_write_int_entry (rc, "TrackedCore", base->tracked_core); + xfce_rc_write_entry (rc, "Command", base->command ? base->command : ""); + xfce_rc_write_int_entry (rc, "InTerminal", base->in_terminal); + xfce_rc_write_int_entry (rc, "StartupNotification", base->startup_notification); + xfce_rc_write_int_entry (rc, "ColorMode", base->color_mode); + + xfce_rc_write_entry (rc, "Foreground1", gdk_rgba_to_string (&(base->colors[1]))); + xfce_rc_write_entry (rc, "Foreground2", gdk_rgba_to_string (&(base->colors[2]))); + xfce_rc_write_entry (rc, "Foreground3", gdk_rgba_to_string (&(base->colors[3]))); + xfce_rc_write_entry (rc, "Background", gdk_rgba_to_string (&(base->colors[0]))); + if (base->has_barcolor) + xfce_rc_write_entry (rc, "BarsColor", gdk_rgba_to_string (&(base->colors[4]))); + xfce_rc_close (rc); } diff --git a/panel-plugin/settings.h b/panel-plugin/settings.h index 77d8648..61f1f76 100644 --- a/panel-plugin/settings.h +++ b/panel-plugin/settings.h @@ -26,7 +26,7 @@ #include "cpu.h" -void read_settings( XfcePanelPlugin *plugin, CPUGraph *base ); -void write_settings( XfcePanelPlugin *plugin, CPUGraph *base ); +void read_settings (XfcePanelPlugin *plugin, CPUGraph *base); +void write_settings (XfcePanelPlugin *plugin, CPUGraph *base); #endif /* !_XFCE_SETTINGS_H_ */ -- To stop receiving notification emails like this one, please contact the administrator of this repository. _______________________________________________ Xfce4-commits mailing list Xfce4-commits@xfce.org https://mail.xfce.org/mailman/listinfo/xfce4-commits