/* called by timer */ static void update() { static light pre_backlight; static Bool in_alarm_mode = False; /* get current ibam data */ i.update(); if(i.valid()) i.update_statistics(); else i.ignore_statistics(); i.save(); /* alarm mode */ if((unsigned int)i.percent_battery() < alarm_level) { if(!in_alarm_mode) { in_alarm_mode = True; pre_backlight = backlight; my_system(notif_cmd); } if((switch_authorized) || ((!switch_authorized) && (backlight != pre_backlight))) { switch_light(); return; } } else { if(in_alarm_mode) { in_alarm_mode = False; if(backlight != pre_backlight) { switch_light(); return; } } } /* all clear */ if(backlight == LIGHTON) dockapp_copyarea(backdrop_on, pixmap, 0, 0, 58, 58, 0, 0); else dockapp_copyarea(backdrop_off, pixmap, 0, 0, 58, 58, 0, 0); /* draw digit */ draw_timedigit(); draw_pcdigit(); draw_statusdigit(); draw_pcgraph(); /* show */ dockapp_copy2window(pixmap); }
int main(int argc, char **argv) { XEvent event; XpmColorSymbol colors[2] = { {"Back0", NULL, 0}, {"Back1", NULL, 0} }; int ncolor = 0; /* Parse Command-Line */ cpu_opts.ignore_nice = False; cpu_opts.cpu_number = CPUNUM_NONE; cpu_opts.ignore_procs = 0; parse_arguments(argc, argv); /* Initialize Application */ cpu_init(); dockapp_open_window(display_name, title == NULL ? PACKAGE : title, SIZE, SIZE, argc, argv); dockapp_set_eventmask(ButtonPressMask); if (light_color) { colors[0].pixel = dockapp_getcolor_pixel(light_color); colors[1].pixel = dockapp_blendedcolor(light_color, -24, -24, -24, 1.0); ncolor = 2; } /* change raw xpm data to pixmap */ if (dockapp_stat == WINDOWED_WITH_PANEL) { backlight_on_xpm[1] = backlight_off_xpm[1] = WINDOWED_BG; } dockapp_xpm2pixmap(backlight_on_xpm, &backdrop_on, &mask, colors, ncolor); dockapp_xpm2pixmap(backlight_off_xpm, &backdrop_off, NULL, NULL, 0); dockapp_xpm2pixmap(parts_xpm, &parts, NULL, colors, ncolor); /* shape window */ if (dockapp_stat == DOCKABLE_ICON || dockapp_stat == WINDOWED) { dockapp_setshape(mask, 0, 0); } if (mask) XFreePixmap(display, mask); /* pixmap : draw area */ pixmap = dockapp_XCreatePixmap(SIZE, SIZE); pix_chartbuf = dockapp_XCreatePixmap(SIZE, SIZE); /* Initialize pixmap */ if (backlight == LIGHTON) { dockapp_copyarea(backdrop_on, pixmap, 0, 0, SIZE, SIZE, 0, 0); } else { dockapp_copyarea(backdrop_off, pixmap, 0, 0, SIZE, SIZE, 0, 0); } dockapp_set_background(pixmap); dockapp_show(); /* Main loop */ for (;;) { if (dockapp_nextevent_or_timeout(&event, update_interval * 1000)) { /* Next Event */ switch(event.type) { case ButtonPress: switch_light(); break; default: /* make gcc happy */ break; } } else { /* Time Out */ update(); } } return 0; }
/* called by timer */ static void update(void) { int usage; int x, h; static light pre_backlight; static Bool in_alarm_mode = False; /* get current cpu usage in percent */ usage = cpu_get_usage(&cpu_opts); hindex++; if (hindex >= MAX_HISTORY) { hindex = 0; } history[hindex] = usage; /* alarm mode */ if (usage >= alarm_threshold) { if (!in_alarm_mode) { in_alarm_mode = True; pre_backlight = backlight; } if (backlight == LIGHTOFF) { switch_light(); return; } } else { if (in_alarm_mode) { in_alarm_mode = False; if (backlight != pre_backlight) { switch_light(); return; } } } /* save current chart */ dockapp_copyarea(pixmap, pix_chartbuf, 9, 33, 44, 21, 0, 0); /* all clear */ if (backlight == LIGHTON) { dockapp_copyarea(backdrop_on, pixmap, 0, 0, 58, 58, 0, 0); x = 2; } else { dockapp_copyarea(backdrop_off, pixmap, 0, 0, 58, 58, 0, 0); x = 0; } /* draw digit */ draw_digit(usage); #ifdef USE_SMP /* draw cpu number */ if (cpu_opts.cpu_number != CPUNUM_NONE) draw_cpunumber(); #endif /* draw chart */ h = (21 * usage) / 100; dockapp_copyarea(pix_chartbuf, pixmap, 0, 0, 44, 21, 6, 33); dockapp_copyarea(parts, pixmap,100+x, 21-h, 2, h, 51, 54-h); /* show */ dockapp_copy2window(pixmap); }
int main(int argc, char **argv) { XEvent event; XpmColorSymbol colors[2] = { {"Back0", NULL, 0}, {"Back1", NULL, 0} }; int ncolor = 0; /* Parse CommandLine */ parse_arguments(argc, argv); /* Initialize Application */ dockapp_open_window(display_name, PACKAGE, SIZE, SIZE, argc, argv); dockapp_set_eventmask(ButtonPressMask); if (light_color) { colors[0].pixel = dockapp_getcolor(light_color); colors[1].pixel = dockapp_blendedcolor(light_color, -24, -24, -24, 1.0); ncolor = 2; } /* change raw xpm data to pixmap */ if (dockapp_iswindowed) backdrop_on_xpm[1] = backdrop_off_xpm[1] = WINDOWED_BG; if (!is_led_style) { dockapp_xpm2pixmap(backdrop_on_xpm, &backdrop_on, &mask, colors,ncolor); dockapp_xpm2pixmap(backdrop_off_xpm, &backdrop_off, NULL, NULL, 0); } else { dockapp_xpm2pixmap(backdrop_led_xpm, &backdrop_led, &mask, colors, ncolor); } dockapp_xpm2pixmap(parts_xpm, &parts, NULL, colors, ncolor); /* shape window */ if (!dockapp_iswindowed) dockapp_setshape(mask, 0, 0); if (mask) XFreePixmap(display, mask); /* pixmap: draw area */ pixmap = dockapp_XCreatePixmap(SIZE, SIZE); /* Initialize pixmap */ longrun_init(cpuid_dev, msr_dev); update(); dockapp_set_background(pixmap); dockapp_show(); /* Main loop */ for (;;) { if (dockapp_nextevent_or_timeout(&event, update_interval)) { /* Next Event */ switch(event.type) { case ButtonPress: if (!is_led_style) { /* led does not have back-light */ switch_light(); update(); } break; default: /* make gcc happy */ break; } } else { /* Time Out */ update(); } } return 0; }
void another_hour(int mode) { char moon[20], buf[100]; int tmp, i; time_info.hours++; tmp = time_info.hours; if (mode) { /* tick */ /* as a test, save a piece of the world every mud hour */ save_the_world(); if (tmp == 0) { for (i = 0; i < 29; i++) /* save the rest of the world automatically */ save_the_world(); } if (tmp == gMoonRise) { if (moontype < 4) { strcpy(moon, "new"); } else if (moontype < 12) { strcpy(moon, "waxing"); } else if (moontype < 20) { strcpy(moon, "full"); } else if (moontype < 28) { strcpy(moon, "waning"); } else { strcpy(moon, "new"); } switch_light(MOON_RISE); SPRINTF(buf, "The %s moon slowly rises from the western horizon.\n\r", moon); send_to_outdoor(buf); if ((moontype > 16) && (moontype < 22)) { gLightLevel++; /* brighter during these moons */ } } if (tmp == gSunRise) { weather_info.sunlight = SUN_RISE; send_to_outdoor("The sun begins to rise from the western horizon.\n\r"); } if (tmp == gSunRise + 1) { weather_info.sunlight = SUN_LIGHT; switch_light(SUN_LIGHT); send_to_outdoor("The day has begun.\n\r"); global_sun_problem_check(TRUE); } if (tmp == gSunSet) { weather_info.sunlight = SUN_SET; send_to_outdoor ("The sun slowly disappears into the eastern horizon.\n\r"); } if (tmp == gSunSet + 1) { weather_info.sunlight = SUN_DARK; switch_light(SUN_DARK); send_to_outdoor("Nightime has settled upon the realms.\n\r"); global_sun_problem_check(FALSE); } if (tmp == gMoonSet) { if ((moontype > 15) && (moontype < 25)) { switch_light(MOON_SET); send_to_outdoor ("Darkness once again fills the realm as the moon sets.\n\r"); } else { send_to_outdoor("The moon sets.\n\r"); } } if (tmp == 12) { send_to_outdoor("It is noon.\n\r"); } if (time_info.hours > 23) { /* Changed by HHS due to bug ??? */ time_info.hours -= 24; time_info.day++; switch (time_info.day) { case 0: case 6: case 13: case 20: case 27: case 34: pulse_mobiles(EVENT_WEEK); break; } /* check the season */ change_season(time_info.month); moontype++; if (moontype > 32) moontype = 1; if (time_info.day > 34) { time_info.day = 0; time_info.month++; get_month(time_info.month); pulse_mobiles(EVENT_MONTH); if (time_info.month > 16) { time_info.month = 0; time_info.year++; } } change_season(time_info.month); } } }
int main(int argc, char **argv) { XEvent event; XpmColorSymbol colors[2] = { {"Back0", NULL, 0}, {"Back1", NULL, 0} }; int ncolor = 0; struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = SA_NOCLDWAIT; sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, NULL); /* Parse CommandLine */ parse_arguments(argc, argv); /* Initialize Application */ dockapp_open_window(display_name, PACKAGE, SIZE, SIZE, argc, argv); dockapp_set_eventmask(ButtonPressMask); if(light_color) { colors[0].pixel = dockapp_getcolor(light_color); colors[1].pixel = dockapp_blendedcolor(light_color, -24, -24, -24, 1.0); ncolor = 2; } /* change raw xpm data to pixmap */ if(dockapp_iswindowed) backlight_on_xpm[1] = backlight_off_xpm[1] = WINDOWED_BG; if(!dockapp_xpm2pixmap(backlight_on_xpm, &backdrop_on, &mask, colors, ncolor)) { fprintf(stderr, "Error initializing backlit background image.\n"); exit(1); } if(!dockapp_xpm2pixmap(backlight_off_xpm, &backdrop_off, NULL, NULL, 0)) { fprintf(stderr, "Error initializing background image.\n"); exit(1); } if(!dockapp_xpm2pixmap(parts_xpm, &parts, NULL, colors, ncolor)) { fprintf(stderr, "Error initializing parts image.\n"); exit(1); } /* shape window */ if(!dockapp_iswindowed) dockapp_setshape(mask, 0, 0); if(mask) XFreePixmap(display, mask); /* pixmap : draw area */ pixmap = dockapp_XCreatePixmap(SIZE, SIZE); /* Initialize pixmap */ if(backlight == LIGHTON) dockapp_copyarea(backdrop_on, pixmap, 0, 0, SIZE, SIZE, 0, 0); else dockapp_copyarea(backdrop_off, pixmap, 0, 0, SIZE, SIZE, 0, 0); dockapp_set_background(pixmap); dockapp_show(); /* initialize ibam */ i.update(); if(i.valid()) i.update_statistics(); else i.ignore_statistics(); i.save(); update(); /* Main loop */ while(1) { if(dockapp_nextevent_or_timeout(&event, update_interval * 1000)) { /* Next Event */ switch(event.type) { case ButtonPress: switch(event.xbutton.button) { case 1: switch_light(); break; case 2: if(event.xbutton.state == ControlMask) my_system((char *)(suspend_cmd ? suspend_cmd : SUSPEND_CMD)); /* Suspend */ else my_system((char *)(standby_cmd ? standby_cmd : STANDBY_CMD)); /* Standby */ break; case 3: switch_authorized = !switch_authorized; break; default: break; } break; default: break; } } else { /* Time Out */ update(); } } return 0; }