int main(int argc, char **argv) #endif { char execute[256]; #ifndef GKRELLM_BFM int proximity = 0; int ch; #endif #ifdef FPS int f, o; time_t y; #endif #ifdef PRO int cnt = 25000; #endif #ifndef GKRELLM_BFM GdkEvent *event; #endif #ifdef FPS o = f = y = 0; #endif /* initialize GDK */ #ifndef GKRELLM_BFM if (!gdk_init_check(&argc, &argv)) { fprintf(stderr, "GDK init failed, bye bye. Check \"DISPLAY\" variable.\n"); exit(-1); } #endif gdk_rgb_init(); /* dynamically generate getopt string depending on compile options * we are going to borrow 256 char string from exec function, and * also build up the "compiled features" string */ memset(execute, 0, 256); strcat(execute, "h"); /* help, always in */ #ifdef ENABLE_DUCK strcat(options, "DUCK "); strcat(execute, "d"); #ifdef UPSIDE_DOWN_DUCK strcat(options, "INVERT "); strcat(execute, "u"); #endif /* UPSIDE_DOWN_DUCK */ #endif /* ENABLE_DUCK */ #ifdef ENABLE_CPU strcat(options, "CPU "); strcat(execute, "c"); #endif /* ENABLE_CPU */ #ifdef ENABLE_MEMSCREEN strcat(options, "MEMSCREEN "); strcat(execute, "pmk"); #endif /* ENABLE_MEMSCREEN */ #ifdef ENABLE_FISH strcat(options, "FISH "); strcat(execute, "f"); strcat(execute, "n::"); #endif #ifdef ENABLE_TIME strcat(options, "TIME "); strcat(execute, "t"); #endif #ifndef GKRELLM_BFM /* command line options */ while ((ch = getopt(argc, argv, execute)) != -1) { switch (ch) { #ifdef ENABLE_DUCK case 'd': duck_enabled = 0; break; #ifdef UPSIDE_DOWN_DUCK case 'u': upside_down_duck_enabled = 0; break; #endif /* UPSIDE_DOWN_DUCK */ #endif /* ENABLE_DUCK */ #ifdef ENABLE_CPU case 'c': cpu_enabled = 0; break; #endif /* ENABLE_CPU */ #ifdef ENABLE_MEMSCREEN case 'm': memscreen_enabled = 0; break; case 'p': { /* no sense having -p if memscreen isn't compiled in, right? * what we are going to do is to change the colors as follows: * * (48,140,240) replaced with (158,196,237) - more pale blue * (237,23,23) replaced with (0,255,233) */ unsigned char *p = mem_screen; while (p < mem_screen + sizeof(mem_screen)) if (*p == 48) { /* hopefully no other colors beginning with 48 */ *p++ = 158; *p++ = 196; *p++ = 237; } else if (*p == 237) { /* hopefully no other colors beginning with 237 */ *p++ = 0; *p++ = 255; *p++ = 233; } else p += 3; p = load_screen; while (p < load_screen + sizeof(load_screen)) if (*p == 48) { /* hopefully no other colors beginning with 48 */ *p++ = 158; *p++ = 196; *p++ = 237; } else p += 3; } break; case 'k': memscreen_megabytes = 1; break; #endif /* ENABLE_MEMSCREEN */ #ifdef ENABLE_FISH case 'f': fish_enabled = 0; break; case 'n': fish_traffic = 1; if (optarg) network_interface = optarg; break; #endif #ifdef ENABLE_TIME case 't': time_enabled = 1; break; #endif default: print_usage(); exit(-1); break; } } argc -= optind; argv += optind; #endif /* zero data structure */ memset(&bm, 0, sizeof(bm)); #ifdef __FreeBSD__ if (init_stuff()) exit(-1); #endif /* set default things, from Xresources or compiled-in defaults */ bubblemon_session_defaults(); /* create dockapp window. creates windows, allocates memory, etc */ make_new_bubblemon_dockapp(); #ifdef ENABLE_FISH if(fish_enabled) { prepare_sprites(); } #endif #ifndef GKRELLM_BFM #ifdef PRO while (cnt--) { #else while (1) { #endif while (gdk_events_pending()) { event = gdk_event_get(); if (event) { switch (event->type) { case GDK_DESTROY: gdk_exit(0); exit(0); break; case GDK_BUTTON_PRESS: if (event->button.button == 3) { bm.picture_lock = 1; break; } if (event->button.button <= argc) { snprintf(execute, 250, "%s &", argv[event->button.button - 1]); system(execute); } break; #if defined(ENABLE_CPU) || defined(ENABLE_MEMSCREEN) case GDK_ENTER_NOTIFY: /* mouse in: make it darker, and eventually bring up * meminfo */ proximity = 1; bm.screen_type = get_screen_selection(); bm.picture_lock = 0; break; case GDK_LEAVE_NOTIFY: /* mouse out: back to light */ proximity = 0; break; #endif /* ENABLE_CPU || ENABLE_MEMSCREEN */ default: break; } } } #ifndef PRO usleep(15000); #else /* amazingly enough just calling this function takes insane * amount of time. usleep(0); */ #endif /* get system statistics */ get_memory_load_percentage(); /* update main rgb buffer: bm.rgb_buf */ bubblemon_update(proximity); /* *INDENT-OFF* */ #ifdef FPS /* render frames per second on bottom-right corner :) * This is GCC-specific (functions inside functions) * and very unoptimized. this is obfuscated 'cause its ugly */ f++;{int b;void q(int sx,int sy,int dx,int dy){int i,j;char *from,*to; for(j=0;j<8;j++){from=mem_screen+56*3*(sy+j)+sx*3;to=bm.rgb_buf+56*3* (dy+j)+dx*3;i=12;while(i--)*to++=*from++;}}b=o;if(b>=100){q((b/100)*4, 60,43,46);b=b%100;}q((b/10)*4,60,47,46);q((b%10)*4,60,51,46);}if(time( NULL)!=y){o=f;f=0;y=time(NULL);} #endif /* *INDENT-ON* */ /* actually draw the screen */ #ifndef BLACKBOX gdk_draw_rgb_image(bm.win, bm.gc, 4, 4, 56, 56, GDK_RGB_DITHER_NONE, bm.rgb_buf, 56 * 3); #endif gdk_draw_rgb_image(bm.iconwin, bm.gc, 4, 4, 56, 56, GDK_RGB_DITHER_NONE, bm.rgb_buf, 56 * 3); #ifdef ENABLE_MEMSCREEN /* update graph histories */ if (memscreen_enabled) roll_history(); #endif /* ENABLE_MEMSCREEN */ } #endif return 0; } /* main */
void ec_gdk_cleanup( void ) { gdk_exit( 0 ); }