1 /* GKrellM
2 |  Copyright (C) 1999-2019 Bill Wilson
3 |
4 |  Author:  Bill Wilson    billw@gkrellm.net
5 |  Latest versions might be found at:  http://gkrellm.net
6 |
7 |
8 |  GKrellM is free software: you can redistribute it and/or modify it
9 |  under the terms of the GNU General Public License as published by
10 |  the Free Software Foundation, either version 3 of the License, or
11 |  (at your option) any later version.
12 |
13 |  GKrellM is distributed in the hope that it will be useful, but WITHOUT
14 |  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 |  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 |  License for more details.
17 |
18 |  You should have received a copy of the GNU General Public License
19 |  along with this program. If not, see http://www.gnu.org/licenses/
20 |
21 |
22 |  Additional permission under GNU GPL version 3 section 7
23 |
24 |  If you modify this program, or any covered work, by linking or
25 |  combining it with the OpenSSL project's OpenSSL library (or a
26 |  modified version of that library), containing parts covered by
27 |  the terms of the OpenSSL or SSLeay licenses, you are granted
28 |  additional permission to convey the resulting work.
29 |  Corresponding Source for a non-source form of such a combination
30 |  shall include the source code for the parts of OpenSSL used as well
31 |  as that of the covered work.
32 */
33 
34 
35 #ifndef GKRELLM_H
36 #define GKRELLM_H
37 
38 #if defined(HAVE_CONFIG_H)
39 #include "config.h"
40 #endif
41 #include "log.h"
42 
43 #if !defined(WIN32)
44 #include <sys/param.h>
45 #endif
46 
47 #include <gtk/gtk.h>
48 #include <glib/gstdio.h>
49 
50 #include <stdio.h>
51 #include <stdlib.h>
52 #include <string.h>
53 #include <ctype.h>
54 #include <fcntl.h>
55 #include <time.h>
56 
57 #if !defined(WIN32)
58 #include <unistd.h>
59 #else
60     #include <winsock2.h>
61     #include <process.h>
62 #endif
63 
64 #include <sys/stat.h>
65 
66 #include <locale.h>
67 
68 #if defined(__sun) && defined(__SVR4)
69 #define __solaris__
70 #endif
71 
72 #if !defined(__FreeBSD__) && !defined(__linux__) && !defined(__NetBSD__) \
73 	&& !defined(__OpenBSD__) && !defined(__solaris__) && !defined(WIN32) \
74 	&& !defined(__APPLE__) && !defined(__DragonFly__)
75 #define  USE_LIBGTOP
76 #endif
77 
78 
79 #if !defined(PACKAGE)
80 #define PACKAGE	"gkrellm"
81 #endif
82 
83 /* Internationalization support.
84 */
85 #if defined (ENABLE_NLS)
86 #include <libintl.h>
87 #	undef _
88 #	define _(String) dgettext(PACKAGE,String)
89 #	if defined(gettext_noop)
90 #		define N_(String) gettext_noop(String)
91 #	else
92 #		define N_(String) (String)
93 #	endif	/* gettext_noop */
94 #else
95 #	define _(String) (String)
96 #	define N_(String) (String)
97 #	define textdomain(String) (String)
98 #	define gettext(String) (String)
99 #	define dgettext(Domain,String) (String)
100 #	define dcgettext(Domain,String,Type) (String)
101 #	define bindtextdomain(Domain,Directory) (Domain)
102 #endif	/* ENABLE_NLS */
103 
104 
105 
106 
107 /* -------------------------------------------------------------------
108 */
109 #define	GKRELLM_VERSION_MAJOR	2
110 #define	GKRELLM_VERSION_MINOR	3
111 #define	GKRELLM_VERSION_REV		11
112 #define	GKRELLM_EXTRAVERSION	""
113 //#define	GKRELLM_EXTRAVERSION	"-pre1"
114 
115 #define GKRELLM_CHECK_VERSION(major,minor,rev)    \
116 	(GKRELLM_VERSION_MAJOR > (major) || \
117 	(GKRELLM_VERSION_MAJOR == (major) && GKRELLM_VERSION_MINOR > (minor)) || \
118 	(GKRELLM_VERSION_MAJOR == (major) && GKRELLM_VERSION_MINOR == (minor) && \
119 	GKRELLM_VERSION_REV >= (rev)))
120 
121 #define	GKRELLM_DIR				".gkrellm2"
122 #define	GKRELLM_USER_CONFIG		".gkrellm2/user-config"
123 #define	GKRELLM_2_1_14_CONFIG	".gkrellm2/user_config"
124 #define	GKRELLM_THEME_CONFIG	".gkrellm2/theme_config"
125 #define GKRELLM_THEMES_DIR		".gkrellm2/themes"
126 #define	GKRELLM_DATA_DIR		".gkrellm2/data"
127 #define	GKRELLM_PLUGINS_DIR		".gkrellm2/plugins"
128 #define	GKRELLM_LOCK_FILE		".gkrellm2/lock"
129 #define GKRELLMRC				"gkrellmrc"
130 
131 #define	PLUGIN_ENABLE_FILE		".gkrellm2/plugin_enable"
132 #define	PLUGIN_PLACEMENT_FILE	".gkrellm2/plugin_placement"
133 
134 
135 #if !defined(WIN32)
136 
137 #define	LOCAL_THEMES_DIR		"/usr/local/share/gkrellm2/themes"
138 #if !defined(SYSTEM_THEMES_DIR)
139 #define	SYSTEM_THEMES_DIR		"/usr/share/gkrellm2/themes"
140 #endif
141 #define	LOCAL_PLUGINS_DIR		"/usr/local/lib/gkrellm2/plugins"
142 #if !defined(SYSTEM_PLUGINS_DIR)
143 #define	SYSTEM_PLUGINS_DIR		"/usr/lib/gkrellm2/plugins"
144 #endif
145 
146 #else
147 
148 #undef      LOCAL_THEMES_DIR
149 #undef      SYSTEM_THEMES_DIR
150 #undef      LOCAL_PLUGINS_DIR
151 #undef      SYSTEM_PLUGINS_DIR
152 
153 #endif
154 
155 
156 #define	ON				1
157 #define	OFF				0
158 
159 #define	CFG_BUFSIZE		512
160 
161 
162   /* Features
163   */
164 #define	GKRELLM_HAVE_THEME_SCALE			1
165 #define	GKRELLM_HAVE_DECAL_TEXT_INSERT		1
166 #define	GKRELLM_HAVE_CLIENT_MODE_PLUGINS 	1
167 #define	GKRELLM_USING_PANGO					1
168 #define	GKRELLM_HAVE_DECAL_SCROLL_TEXT		1
169 
170 
171   /* Label midpoints are positioned as a percent of chart_width.
172   */
173 #define	GKRELLM_LABEL_NONE		-1
174 #define	GKRELLM_LABEL_CENTER	50
175 #define GKRELLM_LABEL_MAX		100
176 
177 #define	GRID_MODE_NORMAL		0
178 #define	GRID_MODE_RESTRAINED	1
179 
180 
181   /* GkrellmDecals in the decal_misc_piximage.
182   */
183 #define	D_MISC_BLANK			0
184 #define	D_MISC_AC				1
185 #define	D_MISC_BATTERY			2
186 #define	D_MISC_BATTERY_WARN		3
187 #define	D_MISC_LED0				4
188 #define	D_MISC_LED1				5
189 #define	D_MISC_FS_UMOUNTED		6
190 #define	D_MISC_FS_MOUNTED		7
191 #define D_MISC_FS_PRESSED		8
192 #define D_MISC_BUTTON_OUT		9
193 #define D_MISC_BUTTON_ON		10
194 #define D_MISC_BUTTON_IN		11
195 #define	N_MISC_DECALS			12
196 
197 
198   /* For formatting sizes in decimal or binary abbreviated notation.
199   */
200 #define	KB_SIZE(s)	((s) * 1e3)
201 #define	KiB_SIZE(s)	((s) * 1024.0)
202 #define	MB_SIZE(s)	((s) * 1e6)
203 #define	MiB_SIZE(s)	((s) * 1024.0 * 1024.0)
204 #define	GB_SIZE(s)	((s) * 1e9)
205 #define	GiB_SIZE(s)	((s) * 1024.0 * 1024.0 * 1024.0)
206 #define	TB_SIZE(s)	((s) * 1e12)
207 #define	TiB_SIZE(s)	((s) * 1024.0 * 1024.0 * 1024.0 * 1024.0)
208 
209 typedef struct
210 	{
211 	gfloat	limit,
212 			divisor;
213 	gchar	*format;
214 	}
215 	GkrellmSizeAbbrev;
216 
217 
218   /* Sensor types so CPU and Proc monitors  can get info from the Sensors
219   |  module.  The sensor module readings for temperature and fan are
220   |  reported on CPU and Proc panels.
221   */
222 #define SENSOR_TEMPERATURE  0
223 #define SENSOR_FAN          1
224 #define SENSOR_VOLTAGE      2
225 
226 #define	SENSOR_GROUP_MAINBOARD	0
227 #define	SENSOR_GROUP_DISK		1
228 
229 
230 #define	FULL_SCALE_GRIDS		5
231 
232 
233 typedef struct
234 	{
235 	PangoFontDescription *font;
236 	PangoFontDescription **font_seed;
237 	gpointer	privat;
238 	gint		effect;
239 	gint		internal;
240 	gint		flags;
241 	GdkColor	color;
242 	GdkColor	shadow_color;
243 	}
244 	GkrellmTextstyle;
245 
246 typedef struct
247 	{
248 	gchar				*text;
249 	gint				x_off,
250 						y_off;
251 	gint				x_off_prev;		/* Kludge to check if d->x_off was */
252 										/* modified directly.		*/
253 	gpointer			privat;
254 	GkrellmTextstyle	text_style;
255 	}
256 	GkrellmText;
257 
258   /* Values for GkrellmDecal flags
259   */
260 #define DF_TOP_LAYER			0x1
261 #define	DF_MOVED				0x2
262 #define DF_LOCAL_PIXMAPS		0x4
263 #define	DF_OVERLAY_PIXMAPS		0x8
264 #define	DF_TEXT_OVERLAPS		0x10
265 #define	DF_SCROLL_TEXT_DIVERTED	0x20
266 #define	DF_SCROLL_TEXT_CENTER	0x40
267 #define	DF_SCROLL_TEXT_H_LOOP	0x80
268 #define	DF_SCROLL_TEXT_V_LOOP	0x100
269 #define	DF_TEXT_USE_MARKUP		0x200
270 
271   /* Values for GkrellmDecal state
272   */
273 #define	DS_INVISIBLE	0
274 #define	DS_VISIBLE		1
275 
276   /* A decal is a pixmap or a part of a pixmap drawn on a panel.  The
277   |  pixmap can be a graphic, a vertical stack of graphics, or a drawn
278   |  text string
279   */
280 typedef struct
281 	{
282 	GdkPixmap	*pixmap;
283 	GdkBitmap	*mask;
284 	GdkBitmap	*stencil;
285 	gint		y_src;		/* Offset into pixmap if a vertical stack	*/
286 	gint		w, h;		/* Size of the decal						*/
287 	gint		x, y;		/* Position of decal in a drawable			*/
288 	gshort		flags,
289 				state;
290 	gint		value;		/* Index into stack, text value, etc	*/
291 	gboolean	modified;
292 	gint		x_off,
293 				y_ink;			/* Pixels from top of Pango glyph to 1st ink*/
294 	gint		x_old, y_old;	/* Used if decal was moved */
295 	GkrellmTextstyle text_style;	/* Used if decal is a drawn text string	*/
296 	gpointer	panel;
297 	GList		*text_list;
298 	gchar		*scroll_text;
299 	gint		scroll_width,
300 				scroll_height,
301 				y_off;
302 
303 	guint		chart_sequence_id;	/* For drawing text decal on a chart */
304 	GdkRectangle ink;
305 	}
306 	GkrellmDecal;
307 
308   /* Get the first decal in a panel decal list.  Use if only one decal in list.
309   */
310 #define	DECAL(p)	((GkrellmDecal *)(((p)->decal_list)->data))
311 
312 
313 
314 typedef struct
315 	{
316 	gchar		*string;
317 	gpointer	privat;
318 	gint		old1,		/* olds are leftovers from GdkFont->Pango */
319 				old2,
320 				width,
321 				height,
322 				old3;
323 	gint		position;		/* 0 - 100 %	*/
324 	gint		x_panel,		/* x position of label start in panel */
325 				y_panel,
326 				h_panel;
327 	}
328 	GkrellmLabel;
329 
330 
331 typedef struct
332 	{
333 	gint		x_src;
334 	gint		y_src;
335 	gint		x_dst;
336 	gint		y_dst;
337 	gint		w;
338 	gint		h;
339 	}
340 	GkrellmDrawrec;
341 
342 
343 typedef struct
344 	{
345 	gint		left,
346 				right,
347 				top,
348 				bottom;
349 	}
350 	GkrellmMargin;
351 
352 typedef struct
353 	{
354 	gint		left,
355 				right,
356 				top,
357 				bottom;
358 	}
359 	GkrellmBorder;
360 
361 
362 typedef struct
363 	{
364 	GdkPixbuf	*pixbuf;
365 	GkrellmBorder border;
366 	}
367 	GkrellmPiximage;
368 
369 
370   /* Bit flags for setting styles in config.c.  Also used as override flags.
371   */
372 #define	GKRELLMSTYLE_KRELL_YOFF			0x1
373 #define	GKRELLMSTYLE_KRELL_LEFT_MARGIN	0x2
374 #define	GKRELLMSTYLE_KRELL_RIGHT_MARGIN	0x4
375 #define	GKRELLMSTYLE_KRELL_EXPAND		0x8
376 #define	GKRELLMSTYLE_KRELL_X_HOT		0x10
377 #define	GKRELLMSTYLE_KRELL_DEPTH		0x20
378 #define	GKRELLMSTYLE_KRELL_EMA_PERIOD	0x40
379 #define	GKRELLMSTYLE_LABEL_POSITION		0x80
380 #define	GKRELLMSTYLE_LEFT_MARGIN		0x100
381 #define	GKRELLMSTYLE_RIGHT_MARGIN		0x200
382 #define	GKRELLMSTYLE_TOP_MARGIN			0x400
383 #define	GKRELLMSTYLE_BOTTOM_MARGIN		0x800
384 #define	GKRELLMSTYLE_TEXTCOLOR_A		0x1000
385 #define	GKRELLMSTYLE_TEXTCOLOR_B		0x2000
386 #define	GKRELLMSTYLE_TEXTFONT_A			0x4000
387 #define	GKRELLMSTYLE_TEXTFONT_B			0x8000
388 #define	GKRELLMSTYLE_BORDER				0x10000
389 #define	GKRELLMSTYLE_TRANSPARENCY		0x20000
390 #define	GKRELLMSTYLE_KRELL_YOFF_NOT_SCALABLE 0x40000
391 #define	GKRELLMSTYLE_SCROLL_TEXT_CACHE_OFF	 0x80000
392 #define	GKRELLMSTYLE_LABEL_YOFF			0x100000
393 
394 
395   /* Some of these style entries do not apply to all monitors.
396   */
397 typedef struct
398 	{
399 	gint		override;		/* Flag which entries have override status */
400 	gint		ref_count;
401 
402 	gint		krell_yoff,
403 				krell_expand,
404 				krell_x_hot,
405 				krell_ema_period,
406 				krell_depth;
407 	gint		krell_left_margin,
408 				krell_right_margin;
409 	gboolean	krell_yoff_not_scalable;
410 	gint		label_yoff;
411 	gint		label_position;
412 	gboolean	scroll_text_cache_off;
413 	gint		spare0;
414 
415 	gboolean	transparency;
416 	gint		themed;			/* Non zero if theme has custom assignments */
417 
418 	GkrellmBorder border;			/* Border for background panel image */
419 	GkrellmMargin margin;
420 	GkrellmTextstyle label_tsA;
421 	GkrellmTextstyle label_tsB;
422 	}
423 	GkrellmStyle;
424 
425 
426 
427   /* The GkrellmPanel of each GkrellmChart or Meter can have a moving indicator
428   |  representing a current sampled data value as a fraction of some full
429   |  scale value.  Since there can be quite a few of them dancing around on
430   |  a maxed out GKrellM display, I call them Krells - inspired by the
431   |  wall full of power monitoring meters the Krell had in Forbidden Planet.
432   */
433   /* Krell.expand values */
434 #define	KRELL_EXPAND_NONE				0
435 #define	KRELL_EXPAND_LEFT				1
436 #define	KRELL_EXPAND_RIGHT				2
437 #define	KRELL_EXPAND_BAR_MODE			3
438 #define KRELL_EXPAND_LEFT_SCALED		4
439 #define KRELL_EXPAND_RIGHT_SCALED		5
440 #define	KRELL_EXPAND_BAR_MODE_SCALED	6
441 
442   /* Krell flags */
443 #define	KRELL_FLAG_BOTTOM_MARGIN	1
444 
445 typedef struct
446 	{
447 	GdkPixmap	*pixmap;
448 	GdkBitmap	*mask;
449 	gint		w, h;	/* Of the full Krell - all the frames included */
450 	gint		depth;	/* How many vertical frames in the krell image */
451 	gint		flags;
452 
453 	GdkBitmap	*stencil;
454 	gint		spare0;
455 	gint		reading;
456 	gint		last_reading;
457 	gint		full_scale;
458 	gulong		previous;
459 	gulong		value;
460 
461 	gint		modified;	/* True if krell has moved.			*/
462 
463 	gint		x_hot;		/* Offset in Krell pixmap to hot spot */
464 	gint		x_position;	/* Current position of x_hot in Panel */
465 
466 	gint		x0,		/* Offset in Panel to start of Krell scale range */
467 				y0;
468 	gint		w_scale;	/* Width of active range, function of margins */
469 	gint		h_frame;	/* Height of one frame */
470 
471 	gint		ema;		/* exponential moving average */
472 	gint		period;		/* of ema */
473 	gint		full_scale_expand;
474 	gboolean	monotonic;
475 	gint		bar_mode;
476 
477 	gpointer	panel;
478 	GkrellmDrawrec	old_draw;	/* Last draw for restoring background.	*/
479 	GkrellmDrawrec	draw;		/* Parameters to currently drawn krell	*/
480 	}
481 	GkrellmKrell;
482 
483   /* Get the first krell in a panel krell list.  Use if only one krell in list.
484   */
485 #define	KRELL(p)	((GkrellmKrell *)(((p)->krell_list)->data))
486 
487 typedef struct
488 	{
489 	GtkWidget	*hbox;			/* Container box this area is packed into */
490 	GdkPixmap	*bg_text_layer_pixmap;  /* A bg_pixmap with text decals */
491 	GtkWidget	*drawing_area;
492 	GdkPixmap	*pixmap;		/* Expose pixmap */
493 	GdkBitmap	*bg_mask;
494 	GdkPixmap	*bg_pixmap;		/* Bg of panel, may be dirtied with label */
495 	GdkPixmap	*bg_clean_pixmap;	/* A no label bg_pixmap				*/
496 	GkrellmPiximage *bg_piximage;
497 
498 	GkrellmLabel *label;
499 	GkrellmTextstyle *textstyle;
500 	GkrellmStyle *style;
501 	gpointer	monitor;
502 	gpointer	privat;
503 	GList		*decal_list;
504 	GList		*krell_list;
505 	GList		*button_list;
506 	gint		x, y, w, h;
507 	gint		h_configure;
508 
509 	PangoLayout	*layout;
510 	PangoLayout	 *label_layout;
511 
512 	gint		transparency;
513 	gboolean	modified;		/* True if decal/krell modified.	*/
514 	gboolean	keep_lists;
515 	gboolean	shown;
516 	gboolean	need_decal_overlap_check;
517 	gboolean	label_on_top_of_decals;
518 	gboolean	scroll_text_cache_off;
519 	gboolean	bg_piximage_override;
520 	gboolean	button_signals_connected;
521 	gint		id_press,		/* Signals if buttons in this panel	*/
522 				id_release,
523 				id_enter,
524 				id_leave;
525 	gint		y_mapped;
526 	}
527 	GkrellmPanel;
528 
529 
530 typedef struct
531 	{
532 	void		(*func)();
533 	gpointer	data;
534 	}
535 	GkrellmCallback;
536 
537 
538 #define CHART_WIDTH_MAX	1000
539 #define CHART_WIDTH_MIN	25
540 
541   /* Each chart must have a GkrellmChartconfig struct associated with it.
542   */
543 #define	GKRELLM_CHARTCONFIG_KEYWORD	"chart_config"
544 
545   /* Values for GkrellmChartconfig flags */
546 #define	NO_CONFIG_AUTO_GRID_RESOLUTION	1
547 #define	NO_CONFIG_FIXED_GRIDS			2
548 
549 typedef struct
550 	{
551 	gint		flags;
552 	gboolean	config_loaded;
553 	gboolean	log;
554 
555 	gint		h;
556 	void		(*cb_height)();
557 	gpointer	cb_height_data;
558 	GtkWidget	*height_spin_button;
559 
560 	/* grid_resolution must be an integer and will be mapped into an integer
561 	|  1,2,5 or 1,1.5,2,3,5,7 sequence if map_sequence is TRUE.  If
562 	|  map_sequence is false, grid_resolution will be the spin_button
563 	|  value * spin_factor so spin buttons may have non-integer settings.
564 	*/
565 	gint		grid_resolution;
566 	gboolean	auto_grid_resolution;
567 	gboolean	auto_resolution_stick;
568 	gboolean	sequence_125;
569 	void		(*cb_grid_resolution)();
570 	gpointer	cb_grid_resolution_data;
571 	GtkWidget	*grid_resolution_spin_button;
572 	GtkWidget	*auto_resolution_control_menubar;
573 	GtkUIManager	*auto_resolution_ui_manager;
574 	gchar		*grid_resolution_label;
575 	gboolean	adjustment_is_set;
576 	gboolean	map_sequence;
577 	gfloat		spin_factor;
578 	gfloat		low,		/* Stuff for the grid_resolution spin adjustment */
579 				high,
580 				step0,
581 				step1;
582 	gint		digits,
583 				width;
584 
585 	gboolean	fixed_grids;
586 	void		(*cb_fixed_grids)();
587 	gpointer	cb_fixed_grids_data;
588 	GtkWidget	*fixed_grids_spin_button;
589 
590 	GList		*cd_list;			/* Same list as in parent GkrellmChart */
591 	GList		**chart_cd_list;
592 
593 	gboolean	cb_block;
594 	}
595 	GkrellmChartconfig;
596 
597   /* GkrellmCharts are drawn in layers and each data value drawn has its own
598   |  layer (the GkrellmChartdata struct -> image/color of the drawn data and
599   |  the data colored grid lines).  Each layer is a chart sized pixmap
600   |  with grid lines drawn on it.  A chart is drawn by drawing the
601   |  background followed by stenciling each data layer through a
602   |  data_bitmap.
603   */
604 typedef struct
605 	{
606 	GdkPixmap	*pixmap;			/* Working layer pixmap with grid lines	*/
607 	GdkPixmap	**src_pixmap;		/* The layer source image/color		*/
608 	GdkPixmap	*grid_pixmap;		/* The grid pixmap to draw on src 	*/
609 	}
610 	GkrellmChartlayer;
611 
612 
613 typedef struct
614 	{
615 	GtkWidget		*vbox,
616 					*image;
617 	GkrellmPiximage	*piximage;
618 	GdkPixmap		*pixmap,
619 					*clean_pixmap;
620 	GdkBitmap		*mask;
621 	gint			height;			/* Width is _GK.chart_width */
622 	}
623 	GkrellmSpacer;
624 
625 typedef struct
626 	{
627 	gchar			*text;
628 	gint			x, y;
629 	gint			w, h;
630 	gint			baseline,
631 					y_ink;
632 	gboolean		cache_valid;
633 	}
634 	GkrellmTextRun;
635 
636 typedef struct
637 	{
638 	GtkWidget	*box;			/* Container box this chart is packed into */
639 	GtkWidget	*drawing_area;
640 
641 	GkrellmPanel *panel;
642 	GList		*cd_list;		/* Same cd_list as in GkrellmChartconfig struct */
643 	gint		cd_list_index;
644 	void		(*draw_chart)(gpointer);
645 	gpointer	draw_chart_data;
646 
647 	gint		x, y, w, h;		/* h tracks h in GkrellmChartconfig	*/
648 
649 	GkrellmChartconfig	*config;
650 	gboolean	shown;
651 	gboolean	redraw_all;
652 
653 	gint		position,
654 				tail;
655 	gboolean	primed;
656 
657 	gint		privat;
658 	gint		i0;				/* Draw start index */
659 	gint		alloc_width;
660 
661 	gint		scale_max;
662 	gint		maxval,
663 				maxval_auto,
664 				maxval_auto_base,
665 				maxval_peak;
666 	gulong		previous_total;
667 
668 	gint		style_id;
669 
670 	GdkPixmap	*pixmap;			/* The expose pixmap.			*/
671 
672 	GkrellmPiximage
673 				*bg_piximage,
674 				*bg_grid_piximage;
675 	GdkPixmap	*bg_pixmap,			/* Working bg with grid lines	*/
676 				*bg_src_pixmap,		/* bg with no grid lines		*/
677 				*bg_grid_pixmap,	/* This + bg_src_pixmap builds bg_pixmap*/
678 				*bg_clean_pixmap,	/* This + trans builds bg_src_pixmap */
679 				*bg_text_pixmap;	/* Pango rendered chart text layer */
680 	GdkBitmap	*bg_mask;
681 	gint		transparency;
682 	gboolean	bg_piximage_override;
683 	guint		bg_sequence_id;
684 
685 	gchar		*text_format_string;
686 	GList		*text_run_list;		/* Caching chart text runs */
687 	gint		h_text,
688 				y_ink,
689 				baseline_ref;
690 	guint		text_run_sequence_id;
691 	gboolean	text_format_reuse;
692 
693 	gint		y_mapped,
694 				auto_recalibrate_delay;
695 
696 	GtkWidget	*config_window;
697 
698 	GkrellmSpacer	top_spacer,
699 					bottom_spacer;
700 
701 	GkrellmStyle	*style;
702 	gpointer		monitor;
703 	}
704 	GkrellmChart;
705 
706 
707   /* Values for GkrellmChartdata draw_style */
708 #define	CHARTDATA_IMPULSE	0
709 #define	CHARTDATA_LINE		1
710 
711   /* Values for GkrellmChartdata flags */
712 #define CHARTDATA_ALLOW_HIDE			1
713 #define CHARTDATA_NO_CONFIG_DRAW_STYLE	2
714 #define CHARTDATA_NO_CONFIG_INVERTED	4
715 #define CHARTDATA_NO_CONFIG_SPLIT		8
716 #define CHARTDATA_NO_CONFIG				0xf
717 
718 typedef struct
719 	{
720 	gint		flags;
721 
722 	GkrellmChart *chart;			/* GkrellmChart this data belong to */
723 	gchar		*label;
724 	gulong		current,
725 				previous,
726 				wrap,
727 				discard;
728 	gboolean	monotonic;
729 	GkrellmChartlayer layer;	/* The image + grid for this data layer */
730 	GdkBitmap	*data_bitmap;	/* Draw data here, use as clipmask for layer*/
731 	gulong		*data;
732 
733 	gint		draw_style;
734 	gboolean	inverted;
735 	gboolean	hide;
736 
737 	gboolean	split_chart;
738 	gfloat		split_fraction,
739 				split_share;
740 	GtkWidget	*split_fraction_spin_button;
741 
742 	gint		y_p,
743 				y_pp;
744 	gboolean	y_p_valid;
745 	gint		y,				/* Each data layer draws at an offset y and */
746 				h,				/* within height h of its parent GkrellmChart*/
747 				w;				/* Width of data allocated.				*/
748 	gulong		maxval;
749 	}
750 	GkrellmChartdata;
751 
752 
753 typedef struct
754 	{
755 	GkrellmPanel *panel;
756 	GkrellmDecal *decal;
757 	void		(*cb_button_click)();
758 	gpointer	data;
759 	gint		(*cb_in_button)();
760 	gpointer	in_button_data;
761 	gpointer	privat;
762 	gint		cur_index;
763 	gint		pressed_index;
764 	gint		saved_index;
765 	gint		sensitive;
766 	gint		type;
767 	void		(*cb_button_right_click)();
768 	gpointer	right_data;
769 	}
770 	GkrellmDecalbutton;
771 
772 
773 
774 typedef struct
775 	{
776 	gchar		*command;
777 	gint		type;
778 	gint		pad;
779 	FILE		*pipe;		/* Read the output of some commands */
780 	GkrellmDecalbutton	*button;
781         void *tooltip_filler;
782 	gchar		*tooltip_comment;
783 	GkrellmDecal *decal;		/* Used if DECAL_LAUNCHER type	*/
784 	GkrellmMargin margin;
785 
786 	GtkWidget	*widget;
787 	}
788 	GkrellmLauncher;
789 
790 
791 /* ------- Alerts ------- */
792 #define	GKRELLM_ALERTCONFIG_KEYWORD			"alert_config"
793 
794 typedef struct
795 	{
796 	struct _GkrellmMonitor	*mon;
797 	gchar		*name,
798 				*tab_name;
799 	void		(*warn_func)(),
800 				(*alarm_func)(),
801 				(*update_func)(),
802 				(*check_func)(),
803 				(*destroy_func)();
804 	void		(*config_create_func)(),
805 				(*config_apply_func)(),
806 				(*config_save_func)(),
807 				(*config_load_func)();
808 	}
809 	GkrellmAlertPlugin;
810 
811 typedef struct
812 	{
813 	GkrellmAlertPlugin	*alert_plugin;
814 	gpointer			data;
815 	}
816 	GkrellmAlertPluginLink;
817 
818 typedef struct
819 	{
820 	gboolean	warn_on,
821 				alarm_on;
822 	gfloat		warn_limit,
823 				alarm_limit;
824 	gint		warn_delay,
825 				alarm_delay;
826 	GtkWidget	*warn_limit_spin_button,
827 				*alarm_limit_spin_button;
828 	}
829 	GkrellmTrigger;
830 
831 typedef struct
832 	{
833 	GkrellmDecal *decal;
834 	gint		x, y, w, h;
835 	GdkPixmap	*pixmap;
836 	GdkBitmap	*mask;
837 	gint		frame,
838 				nframes,
839 				dir;
840 	}
841 	GkrellmAlertdecal;
842 
843 typedef struct
844 	{
845 	GkrellmKrell *krell;
846 	gint		krell_position;
847 	}
848 	GkrellmAlertkrell;
849 
850 typedef struct
851 	{
852 	GkrellmPanel *panel;
853 	gchar		*name,
854 				*unit_string;
855 	GkrellmAlertdecal ad;
856 	GkrellmAlertkrell ak;
857 
858 	gboolean	activated,
859 				freeze,
860 				do_panel_updates,
861 				suppress_command,
862 				check_low,
863 				check_high,
864 				check_hardwired;
865 	gchar		*warn_command,
866 				*alarm_command;
867 	gint		warn_repeat_set,
868 				warn_repeat,
869 				alarm_repeat_set,
870 				alarm_repeat;
871 	gint		delay;
872 
873 	void		(*cb_trigger)();
874 	gpointer	cb_trigger_data;
875 	void		(*cb_stop)();
876 	gpointer	cb_stop_data;
877 	void		(*cb_config)();
878 	gpointer	cb_config_data;
879 	void		(*cb_config_create)();
880 	gpointer	cb_config_create_data;
881 	void		(*cb_command_process)();
882 	gpointer	cb_command_process_data;
883 
884 	GtkWidget	*config_window,
885 				*warn_command_entry,
886 				*alarm_command_entry,
887 				*warn_repeat_spin_button,
888 				*alarm_repeat_spin_button,
889 				*delay_spin_button,
890 				*delete_button,
891 				*icon_box;
892 	gboolean	do_alarm_command,
893 				do_warn_command;
894 
895 	gfloat		max_high,		/* limit adjustment values */
896 				min_low,
897 				step0,
898 				step1;
899 	gint		digits;
900 
901 	gint		delay_high,		/* delay adjustment values */
902 				delay_low,
903 				delay_step;
904 
905 	GkrellmTrigger low,
906 				high;
907 
908 	gboolean	config_closing,
909 				config_modified;
910 
911 	gchar		*id_string;		/* For unique alert names for alert plugins */
912 	GList		*plugin_list;
913 	}
914 	GkrellmAlert;
915 
916 /* ------------------------ */
917 
918 
919 #define	GKRELLM_SPACER_CHART	0
920 #define	GKRELLM_SPACER_METER	1
921 
922 #define	CHART_PANEL_TYPE	0
923 #define	METER_PANEL_TYPE	1
924 #define	N_PANEL_TYPES		2
925 
926 #define	PANEL_LAUNCHER		CHART_PANEL_TYPE
927 #define	METER_LAUNCHER		METER_PANEL_TYPE
928 #define	DECAL_LAUNCHER		3
929 
930 #define	DEFAULT_STYLE_ID	0
931 
932 
933 /* GkrellmStyle names for the builtin monitors.  Define them globally so plugins
934 |  can lookup a builtin style_id.  These names are used as subdirectory
935 |  names under the current theme where monitor specific images are located.
936 |  They also are used in the GkrellmStyle lines in the gkrellmrc
937 |		(eg. GkrellmStyleMeter  cpu.textcolor ....
938 */
939 #define	CPU_STYLE_NAME			"cpu"
940 #define	DISK_STYLE_NAME			"disk"
941 #define	NET_STYLE_NAME			"net"
942 #define	PROC_STYLE_NAME			"proc"
943 #define	INET_STYLE_NAME			"inet"
944 
945 #define	MEM_STYLE_NAME			"mem"
946 #define SWAP_STYLE_NAME			"swap"
947 #define	FS_STYLE_NAME			"fs"
948 #define	MAIL_STYLE_NAME			"mail"
949 
950   /* APM monitor is now named Battery, but don't want to break themes. */
951 #define	BATTERY_STYLE_NAME		"apm"
952 #define UPTIME_STYLE_NAME		"uptime"
953 #define	CLOCK_STYLE_NAME		"clock"
954 #define	CAL_STYLE_NAME			"cal"
955 #define	HOST_STYLE_NAME			"host"
956 #define	TIMER_STYLE_NAME		"timer"
957 
958 
959 typedef struct
960 	{
961 	gint		timer_ticks,
962 				second_tick,
963 				two_second_tick,
964 				five_second_tick,
965 				ten_second_tick,
966 				minute_tick,
967 				hour_tick,
968 				day_tick;
969 
970 	}
971 	GkrellmTicks;
972 
973 extern GkrellmTicks	GK;
974 
975 
976 /* ================= User Config ==================*/
977 
978   /* Values for GkrellmMonitor id
979   |  Give an id number to all builtin monitors
980   |				____ cccc ___i iiii
981   */
982 #define	MON_CPU		0
983 #define	MON_PROC	1
984 #define	MON_DISK	2
985 #define	MON_NET		3
986 #define	MON_INET	4
987 #define	N_CHART_MONITORS 5
988 
989 #define	MON_MEM		5
990 #define	MON_FS		6
991 #define	MON_MAIL	7
992 #define	MON_BATTERY	8
993 #define	MON_APM		MON_BATTERY
994 #define	MON_UPTIME	9
995 #define	MON_CLOCK	10
996 #define	MON_CAL		11
997 #define	MON_TIMER	12
998 #define	MON_HOST	13
999 #define	MON_SWAP	14
1000 #define MON_VOLTAGE	15
1001 #define N_BUILTIN_MONITORS	16
1002 #define MON_PLUGIN	16
1003 
1004 #define	MON_ID_MASK		0x1f
1005 
1006 #define MON_INSERT_AFTER		0x200
1007 #define MON_CONFIG_MASK			0xf00
1008 #define	MON_GRAVITY_MASK		0xf000
1009 
1010 #define	GRAVITY(n)			((n) << 12)
1011 #define	PLUGIN_GRAVITY(m)	(((m)->insert_before_id & MON_GRAVITY_MASK) >> 12)
1012 
1013 #define	PLUGIN_INSERT_BEFORE_ID(p)	((p)->insert_before_id & MON_ID_MASK)
1014 #define PLUGIN_INSERT_AFTER(p)	\
1015 							(((p)->insert_before_id & MON_INSERT_AFTER) >> 9)
1016 
1017 #define	MONITOR_ID(m)			((m)->id & MON_ID_MASK)
1018 #define	MONITOR_CONFIG(m,flag)	(((m)->id & MON_CONFIG_MASK) & flag)
1019 
1020 #define	MONITOR_ENABLED(mon)	((mon)->privat->enabled)
1021 
1022 typedef struct
1023 	{
1024 	GtkWidget		*main_vbox,
1025 					*vbox;
1026 
1027 	gint			config_page;
1028 	GtkTreeRowReference	*row_reference;
1029 	GtkWidget		*config_vbox;
1030 	gboolean		config_created;
1031 
1032 	void			(*cb_disable_plugin)(void);
1033 	gint			insert_before_id,
1034 					gravity,
1035 					button_id;
1036 	gboolean		insert_after;
1037 	gboolean		enabled,
1038 					created,
1039 					from_command_line,
1040 					spacers_shown,
1041 					cap_images_off,
1042 					spacer_overlap_off,
1043 					instant_apply;
1044 	GkrellmStyle	*panel_style,
1045 					*chart_style;
1046 	gchar			*style_name;
1047 	gint			style_type,
1048 					style_id;	/* helper until I consolidate image lists */
1049 	gint			top_type,
1050 					bottom_type;
1051 	GkrellmSpacer	top_spacer,
1052 					bottom_spacer;
1053 	}
1054 	GkrellmMonprivate;
1055 
1056 
1057 
1058 typedef struct _GkrellmMonitor
1059 	{
1060 	gchar		*name;
1061 	gint		id;
1062 	void		(*create_monitor)(GtkWidget *, gint);
1063 	void		(*update_monitor)(void);
1064 	void		(*create_config)(GtkWidget *);
1065 	void		(*apply_config)(void);
1066 
1067 	void		(*save_user_config)(FILE *);
1068 	void		(*load_user_config)(gchar *);
1069 	gchar		*config_keyword;
1070 
1071 	void		(*undef2)(void);
1072 	void		(*undef1)(void);
1073 	GkrellmMonprivate *privat;
1074 
1075 	gint		insert_before_id;		/* If plugin, insert before this mon*/
1076 
1077 	void		*handle;				/* If monitor is a plugin.	*/
1078 	gchar		*path;					/* 	"						*/
1079 	}
1080 	GkrellmMonitor;
1081 
1082 
1083 #include "gkrellm-public-proto.h"
1084 
1085 #endif // GKRELLM_H
1086 
1087