int main(int argc, char *argv[]) { XEvent event; ParseCMDLine(argc, argv); openXwindow(argc, argv, xpm_master, xpm_mask_bits, xpm_mask_width, xpm_mask_height); /* Loop Forever */ while (1) { /* Process any pending X events. */ while (XPending(display)) { XNextEvent(display, &event); switch (event.type) { case Expose: RedrawWindow(); break; case ButtonPress: break; case ButtonRelease: break; } } usleep(10000); } /* we should never get here */ return (0); }
void wmkeys_routine(int argc, char **argv) { int i; XEvent Event; int but_stat = -1; openXwindow(argc, argv, wmkeys_master_xpm, wmkeys_mask_bits, 64, 64); enable_configuration(0); /* add mouse region */ AddMouseRegion(0, 5, 5, 58, 122); while (1) { waitpid(0, NULL, WNOHANG); RedrawWindow(); while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { switch (but_stat) { case 0: current_config++; if(current_config == num_configs) current_config = 0; enable_configuration(current_config); break; } } break; } } /* Sleep 0.3 seconds */ usleep(300000L); } }
int main(int argc, char *argv[]) { int n, show_days = 0, but_stat = 0, microtm = 0, running = 0, force = 0; time_t last_time = 0; char *geometry = NULL, *xdisplay = NULL; static int signals[] = {SIGALRM, SIGHUP, SIGINT, SIGPIPE, SIGTERM, SIGUSR1, SIGUSR2, 0}; XEvent Event; assert(sizeof(char) == 1); umask(077); do_opts(argc, argv, &show_days, &xdisplay, &geometry, &force); path_len = strlen(getenv("HOME")) + strlen("/.wmwork/worklog") + 1; if ((dirName = malloc(path_len)) == NULL || (logname = malloc(path_len)) == NULL || (lockname = malloc(path_len)) == NULL) { fprintf(stderr, "%s: cannot allocate memory for path variable\n", PACKAGE_NAME); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } snprintf(dirName, path_len, "%s/.wmwork", getenv("HOME")); snprintf(logname, path_len, "%s/worklog", dirName); snprintf(lockname, path_len, "%s/.#LOCK", dirName); if (chdir(dirName) < 0) { if (errno == ENOENT) { if (mkdir(dirName, 0777)) { fprintf(stderr, "%s: cannot mkdir '%s'\n", PACKAGE_NAME, dirName); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } compat(); } else { fprintf(stderr, "%s: cannot chdir into '%s'\n", PACKAGE_NAME, dirName); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); exit(1); } } for (n = 0; signals[n]; n++) { if (signal(signals[n], handler) == SIG_ERR) { fprintf(stderr, "%s: cannot set handler for signal %d\n", PACKAGE_NAME, signals[n]); fprintf(stderr, "%s: %s\n", PACKAGE_NAME, strerror(errno)); } } make_lock(force); atexit(at_exit); read_log(); current = first; initXwindow(xdisplay); createXBMfromXPM(wmwork_mask_bits, wmwork_master_xpm, 64, 64); openXwindow(argc, argv, wmwork_master_xpm, wmwork_mask_bits, 64, 64, geometry, NULL); AddMouseRegion(BUT_START, 5, 48, 22, 58); AddMouseRegion(BUT_PAUSE, 23, 48, 40, 58); AddMouseRegion(BUT_STOP, 41, 48, 58, 58); AddMouseRegion(BUT_PREV, 5, 33, 16, 43); AddMouseRegion(BUT_NEXT, 47, 33, 58, 43); drawTime(current->time, sess_time, microtm, show_days, running); drawProject(current->name); while (1) { last_time = now.tv_sec; gettimeofday(&now, &tz); if (running) { current->time += now.tv_sec - last_time; sess_time += now.tv_sec - last_time; microtm = now.tv_usec; drawTime(current->time, sess_time, microtm, show_days, running); RedrawWindow(); } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); case ButtonPress: n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); switch (n) { case BUT_START: case BUT_PAUSE: case BUT_STOP: case BUT_PREV: case BUT_NEXT: ButtonDown(n); break; } but_stat = n; RedrawWindow(); break; case ButtonRelease: n = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); switch (but_stat) { case BUT_START: case BUT_PAUSE: case BUT_STOP: case BUT_PREV: case BUT_NEXT: ButtonUp(but_stat); break; } if (but_stat && n == but_stat) { switch (but_stat) { case BUT_START: running = 1; break; case BUT_PAUSE: running = 0; break; case BUT_STOP: write_log(); write_record(); running = 0; sess_time = 0; break; case BUT_PREV: if (!running && sess_time == 0) current = current->prev; break; case BUT_NEXT: if (!running && sess_time == 0) current = current->next; break; } drawTime(current->time, sess_time, microtm, show_days, running); drawProject(current->name); } RedrawWindow(); but_stat = 0; break; } } usleep(50000L); if (do_exit) exit(0); } }
void wmsysmon_routine(int argc, char **argv) { int i; XEvent Event; FILE *fp; int xfd; struct pollfd pfd; createXBMfromXPM(wmsysmon_mask_bits, wmsysmon_master_xpm, wmsysmon_mask_width, wmsysmon_mask_height); xfd = openXwindow(argc, argv, wmsysmon_master_xpm, wmsysmon_mask_bits, wmsysmon_mask_width, wmsysmon_mask_height); if (xfd < 0) exit(1); pfd.fd = xfd; pfd.events = (POLLIN); /* init ints */ bzero(&_last_ints, sizeof(_last_ints)); bzero(&_ints, sizeof(_ints)); bzero(&int_peaks, sizeof(int_peaks)); /* init uptime */ fp = fopen("/proc/uptime", "r"); if (fp) { if (fscanf(fp, "%ld", &start_time) < 1) fprintf(stderr, "warning: could not read uptime\n"); fclose(fp); start_uptime = time(NULL); } statfp = fopen("/proc/stat", "r"); memfp = fopen("/proc/meminfo", "r"); /* here we find tags in /proc/stat & /proc/meminfo and note their * lines, for faster lookup throughout execution. */ /* /proc/meminfo */ for (i = 0; fgets(buf, 1024, memfp); i++) { if(strstr(buf, "Mem:")) Mem_l = i; else if(strstr(buf, "Swap:")) Swap_l = i; } /* /proc/stat */ for (i = 0; fgets(buf, 1024, statfp); i++) { if (strstr(buf, "disk_wio")) wio_l = i; else if (strstr(buf, "disk_rio")) rio_l = i; else if (strstr(buf, "page")) page_l = i; else if (strstr(buf, "swap")) swap_l = i; else if (strstr(buf, "intr")) intr_l = i; } while (1) { curtime = time(0); DrawUptime(); DrawStuff(); DrawMem(); RedrawWindow(); /* X Events */ poll(&pfd, 1, update_rate); while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: DirtyWindow(Event.xexpose.x, Event.xexpose.y, Event.xexpose.width, Event.xexpose.height); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; #ifdef MONDEBUG default: printf("got: %i\n", Event.type); #endif break; } } } }
void yawmppp_routine (int argc, char **argv) { int i, j; int but_stat; long currenttime; long lasttime; long waittime; long ppptime; int hour, minute; long timetolog; long ppp_send, ppp_sl = -1; long ppp_recv, ppp_rl = -1; long ppp_sbytes, ppp_rbytes; long ppp_osbytes, ppp_orbytes; struct stat st; pid_t stop_child = 0; pid_t start_child = 0; int status; int isonline = 0; XEvent Event; int speed_ind = 10; /* Initialize some stuff */ get_statistics (active_interface, &ppp_rl, &ppp_sl, &ppp_orbytes, &ppp_osbytes); if (caution>0) close_ppp(); grab_isp_info(1); /* Open the display */ createXBMfromXPM (dock_mask_bits, dockxpm_xpm, dock_mask_width, dock_mask_height); openXwindow (argc, argv, dockxpm_xpm, dock_mask_bits, dock_mask_width, dock_mask_height); /* V Button */ AddMouseRegion (0, 35, 48, 46, 58); /* x Button */ AddMouseRegion (1, 47, 48, 58, 58); /* < Button */ AddMouseRegion (2, 5, 48, 16, 58); /* > Button */ AddMouseRegion (3, 17, 48, 28, 58); /* ISP display */ AddMouseRegion (4, 5, 6, 59, 43); starttime = 0; currenttime = time (0); ppptime = 0; but_stat = -1; waittime = 0; timetolog=0; /* 888k8 on bottom */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); DrawISPName (); while (1) { lasttime = currenttime; currenttime = time (0); /* Check if any child has left the playground */ i = waitpid (0, &status, WNOHANG); if (i == stop_child && stop_child != 0) { starttime = 0; SetOffLED (LED_PPP_POWER); SetOffLED (LED_PPP_RX); SetOffLED (LED_PPP_TX); /* 888k8 on bottom */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); RedrawWindow (); stop_child = 0; } if (i == start_child && start_child != 0) { if (WIFEXITED (status)) { if (WEXITSTATUS (status) == 10) { starttime = 0; /* 88k8 on bottom */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); SetOffLED (LED_PPP_POWER); DrawTime (0, 1); RedrawWindow (); } start_child = 0; } } /* On-line detectie! 1x per second */ if (currenttime != lasttime) { i = 0; if (stillonline (active_interface)) { i = 1; if (!starttime) { starttime = currenttime; if (stat (STAMP_FILE, &st) == 0) starttime = st.st_mtime; SetOnLED (LED_PPP_POWER); waittime = 0; /* 88k8 on bottom */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); if (IspData[current_isp].SpeedAction) DrawSpeedInd (IspData[current_isp].SpeedAction); speed_ind = currenttime + 10; RedrawWindow (); } } if (!i && starttime) { starttime = 0; SetErrLED (LED_PPP_POWER); logconn.status=1; /* Error */ copyXPMArea (ERR_SRC_X, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); if (IspData[current_isp].IfDownAction) execCommand (IspData[current_isp].IfDownAction); RedrawWindow (); } } if (waittime && waittime <= currenttime) { SetOffLED (LED_PPP_POWER); RedrawWindow (); waittime = 0; } if ((starttime)&&(!isonline)) { isonline=1; logconn.start=time(NULL); logconn.status=0; strcpy(logconn.longname,IspData[current_isp].LongName); strcpy(logconn.shortname,IspData[current_isp].ShortName); strcpy(logconn.user,IspData[current_isp].User); strcpy(logconn.phone,IspData[current_isp].Phone); if (!strlen(logconn.shortname)) strcpy(logconn.shortname,"empty"); if (!strlen(logconn.longname)) strcpy(logconn.longname,"empty"); if (!strlen(logconn.user)) strcpy(logconn.user,"empty"); if (!strlen(logconn.phone)) strcpy(logconn.phone,"empty"); make_guards(); } if ((!starttime)&&(isonline)) { isonline=0; logconn.end=time(NULL); write_log(); if (got_sched) make_delayed_update(); if (caution>0) close_ppp(); } /* If we are on-line. Print the time we are */ if (starttime) { i = currenttime - starttime; i /= TimerDivisor; if (TimerDivisor == 1) if (i > 59 * 60 + 59) i /= 60; minute = i % 60; hour = (i / 60) % 100; i = hour * 100 + minute; DrawTime (i, currenttime % 2); /* We are online, so we can check for send/recv packets */ get_statistics (active_interface, &ppp_recv, &ppp_send, &ppp_rbytes, &ppp_sbytes); if (caution>1) close_ppp(); if (ppp_send != ppp_sl) SetOnLED (LED_PPP_TX); else SetOffLED (LED_PPP_TX); if (ppp_recv != ppp_rl) SetOnLED (LED_PPP_RX); else SetOffLED (LED_PPP_RX); ppp_sl = ppp_send; ppp_rl = ppp_recv; /* Every five seconds we check to load on the line */ if (currenttime - timetolog >= 0) { timetolog=currenttime + 60; make_guards(); } if ((currenttime - ppptime >= 0) || (ppptime == 0)) { ppptime = currenttime + updaterate; ppp_history[PPP_STATS_HIS][0] = ppp_rbytes - ppp_orbytes; ppp_history[PPP_STATS_HIS][1] = ppp_sbytes - ppp_osbytes; ppp_orbytes = ppp_rbytes; ppp_osbytes = ppp_sbytes; DrawStats (54, 17, 5, 32); for (j = 1; j < 55; j++) { ppp_history[j - 1][0] = ppp_history[j][0]; ppp_history[j - 1][1] = ppp_history[j][1]; } if (currenttime > speed_ind) { DrawLoadInd ((ppp_history[54][0] + ppp_history[54][1]) / updaterate); } } RedrawWindow (); } while (XPending (display)) { XNextEvent (display, &Event); switch (Event.type) { case Expose: RedrawWindow (); break; case DestroyNotify: XCloseDisplay (display); while (start_child | stop_child) { i = waitpid (0, &status, WNOHANG); if (i == stop_child) stop_child = 0; if (i == start_child) start_child = 0; usleep (50000l); } exit (0); break; case ButtonPress: i = CheckMouseRegion (Event.xbutton.x, Event.xbutton.y); switch (i) { case 0: ButtonDown (BUT_V); break; case 1: ButtonDown (BUT_X); break; case 2: ButtonDown (BUT_REW); break; case 3: ButtonDown (BUT_FF); break; } but_stat = i; RedrawWindow (); break; case ButtonRelease: i = CheckMouseRegion (Event.xbutton.x, Event.xbutton.y); // Button but_stat omhoogdoen! switch (but_stat) { case 0: ButtonUp (BUT_V); break; case 1: ButtonUp (BUT_X); break; case 2: ButtonUp (BUT_REW); break; case 3: ButtonUp (BUT_FF); break; } if (i == but_stat && but_stat >= 0) { switch (i) { case 0: if (!starttime) { /* 888k8 */ copyXPMArea (ERR_SRC_X+28, ERR_SRC_Y+9, 25, 8, ERR_DEST_X, ERR_DEST_Y); DrawTime (0, 1); start_child = execCommand (IspData[current_isp].StartAction); SetWaitLED (LED_PPP_POWER); waittime = ORANGE_LED_TIMEOUT + currenttime; } break; case 1: if (stop_child == 0) { stop_child = execCommand (IspData[current_isp].StopAction); } break; case 2: if (!starttime) { current_isp--; if (current_isp < 0) current_isp = num_isps - 1; if (current_isp < 0) current_isp=0; DrawISPName (); } break; case 3: if (!starttime) { current_isp++; if (current_isp == num_isps) current_isp = 0; DrawISPName (); } break; case 4: if (Event.xbutton.button==Button1) run_pref_app(); else run_log_app(); break; } } RedrawWindow (); but_stat = -1; break; default: break; } } usleep (50000L); } }
void wmtime_routine(int argc, char **argv) { rckeys wmtime_keys[] = { { "left", &left_action }, { "right", &right_action }, { "middle", &middle_action }, { NULL, NULL } }; int i; XEvent Event; int but_stat = -1; struct tm *time_struct; long starttime; long curtime; char *conffile = NULL; /* Scan through ~/.wmtimerc for the mouse button actions. */ if (default_left_action) left_action = strdup(default_left_action); if (default_middle_action) middle_action = strdup(default_middle_action); if (default_right_action) right_action = strdup(default_right_action); /* Scan through the .rc files */ if (asprintf(&conffile, "/etc/wmtimerc") >= 0) { parse_rcfile(conffile, wmtime_keys); free(conffile); } if (asprintf(&conffile, "%s/.wmtimerc", getenv("HOME")) >= 0) { parse_rcfile(conffile, wmtime_keys); free(conffile); } if (asprintf(&conffile, "/etc/wmtimerc.fixed") >= 0) { parse_rcfile(conffile, wmtime_keys); free(conffile); } /* set user-defined colors */ if (color[0] != 0) { Window Root; XColor col; XWindowAttributes attributes; int screen; Pixel pixel; #define NUMSYMBOLS 10 XpmColorSymbol user_color[NUMSYMBOLS] = { {NULL, "#2081B2CAAEBA", 0}, /* O */ {NULL, "#000049244103", 0}, /* + */ {NULL, "#00007DF771C6", 0}, /* @ */ {NULL, "#18618A288617", 0}, /* # */ {NULL, "#18619A699658", 0}, /* ; */ {NULL, "#0820861779E7", 0}, /* : */ {NULL, "#000071C66185", 0}, /* > */ {NULL, "#000061855144", 0}, /* , */ {NULL, "#00004D344103", 0}, /* < */ {NULL, "#10407DF779E7", 0} /* 1 */ }; /* code based on GetColor() from wmgeneral.c */ /* we need a temporary display to parse the color */ display = XOpenDisplay(NULL); screen = DefaultScreen(display); Root = RootWindow(display, screen); XGetWindowAttributes(display, Root, &attributes); col.pixel = 0; if (!XParseColor(display, attributes.colormap, color, &col)) { fprintf(stderr, "wmtime: can't parse %s.\n", color); goto draw_window; } else if (!XAllocColor(display, attributes.colormap, &col)) { fprintf(stderr, "wmtime: can't allocate %s.\n", color); goto draw_window; } pixel = col.pixel; /* replace colors from wmtime-master.xpm */ user_color[0].pixel = pixel; user_color[1].pixel = scale_pixel(pixel, .4); user_color[2].pixel = scale_pixel(pixel, .7); user_color[3].pixel = scale_pixel(pixel, .8); user_color[4].pixel = scale_pixel(pixel, .9); user_color[5].pixel = scale_pixel(pixel, .8); user_color[6].pixel = scale_pixel(pixel, .6); user_color[7].pixel = scale_pixel(pixel, .5); user_color[8].pixel = scale_pixel(pixel, .4); user_color[9].pixel = scale_pixel(pixel, .7); wmgen.attributes.valuemask |= XpmColorSymbols; wmgen.attributes.numsymbols = NUMSYMBOLS; wmgen.attributes.colorsymbols = user_color; XCloseDisplay(display); } draw_window: openXwindow(argc, argv, wmtime_master_xpm, (char*)wmtime_mask_bits, 128, 64); /* Mask out the right parts of the clock */ copyXPMArea(0, 0, 128, 64, 0, 98); /* Draw the borders */ copyXPMArea(0, 0, 64, 64, 64, 0); /* Draw the clock face */ copyXPMArea(64, 98, 64, 64, 0, 0); /* Draw the LCD background */ setMaskXY(0, 0); /* add mouse region */ AddMouseRegion(0, 5, 48, 58, 60); AddMouseRegion(1, 5, 5, 58, 46); starttime = time(0); curtime = time(0); time_struct = localtime(&curtime); while (1) { curtime = time(0); waitpid(0, NULL, WNOHANG); time_struct = localtime(&curtime); if (curtime >= starttime) { if (!digital) { /* Now to update the seconds */ DrawWijzer(time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec); DrawDate(time_struct->tm_wday, time_struct->tm_mday, time_struct->tm_mon); } else { DrawTime(time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec); DrawDate(time_struct->tm_wday, time_struct->tm_mday, time_struct->tm_mon); } RedrawWindow(); } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { switch (but_stat) { case 0: digital = 1-digital; if (digital) { copyXPMArea(64, 98, 64, 64, 0, 0); DrawTime(time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec); DrawDate(time_struct->tm_wday, time_struct->tm_mday, time_struct->tm_mon); } else { copyXPMArea(0, 98, 64, 64, 0, 0); DrawWijzer(time_struct->tm_hour, time_struct->tm_min, time_struct->tm_sec); DrawDate(time_struct->tm_wday, time_struct->tm_mday, time_struct->tm_mon); } RedrawWindow(); break; case 1: switch (Event.xbutton.button) { case 1: if (left_action) execCommand(left_action); break; case 2: if (middle_action) execCommand(middle_action); break; case 3: if (right_action) execCommand(right_action); break; } } } break; } } /* Sleep 0.3 seconds */ usleep(300000L); } }
int main (int argc, char *argv[]) { pm_status power_status; XEvent event; int fbc_toggle=1, fbc_auto=1; int old_battery_charging; time_t polling = 0; struct timespec delay; /* pause between interface updates */ char Command[CMDLINELEN+3]; int warned = 0; delay.tv_sec = 0; delay.tv_nsec = 500000000; BlinkRate = (BlinkRate >= 0.0) ? BlinkRate : -1.0 * BlinkRate; waittime = 0; /* /proc polling interval */ minBrightness = -1; maxBrightness = -1; fprintf(stderr, "\nWelcome to wmpower version %s...\n", VERSION); cpufreq_online_governor = NULL; cpufreq_offline_governor = NULL; /* Parse any command line arguments. */ ParseCMDLine (argc, argv); /* Check for Power Management support */ if (!pm_support(our_battery)) { fprintf (stderr, "\nNo power management support...\n"); return EXIT_FAILURE; } /* Create window of the program */ if (UseLowColorPixmap) openXwindow (argc, argv, wmpower_master_LowColor, (char *) wmpower_mask_bits, wmpower_mask_width, wmpower_mask_height); else openXwindow (argc, argv, wmpower_master, (char *) wmpower_mask_bits, wmpower_mask_width, wmpower_mask_height); /* Loop until we die... */ while (1) { /* Get current power status */ old_battery_charging = power_status.battery_charging; if (!waittime) get_power_status(&power_status); else if ((time(NULL)-polling) >= waittime) { get_power_status(&power_status); polling = time(NULL); } /* Manage power features only if function is not disabled */ if (!no_meddling) { /* Re-enable auto power mode switching whan battery status changes */ if (old_battery_charging != power_status.battery_charging) fbc_auto = 1; /* Enable fast battery charge mode if on AC and batt is charging */ if (!no_full_battery && power_status.ac_on_line && power_status.battery_charging && fbc_auto && !fbc_toggle && !(power_status.battery_percentage == 100)) { fast_battery_charge(1); fbc_toggle = 1; fbc_auto = 1; } /* Adjust variables value when battery reaches 100% */ if (fbc_toggle && (power_status.battery_percentage == 100)) { fast_battery_charge(0); fbc_toggle = 0; fbc_auto = 1; } /* If battery not present and fast charge mode, disable it */ if (fbc_toggle && !(power_status.battery_present)) { fast_battery_charge(0); fbc_toggle = 0; fbc_auto = 1; } /* Set various pm features whenever applicable */ set_pm_features(); } /* Execute the warning command, if needed */ if (WarnCommand && *WarnCommand && !power_status.ac_on_line && !warned && power_status.battery_time <= WarnTime) { warned = 1; sprintf(Command, "%s &", WarnCommand); system(Command); } if (power_status.ac_on_line) warned = 0; /* Show AC status led */ ShowACstatus(power_status.ac_on_line); /* Display FAN status. */ ShowFanStatus(power_status.fan_status); /* Display temperature. */ ShowTemperature(power_status.temperature, power_status.temp_is_celsius); /* Display charge status */ ShowChargeStatus(power_status.battery_charging); /* Display the "Time Left" */ ShowBatteryTime(power_status.battery_time, power_status.battery_percentage, power_status.battery_charging, power_status.ac_on_line); /* Display battery percentage */ ShowBatteryPercentage(power_status.battery_percentage); /* Display battery status led */ ShowBatteryLed(power_status.battery_present, power_status.battery_percentage, power_status.ac_on_line); /* Process any pending X events. */ while (XPending (display)) { XNextEvent (display, &event); switch (event.type) { case Expose: RedrawWindow (); continue; case ButtonPress: if (no_meddling) { fprintf(stderr, "You cannot change PM status in '-no-meddling' mode of operation\n"); continue; } if (event.xbutton.button == wheel_button_up) { lcdBrightness_UpOneStep(); continue; } if (event.xbutton.button == wheel_button_down) { lcdBrightness_DownOneStep(); continue; } fbc_toggle = !get_fast_battery_charge_mode(); fbc_auto = 0; fast_battery_charge(fbc_toggle); continue; case ButtonRelease: continue; } } /* Redraw and wait for next update */ RedrawWindow (); nanosleep(&delay, NULL); } }
int main( int argc, char** argv ) { int opt = 0; const struct option longopts[] = { {"display", required_argument, NULL, 0}, {"geometry", required_argument, NULL, 0}, {0, 0, 0, 0} }; #ifdef USE_MTRACE mtrace(); #endif /* USE_MTRACE */ signal( SIGINT, dockapp_exit ); signal( SIGSEGV, dockapp_crash ); opt = getopt_long_only( argc, argv, "hv", longopts, NULL); while ( -1 != opt ) { switch ( opt ) { case 'h': { dockapp_show_help( argv[0] ); exit( 1 ); /* Never reached. */ } case 'v': { dockapp_show_version(); exit( 1 ); /* Never reached. */ } } opt = getopt_long_only( argc, argv, "hv", longopts, NULL); } createXBMfromXPM( wmmisc_mask_bits, wmmisc_master_xpm, wmmisc_mask_width, wmmisc_mask_height ); openXwindow( argc, argv, wmmisc_master_xpm, wmmisc_mask_bits, wmmisc_mask_width, wmmisc_mask_height ); RedrawWindow(); dockapp_draw_small_str( "USERS", 4, 4 ); dockapp_draw_small_str( "PROCS", 4, 11 ); dockapp_draw_small_str( "ACTIVE", 4, 18 ); dockapp_draw_small_str( "UP", 4, 28 ); dockapp_draw_small_str( "DAYS", 4, 37 ); dockapp_draw_small_str( "WEEKS", 4, 44 ); dockapp_draw_small_str( "LOAD", 4, 53 ); do { dockapp_draw_data(); usleep( 250000L ); } while( 1 ); return 0; }
int main(int argc, char *argv[]) { XEvent event; char buf[16]; int d=0; int pifno=-1; int lastbytes=0; struct timeval tv; fd_set fds; int x; int prev_exec_busy=0; exec_up = exec_dflt; exec_down = exec_dflt; parse_cmdline(argc, argv); initXwindow(argc, argv); if(mode == MODE_LED) { openXwindow(argc, argv, wmifinfo_led_xpm, wmifinfo_led_bits, wmifinfo_led_width, wmifinfo_led_height, BackColor, LabelColor, WindGustColor, DataColor, StationTimeColor); } else { openXwindow(argc, argv, wmifinfo_lcd_xpm, wmifinfo_lcd_bits, wmifinfo_lcd_width, wmifinfo_lcd_height, BackColor, LabelColor, WindGustColor, DataColor, StationTimeColor); } // Initialize global variables fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); ifc.ifc_len = sizeof(struct ifreq) * 10; ifc.ifc_buf = malloc(ifc.ifc_len); while(1) { while (XPending(display)) { XNextEvent(display, &event); switch (event.type) { case Expose: RedrawWindow(); break; case ButtonPress: ButtonPressEvent(&event.xbutton); break; case ButtonRelease: break; } } if ((d++ == 3) || (ifno != pifno) || (exec_busy != prev_exec_busy)) { d=0; copyXPMArea(64, 0, 64, 64, 0, 0); getifnames(); if(ifaces>0) { ifno = ifno % ifaces; getifinfo(ifname[ifno], &ifinfo); if(ifno != pifno) lastbytes = ifinfo.bytes; sprintf(buf, "%-7s", ifinfo.id); strupper(buf); drawtext(buf, &font2, 6, 4); if(memcmp(ifinfo.hw, "\x00\x00\x00\x00\x00\x00", 6) != 0) { drawhwaddr(ifinfo.hw); } if(ifinfo.ip) drawipaddr(ifinfo.ip, 0); if(ifinfo.nm) drawipaddr(ifinfo.nm, 1); if(ifinfo.gw) drawipaddr(ifinfo.gw, 2); // WLAN signal level #ifdef linux x = ifinfo.sl/4; #elif defined(__OpenBSD__) x = ifinfo.sl/7; #endif if(x>13) x=13; copyXPMArea(4, 82, x*4, 4, 6, 53); // LED x=0; if(exec_busy) { x=0; } else { if(ifinfo.state) x += 8; if(lastbytes == ifinfo.bytes) x+= 16; } copyXPMArea(64 + x, 81, 8, 8, 50, 4); lastbytes = ifinfo.bytes; } RedrawWindow(); prev_exec_busy = exec_busy; pifno = ifno; } #ifdef linux tv.tv_sec = 0; tv.tv_usec = DELAY; FD_ZERO(&fds); FD_SET(ConnectionNumber(display), &fds); select(ConnectionNumber(display)+1, &fds, NULL, NULL, &tv); #elif defined(__OpenBSD__) usleep(DELAY); #endif } }
int main(int argc, char *argv[]) { int i=0,debug=0,r,j=0,x=0,selected=-1; long int gi=0,gf=0; int colord=66,colorg=71; struct dirent **namelist; int ls=0,metnum=0; unsigned char buf[516] ; char * tmpdir = NULL; for (i=1; i<argc; i++) { char *arg = argv[i]; if (*arg=='-') { switch (arg[1]) { case 't' : tmpdir = argv[i+1]; printf("Using temp dir %s\n",tmpdir); break; case 'w' : if (argc>i+1){ if (!strcasecmp(argv[i+1],"red")) colord=71; else if (!strcasecmp(argv[i+1],"blue")) colord=76; else if (!strcasecmp(argv[i+1],"yellow")) colord=81; else if (!strcasecmp(argv[i+1],"white")) colord=86; else if (!strcasecmp(argv[i+1],"cyan")) colord=91; else if (!strcasecmp(argv[i+1],"black")) colord=96; else if (!strcasecmp(argv[i+1],"blank")) colord=101; else printf("Invalid color %s\n",argv[i+1]); }else {usage();exit(-1);} break; case 'g' : if (argc>i+1){ if (!strcasecmp(argv[i+1],"green")) colorg=66; else if (!strcasecmp(argv[i+1],"blue")) colorg=76; else if (!strcasecmp(argv[i+1],"yellow")) colorg=81; else if (!strcasecmp(argv[i+1],"white")) colorg=86; else if (!strcasecmp(argv[i+1],"cyan")) colorg=91; else if (!strcasecmp(argv[i+1],"black")) colorg=96; else if (!strcasecmp(argv[i+1],"blank")) colorg=101; else printf("Invalid color %s\n",argv[i+1]); }else {usage();exit(-1);} break; case 'v' : printversion(); exit(0); break; case 'd' : debug=1; printf("Debuggin mode: \n"); break; default: usage(); exit(0); break; } } } if (!tmpdir) { usage(); exit(-1);} openXwindow(argc, argv, wmdonkeymon_master_xpm, wmdonkeymon_mask_bits, wmdonkeymon_mask_width, wmdonkeymon_mask_height); copyXPMArea(5,60,52,54,5,3); RedrawWindow(); splash(); r = 0; while (1) { if (!r) { FILE * met; unsigned char type; short int len=0,vlen=0; int gaps=0, firstgap = 0x7fffffff, miss=0, fsize=0,metcount=0; long int fileSize=0, num =0; char nvalue[516],value[516]; j =0; metnum=0; // Search for files in temp directory ls = scandir(tmpdir, &namelist, 0, alphasort); if (ls < 0){ printf("Can't find files in %s",tmpdir); exit(-1); } else { while(ls-- && (metcount<4)) { char * pt; pt = strstr(namelist[ls]->d_name,".part.met"); if (pt && !strcmp(pt,".part.met")) { if(debug)printf("File: %s\n",namelist[ls]->d_name); strcpy(files[metcount].metname,namelist[ls]->d_name); metcount++; } free(namelist[ls]); } free(namelist); } for (metnum=0; metnum < metcount; metnum++) { i=0; sprintf(buf,"%s%s",tmpdir,files[metnum].metname); files[metnum].t_miss=0; if(debug)printf("opening %s\n",buf); if ( (met = fopen(buf,"rb")) != NULL) {} else {printf("Nada\n");}; // Version i += fread(buf,1,1,met); if(debug){ printf("Version: %x\n",buf[0]); } // Date ?? i += fread(buf,1,4,met); if(debug) { printf("Date: %x %x %x %x \n",buf[0],buf[1],buf[2],buf[3]); } // Hash i += fread(buf,1,16,met); if(debug){ printf("Hash: "); for (j=0;j<16;j++) printf("%x ",buf[j]); printf("\n"); } // Partial Hashes i += fread(buf,1,2,met); memcpy(&j,buf,2); if(debug) printf("Num of Hashes: %d\n",j); // Hashes for (i=0;i<j;i++){ fread(buf,1,16,met); if(debug){printf("Hash %d: ",i+1); for (x=0;x<16;x++) printf("%x ",buf[x]); printf("\n");} } // Num of Meta Tags i = fread(buf,1,4,met); memcpy(&num,buf,4); if(debug){printf("Num of Meta Tags: %ld\n",num);} x = 0; // Meta Tags for (i=0;i<num;i++){ fread(&type,1,1,met); fread(&len,2,1,met); fread(nvalue,1,len,met); if (type==2){ // String Tag fread(&vlen,1,2,met); fread(value,1,vlen,met); value[vlen] = '\0'; if (len==1){ // Special Tag switch (nvalue[0]){ case 1: strcpy(files[metnum].name,value); if(debug){printf("File Name: %s\n",value);} break; case 3: if(debug){printf("File Type: %s\n",value);} strcpy(files[metnum].type,value); break; case 4: if(debug){printf("File Format: %s\n",value);} break; case 18: if(debug){printf("Temp file: %s\n",value);} break; } } else if (debug)printf("Unknow String Tag %d: %s",nvalue[0],value); }else if (type==3){ fread(&fsize,1,4,met); if (len==1){ // Special Tag switch (nvalue[0]){ case 2: if(debug)printf("File Size: %d KB\n",fsize/(1024)); fileSize = fsize; break; case 8: if(debug)printf("Copied so Far: %d KB\n",fsize/(1024)); files[metnum].copied=fsize; break; case 19: if(debug) printf("Priority: %d\n",fsize); break; case 20: if(debug)printf("Status: %d\n",fsize); files[metnum].status = fsize; break; default: if(debug)printf("Unknow Tag %d: %d\n",nvalue[0],fsize); break; } } else { if (nvalue[0]==9){ nvalue[len]='\0'; if(debug)printf("gap %3s from %10d", &nvalue[1], fsize); gaps = fsize; if (gaps < firstgap) firstgap = gaps; }else if (nvalue[0]==10){ miss = fsize - gaps; gi = (long int)((SLOT_SIZE * (gaps/1024)) / (fileSize/1024)); gf = (long int)((SLOT_SIZE * (fsize/1024)) / (fileSize/1024)); if (gf>=gi){ files[metnum].gappos[x][0] = gi; files[metnum].gappos[x][1] = gf; x++; } files[metnum].t_miss += miss; if(debug)printf(" to %10d = %10d Size(%d) Gaprel: %d-%d\n",fsize,miss,9728000,files[metnum].gappos[x][0],files[metnum].gappos[x][1]); } } } } files[metnum].gapnum = x; files[metnum].firstgap = firstgap; files[metnum].lastsize = files[metnum].copied; files[metnum].size = fileSize; // sort gaps /* don'n needed * for (i=0; i<x; i++) for (j=0; j<x; j++) { if (files[0].gappos[i][0]<files[0].gappos[j][0]) { z = files[0].gappos[i][0]; files[0].gappos[i][0] = files[0].gappos[j][0]; files[0].gappos[j][0] = z; z = files[0].gappos[i][1]; files[0].gappos[i][1] = files[0].gappos[j][1]; files[0].gappos[j][1] = z; } } if(debug)for (i=0; i<x; i++){ printf("[%d-%d]",files[0].gappos[i][0],files[0].gappos[i][1]); } */ if(debug)printf("%d bytes = %.2f mb missing\n", files[metnum].t_miss, (double)files[metnum].t_miss/(1024*1024)); if(debug)if (firstgap < 0x7fffffff) printf("first gap starts at %d (%d blocks are complete)\n", firstgap, firstgap/(9500*1024)); fclose(met); } } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { if (selected>-1) selected=-1; else selected=i; } break; } } for (j=0;j<15;j++) DelMouseRegion(j); if (metnum==0){ splash(); showString("NO FILES",8); showString("FOUND IN",9); showString("TEMP DIR",10); }else if (selected>-1){ char out[30]; char unit[4] = " KMG"; long int s,c; int sk=0,ck=0; copyXPMArea(5,60,52,54,5,3); AddMouseRegion(0,5,5,54,54); showString(files[selected].name,1); s=files[selected].size; while (s>1024){s/=1024;sk++;} c=files[selected].copied; while (c>1024){c/=1024;ck++;} sprintf(out,"%ld%c/%ld%c",c,unit[ck],s,unit[sk]); showString(out,4); sprintf(out,"%s",files[selected].type); showString(out,5); // ************** // Donwload Rate // Don't work unless edonkey update met files more frequently // // s = (files[selected].copied) - (files[selected].lastsize); // sprintf(out,"%ld B/S",(s/REF_RATE)); // showString(out,8); //************************ //STATUS //status tag is always "Looking..." :( // //getStatus(files[selected].status,out); //showString(out,9); sprintf(out,"%.3f%%", (( 1.0 * files[selected].copied / files[selected].size))*100); showString(out,8); copyXPMArea(66,colord,52,5,5,11); for (i=0; i < files[selected].gapnum ; i++) { copyXPMArea(66,colorg,files[selected].gappos[i][1]-files[selected].gappos[i][0],5,files[selected].gappos[i][0]+5 ,11); } }else{ copyXPMArea(5,60,52,54,5,3); for (j=0; j<metnum; j++){ showString(files[j].name,(j*2)+1+j); copyXPMArea(66,colord,52,5,5,(j+1)*10+(j*5) ); // printf("top: %d\n",((j+1)*10+(j*5))); for (i=0; i < files[j].gapnum ; i++) { copyXPMArea(66,colorg,files[j].gappos[i][1]-files[j].gappos[i][0],5,files[j].gappos[i][0]+5 ,(j+1)*10+(j*5)); } AddMouseRegion(j,5,(j+1)*5,52,(j+1)*10+(j*5)+5); } } RedrawWindow(); sleep(1); r++; if (r==REF_RATE) r=0; } }
int main(int argc,char *argv[]) { FILE *file; char line[256]; char xx[256]; int revision=0,release=0,patchlevel=0; XEvent event; int opt; scale_width=xpm_scale_width; scale_height=xpm_scale_height; scale_f_x=xpm_scale_2_f_x; scale_f_y=xpm_scale_2_f_y; scale_b_x=xpm_scale_1_b_x; scale_b_y=xpm_scale_1_b_y; mem_correction=0; dev_name="hda"; while((opt=getopt(argc,argv,"hmt:d:"))!=-1) { switch(opt) { case 'd': dev_name=optarg; break; case 'm': mem_correction=1; break; case 't': switch(atoi(optarg)) { case 4: scale_f_x=xpm_scale_2_f_x; scale_f_y=xpm_scale_2_f_y; scale_b_x=xpm_scale_2_b_x; scale_b_y=xpm_scale_2_b_y; break; case 3: scale_f_x=xpm_scale_1_f_x; scale_f_y=xpm_scale_1_f_y; scale_b_x=xpm_scale_1_b_x; scale_b_y=xpm_scale_1_b_y; break; case 2: scale_f_x=xpm_scale_1_f_x; scale_f_y=xpm_scale_1_f_y; scale_b_x=xpm_scale_2_b_x; scale_b_y=xpm_scale_2_b_y; break; case 1: default: scale_f_x=xpm_scale_2_f_x; scale_f_y=xpm_scale_2_f_y; scale_b_x=xpm_scale_1_b_x; scale_b_y=xpm_scale_1_b_y; } break; case 'h': default: usage(argv[0]); exit(0); } } file=fopen("/proc/version","r"); fgets(line,sizeof(line),file); sscanf(line,"%s %s %d.%d.%d%s",xx,xx,&revision,&release,&patchlevel,xx); fclose(file); createXBMfromXPM(wmsm_mask_bits,wmsm_master_xpm,wmsm_mask_width,wmsm_mask_height); openXwindow(argc,argv,wmsm_master_xpm,wmsm_mask_bits,wmsm_mask_width,wmsm_mask_height); RedrawWindowXY(0,0); get_values(1,(revision<<16)+(release<<8)+patchlevel); while(1) { while (XPending(display)) { XNextEvent(display, &event); switch (event.type) { case Expose: RedrawWindowXY(0,0); break; case DestroyNotify: XCloseDisplay(display); exit(0); } } get_values(0,(revision<<16)+(release<<8)+patchlevel); usleep(150000L); } }
int main(int argc, char *argv[]) { struct timespec ts,ts1; int i,ncpu; int idcpu; unsigned long freq[8]; XEvent event; char gov[20]; char drv[20],*ptr,*endptr; char prg[LN_PATH]; ts.tv_sec=0; ts.tv_nsec=DELAY; prg[0]=0; idcpu=0; for(i=0;i<MAX_CPU;i++) freq[i]=0; if(argc >1) { for (i=1; i<=argc; i++) { if (!strcmp(argv[i], "-v")) { printf(WMCPUFREQ_VERSION); exit(0); } if (!strcmp(argv[i], "-exe")) { if(strlen(argv[i+1]) < LN_PATH ) strcpy(prg,argv[i+1]); break; } if (!strcmp(argv[i], "-cpuid")) { if(strlen(argv[i+1]) < LN_PATH ) idcpu=strtol(argv[i+1],&endptr,0); printf("cpuid= %d \n",idcpu); break; } printf("only -v, -exe, -cpuid supported \n"); exit(0); } } /* basic checks */ if ( idcpu < 0 ) { printf("cpuid < 0 \n"); exit(-1); } /* get driver name (guess all cpu have the same driver) */ ptr=cpufreq_get_driver(cpu); if(!ptr) { printf("no driver found \n"); exit(-1); } strcpy(drv,ptr); cpufreq_put_driver(ptr); /* get number of cpu (0=cpu0, 1=cpu1 ...) */ ncpu=-1; for(i=0;i<MAX_CPU;i++) { if( cpufreq_cpu_exists(idcpu+i) ==0) { printf("cpuid %d found\n",idcpu+i); ncpu=i; } } switch ( ncpu ) { case -1: printf("no cpuid found \n"); exit(-1); case 0: wm_xpm=wmcpufreq_master_xpm_1; wm_bits=wmcpufreq_mask_bits_1; break; case 1: wm_xpm=wmcpufreq_master_xpm_2; wm_bits=wmcpufreq_mask_bits_2; break; case 2: wm_xpm=wmcpufreq_master_3; wm_bits=wmcpufreq_mask_3_bits; break; case 3: wm_xpm=wmcpufreq_master_3; wm_bits=wmcpufreq_mask_3_bits; break; default: printf("no yet implemented: cpuid %d \n",ncpu); exit(-1); break; } /* guess every cpu has the same limits */ if(cpufreq_get_hardware_limits(cpu, &f_min, &f_max)) { printf("can't determine hardware limits \n"); exit(-1); } openXwindow(argc,argv, wm_xpm, (char*)wm_bits, wmcpufreq_mask_width, wmcpufreq_mask_height); while(1) { /* Process any pending X events */ while(XPending(display)) { XNextEvent(display, &event); switch(event.type) { case Expose: RedrawWindow(); break; case ButtonPress: if(strlen(prg)) execCommand(prg); break; case ButtonRelease: break; } } RedrawWindow(); /* get info */ for(i=0;i<=ncpu;i++) freq[i]=cpufreq_get_freq_kernel(i+idcpu); policy=cpufreq_get_policy(cpu); strcpy(gov,policy->governor); max=policy->max; min=policy->min; cpufreq_put_policy(policy); /* show info */ show_mhz(freq,ncpu); if (ncpu==0) show_driver(drv); show_governor(gov); /* delay */ nanosleep(&ts,&ts1); } }
/* * main */ int main(int argc, char *argv[]) { struct tm *gTime, *gmt; struct stat fi; XEvent event; Pixmap NewPixmap, NewShapeMask; XpmAttributes Attributes; Colormap cmap; int n, s, m, dt1, dt2, dt3, len; int Year, Month, Day; int Hours, Mins, Secs; int i, j, Width, Height, yoff, fd, Flag; long CurrentLocalTime; double UT, hour24(), jd(), CurrentJD, OldFileUT, FileUT; char command[1040], ImageName[256]; int havePixmap= 0; /* * Parse any command line arguments. */ ParseCMDLine(argc, argv); /* * Figure out what the name of the image xpm file should be... */ len = strlen(ImageURL); for (j = 0, i=0; i<len; ++i){ if (ImageURL[i] == '/') j = i; } strcpy(ImageName, ImageURL+j+1); sprintf(XpmFileName, "%s/.wmGrabImage/%s.xpm", getenv("HOME"), ImageName); sprintf(ImageFileName, "%s/.wmGrabImage/%s", getenv("HOME"), ImageName); openXwindow(argc, argv, wmGrabImage_master, wmGrabImage_mask_bits, wmGrabImage_mask_width, wmGrabImage_mask_height); cmap = DefaultColormap(display, DefaultScreen(display)); /* * Loop until we die */ n = 32000; s = 32000; m = 32000; dt1 = 32000; dt2 = 32000; dt3 = 32000; DblClkDelay = 32000; UpToDate = 0; FileUT = -999.0; Flag = 1; NewShapeMask = 0; Attributes.nalloc_pixels = 0; while(1) { /* * Keep track of # of seconds */ if (m > 100){ m = 0; ++dt1; ++dt2; ++dt3; } else { /* * Increment counter */ ++m; } /* * Double Click Delays * Keep track of click events. If Delay too long, set GotFirstClick's to False. */ if (DblClkDelay > 15) { DblClkDelay = 0; GotFirstClick1 = 0; GotDoubleClick1 = 0; GotFirstClick2 = 0; GotDoubleClick2 = 0; GotFirstClick3 = 0; GotDoubleClick3 = 0; } else { ++DblClkDelay; } /* * Process any pending X events. */ while(XPending(display)){ XNextEvent(display, &event); switch(event.type){ case Expose: RedrawWindow(); break; case ButtonPress: pressEvent(&event.xbutton); break; case ButtonRelease: break; } } /* * Draw window. */ if (ForceUpdate||Flag){ /* * Compute Current Julian Date */ CurrentLocalTime = time(CurrentTime); gTime = gmtime(&CurrentLocalTime); Year = gTime->tm_year+1900; Month = gTime->tm_mon+1; Day = gTime->tm_mday; Hours = gTime->tm_hour; Mins = gTime->tm_min; Secs = gTime->tm_sec; UT = (double)Hours + (double)Mins/60.0 + (double)Secs/3600.0; CurrentJD = jd(Year, Month, Day, UT); /* * Clear window. */ copyXPMArea(5, 69, 54, 54, 5, 5); if (havePixmap) { /* * free up the colors, if we alloc'd some before */ if (Attributes.nalloc_pixels > 0) XFreeColors(display, cmap, Attributes.alloc_pixels, Attributes.nalloc_pixels, 0); /* * Free last pixmap -- we dont need it anymore... * A ShapeMask is returned if the Pixmap had the color None used. * We could probably change Transparent to None to make use of this, but for now, * lets just ignore it... */ if ( NewShapeMask != 0 ) XFreePixmap(display, NewShapeMask); XFreePixmap(display, NewPixmap); XpmFreeAttributes(&Attributes); havePixmap= 0; } /* * Grab new pixmap. Accept a reasonable color match. */ Attributes.valuemask = XpmExactColors | XpmCloseness | XpmReturnAllocPixels; Attributes.exactColors = 0; Attributes.closeness = 40000; if (XpmReadFileToPixmap(display, Root, XpmFileName, &NewPixmap, &NewShapeMask, &Attributes) >= 0){ Height = Attributes.height; Width = Attributes.width; yoff = (CenterImage) ? (54 - Height)/2 : 0; XCopyArea(display, NewPixmap, wmgen.pixmap, NormalGC, 0, 0, Width, Height, 5, 5+yoff); Flag = 0; ForceUpdate = 0; havePixmap= 1; } /* * Make changes visible */ RedrawWindow(); } /* * Check xpm file status */ if (dt2 > 1){ dt2 = 0; if ( (fd = open(XpmFileName, O_RDONLY)) >= 0 ) { fstat(fd, &fi); close(fd); gmt = gmtime(&fi.st_mtime); OldFileUT = FileUT; FileUT = (double)gmt->tm_hour + (double)gmt->tm_min/60.0 + (double)gmt->tm_sec/3600.0; if (FileUT != OldFileUT) ForceUpdate = 1; } } /* * Check every 5 min if the values are not up to date... */ if (ForceUpdate2||(dt3 > UpdateDELAY)){ dt3 = 0; /* * Execute Perl script to grab the Latest METAR Report */ if (ConvertGeometry != NULL) sprintf(command, "GrabImage %s %s &", ImageURL, ConvertGeometry); else sprintf(command, "GrabImage %s &", ImageURL); system(command); ForceUpdate = 1; ForceUpdate2 = 0; } /* * Wait for next update */ usleep(DELAY); } }
void wmifs_routine(int argc, char **argv) { rckeys wmifs_keys[] = { { "left", &left_action }, { "middle", &middle_action }, { "right", &right_action }, { NULL, NULL } }; int i, j; XEvent Event; int but_stat = -1; int stat_online; int stat_current; int first_time = 1; unsigned int curtime; unsigned int nexttime; struct timeval tv, tv2; long ipacket, opacket, istat, ostat; char temp[BUFFER_SIZE]; char *p; for (i = 0; i < MAX_STAT_DEVICES; i++) { stat_devices[i].name[0] = 0; for (j = 0; j < 48; j++) { stat_devices[i].his[j][0] = 0; stat_devices[i].his[j][1] = 0; } } stat_online = checknetdevs(); stat_current = 0; if (active_interface) { int isauto = !strcmp(active_interface, "auto"); for (i = 0; i < stat_online; i++) { if ((isauto && stillonline(stat_devices[i].name)) || !strcmp(stat_devices[i].name, active_interface)) { stat_current = i; break; } } } #ifdef LEFT_ACTION left_action = strdup(LEFT_ACTION); #endif #ifdef MIDDLE_ACTION middle_action = strdup(MIDDLE_ACTION); #endif #ifdef RIGHT_ACTION right_action = strdup(RIGHT_ACTION); #endif /* Scan throught the .rc files */ parse_rcfile(CONF"/wmifsrc", wmifs_keys); p = getenv("HOME"); if (p == NULL || *p == 0) { fprintf(stderr, "Unknown $HOME directory, please check your environment\n"); return; } strncpy(temp, p, BUFFER_SIZE - 10); strcat(temp, "/.wmifsrc"); parse_rcfile(temp, wmifs_keys); parse_rcfile(CONF"/wmifsrc.fixed", wmifs_keys); /* set user-defined colors */ if (color[0] != 0) { Window Root; XColor col; XWindowAttributes attributes; int screen; Pixel pixel; #define NUMSYMBOLS 4 XpmColorSymbol user_color[NUMSYMBOLS] = { {NULL, "#2081B2CAAEBA", 0}, /* + */ {NULL, "#28A23CF338E3", 0}, /* O */ {NULL, "#000049244103", 0}, /* @ */ {NULL, "#18618A288617", 0}, /* # */ }; /* code based on GetColor() from wmgeneral.c */ /* we need a temporary display to parse the color */ display = XOpenDisplay(NULL); screen = DefaultScreen(display); Root = RootWindow(display, screen); XGetWindowAttributes(display, Root, &attributes); col.pixel = 0; if (!XParseColor(display, attributes.colormap, color, &col)) { fprintf(stderr, "wmtime: can't parse %s.\n", color); goto draw_window; } else if (!XAllocColor(display, attributes.colormap, &col)) { fprintf(stderr, "wmtime: can't allocate %s.\n", color); goto draw_window; } pixel = col.pixel; /* replace colors from wmtime-master.xpm */ user_color[0].pixel = pixel; user_color[1].pixel = scale_pixel(pixel, .3); user_color[2].pixel = scale_pixel(pixel, .4); user_color[3].pixel = scale_pixel(pixel, .8); wmgen.attributes.valuemask |= XpmColorSymbols; wmgen.attributes.numsymbols = NUMSYMBOLS; wmgen.attributes.colorsymbols = user_color; XCloseDisplay(display); } draw_window: openXwindow(argc, argv, wmifs_master_xpm, (char*)wmifs_mask_bits, wmifs_mask_width, wmifs_mask_height); /* > Button */ AddMouseRegion(0, 5, 5, 35, 15); AddMouseRegion(1, 5, 20, 58, 58); gettimeofday(&tv2, NULL); nexttime = ScrollSpeed; DrawActiveIFS(stat_devices[stat_current].name); while (1) { struct timespec ts; gettimeofday(&tv, NULL); curtime = (tv.tv_sec - tv2.tv_sec) * 1000 + (tv.tv_usec - tv2.tv_usec) / 1000; waitpid(0, NULL, WNOHANG); for (i = 0; i < stat_online; i++) { get_statistics(stat_devices[i].name, &ipacket, &opacket, &istat, &ostat); if (first_time) { first_time = 0; } else { stat_devices[i].his[53][0] += istat - stat_devices[i].istatlast; stat_devices[i].his[53][1] += ostat - stat_devices[i].ostatlast; } if (i == stat_current) { if (!stillonline(stat_devices[i].name)) SetErrLED(LED_NET_POWER); else SetOnLED(LED_NET_POWER); if (stat_devices[i].istatlast == istat) SetOffLED(LED_NET_RX); else SetOnLED(LED_NET_RX); if (stat_devices[i].ostatlast == ostat) SetOffLED(LED_NET_TX); else SetOnLED(LED_NET_TX); } stat_devices[i].istatlast = istat; stat_devices[i].ostatlast = ostat; } RedrawWindow(); if (curtime >= nexttime) { nexttime = curtime + ScrollSpeed; DrawStats(&stat_devices[stat_current].his[0][0], 54, 40, 5, 58); for (i = 0; i < stat_online; i++) { if (stillonline(stat_devices[i].name)) { for (j = 1; j < 54; j++) { stat_devices[i].his[j-1][0] = stat_devices[i].his[j][0]; stat_devices[i].his[j-1][1] = stat_devices[i].his[j][1]; } stat_devices[i].his[53][0] = 0; stat_devices[i].his[53][1] = 0; } } RedrawWindow(); } while (XPending(display)) { XNextEvent(display, &Event); switch (Event.type) { case Expose: RedrawWindow(); break; case DestroyNotify: XCloseDisplay(display); exit(0); break; case ButtonPress: but_stat = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); break; case ButtonRelease: i = CheckMouseRegion(Event.xbutton.x, Event.xbutton.y); if (but_stat == i && but_stat >= 0) { switch (but_stat) { case 0: /* re-read the table */ strcpy(temp, stat_devices[stat_current].name); stat_online = checknetdevs(); stat_current = 0; for (i = 0; i < stat_online; i++) { if (!strcmp(temp, stat_devices[i].name)) stat_current = i; } stat_current++; if (stat_current == stat_online) stat_current = 0; DrawActiveIFS(stat_devices[stat_current].name); DrawStats(&stat_devices[stat_current].his[0][0], 54, 40, 5, 58); break; case 1: switch (Event.xbutton.button) { case 1: if (left_action) execCommand(left_action); break; case 2: if (middle_action) execCommand(middle_action); break; case 3: if (right_action) execCommand(right_action); break; } break; } } but_stat = -1; RedrawWindow(); break; } } ts.tv_sec = 0; ts.tv_nsec = SampleInt * 1000000; nanosleep(&ts, NULL); } }
int main(int argc, char *argv[]) { int b; extern int d_depth; extern Window iconwin, win; Visual *visual; XEvent event; Pixmap xpm; Time lastTime=0; Imlib_Image image; ParseCMDLine(argc, argv); openXwindow(argc, argv, xpm_master, xpm_mask_bits, xpm_mask_width, xpm_mask_height); xpm = XCreatePixmap(display, win, 64, 64, d_depth); XFillRectangle(display, xpm, NormalGC, 0, 0, 64, 64); if (fname) { visual = DefaultVisual(display, DefaultScreen(display)); imlib_context_set_dither(1); imlib_context_set_display(display); imlib_context_set_visual(visual); image = imlib_load_image(fname); imlib_context_set_image(image); imlib_context_set_drawable(xpm); imlib_render_image_on_drawable_at_size(0, 0, isize, isize); } b = (64-isize)/2; /* Loop Forever */ while (1) { /* Process any pending X events. */ while (XPending(display)) { XNextEvent(display, &event); switch (event.type) { case Expose: RedrawWindow(); XCopyArea(display, xpm, iconwin, NormalGC, 0, 0, isize, isize, b, b); break; case MotionNotify: break; case ButtonPress: /*printf("ButtonPress\n");*/ break; case ButtonRelease: if (event.xbutton.button == Button1) { if (event.xbutton.time - lastTime < 250) { if (system(cmd) == -1) { fprintf(stdout, "Failed to run command:%s\n", cmd); exit(0); } } else { lastTime = event.xbutton.time; } } else if (event.xbutton.button == Button3) { exit(0); } /*printf("ButtonRelease\n");*/ break; } } usleep(10000); } /* we should never get here */ return (0); }