/*
* Cpumem-applet - status area plugin
+ *
+ * Copyright (c) 2005-2009 Jakub Pavelek
+ * Copyright (c) 2009-2010 Tuomo Tanskanen
*/
-
#include <gtk/gtk.h>
#include <hildon/hildon.h>
#include <glib/gerror.h>
* Read current MEM usage and return indicator between 5 and 1 - how many bars are "full"
*/
static guchar
-la_check_mem (CpumemAppletStatusAreaItemPrivate *priv)
+check_mem (CpumemAppletStatusAreaItemPrivate *priv)
{
#define MEMFILE "/proc/meminfo"
#define MAX_READ_CHARS 128
* Read current CPU usage and return indicator between 5 and 1 - how many bars are "full"
*/
static guchar
-la_check_cpu (CpumemAppletStatusAreaItemPrivate *priv)
+check_cpu (CpumemAppletStatusAreaItemPrivate *priv)
{
#define CPUFILE "/proc/stat"
gint curU, curN, curIO, curI;
* Compose and blit the current status of memory bars
*/
static void
-la_blit_memory_bars (const guchar level, CpumemAppletStatusAreaItemPrivate *priv)
+blit_mem_barsconst guchar level, CpumemAppletStatusAreaItemPrivate *priv)
{
guint x, y;
x = 9;
y = 1;
if (level > 4)
- gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
y = 5;
if (level > 3)
- gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
y = 9;
if (level > 2)
- gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
y = 13;
if (level > 1)
- gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
else
- gdk_pixbuf_composite(priv->pixbuf_off, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_off, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
}
* Compose and blit current status of CPU bars
*/
static void
-la_blit_cpu_bars (const guchar level, CpumemAppletStatusAreaItemPrivate *priv)
+blit_cpu_bars (const guchar level, CpumemAppletStatusAreaItemPrivate *priv)
{
guint x, y;
if (level > 4)
{
if (priv->red == TRUE) {
- gdk_pixbuf_composite(priv->pixbuf_red, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_red, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
priv->red = FALSE;
} else {
- gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
priv->red = TRUE;
}
}
y = 5;
if (level > 3)
- gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
y = 9;
if (level > 2)
- gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
y = 13;
if (level > 1)
- gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_on, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
else
- gdk_pixbuf_composite(priv->pixbuf_off, priv->pixbuf, x, y, CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
+ gdk_pixbuf_composite(priv->pixbuf_off, priv->pixbuf, x, y,
+ CPUMEM_BOX_WIDTH, CPUMEM_BOX_HEIGHT, x, y, 1, 1, GDK_INTERP_NEAREST, 255);
}
* Ran to check and update the CPU and memory reading
*/
static gboolean
-la_check_load (gpointer data)
+check_load (gpointer data)
{
guchar current_cpu_level;
guchar current_mem_level;
CpumemAppletStatusAreaItem *item = (CpumemAppletStatusAreaItem*)data;
CpumemAppletStatusAreaItemPrivate *priv = (CpumemAppletStatusAreaItemPrivate*)item->priv;
- current_cpu_level = la_check_cpu(priv);
- current_mem_level = la_check_mem(priv);
+ current_cpu_level = check_cpu(priv);
+ current_mem_level = check_mem(priv);
//g_debug(g_strdup_printf("LOADAPLET - UPDATED CPU %d MEM %d", current_cpu_level, current_mem_level));
//Update and blit only if data changed!
if ((current_mem_level != priv->last_mem_level) || (current_cpu_level != priv->last_cpu_level)) {
- la_blit_memory_bars (current_mem_level, priv);
- la_blit_cpu_bars (current_cpu_level, priv);
+ blit_mem_bars (current_mem_level, priv);
+ blit_cpu_bars (current_cpu_level, priv);
if (current_cpu_level == CPUMEM_CPU_MAX)
priv->red = FALSE;
hd_status_plugin_item_set_status_area_icon (HD_STATUS_PLUGIN_ITEM(data), priv->pixbuf);
priv->last_cpu_level = current_cpu_level;
} else if (current_cpu_level == CPUMEM_CPU_MAX) {
//Pulsate max CPU load icon also when CPU load stays at max
- la_blit_cpu_bars (current_cpu_level, priv);
+ blit_cpu_bars (current_cpu_level, priv);
hd_status_plugin_item_set_status_area_icon (HD_STATUS_PLUGIN_ITEM(data), priv->pixbuf);
}
if (state == OSSO_DISPLAY_ON)
{
//Restart the updates, do one right away
- if (item->priv->timeout_id == -1)
+ if (item->priv->timeout_id == 0)
{
- item->priv->timeout_id = gtk_timeout_add(1000, la_check_load, item);
+ item->priv->timeout_id = gtk_timeout_add(1000, check_load, item);
+ check_load(item);
}
} else {
//Suspend the updates - screen is off
- if (g_source_remove(item->priv->timeout_id) != TRUE)
- {
- } else {
- item->priv->timeout_id = -1;
+ if (item->priv->timeout_id) != 0) {
+ g_source_remove(item->priv->timeout_id);
+ item->priv->timeout_id = 0;
}
}
}
cpumem_applet_status_area_item_set_area_icon(item);
item->priv->osso = osso_initialize ("cpumem_applet_status_area_item", "Maemo5", TRUE, NULL);
- item->priv->timeout_id = gtk_timeout_add(1000, la_check_load, item);
+ item->priv->timeout_id = gtk_timeout_add(1000, check_load, item);
osso_hw_set_display_event_cb (item->priv->osso, cpumem_applet_status_area_item_display_cb, item);
}