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); } }
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 } }