/* * Dump the display surface(s) to a jpeg in ~/.appname/screenshot/. * It is customary to assign a AG_GlobalKeys(3) shortcut for this function. */ void AG_ViewCapture(void) { AG_Surface *s; char *pname; char dir[AG_PATHNAME_MAX]; char file[AG_PATHNAME_MAX]; Uint seq; if (agDriverSw == NULL) { Verbose("AG_ViewCapture() is not implemented under " "multiple-window drivers\n"); return; } AG_LockVFS(&agDrivers); if (AGDRIVER_SW_CLASS(agDriverSw)->videoCapture(agDriverSw, &s) == -1) { Verbose("Capture failed: %s\n", AG_GetError()); goto out; } /* Save to a new file. */ AG_GetString(agConfig, "save-path", dir, sizeof(dir)); Strlcat(dir, AG_PATHSEP, sizeof(dir)); Strlcat(dir, "screenshot", sizeof(dir)); if (!AG_FileExists(dir) && AG_MkPath(dir) == -1) { Verbose("Capture failed: %s\n", AG_GetError()); goto out; } pname = (agProgName != NULL) ? agProgName : "agarapp"; for (seq = 0; ; seq++) { Snprintf(file, sizeof(file), "%s%c%s%u.jpg", dir, AG_PATHSEPCHAR, pname, seq++); if (!AG_FileExists(file)) break; /* XXX race condition */ } if (AG_SurfaceExportJPEG(s, file) == 0) { Verbose("Saved capture to: %s\n", file); } else { Verbose("Capture failed: %s\n", AG_GetError()); } AG_SurfaceFree(s); out: AG_UnlockVFS(&agDrivers); }
static void SelectPath(AG_Event *event) { char path[AG_PATHNAME_MAX]; AG_Window *win; AG_DirDlg *dd; char *key = AG_STRING(1); AG_Textbox *tbox = AG_PTR(2); win = AG_WindowNew(0); dd = AG_DirDlgNew(win, AG_DIRDLG_EXPAND|AG_DIRDLG_CLOSEWIN); AG_GetString(agConfig, key, path, sizeof(path)); if (AG_DirDlgSetDirectoryS(dd, path) == -1) { AG_MkPath(path); (void)AG_DirDlgSetDirectoryS(dd, path); } AG_WindowSetGeometryAlignedPct(win, AG_WINDOW_MC, 30, 30); AG_WindowSetCaption(win, _("Select %s directory"), key); AG_DirDlgOkAction(dd, SelectPathOK, "%s,%p,%p", key, tbox, win); AG_WindowShow(win); }