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); }
int wmain(int argc, const wchar_t *_argv[]) { std::vector<const char *> StringPtrs(argc); std::vector<std::string> StringStorage(argc); for (int i = 0; i < argc; i++) { StringStorage[i] = utf16_to_utf8(_argv[i]); StringPtrs[i] = StringStorage[i].c_str(); } const char **argv = StringPtrs.data(); #else int main(int argc, const char *argv[]) { #endif try { if (argc <= 1) { PrintUsage(); return 0; } ParseCMDLine(argc, argv); } catch (Error const& e) { std::cout << e.msg << std::endl; return 1; } FFMS_Init(0, 0); switch (Verbose) { case 0: FFMS_SetLogLevel(FFMS_LOG_QUIET); break; case 1: FFMS_SetLogLevel(FFMS_LOG_WARNING); break; case 2: FFMS_SetLogLevel(FFMS_LOG_INFO); break; case 3: FFMS_SetLogLevel(FFMS_LOG_VERBOSE); break; default: FFMS_SetLogLevel(FFMS_LOG_DEBUG); // if user used -v 4 or more times, he deserves the spam } try { DoIndexing(); } catch (Error const& e) { std::cout << e.msg << std::endl; FFMS_Deinit(); return 1; } FFMS_Deinit(); return 0; }
int main() { int argc; wchar_t **_argv; wchar_t **env; int si = 0; __wgetmainargs(&argc, &_argv, &env, _CRT_glob, &si); #else int wmain(int argc, wchar_t *_argv[]) { #endif char **argv = (char**)malloc(argc*sizeof(char*)); for (int i=0; i<argc; i++) { int len = WideCharToMultiByte(CP_UTF8, 0, _argv[i], -1, NULL, 0, NULL, NULL); if (!len) { std::cout << "Failed to translate commandline to Unicode" << std::endl; return 1; } char *temp = (char*)malloc(len*sizeof(char)); len = WideCharToMultiByte(CP_UTF8, 0, _argv[i], -1, temp, len, NULL, NULL); if (!len) { std::cout << "Failed to translate commandline to Unicode" << std::endl; return 1; } argv[i] = temp; } #else /* defined(_WIN32) && !defined(__MINGW32__) */ int main(int argc, char *argv[]) { #endif /* defined(_WIN32) && !defined(__MINGW32__) */ try { ParseCMDLine(argc, argv); } catch (const char *Error) { std::cout << std::endl << Error << std::endl; return 1; } catch (std::string Error) { std::cout << std::endl << Error << std::endl; return 1; } catch (...) { std::cout << std::endl << "Unknown error" << std::endl; return 1; } #ifdef _WIN32 if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) { std::cout << "COM initialization failure" << std::endl; return 1; } #endif /* _WIN32 */ FFMS_Init(0, 1); switch (Verbose) { case 0: FFMS_SetLogLevel(AV_LOG_QUIET); break; case 1: FFMS_SetLogLevel(AV_LOG_WARNING); break; case 2: FFMS_SetLogLevel(AV_LOG_INFO); break; case 3: FFMS_SetLogLevel(AV_LOG_VERBOSE); break; default: FFMS_SetLogLevel(AV_LOG_DEBUG); // if user used -v 4 or more times, he deserves the spam } try { DoIndexing(); } catch (const char *Error) { std::cout << Error << std::endl; if (Index) FFMS_DestroyIndex(Index); return 1; } catch (std::string Error) { std::cout << std::endl << Error << std::endl; if (Index) FFMS_DestroyIndex(Index); return 1; } catch (...) { std::cout << std::endl << "Unknown error" << std::endl; if (Index) FFMS_DestroyIndex(Index); return 1; } if (Index) FFMS_DestroyIndex(Index); #ifdef _WIN32 CoUninitialize(); #endif return 0; }
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); } }
/* * 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); } }
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); }