diff -ru xfce4-cpufreq-plugin-1.1.3/panel-plugin/xfce4-cpufreq-plugin.c xfce4-cpufreq-plugin-1.1.3.new/panel-plugin/xfce4-cpufreq-plugin.c --- xfce4-cpufreq-plugin-1.1.3/panel-plugin/xfce4-cpufreq-plugin.c 2014-12-22 18:50:31.000000000 +0100 +++ xfce4-cpufreq-plugin-1.1.3.new/panel-plugin/xfce4-cpufreq-plugin.c 2017-10-15 17:25:42.887394624 +0200 @@ -302,6 +302,61 @@ return cpu; } +static +void cpufreq_update_pixmap(CpuInfo *cpu) +{ + GdkPixbuf *cur_pixmap; + GdkPixbuf *img_pixmap; + gint freq_hash; + + gdouble delta = cpu->max_freq - cpu->min_freq; + + if (delta <= 0.0) + return; + + freq_hash = cpu->cur_freq >> 16; + + cur_pixmap = g_hash_table_lookup(cpuFreq->colored_pixmaps, + GINT_TO_POINTER(freq_hash)); + + if (!cur_pixmap) { + guchar *pixels = NULL; + gsize plength; + gsize pcomps; + gsize p; + + gdouble scale = (cpu->cur_freq - cpu->min_freq) / delta; + if (scale > 1.0) + scale = 1.0; + + guint val = (guchar)(255.0 * scale); + cur_pixmap = gdk_pixbuf_copy (cpuFreq->template_icon); + + if (!cur_pixmap) + return; + + pixels = gdk_pixbuf_get_pixels (cur_pixmap); + plength = gdk_pixbuf_get_byte_length (cur_pixmap); + pcomps = gdk_pixbuf_get_n_channels (cur_pixmap); + + for (p = 0; p < plength; p += pcomps) { + gint delta1 = abs(pixels[p] - pixels[p+1]); + gint delta2 = abs(pixels[p] - pixels[p+2]); + if (delta1 < 10 && delta2 < 10) + pixels[p] = val; + } + + g_hash_table_insert(cpuFreq->colored_pixmaps, + GINT_TO_POINTER(freq_hash), cur_pixmap); + } + gdk_pixbuf_copy_area (cur_pixmap, 0, 0, + gdk_pixbuf_get_width(cur_pixmap), + gdk_pixbuf_get_height(cur_pixmap), + gtk_image_get_pixbuf(cpuFreq->icon), + 0, 0); + gtk_widget_queue_draw (cpuFreq->icon); +} + gboolean cpufreq_update_plugin (gboolean reset_label_size) { @@ -318,6 +373,8 @@ ret = cpufreq_update_label (cpu); + cpufreq_update_pixmap(cpu); + if (cpuFreq->layout_changed) { cpufreq_label_set_font (); cpufreq_widgets_layout (); @@ -412,16 +469,23 @@ !cpufreq->options->show_label_governor)) icon_size -= 4; - buf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), + if (cpufreq->template_icon) + g_object_unref (G_OBJECT (cpufreq->template_icon)); + + cpufreq->template_icon = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), "xfce4-cpufreq-plugin", icon_size, 0, NULL); - if (buf) { - cpufreq->icon = gtk_image_new_from_pixbuf (buf); - g_object_unref (G_OBJECT (buf)); + if (cpufreq->template_icon) { + cpufreq->icon = gtk_image_new_from_pixbuf (cpufreq->template_icon); } else { cpufreq->icon = gtk_image_new_from_icon_name ("xfce4-cpufreq-plugin", GTK_ICON_SIZE_BUTTON); + cpufreq->template_icon = gtk_image_get_pixbuf(cpufreq->icon); } + + cpufreq->template_icon = gdk_pixbuf_copy(cpufreq->template_icon); + g_hash_table_remove_all (cpufreq->colored_pixmaps); + gtk_box_pack_start (GTK_BOX (cpufreq->box), cpufreq->icon, FALSE, FALSE, 0); gtk_widget_show (cpufreq->icon); } @@ -555,6 +619,9 @@ { gint i; + g_object_unref(G_OBJECT(cpuFreq->template_icon)); + g_hash_table_unref(cpuFreq->colored_pixmaps); + if (cpuFreq->timeoutHandle) g_source_remove (cpuFreq->timeoutHandle); @@ -625,7 +692,11 @@ cpuFreq->panel_size = xfce_panel_plugin_get_size (cpuFreq->plugin); cpuFreq->label_max_width = -1; cpuFreq->cpus = g_ptr_array_new (); - + cpuFreq->template_icon = NULL; + cpuFreq->colored_pixmaps = g_hash_table_new_full (NULL, + NULL, + NULL, + g_object_unref); cpufreq_read_config (); cpuFreq->layout_changed = TRUE; diff -ru xfce4-cpufreq-plugin-1.1.3/panel-plugin/xfce4-cpufreq-plugin.h xfce4-cpufreq-plugin-1.1.3.new/panel-plugin/xfce4-cpufreq-plugin.h --- xfce4-cpufreq-plugin-1.1.3/panel-plugin/xfce4-cpufreq-plugin.h 2014-12-22 18:50:31.000000000 +0100 +++ xfce4-cpufreq-plugin-1.1.3.new/panel-plugin/xfce4-cpufreq-plugin.h 2017-10-15 17:26:35.183787170 +0200 @@ -81,8 +81,13 @@ /* Intel P-State parameters */ IntelPState *intel_pstate; + /* Table with frequency color coded pixbufs */ + GHashTable *colored_pixmaps; + /* Widgets */ - GtkWidget *button, *box, *icon, *label; + GtkWidget *button, *box, *label; + GtkImage *icon; + GdkPixbuf *template_icon; gboolean layout_changed; gint label_max_width;