diff --git a/src/WindowMaker.h b/src/WindowMaker.h index 7255ab33..cd2c9b48 100644 --- a/src/WindowMaker.h +++ b/src/WindowMaker.h @@ -505,6 +505,7 @@ extern struct WPreferences { Cursor cursor[WCUR_LAST]; int switch_panel_icon_size; /* icon size in switch panel */ + char *screenshot_filename_template; /* strftime format for screenshot filenames */ } wPreferences; diff --git a/src/defaults.c b/src/defaults.c index f8fae418..d5d81a2d 100644 --- a/src/defaults.c +++ b/src/defaults.c @@ -91,6 +91,7 @@ typedef struct { /* type converters */ static WDECallbackConvert getBool; static WDECallbackConvert getInt; +static WDECallbackConvert getString; static WDECallbackConvert getCoord; static WDECallbackConvert getPathList; static WDECallbackConvert getEnum; @@ -540,6 +541,8 @@ WDefaultEntry optionList[] = { &wPreferences.mouse_wheel_focus, getBool, NULL, NULL, NULL}, {"KeychainTimeoutDelay", "500", NULL, &wPreferences.keychain_timeout_delay, getInt, NULL, NULL, NULL}, + {"ScreenshotFilenameTemplate", DEF_SCREENSHOT_FILENAME_TEMPLATE, NULL, + &wPreferences.screenshot_filename_template, getString, NULL, NULL, NULL}, /* style options */ @@ -1496,6 +1499,29 @@ static int string2index(WMPropList *key, WMPropList *val, const char *def, WOpti * ret - is the address to store a pointer to a temporary buffer. ret * must not be freed and is used by the set functions */ +static int getString(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret) +{ + const char *val; + char **sptr; + + /* Parameter not used, but tell the compiler that it is ok */ + (void) scr; + + GET_STRING_OR_DEFAULT("String", val); + + if (ret) + *ret = (void *)val; + + if (addr) { + sptr = (char **)addr; + if (*sptr) + wfree(*sptr); + *sptr = wstrdup(val); + } + + return True; +} + static int getBool(WScreen * scr, WDefaultEntry * entry, WMPropList * value, void *addr, void **ret) { static char data; diff --git a/src/screen.c b/src/screen.c index 172a6078..a737c095 100644 --- a/src/screen.c +++ b/src/screen.c @@ -1270,7 +1270,14 @@ void ScreenCapture(WScreen *scr, int mode) s = time(NULL); tm_info = localtime(&s); - strftime(filename_date_part, sizeof(filename_date_part), "screenshot_%Y-%m-%d_at_%H:%M:%S", tm_info); + strftime(filename_date_part, sizeof(filename_date_part), wPreferences.screenshot_filename_template, tm_info); + + if (strchr(filename_date_part, '/') != NULL) { + wfree(screenshot_dir); + werror(_("Unsafe screenshot filename template, it should not contain a path separator")); + return; + } + strcpy(filename, filename_date_part); filepath = wstrconcat(screenshot_dir, strcat(filename, filetype)); diff --git a/src/wconfig.h.in b/src/wconfig.h.in index 2c4900e9..d87cf206 100644 --- a/src/wconfig.h.in +++ b/src/wconfig.h.in @@ -191,6 +191,9 @@ #define DEF_APPMENU_X 10 #define DEF_APPMENU_Y 10 +/* default strftime format for screenshot filenames */ +#define DEF_SCREENSHOT_FILENAME_TEMPLATE "\"screenshot_%Y-%m-%d_at_%H:%M:%S\"" + /* calculate window edge resistance from edge resistance */ #define WIN_RESISTANCE(x) (((x)*20)/30)