summaryrefslogtreecommitdiff
path: root/multiload/cpuload.c
diff options
context:
space:
mode:
authorMartin Baulig <martin@home-of-linux.org>1998-12-28 14:58:43 +0000
committerMartin Baulig <martin@src.gnome.org>1998-12-28 14:58:43 +0000
commit2dfb06da16c7f1bade882256e9e855c04ae76c50 (patch)
treead6946816c9a60b466c4a3c6ed0fdc4a9a7799e2 /multiload/cpuload.c
parentc81b2fbb0e4a9bd24e29bb399cd0f51381e71969 (diff)
The "MultiLoad Applet Revolution".
1998-12-28 Martin Baulig <martin@home-of-linux.org> The "MultiLoad Applet Revolution". All three multiload applets (cpuload, memload, swapload) now use the same load graph object and the same properties code. This will make it much easier to add a new applet here. * multiload/cpuload.h: Removed. * multiload/memload.h: Removed. * multiload/swapload.h: Removed. * multiload/properties-cpu.[ch]: Removed. * multiload/properties-mem.[ch]: Removed. * multiload/properties-swap.[ch]: Removed. * multiload/global.h: New file. * multiload/property-entries.[ch]: New files. This code will be moved into libgnomeui after GNOME 1.0 is released. * multiload/load-graph.[ch]: New files. Contains some kind of load graph widget/object that is used in all multiload applets. * multiload/properties.[ch]: New files. Contains general properties stuff that is used in all multiload applets. * multiload/cpuload.c: Use the new load graph. * multiload/memload.c: Likewise. * multiload/swapload.c: Likewise.
Diffstat (limited to 'multiload/cpuload.c')
-rw-r--r--multiload/cpuload.c242
1 files changed, 37 insertions, 205 deletions
diff --git a/multiload/cpuload.c b/multiload/cpuload.c
index 616cbdcd5..37a9096fa 100644
--- a/multiload/cpuload.c
+++ b/multiload/cpuload.c
@@ -21,185 +21,15 @@
#include <gdk/gdkx.h>
#include <applet-widget.h>
-#include "linux-proc.h"
-#include "properties-cpu.h"
-#include "cpuload.h"
-
-cpuload_properties cpu_props;
-
-static guchar udata [128];
-static guchar oudata [128];
-static guchar sdata [128];
-static guchar osdata [128];
-
-static int
-draw (gpointer data_ptr)
-{
- int usr=0, sys=0, nice=0, free=0, i;
- Cpuload *c = (Cpuload *) data_ptr;
-
- GetLoad (cpu_props.height, &usr, &nice, &sys, &free );
-
- for (i=0; i < cpu_props.width-1; i++) {
- udata [i+1] = oudata [i];
- sdata [i+1] = osdata [i];
- }
- udata [0] = usr;
- sdata [0] = sys;
-
- /* Erase Rectangle */
- gdk_draw_rectangle (c->pixmap,
- c->disp->style->black_gc,
- TRUE, 0, 0,
- c->disp->allocation.width,
- c->disp->allocation.height);
-
- gdk_gc_set_foreground (c->gc, &c->ucolor);
- for (i=0; i < cpu_props.width; i++) {
- if (udata[i])
- gdk_draw_line (c->pixmap,
- c->gc,
- i, cpu_props.height,
- i, (cpu_props.height - udata[i]));
- }
-
- gdk_gc_set_foreground (c->gc, &c->scolor);
- for (i=0; i < cpu_props.width; i++) {
- if (sdata[i])
- gdk_draw_line (c->pixmap,
- c->gc,
- i, (cpu_props.height - udata[i]),
- i, ((cpu_props.height - udata[i]) -
- sdata[i]));
- }
-
- gdk_draw_pixmap (c->disp->window,
- c->disp->style->fg_gc [GTK_WIDGET_STATE(c->disp)],
- c->pixmap,
- 0, 0,
- 0, 0,
- c->disp->allocation.width,
- c->disp->allocation.height);
-
- for (i=0; i < cpu_props.width; i++) {
- oudata[i] = udata[i];
- osdata[i] = sdata[i];
- }
- return TRUE;
-}
-
-static gint
-cpuload_configure (GtkWidget *widget, GdkEventConfigure *event,
- gpointer data_ptr)
-{
- Cpuload *c = (Cpuload *) data_ptr;
-
- c->pixmap = gdk_pixmap_new (widget->window,
- widget->allocation.width,
- widget->allocation.height,
- gtk_widget_get_visual (c->disp)->depth);
- gdk_draw_rectangle (c->pixmap,
- widget->style->black_gc,
- TRUE, 0,0,
- widget->allocation.width,
- widget->allocation.height);
- gdk_draw_pixmap (widget->window,
- c->disp->style->fg_gc [GTK_WIDGET_STATE(widget)],
- c->pixmap,
- 0, 0,
- 0, 0,
- c->disp->allocation.width,
- c->disp->allocation.height);
- return TRUE;
-}
-
-static gint
-cpuload_expose (GtkWidget *widget, GdkEventExpose *event,
- gpointer data_ptr)
-{
- Cpuload *c = (Cpuload *) data_ptr;
-
- gdk_draw_pixmap (widget->window,
- widget->style->fg_gc [GTK_WIDGET_STATE(widget)],
- c->pixmap,
- event->area.x, event->area.y,
- event->area.x, event->area.y,
- event->area.width, event->area.height);
- return FALSE;
-}
-
-static Cpuload *
-cpuload_new (void)
-{
- GtkWidget *box;
- Cpuload *c;
-
- c = g_malloc (sizeof (Cpuload));
- memset (c, 0, sizeof (Cpuload));
-
- c->timer_index = -1;
-
- box = gtk_vbox_new (FALSE, FALSE);
- gtk_widget_show (box);
-
- c->frame = gtk_frame_new (NULL);
- gtk_frame_set_shadow_type (GTK_FRAME (c->frame),
- cpu_props.look?GTK_SHADOW_OUT:GTK_SHADOW_IN);
-
- c->disp = gtk_drawing_area_new ();
- gtk_signal_connect (GTK_OBJECT (c->disp), "expose_event",
- (GtkSignalFunc)cpuload_expose, c);
- gtk_signal_connect (GTK_OBJECT(c->disp), "configure_event",
- (GtkSignalFunc)cpuload_configure, c);
- gtk_widget_set_events (c->disp, GDK_EXPOSURE_MASK);
-
- gtk_box_pack_start_defaults (GTK_BOX (box), c->disp);
- gtk_container_add (GTK_CONTAINER (c->frame), box);
-
- gtk_widget_set_usize (c->disp, cpu_props.width, cpu_props.height);
-
- cpuload_start_timer (c);
-
- gtk_widget_show_all (c->frame);
- return c;
-}
-
-void
-cpuload_start_timer (Cpuload *c)
-{
- if (c->timer_index != -1)
- gtk_timeout_remove (c->timer_index);
-
- c->timer_index =
- gtk_timeout_add (cpu_props.speed, (GtkFunction)draw, c);
-}
-
-void
-cpuload_setup_colors (Cpuload *c)
-{
- GdkColormap *colormap;
-
- colormap = gtk_widget_get_colormap (c->disp);
-
- gdk_color_parse (cpu_props.ucolor, &c->ucolor);
- gdk_color_alloc (colormap, &c->ucolor);
-
- gdk_color_parse (cpu_props.scolor, &c->scolor);
- gdk_color_alloc (colormap, &c->scolor);
-}
-
-static void
-create_gc (Cpuload *c)
-{
- c->gc = gdk_gc_new (c->disp->window);
- gdk_gc_copy (c->gc, c->disp->style->white_gc);
-}
+#include "global.h"
static gint
applet_save_session (GtkWidget *widget, char *privcfgpath,
char *globcfgpath, gpointer data)
{
+#if 0
save_cpu_properties (privcfgpath, &cpu_props);
+#endif
return FALSE;
}
@@ -207,36 +37,38 @@ applet_save_session (GtkWidget *widget, char *privcfgpath,
GtkWidget *
make_cpuload_applet (const gchar *goad_id)
{
- GtkWidget *applet;
- GtkWidget *label;
- Cpuload *cpuload;
-
- /* create a new applet_widget */
- applet = applet_widget_new(goad_id);
- /* in the rare case that the communication with the panel
- failed, error out */
- if (!applet)
- g_error ("Can't create applet!\n");
-
- load_cpu_properties (APPLET_WIDGET(applet)->privcfgpath, &cpu_props);
-
- cpuload = cpuload_new ();
- applet_widget_add (APPLET_WIDGET(applet), cpuload->frame);
- gtk_widget_show (applet);
-
- create_gc (cpuload);
- cpuload_setup_colors (cpuload);
-
- gtk_signal_connect (GTK_OBJECT(applet),"save_session",
- GTK_SIGNAL_FUNC(applet_save_session),
- NULL);
-
- applet_widget_register_stock_callback (APPLET_WIDGET(applet),
- "properties",
- GNOME_STOCK_MENU_PROP,
- _("Properties..."),
- cpu_properties,
- cpuload);
-
- return applet;
+ GtkWidget *applet;
+ LoadGraph *g;
+
+ /* create a new applet_widget */
+ applet = applet_widget_new(goad_id);
+ /* in the rare case that the communication with the panel
+ failed, error out */
+ if (!applet)
+ g_error ("Can't create applet!\n");
+
+#if 0
+ load_cpu_properties (APPLET_WIDGET(applet)->privcfgpath, &cpu_props);
+#endif
+
+ g = load_graph_new (4, N_("CPU Load"), &multiload_properties.cpuload,
+ 500, 40, 40, GetLoad);
+
+ applet_widget_add (APPLET_WIDGET(applet), g->frame);
+ gtk_widget_show (applet);
+
+ load_graph_start (g);
+
+ gtk_signal_connect (GTK_OBJECT(applet),"save_session",
+ GTK_SIGNAL_FUNC(applet_save_session),
+ NULL);
+
+ applet_widget_register_stock_callback (APPLET_WIDGET(applet),
+ "properties",
+ GNOME_STOCK_MENU_PROP,
+ _("Properties..."),
+ multiload_properties_cb,
+ g);
+
+ return applet;
}