ups the version number to 0.1.11
[gkrellmbgchg.git] / gkrellmbgchg.c
blob6ab948ed1cc95a903308647d73b76cbab6cef571
1 /*
2 * GKrellMBgChg: a GKrellM plugin to change the desktop wallpaper
3 * Copyright (C) 2002-2010 Stefan Bender
4 * Author: Stefan Bender <stefan@bender-suhl.de>
6 * This program is free software which I release under the GNU General Public
7 * License. You may redistribute and/or modify this program under the terms of
8 * that license as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
20 * For more information, see the README and LICENSE files.
22 #include <stdio.h>
23 #include <stdlib.h>
24 #if !defined(WIN32)
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <unistd.h>
28 #endif
30 #include "gkrellmbgchg.h"
32 /* Uncomment this or add -DGKBG_DEBUG to compiler's option to see a
33 lot of debug output. */
34 /* #define GKBG_DEBUG */
35 #ifdef GKBG_DEBUG
36 #define GKBG_debug(fmt, ...) fprintf(stderr, "debug: " fmt "\n", ##__VA_ARGS__)
37 #else
38 #define GKBG_debug(fmt, ...)
39 #endif
41 static GtkWidget *gkrellm_vbox;
43 static GkrellmKrell *krell_time;
44 static GkrellmPanel *panel;
45 static GkrellmMonitor *monitor;
46 static GkrellmDecal *decal_wu;
47 static GkrellmTicks *pGK;
48 static gint style_id;
50 /* all the stuff we need goes into this */
51 struct bg_ctx {
52 GList *idb;
53 GList *idb_orig;
54 GRand *bgchg_rand;
55 GtkTooltips *tip;
56 gint32 cur_img;
57 gint seconds_left;
58 gint locked;
60 /* so we have only this global (still) */
61 static struct bg_ctx *pbg_ctx;
63 /* config widgets */
64 static GtkWidget *entry_format_str;
65 static GtkWidget *entry_idb;
66 static GtkWidget *wait_seconds_spin_button;
67 static GtkWidget *scroll_adj_spin_button;
68 static GtkWidget *entry_command;
69 static GtkWidget *parse_cmd_entry;
70 #if !defined(WIN32)
71 static GtkWidget *auto_update_entry;
72 #endif
73 static GtkWidget *ignore_entry;
74 static GtkWidget *randomise_entry;
75 static GtkWidget *reset_entry;
76 static GtkWidget *reset_entry2;
77 static GtkWidget *change_on_load;
78 static GtkWidget *change_on_apply;
79 static GtkWidget *remember_locked_state;
80 static GtkWidget *remember_image_number;
81 static GtkWidget *simple_scroll_adj;
82 static GtkWidget *center_text;
83 static GtkWidget *display_text;
84 static GtkWidget *display_krell;
86 struct bg_monitor {
87 gint wait_seconds; /* sec. between updates */
88 gint randomise; /* randomise images? */
89 gint reset; /* reset the counter if lock is released */
90 gint reset_config; /* reset the counter on "apply" */
91 gchar format_string[128]; /* output format string */
92 gchar command[256]; /* command to change bg */
93 gboolean parse_cmd_output; /* parse command's output */
94 gchar idb[256]; /* full path to image database */
95 gint change_on_load; /* change image on load */
96 gint change_on_apply; /* change image on config changes */
97 gint remember_locked_state;
98 gint locked_last_run; /* was it locked the last time? */
99 gint remember_image_number;
100 gint32 image_nr_last_run; /* the number when we last shut down */
101 gint simple_scroll_adj; /* mouse wheel adjusts timer w/o "shift" */
102 gint scroll_adj_time; /* time that the mouse wheel adjusts */
103 gboolean center_text; /* Center time text */
104 gboolean display_text; /* Display text countdown */
105 gboolean display_krell; /* Display krell - slider */
106 gboolean ignore; /* discard files we can not stat */
107 #if !defined(WIN32)
108 gboolean auto_update; /* auto update image list if changed? */
109 time_t idb_mtime; /* IDB file mtime */
110 #endif
113 static struct bg_monitor bgmon = {
114 .wait_seconds = 600,
115 .randomise = 1,
116 .reset = 0,
117 .reset_config = 0,
118 .format_string = "$t",
119 #if defined(WIN32)
120 .command = "",
121 #else
122 .command = "Esetroot -f",
123 #endif
124 .parse_cmd_output = 0,
125 .idb = "~/images.idb",
126 .change_on_load = 0,
127 .change_on_apply = 0,
128 .remember_locked_state = 0,
129 .locked_last_run = 0,
130 .remember_image_number = 0,
131 .image_nr_last_run = -1,
132 .simple_scroll_adj = 0,
133 .scroll_adj_time = 60,
134 .center_text = 1,
135 .display_text = 1,
136 .display_krell = 1,
137 .ignore = 0
138 #if !defined(WIN32)
140 .auto_update = 0,
141 .idb_mtime = 0
142 #endif
145 struct idb_entry {
146 gchar *filename;
149 /* returns the pointer to the successfully opened file and
150 * NULL if something weird happened or the file was not modified
151 * and `force' was not set (to 1). */
152 FILE *open_imagelist( gchar *filename, int force )
154 FILE *file;
155 gchar *tmp;
157 if( filename ) {
158 if( !strncmp( filename, "~/", MIN(2, strlen(filename)) ) )
159 tmp = g_strdup_printf( "%s/%s", g_get_home_dir(), filename+2 );
160 else
161 tmp = g_strdup_printf( "%s", filename );
162 } else return NULL;
163 GKBG_debug("bgmon.idb = %s; tmp = %s", bgmon.idb, tmp);
165 #if !defined(WIN32)
166 /* don't load if no force and not modified */
167 struct stat buf;
168 if( stat( tmp, &buf ) == -1 ) {
169 /* something went wrong, we just don't care what for now */
170 GKBG_debug("stat: error on `%s'", tmp);
171 return NULL;
173 if( !force && bgmon.idb_mtime == buf.st_mtime) {
174 GKBG_debug("%s was not modified", tmp);
175 return NULL;
177 #endif
179 GKBG_debug("opening database `%s'", tmp);
180 if( (file = fopen( tmp, "r" )) == NULL) {
181 /* fwiw, print an error message to stderr */
182 fprintf( stderr, _("Could not open image database. (%s)\n"), _(tmp) );
183 if( tmp!=bgmon.idb ) g_free( tmp );
184 return NULL;
186 if( tmp!=bgmon.idb ) g_free( tmp );
188 #if !defined(WIN32)
189 bgmon.idb_mtime = buf.st_mtime;
190 #endif
192 return file;
195 /* Randomise image list in a non-repeating manner. */
196 static void randomise_image_list()
198 GList *gl = NULL;
199 GList *entry = NULL, *tentry = NULL;
200 guint gll = g_list_length( pbg_ctx->idb );
201 int i, tmp;
202 gint32 randval;
203 gint gli[gll];
205 /* Save the original list */
206 pbg_ctx->idb_orig = g_list_copy(pbg_ctx->idb);
208 /* Randomise the index list */
209 for( i = 0; i < gll; i++ ) gli[i] = i;
210 for( i = 0; i < gll; i++ ) {
211 randval = g_rand_int_range( pbg_ctx->bgchg_rand, 0, gll );
212 tmp = gli[i];
213 gli[i] = gli[randval];
214 gli[randval] = tmp;
217 /* save old image entry */
218 if( pbg_ctx->cur_img > -1 && pbg_ctx->cur_img < gll )
219 entry = g_list_nth( pbg_ctx->idb, pbg_ctx->cur_img );
221 /* Create new list from randomised index list */
222 for( i = 0; i < gll; i++ )
223 gl = g_list_append( gl, ((struct idb_entry *)g_list_nth( pbg_ctx->idb, gli[i] )->data));
225 /* exchange entries if remembering is set and the image is in the list */
226 if( bgmon.remember_image_number && entry ) {
227 i = g_list_index( gl, entry->data);
228 tentry = g_list_nth( gl, i );
229 gl = g_list_remove_link( gl, tentry );
230 gl = g_list_prepend( gl, tentry->data );
233 /* Switch to the randomised list */
234 g_list_free(pbg_ctx->idb); pbg_ctx->idb = gl;
236 /* begin with zero */
237 pbg_ctx->cur_img = 0;
239 /* Uncomment code below to show indices and filenames */
241 for( i = 0; i < gll; i++ ) printf(" %d ", gli[i]);
242 fprintf(stderr, "\n");
244 gchar *fname = NULL;
245 for( i = 0; i < gll; i++ ) {
246 fname = g_strdup( ((struct idb_entry *)g_list_nth( pbg_ctx->idb, i )->data)->filename );
247 fprintf(stderr, "%d <%s>\n", i, fname );
249 g_free( fname );
253 /* returns 0 if list was updated (= normal operation), 1 otherwise */
254 /* force - whether to load list even if not modified */
255 static int update_image_list(int force)
257 gchar *tmp = NULL;
258 #if !defined(MAXPATHLEN)
259 gchar *tmp2 = NULL;
260 #endif
261 gchar c;
262 gint num=1;
263 FILE *idb_file;
264 struct idb_entry *idb_e;
266 if((idb_file = open_imagelist( bgmon.idb, force )) == NULL) return 1;
268 if(pbg_ctx->idb != NULL) { g_list_free(pbg_ctx->idb); pbg_ctx->idb = NULL; }
270 tmp = g_malloc( num*BUFFSIZE );
271 while(!feof(idb_file)) {
273 /* skip leading blanks and tabs */
274 while( ((c = fgetc( idb_file )) == 0x20 || c == '\t') && !feof( idb_file ));
276 if( c == '#' ) { /* skip entry */
277 while( ((char)fgetc( idb_file ) != '\n') && !feof( idb_file ) );
278 continue;
281 if( c == '\n' ) continue;
283 *tmp=c; /* copy entry */
284 /* abort on error and eof when no bytes were read */
285 if( !fgets( tmp+1, (num*BUFFSIZE)-1, idb_file ) ) continue;
286 #if !defined(MAXPATHLEN)
287 while( tmp[strlen(tmp)-1]!='\n' && !feof( idb_file ) ) {
288 if( (tmp2 = g_realloc( tmp, ++num*BUFFSIZE )) == NULL ) break;
289 tmp = tmp2;
290 if( !fgets( tmp+strlen(tmp), BUFFSIZE, idb_file ) ) break;
292 #endif
293 if( tmp[strlen(tmp)-1]=='\n' )
294 tmp[strlen(tmp)-1] = 0x00; /* strip trailing newline */
295 #if defined(MAXPATHLEN)
296 else if( !feof( idb_file ) )
297 /* skip to eol or eof */
298 while( ((char)fgetc( idb_file ) != '\n') && !feof( idb_file ) );
299 #endif
301 /* ignore the file if doesn't exist */
302 if( bgmon.ignore && !g_file_test( tmp, G_FILE_TEST_EXISTS ) ) {
303 GKBG_debug( "ignoring `%s'", tmp );
304 } else {
305 idb_e = (struct idb_entry *)calloc( 1, sizeof( struct idb_entry ));
306 idb_e->filename = g_strdup( tmp );
307 pbg_ctx->idb = g_list_append( pbg_ctx->idb, idb_e );
312 g_free( tmp );
313 fclose(idb_file);
315 if( bgmon.randomise )
316 randomise_image_list();
317 else
318 pbg_ctx->cur_img = bgmon.image_nr_last_run;
320 return 0;
326 static void update_image(gint32 inr)
328 gchar *fname = NULL, *tiptext = NULL, *ch, *tmp = NULL, *tag, *value;
329 gint count = 0;
330 double val;
331 guint gll = g_list_length( pbg_ctx->idb );
333 GKBG_debug("update_image(%i) [%i]", inr, gll);
336 #if !defined(WIN32)
338 * Auto update
340 if( bgmon.auto_update && !update_image_list(0)) {
341 GKBG_debug("list modified.");
342 inr = -1;
344 #endif
348 * Choose file
350 /* nothing to change, if there are not at least 2 images,
351 however, if list was just updated image in it may be different. */
352 if( !gll || (inr!=-1 && gll==1) ) return;
353 /* start over, if the number is larger than the database's length */
354 if( gll < inr ) inr = -1;
356 /* If randomising, images are already randomised; hence we just
357 increment index no matter what. */
358 if( inr == -1) { /* -1 means change */
359 if( ++pbg_ctx->cur_img >= gll ) {
360 if( bgmon.randomise ) randomise_image_list();
361 pbg_ctx->cur_img=0;
363 /* make sure GKrellM will save the image number */
364 gkrellm_config_modified();
365 } else pbg_ctx->cur_img = inr;
366 fname = g_strdup( ((struct idb_entry *)g_list_nth( pbg_ctx->idb, pbg_ctx->cur_img )->data)->filename );
371 * Make command string
373 pbg_ctx->seconds_left = bgmon.wait_seconds;
374 #if defined(WIN32)
375 if (bgmon.parse_cmd_output) {
376 #endif
378 for (ch = bgmon.command; *ch; ) {
379 if (*ch++=='%') {
380 switch (*ch) {
381 case '%': if (count==0) count = 1; break;
382 case 's': ++count; break;
383 default: count = 2;
385 if (*ch) ++ch;
389 /* If there was exactly one '%s' in command use it as format */
390 tmp = count==1
391 ? g_strdup_printf( bgmon.command, g_shell_quote(fname) )
392 : g_strdup_printf( "%s %s", bgmon.command, g_shell_quote(fname) );
393 GKBG_debug("command: %s", tmp);
395 #if defined(WIN32)
397 #endif
401 * Parse output
403 if (bgmon.parse_cmd_output) {
405 if (!g_spawn_command_line_sync(tmp, &ch, NULL, &count, NULL)) {
406 count = 1;
408 free(tmp);
410 /* Failed */
411 if (count) {
412 pbg_ctx->seconds_left = 10;
413 return;
416 /* Parse */
417 for (tmp = ch; *ch; ) {
418 for (tag = ch; *ch && *ch!=':'; ++ch);
419 if (!*ch) break;
420 *ch++ = 0;
421 for (value = ch; *ch && *ch!='\n'; ++ch);
422 if (!*ch) break;
423 *ch++ = 0;
425 if (!strcmp(tag, "file")) {
426 if (fname) free(fname);
427 fname = g_strdup(value);
428 } else if (!strcmp(tag, "tooltip")) {
429 if (tiptext) free(tiptext);
430 tiptext = g_strdup(value);
431 } else if (strcmp(tag, "time")) {
432 continue;
435 if (*value=='+' || *value=='-') {
436 count = strtol(value, &value, 0);
437 if (!*value) pbg_ctx->seconds_left += count;
438 } else if (*value=='*' || *value=='x') {
439 val = strtod(value+1, &value);
440 if (!*value && val>0) pbg_ctx->seconds_left *= val;
441 } else if (*value=='/') {
442 val = strtod(value+1, &value);
443 if (!*value && val>0) pbg_ctx->seconds_left /= val;
444 } else if (*value=='<') {
445 count = strtol(value+1, &value, 0);
446 if (!*value && value>0 && pbg_ctx->seconds_left<count)
447 pbg_ctx->seconds_left = count;
448 } else if (*value=='>') {
449 count = strtol(value+1, &value, 0);
450 if (!*value && value>0 && pbg_ctx->seconds_left>count)
451 pbg_ctx->seconds_left = count;
452 } else {
453 count = strtol(value, &value, 0);
454 if (!*value && count>=0) pbg_ctx->seconds_left = count;
457 free(tmp);
460 #if !defined(WIN32)
462 * Don't parse output
464 } else {
465 g_spawn_command_line_async( tmp, NULL );
466 g_free( tmp );
467 #endif
471 #if defined(WIN32)
473 * Set background under Win32
475 SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, fname, 0);
476 #endif
480 * Set tool tip text
482 if( tiptext == NULL && fname ) {
483 for (tiptext = ch = fname; *ch; ++ch) {
484 if (*ch=='/' && *(ch+1)) tiptext = ch+1;
486 tiptext = g_locale_to_utf8( tiptext, -1, NULL, NULL, NULL);
488 gtk_tooltips_set_tip( pbg_ctx->tip, panel->drawing_area, tiptext, NULL );
489 gtk_tooltips_enable( pbg_ctx->tip );
490 g_free( tiptext );
491 g_free( fname );
497 static void update_decals_text( gchar *text )
499 gchar *s, buf[48];
501 if( pbg_ctx->locked ) return;
503 text[0] = '\0';
504 for( s=bgmon.format_string; *s!='\0'; s++ ) {
505 buf[0] = *s; buf[1]='\0';
506 if( *s == '$' && *(s+1) !='\0' )
507 switch( *(s+1) ) {
508 case 's':
509 g_snprintf( buf, 12, "%d", pbg_ctx->seconds_left );
510 s++;
511 break;
512 case 'S':
513 g_snprintf( buf, 12, "%d", bgmon.wait_seconds - pbg_ctx->seconds_left );
514 s++;
515 break;
516 case 'm':
517 g_snprintf( buf, 12, "%d", pbg_ctx->seconds_left / 60 );
518 s++;
519 break;
520 case 'M':
521 g_snprintf( buf, 12, "%d", (bgmon.wait_seconds-pbg_ctx->seconds_left) / 60 );
522 s++;
523 break;
524 case 't':
525 if (bgmon.wait_seconds > 3600) { /* If over an hour, display hh:mm */
526 gint hours = pbg_ctx->seconds_left / 3600;
527 g_snprintf( buf, 12, "%.2d:%.2d",
528 hours, (pbg_ctx->seconds_left - hours*3600)/ 60 );
529 } else
530 g_snprintf( buf, 12, "%.2d:%.2d",
531 pbg_ctx->seconds_left / 60, pbg_ctx->seconds_left % 60 );
532 s++;
533 break;
534 case 'T':
535 if (bgmon.wait_seconds > 3600) { /* If over an hour, display hh:mm */
536 gint hours = (bgmon.wait_seconds-pbg_ctx->seconds_left) / 3600;
537 g_snprintf( buf, 12, "%.2d:%.2d",
538 hours,
539 (bgmon.wait_seconds-hours*3600-pbg_ctx->seconds_left) / 60 );
540 } else
541 g_snprintf( buf, 12, "%.2d:%.2d",
542 (bgmon.wait_seconds-pbg_ctx->seconds_left) / 60,
543 (bgmon.wait_seconds-pbg_ctx->seconds_left) % 60 );
544 s++;
545 break;
547 strncat( text, buf,
548 (strlen(text)+strlen(buf)) > TEXTSIZE ? TEXTSIZE - strlen(text) : strlen(buf) );
550 text = g_locale_to_utf8( text, -1, NULL, NULL, NULL );
553 static void update_krell(void)
555 if ( ! bgmon.display_krell ) return;
556 gkrellm_update_krell( panel, krell_time, (gulong) bgmon.wait_seconds - pbg_ctx->seconds_left );
559 static void update_plugin(void)
561 int w = 0, c = 0;
562 gchar text[TEXTSIZE] = "locked";
564 if(pGK->second_tick && !pbg_ctx->locked && !(pbg_ctx->seconds_left--)) {
565 update_image(-1);
568 if(!(pGK->timer_ticks % 2)) return;
570 if( !pbg_ctx->locked ) update_decals_text( text );
572 /* No need to do these calculations every time... FIXME */
573 if ( bgmon.center_text ) {
574 GkrellmMargin *m =gkrellm_get_style_margins(gkrellm_panel_style(style_id));
575 w = gkrellm_gdk_string_width(gkrellm_panel_textstyle(style_id)->font, text);
576 c = (gkrellm_chart_width() - w ) / 2 - m->left;
578 gkrellm_decal_text_set_offset(decal_wu, c, 2);
579 if ( bgmon.display_text )
580 gkrellm_draw_decal_text( panel, decal_wu, text, -1 );
582 update_krell();
583 gkrellm_draw_panel_layers( panel );
586 static gint panel_expose_event( GtkWidget *widget, GdkEventExpose *ev)
588 if( widget == panel->drawing_area ) {
589 gdk_draw_pixmap( widget->window,
590 widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
591 panel->pixmap,
592 ev->area.x, ev->area.y,
593 ev->area.x, ev->area.y,
594 ev->area.width, ev->area.height );
596 return FALSE;
599 static gint cb_panel_scroll( GtkWidget *widget, GdkEventScroll *ev )
601 gint shift_modifier = (ev->state & GDK_SHIFT_MASK) ? !bgmon.simple_scroll_adj : bgmon.simple_scroll_adj;
602 gint prev_locked = pbg_ctx->locked;
604 if (ev->direction == GDK_SCROLL_UP) {
605 if( !shift_modifier ) pbg_ctx->locked = 1;
606 else pbg_ctx->seconds_left += bgmon.scroll_adj_time;
607 } else if (ev->direction == GDK_SCROLL_DOWN) {
608 if( !shift_modifier && pbg_ctx->locked) {
609 pbg_ctx->locked = 0;
610 if( bgmon.reset ) pbg_ctx->seconds_left = bgmon.wait_seconds;
611 } else if( shift_modifier ) {
612 pbg_ctx->seconds_left -= bgmon.scroll_adj_time;
613 if( pbg_ctx->seconds_left < 0 ) pbg_ctx->seconds_left = 1;
617 /* make sure GKrellM will save the lock state if it changed */
618 if ( prev_locked != pbg_ctx->locked ) gkrellm_config_modified();
620 return FALSE;
623 static gint cb_button_press( GtkWidget *widget, GdkEventButton *ev )
625 gint shift_modifier = (ev->state & GDK_SHIFT_MASK ) ? 1 : 0;
627 switch( ev->button ) {
628 /* left */
629 case 1:
630 if( shift_modifier ) { /* shift+left -> lock/unlock the bg */
631 if( pbg_ctx->locked ) {
632 pbg_ctx->locked = 0;
633 if( bgmon.reset ) pbg_ctx->seconds_left = bgmon.wait_seconds;
634 } else pbg_ctx->locked = 1;
635 /* make sure GKrellM will save the lock state */
636 gkrellm_config_modified();
637 } else {
638 update_image(-1);
640 break;
641 /* middle */
642 case 2:
643 update_image_list(1);
644 break;
645 /* right */
646 case 3:
647 if( shift_modifier ) {/* shift+right -> lock/unlock the bg */
648 if( pbg_ctx->locked ) {
649 pbg_ctx->locked = 0;
650 if( bgmon.reset ) pbg_ctx->seconds_left = bgmon.wait_seconds;
651 } else pbg_ctx->locked = 1;
652 /* make sure GKrellM will save the lock state */
653 gkrellm_config_modified();
654 } else
655 gkrellm_open_config_window( monitor );
656 break;
659 return FALSE;
662 static void create_plugin( GtkWidget *vbox, gint first_create )
664 GkrellmPiximage *krell_img;
665 GkrellmStyle *style;
666 GkrellmTextstyle *ts;
667 gchar text[TEXTSIZE] = "bgchg" ;
669 gkrellm_vbox = vbox;
671 if (first_create) panel = gkrellm_panel_new0 ();
672 else gkrellm_destroy_decal_list( panel );
674 style = gkrellm_meter_style( style_id );
675 krell_img = gkrellm_krell_meter_piximage( style_id );
676 ts = gkrellm_panel_textstyle( style_id );
677 panel->textstyle = ts;
679 krell_time = gkrellm_create_krell( panel, krell_img, style );
680 gkrellm_monotonic_krell_values(krell_time, FALSE);
681 gkrellm_set_krell_full_scale( krell_time, bgmon.wait_seconds, 1 );
682 if ( ! bgmon.display_krell )
683 gkrellm_remove_krell( panel, krell_time );
685 decal_wu = gkrellm_create_decal_text( panel, "Apif0", ts, style, -1, -1, -1 );
687 gkrellm_panel_configure( panel, NULL, style );
688 gkrellm_panel_create( vbox, monitor, panel );
690 gkrellm_draw_decal_text( panel, decal_wu, text, -1 );
692 if(first_create) {
693 g_signal_connect( G_OBJECT (panel->drawing_area), "expose_event",
694 G_CALLBACK(panel_expose_event), NULL );
695 g_signal_connect( G_OBJECT (panel->drawing_area), "button_press_event",
696 G_CALLBACK(cb_button_press), NULL );
697 g_signal_connect(G_OBJECT(panel->drawing_area),"scroll_event",
698 G_CALLBACK(cb_panel_scroll), NULL);
700 pbg_ctx = g_malloc( sizeof(struct bg_ctx) );
701 memset( pbg_ctx, 0x00, sizeof(struct bg_ctx) );
702 if (bgmon.remember_image_number) pbg_ctx->cur_img = bgmon.image_nr_last_run;
703 else pbg_ctx->cur_img = -1;
704 } else pbg_ctx->cur_img = -1;
706 pbg_ctx->tip = gtk_tooltips_new();
707 gtk_tooltips_enable( pbg_ctx->tip );
709 pbg_ctx->bgchg_rand = g_rand_new_with_seed( (guint32)time(NULL) );
711 if (bgmon.remember_locked_state) pbg_ctx->locked = bgmon.locked_last_run;
712 else pbg_ctx->locked = 0;
713 pbg_ctx->seconds_left = bgmon.wait_seconds;
715 update_image_list(1);
716 if (bgmon.change_on_load) update_image( pbg_ctx->cur_img );
717 update_krell();
719 gkrellm_draw_panel_layers( panel );
722 static gchar *plugin_info_text[] = {
723 "<b>GKrellMBgChg ",
724 "is a GKrellM plugin which periodically changes\n",
725 "your desktop background. It also allows you to monitor the time\n",
726 "between the updates in various ways. It is possible, to force a\n",
727 "change by clicking on the panel.\n\n",
728 "<h>Mouse Actions:\n\n",
729 "<b>- Left ", "changes the background image and resets the timer,\n",
730 "\t+<Shift> toggles the background lock.\n",
731 "<b>- Middle ", "reloads the images from the image database\n",
732 "\t(see \"Image Database\" below).\n",
733 "<b>- Right ", "opens the GKrellM Background Changer config window.\n",
734 "\t+<Shift> toggles the background lock.\n\n",
735 "<b>Mouse Wheel Actions:\n\n",
736 "<b>- Up ", "\"locks\" the current background image (if you like it very much).\n",
737 "\t+<Shift> prolongs the timer by the seconds given below.\n",
738 "<b>- Down ", "\"unlocks\" the image and the counter continues.\n",
739 "\t+<Shift> shortens the timer by the seconds given below.\n",
740 "The option \"Mouse wheel adjusts timer\" below exchanges the\n",
741 "<Shift>-behaviour of the mouse wheel.\n\n",
742 "<h>Configuration:\n\n",
743 "<b>- Format String\n",
744 "\tThe text output format is controlled by this string (default: $s).\n",
745 "<b>\t$s ", "are the seconds that are remaining to the next update\n",
746 "<b>\t$S ", "are the seconds that passed since the last change\n",
747 "<b>\t$m ", "are the minutes that are remaining to the next update\n",
748 "<b>\t$M ", "are the minutes that passed since the last change\n",
749 "<b>\t$t ", "is the time remaining to the next update, displayed as '-mm:ss'\n",
750 "<b>\t$T ", "is the time that passed since the last change, displayed as 'mm:ss'.\n\n",
751 #if defined(WIN32)
752 "<b>- Background Info Command\n",
753 "\tProgram to return information such as timeout, filename and tooltip.\n"
754 "\tIt is used only if Use Background Info Command is checked.\n"
755 "\tSee ", "<b>README: Tips and Tricks", " for info about output format\n",
756 "\tand some ideas.\n"
757 "\tdefault: empty",
758 "<b>- Use Background Info Command\n",
759 "\tWhether to use Background Info Command. This option is experimental.\n",
760 "\tdefault: ", "<b>off\n\n",
761 #else
762 "<b>- Background Change Command\n",
763 "\tProgram to use to set the desktop background image (including args).\n",
764 "\tIf the command has exactly one '%s' it will be replaced by the\n",
765 "\tproperly quoted background file name.\n",
766 "\tCommon cases are:\n",
767 "\tfor plain X11: ", "<b>xsetbg -fullscreen\n",
768 "\tusing Eterm's Esetroot: ", "<b>Esetroot -f\n",
769 "\tfor Gnome2 set it to:\n\t\t",
770 "<b>gconftool-2 --type=string --set /desktop/gnome/background/picture_filename\n",
771 "\tand for KDE 3.x:\n\t\t",
772 "<b>dcop kdesktop KBackgroundIface setWallpaper %s 6\n",
773 "\tdefault: ", "<b>Esetroot -f\n\n",
774 "<b>- Parse Background Change Command output\n",
775 "\tWhether to parse output of Background Change Command. This allows\n",
776 "\tsetting such information as tooltip and timeout from the command.\n",
777 "\tSee ", "<b>README: Tips and Tricks", " for info about output format\n",
778 "\tand some ideas. This option is experimental.\n",
779 "\tdefault: ", "<b>off\n\n",
780 #endif
781 "<b>- Image Database\n",
782 "\tFull path to a file containing all the images (full path/line) to be\n",
783 "\tused by the plugin. (e.g. the output from: ", "<b>find / -name *.jpg | sort", ")\n",
784 "\tEntries starting with a '#' will be ", "<i>ignored.\n",
785 "\tdefault: ", "<b>~/images.idb\n\n",
786 #if !defined(WIN32)
787 "<b>- Auto update image list\n",
788 "\tSelect whether the image list should be automatically updated \n",
789 "\twhen the image database file is modified.\n",
790 "\tdefault: ", "<b>off\n\n",
791 "<b>- Ignore not found images\n",
792 "\tIgnore image files that could not be found.\n",
793 "\tdefault: ", "<b>off\n\n",
794 #endif
795 "<b>- Randomise images\n",
796 "\tSelect whether the image list should be randomised or not.\n",
797 "<b>\tNote: ", "If it is not set, it will ", "<i>always ",
798 "start at the first image in the list.\n",
799 "\tdefault: ", "<b>on\n\n",
800 "<b>- Reset timer on \"lock\" release\n",
801 "\tReset the timer to the initial value when the \"image lock\" is released.\n",
802 "\tdefault: ", "<b>off\n\n",
803 "<b>- Reset timer on config changes\n",
804 "\tReset the timer on config changes, i.e. when you hit \"apply\" button.\n",
805 "\tdefault: ", "<b>off\n\n",
806 "<b>- Change wallpaper on load\n",
807 "\tChanges the wallpaper when the plugin loads.\n",
808 "\tdefault: ", "<b>off\n\n",
809 "<b>- Change wallpaper on config changes\n",
810 "\tChanges the wallpaper when the config changes.\n",
811 "\tdefault: ", "<b>off\n\n",
812 "<b>- Remember \"locked\" state from last run\n",
813 "\tRemembers whether the current wallpaper was \"locked\"\n",
814 "\tor not when GKrellM last shut down. Use with change-on-load\n",
815 "\toption off to load a new wallpaper ", "<i>only", " on request.\n",
816 "\tdefault: ", "<b>off\n\n",
817 "<b>- Remember image number from last run\n",
818 "\tRemembers the image number from the database that was\n",
819 "\tshown when GKrellM last shut down. It starts the next time with\n",
820 "\tthis image if the image list didn't change.\n",
821 "\tdefault: ", "<b>off\n\n",
822 "<b>- Center text\n",
823 "\tCenters the displayed text.\n",
824 "\tdefault: ", "<b>on\n\n",
825 "<b>- Display text\n",
826 "\tToggles the text on or off.\n",
827 "\tdefault: ", "<b>on\n\n",
828 "<b>- Display krell/slider\n",
829 "\tToggles the krell on or off.\n",
830 "\tdefault: ", "<b>on\n\n",
831 "<b>- Mouse wheel adjusts timer\n",
832 "\tWhen selected, scrolling the mouse wheel adjusts the time\n",
833 "\trather than \"lock\" the image. Otherwise the adjustment\n",
834 "\tworks in combination with the <Shift>-key.\n",
835 "\tdefault: ", "<b>off\n\n",
836 "<b>- Mouse wheel adjusts the timer by nnn seconds\n",
837 "\tThis is the amount of seconds by which the timer is adjusted\n",
838 "\twhen scrolling the mouse wheel while holding the <Shift>-key.\n",
839 "\tSee also \"Mouse wheel adjusts timer.\"\n",
840 "\tdefault: ", "<b>60\n"
843 static void create_bgchg_tab( GtkWidget *tab )
845 GtkWidget *tabs, *vbox, *hbox;
846 GtkWidget *label, *frame;
847 GtkWidget *text;
848 GtkAdjustment *adj, *mouse_wheel_adj;
849 gchar *about_text = NULL;
851 tabs = gtk_notebook_new();
852 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(tabs),GTK_POS_TOP);
853 gtk_box_pack_start(GTK_BOX(tab),tabs,TRUE,TRUE,0);
855 /* options */
856 frame = gtk_frame_new(NULL);
857 gtk_container_border_width(GTK_CONTAINER(frame),3);
858 label = gtk_label_new(_("Options"));
859 gtk_notebook_append_page(GTK_NOTEBOOK(tabs),frame,label);
861 vbox = gtk_vbox_new(FALSE,0);
862 gtk_container_add(GTK_CONTAINER(frame),vbox);
864 hbox = gtk_hbox_new(FALSE, 0);
865 label = gtk_label_new(_("Format String"));
866 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
867 entry_format_str = gtk_entry_new_with_max_length(127);
868 gtk_entry_set_text(GTK_ENTRY(entry_format_str),bgmon.format_string);
869 gtk_box_pack_start(GTK_BOX(hbox), entry_format_str, FALSE, FALSE, 4);
870 gtk_container_add(GTK_CONTAINER(vbox),hbox);
872 hbox = gtk_hbox_new(FALSE, 0);
873 #if defined(WIN32)
874 label = gtk_label_new(_("Background Info Command"));
875 #else
876 label = gtk_label_new(_("Background Change Command"));
877 #endif
878 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
879 entry_command = gtk_entry_new_with_max_length(255);
880 gtk_entry_set_text(GTK_ENTRY(entry_command),bgmon.command);
881 gtk_box_pack_start(GTK_BOX(hbox), entry_command, TRUE, TRUE, 4);
882 gtk_container_add(GTK_CONTAINER(vbox),hbox);
884 #if defined(WIN32)
885 parse_cmd_entry = gtk_check_button_new_with_label( _("Use Background Info Command (experimental)"));
886 #else
887 parse_cmd_entry = gtk_check_button_new_with_label( _("Parse Background Change Command output (experimental)"));
888 #endif
889 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( parse_cmd_entry ), bgmon.parse_cmd_output );
890 gtk_container_add( GTK_CONTAINER(vbox), parse_cmd_entry );
893 hbox = gtk_hbox_new(FALSE, 0);
894 label = gtk_label_new(_("Image Database"));
895 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
896 entry_idb = gtk_entry_new_with_max_length(255);
897 gtk_entry_set_text(GTK_ENTRY(entry_idb),bgmon.idb);
898 gtk_box_pack_start(GTK_BOX(hbox), entry_idb, TRUE, TRUE, 4);
899 gtk_container_add(GTK_CONTAINER(vbox),hbox);
901 hbox = gtk_hbox_new(FALSE, 0);
902 adj = (GtkAdjustment *) gtk_adjustment_new(bgmon.wait_seconds,
903 1.0, 99999.0, 1.0, 5.0, 0.0);
904 wait_seconds_spin_button = gtk_spin_button_new(adj, 0.5, 0);
905 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(wait_seconds_spin_button), TRUE);
906 gtk_box_pack_start(GTK_BOX(hbox), wait_seconds_spin_button, FALSE, FALSE, 4);
907 label = gtk_label_new(_("Seconds between image changes"));
908 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
909 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
910 gtk_container_add(GTK_CONTAINER(vbox),hbox);
912 #if !defined(WIN32)
913 auto_update_entry = gtk_check_button_new_with_label( _("Auto update image list"));
914 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( auto_update_entry ), bgmon.auto_update );
915 gtk_container_add( GTK_CONTAINER(vbox), auto_update_entry );
916 #endif
918 ignore_entry = gtk_check_button_new_with_label( _("Ignore not found images"));
919 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( ignore_entry ), bgmon.ignore );
920 gtk_container_add( GTK_CONTAINER(vbox), ignore_entry );
922 randomise_entry = gtk_check_button_new_with_label( _("Randomise images"));
923 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( randomise_entry ), bgmon.randomise );
924 gtk_container_add( GTK_CONTAINER(vbox), randomise_entry );
926 reset_entry = gtk_check_button_new_with_label( _("Reset timer on \"lock\" release"));
927 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( reset_entry ), bgmon.reset );
928 gtk_container_add( GTK_CONTAINER(vbox), reset_entry );
930 reset_entry2 = gtk_check_button_new_with_label( _("Reset timer on config changes"));
931 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( reset_entry2 ), bgmon.reset_config );
932 gtk_container_add( GTK_CONTAINER(vbox), reset_entry2 );
934 change_on_load = gtk_check_button_new_with_label(_("Change wallpaper on load"));
935 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( change_on_load ), bgmon.change_on_load );
936 gtk_container_add( GTK_CONTAINER(vbox), change_on_load );
938 change_on_apply = gtk_check_button_new_with_label(_("Change wallpaper on config changes"));
939 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( change_on_apply ), bgmon.change_on_apply );
940 gtk_container_add( GTK_CONTAINER(vbox), change_on_apply );
942 remember_locked_state = gtk_check_button_new_with_label(_("Remember \"locked\" state from last run"));
943 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( remember_locked_state ), bgmon.remember_locked_state );
944 gtk_container_add( GTK_CONTAINER(vbox), remember_locked_state );
946 remember_image_number = gtk_check_button_new_with_label(_("Remember image number from last run"));
947 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( remember_image_number ), bgmon.remember_image_number );
948 gtk_container_add( GTK_CONTAINER(vbox), remember_image_number );
950 center_text = gtk_check_button_new_with_label(_("Center text"));
951 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( center_text ), bgmon.center_text );
952 gtk_container_add( GTK_CONTAINER(vbox), center_text );
954 display_text = gtk_check_button_new_with_label(_("Display text"));
955 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( display_text ), bgmon.display_text );
956 gtk_container_add( GTK_CONTAINER(vbox), display_text );
958 display_krell = gtk_check_button_new_with_label(_("Display krell/slider"));
959 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( display_krell ), bgmon.display_krell );
960 gtk_container_add( GTK_CONTAINER(vbox), display_krell );
962 simple_scroll_adj = gtk_check_button_new_with_label(_("Mouse wheel adjusts timer"));
963 gtk_toggle_button_set_active( GTK_TOGGLE_BUTTON( simple_scroll_adj ), bgmon.simple_scroll_adj );
964 gtk_container_add( GTK_CONTAINER(vbox), simple_scroll_adj );
966 hbox = gtk_hbox_new (FALSE, 5);
967 gtk_widget_show (hbox);
968 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
970 label = gtk_label_new (_("Mouse wheel adjusts the timer by"));
971 gtk_widget_show (label);
972 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
973 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
975 mouse_wheel_adj = (GtkAdjustment *) gtk_adjustment_new (bgmon.scroll_adj_time, 1, 1000, 1, 10, 0);
976 scroll_adj_spin_button = gtk_spin_button_new (GTK_ADJUSTMENT (mouse_wheel_adj), 1, 0);
977 gtk_widget_show (scroll_adj_spin_button);
978 gtk_box_pack_start (GTK_BOX (hbox), scroll_adj_spin_button, FALSE, TRUE, 0);
980 label = gtk_label_new (_("second(s)"));
981 gtk_widget_show (label);
982 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
983 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
985 /* info */
986 vbox = gkrellm_gtk_framed_notebook_page(tabs,_("Info"));
987 text = gkrellm_gtk_scrolled_text_view(vbox, NULL,
988 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
989 gkrellm_gtk_text_view_append_strings(text, _(plugin_info_text),
990 sizeof(plugin_info_text) / sizeof(gchar *));
992 /* about */
993 about_text = g_strdup_printf(
994 "GKrellMBgChg %s\n" \
995 "GKrellM Background Changer Plugin\n\n" \
996 "Copyright © 2002-2010 Stefan Bender\n" \
997 "stefan@bender-suhl.de\n" \
998 "http://www.bender-suhl.de/stefan/english/comp/gkrellmbgchg.html\n\n" \
999 "Released under the GNU General Public Licence",
1000 GKRELLMBGCHG_VERSION);
1002 text = gtk_label_new(about_text);
1003 label = gtk_label_new(_("About"));
1004 gtk_notebook_append_page(GTK_NOTEBOOK(tabs),text,label);
1005 g_free(about_text);
1008 static void apply_config(void)
1010 const gchar *s;
1012 /* update config vars */
1013 bgmon.wait_seconds = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(wait_seconds_spin_button));
1014 s = gtk_entry_get_text(GTK_ENTRY(entry_format_str));
1015 strcpy(bgmon.format_string,s);
1016 s = gtk_entry_get_text(GTK_ENTRY(entry_idb));
1017 strcpy(bgmon.idb,s);
1018 #if !defined(WIN32)
1019 bgmon.auto_update = GTK_TOGGLE_BUTTON( auto_update_entry )->active;
1020 #endif
1021 bgmon.ignore = GTK_TOGGLE_BUTTON( ignore_entry )->active;
1022 s = gtk_entry_get_text(GTK_ENTRY(entry_command));
1023 strcpy(bgmon.command,s);
1024 bgmon.parse_cmd_output = GTK_TOGGLE_BUTTON( parse_cmd_entry )->active;
1025 bgmon.randomise = GTK_TOGGLE_BUTTON( randomise_entry )->active;
1026 bgmon.reset = GTK_TOGGLE_BUTTON( reset_entry )->active;
1027 bgmon.reset_config = GTK_TOGGLE_BUTTON( reset_entry2 )->active;
1028 bgmon.change_on_load = GTK_TOGGLE_BUTTON( change_on_load )->active;
1029 bgmon.change_on_apply = GTK_TOGGLE_BUTTON( change_on_apply )->active;
1030 bgmon.remember_locked_state = GTK_TOGGLE_BUTTON( remember_locked_state )->active;
1031 bgmon.remember_image_number = GTK_TOGGLE_BUTTON( remember_image_number )->active;
1032 bgmon.simple_scroll_adj = GTK_TOGGLE_BUTTON( simple_scroll_adj )->active;
1033 bgmon.display_text = GTK_TOGGLE_BUTTON( display_text )->active;
1034 bgmon.center_text = GTK_TOGGLE_BUTTON( center_text )->active;
1035 bgmon.display_krell = GTK_TOGGLE_BUTTON( display_krell )->active;
1037 /* create new panel, not the first time */
1038 if( bgmon.reset_config ) pbg_ctx->seconds_left = bgmon.wait_seconds;
1039 update_image_list(1);
1040 if( bgmon.change_on_apply ) update_image(-1);
1042 if ( bgmon.display_text )
1043 gkrellm_make_decal_visible( panel, decal_wu );
1044 else
1045 gkrellm_make_decal_invisible( panel, decal_wu );
1046 if ( bgmon.display_krell )
1047 gkrellm_insert_krell( panel, krell_time, 1 );
1048 else
1049 gkrellm_remove_krell( panel, krell_time );
1052 static void save_config( FILE *f)
1054 fprintf( f, "%s wait_seconds %d\n", CONFIG_KEYWORD, bgmon.wait_seconds );
1055 #if !defined(WIN32)
1056 fprintf( f, "%s auto_update %d\n", CONFIG_KEYWORD, bgmon.auto_update );
1057 #endif
1058 fprintf( f, "%s ignore %d\n", CONFIG_KEYWORD, bgmon.ignore );
1059 fprintf( f, "%s command %s\n", CONFIG_KEYWORD, bgmon.command );
1060 fprintf( f, "%s parse_cmd_output %d\n", CONFIG_KEYWORD, bgmon.parse_cmd_output );
1061 fprintf( f, "%s randomise %d\n", CONFIG_KEYWORD, bgmon.randomise );
1062 fprintf( f, "%s reset %d\n", CONFIG_KEYWORD, bgmon.reset );
1063 fprintf( f, "%s reset_config %d\n", CONFIG_KEYWORD, bgmon.reset_config );
1064 fprintf( f, "%s format_string %s\n", CONFIG_KEYWORD, bgmon.format_string );
1065 fprintf( f, "%s idb %s\n", CONFIG_KEYWORD, bgmon.idb );
1066 fprintf( f, "%s change_on_load %d\n", CONFIG_KEYWORD, bgmon.change_on_load );
1067 fprintf( f, "%s change_on_apply %d\n", CONFIG_KEYWORD, bgmon.change_on_apply );
1068 fprintf( f, "%s remember_locked_state %d\n", CONFIG_KEYWORD, bgmon.remember_locked_state );
1069 fprintf( f, "%s locked_last_run %d\n", CONFIG_KEYWORD, pbg_ctx->locked );
1070 fprintf( f, "%s remember_image_number %d\n", CONFIG_KEYWORD, bgmon.remember_image_number );
1071 if (!pbg_ctx->idb || pbg_ctx->cur_img < 0) {
1072 fprintf( f, "%s image_nr_last_run %d\n", CONFIG_KEYWORD, 0 );
1073 } else if (!pbg_ctx->idb_orig) {
1074 fprintf( f, "%s image_nr_last_run %d\n", CONFIG_KEYWORD,
1075 pbg_ctx->cur_img );
1076 } else {
1077 GList *list = g_list_nth(pbg_ctx->idb, pbg_ctx->cur_img);
1078 fprintf( f, "%s image_nr_last_run %d\n", CONFIG_KEYWORD,
1079 list ? g_list_index( pbg_ctx->idb_orig, list->data) : 0);
1081 fprintf( f, "%s simple_scroll_adj %d\n", CONFIG_KEYWORD, bgmon.simple_scroll_adj );
1082 fprintf( f, "%s scroll_adj_time %d\n", CONFIG_KEYWORD, bgmon.scroll_adj_time );
1083 fprintf( f, "%s center_text %d\n", CONFIG_KEYWORD, bgmon.center_text );
1084 fprintf( f, "%s display_text %d\n", CONFIG_KEYWORD, bgmon.display_text );
1085 fprintf( f, "%s display_krell %d\n", CONFIG_KEYWORD, bgmon.display_krell );
1088 static void load_config( gchar *arg )
1090 gchar *command, *p;
1092 for( p = arg; *p && isspace(*p); p++ );
1093 for( ; *p && !isspace(*p); p++ );
1095 command = g_malloc( (p-arg+1)*sizeof(char) );
1096 memset( command, 0x00, p-arg+1 );
1097 memcpy( command, arg, p-arg );
1099 for( ; *p && isspace(*p); p++ );
1101 if( !strcmp(command, "wait_seconds") ) bgmon.wait_seconds = atoi( p );
1102 #if !defined(WIN32)
1103 else if( !strcmp(command, "auto_update") ) bgmon.auto_update = atoi( p );
1104 #endif
1105 else if( !strcmp(command, "ignore") ) bgmon.ignore = atoi( p );
1106 else if( !strcmp(command, "command") ) strcpy( bgmon.command, p );
1107 else if( !strcmp(command, "parse_cmd_output") ) bgmon.parse_cmd_output = atoi( p );
1108 else if( !strcmp(command, "randomise") ) bgmon.randomise = atoi( p );
1109 else if( !strcmp(command, "reset") ) bgmon.reset = atoi( p );
1110 else if( !strcmp(command, "reset_config") ) bgmon.reset_config = atoi( p );
1111 else if( !strcmp(command, "format_string") ) strcpy( bgmon.format_string, p );
1112 else if( !strcmp(command, "idb") ) strcpy( bgmon.idb, p );
1113 else if( !strcmp(command, "change_on_load") ) bgmon.change_on_load = atoi( p );
1114 else if( !strcmp(command, "change_on_apply") ) bgmon.change_on_apply = atoi( p );
1115 else if( !strcmp(command, "remember_locked_state") ) bgmon.remember_locked_state = atoi( p );
1116 else if( !strcmp(command, "locked_last_run") ) bgmon.locked_last_run = atoi( p );
1117 else if( !strcmp(command, "remember_image_number") ) bgmon.remember_image_number = atoi( p );
1118 else if( !strcmp(command, "image_nr_last_run") ) bgmon.image_nr_last_run = atoi( p );
1119 else if( !strcmp(command, "simple_scroll_adj") ) bgmon.simple_scroll_adj = atoi( p );
1120 else if( !strcmp(command, "scroll_adj_time") ) bgmon.scroll_adj_time = atoi( p );
1121 else if( !strcmp(command, "center_text") ) bgmon.center_text = atoi( p );
1122 else if( !strcmp(command, "display_text") ) bgmon.display_text = atoi( p );
1123 else if( !strcmp(command, "display_krell") ) bgmon.display_krell = atoi( p );
1125 g_free( command );
1128 void bgchg_atexit()
1130 g_free( pbg_ctx );
1133 static GkrellmMonitor plugin_mon = {
1134 .name = CONFIG_NAME,
1135 .id = 0,
1136 .create_monitor = create_plugin,
1137 .update_monitor = update_plugin,
1138 .create_config = create_bgchg_tab,
1139 .apply_config = apply_config,
1140 .save_user_config = save_config,
1141 .load_user_config = load_config,
1142 .config_keyword = CONFIG_KEYWORD,
1143 .undef2 = NULL,
1144 .undef1 = NULL,
1145 .privat = NULL,
1146 .insert_before_id = PLACEMENT,
1147 .handle = NULL,
1148 .path = NULL
1151 #if defined(WIN32)
1152 __declspec(dllexport) GkrellmMonitor *
1153 gkrellm_init_plugin(win32_plugin_callbacks* calls)
1154 #else
1155 GkrellmMonitor *gkrellm_init_plugin()
1156 #endif
1158 #if defined(WIN32)
1159 callbacks = calls;
1160 #endif
1162 g_atexit( bgchg_atexit );
1164 pGK = gkrellm_ticks();
1165 style_id = gkrellm_add_meter_style( &plugin_mon, STYLE_NAME );
1166 monitor = &plugin_mon;
1167 return &plugin_mon;