forked from speedie/spmenu
allow overriding image cache directory
This commit is contained in:
parent
21711e4236
commit
3da21bc052
|
@ -48,6 +48,9 @@ You may use long, descriptive arguments or the shorter arguments.
|
|||
`-mc, --max-cache size`
|
||||
: Set max image cache size to size
|
||||
|
||||
`-cd, --cache-dir dir`
|
||||
: Set cache directory to dir
|
||||
|
||||
`-rw, --relative-width`
|
||||
: Enable relative input width
|
||||
|
||||
|
|
|
@ -185,7 +185,8 @@ spmenu = {
|
|||
gaps = 0; // Image gaps (px)
|
||||
position = 0; // Image position (0: Top, 1: Bottom, 2: Center, 3: Top center)
|
||||
cache = 1; // Cache images (0/1)
|
||||
maxcache = 512; // Max image width/height to cache (px)
|
||||
maxcache = 512; // Max image size to cache (px)
|
||||
cachedir = "default"; // Cache directory. "default" means spmenu will determine automatically based on $XDG_CACHE_DIR
|
||||
} );
|
||||
|
||||
/* File options */
|
||||
|
|
|
@ -237,6 +237,11 @@ void readargs(int argc, char *argv[]) {
|
|||
if (lines == 0) lines = 1;
|
||||
} else if (!strcmp(argv[i], "-mc") || (!strcmp(argv[i], "--max-cache"))) { // max cache
|
||||
maxcache = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-cd") || (!strcmp(argv[i], "--cache-dir"))) { // cache directory
|
||||
cachedir = argv[++i];
|
||||
if (access(cachedir, F_OK) != 0) {
|
||||
cachedir = "default";
|
||||
}
|
||||
} else if (!strcmp(argv[i], "-l") || (!strcmp(argv[i], "--lines"))) { // number of lines in grid
|
||||
lines = atoi(argv[++i]);
|
||||
} else if (!strcmp(argv[i], "-mh") || (!strcmp(argv[i], "--lineheight")) || (!strcmp(argv[i], "--line-height"))) { // line height
|
||||
|
@ -459,7 +464,8 @@ void usage(void) {
|
|||
"spmenu -g, --columns <grid> Set the number of grids to <grid>\n"
|
||||
"spmenu -gc, --generate-cache Generate image cache\n"
|
||||
"spmenu -ngc, --no-generate-cache Don't generate image cache\n"
|
||||
"spmenu -mc --max-cache <size> Set max image cache size to <size>\n"
|
||||
"spmenu -mc, --max-cache <size> Set max image cache size to <size>\n"
|
||||
"spmenu -cd, --cache-dir <dir> Set cache directory to <dir>\n"
|
||||
"spmenu -rw, --relative-width Enable relative input width\n"
|
||||
"spmenu -nrw, --no-relative-width Disable relative input width\n"
|
||||
"spmenu -ix, --print-index Print index instead of actual text\n"
|
||||
|
|
|
@ -371,6 +371,8 @@ void conf_init(void) {
|
|||
config_setting_lookup_int(conf, "position", &imageposition); // spmenu.image.position
|
||||
config_setting_lookup_int(conf, "cache", &generatecache); // spmenu.image.cache
|
||||
config_setting_lookup_int(conf, "maxcache", &maxcache); // spmenu.image.maxcache
|
||||
if (config_setting_lookup_string(conf, "cachedir", &dest)) // spmenu.image.cachedir
|
||||
cachedir = strdup(dest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -258,20 +258,28 @@ void loadimagecache(const char *file, int *width, int *height) {
|
|||
sprintf(&md5[i*2], "%02x", (unsigned int)digest[i]);
|
||||
|
||||
// path for cached thumbnail
|
||||
if (!cachedir || !strcmp(cachedir, "default")) {
|
||||
if (xdg_cache)
|
||||
slen = snprintf(NULL, 0, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5)+1;
|
||||
else
|
||||
slen = snprintf(NULL, 0, "%s/.thumbnails/%s/%s.png", home, dsize, md5)+1;
|
||||
} else {
|
||||
slen = snprintf(NULL, 0, "%s/%s/%s.png", cachedir, dsize, md5)+1;
|
||||
}
|
||||
|
||||
if(!(buf = malloc(slen))) {
|
||||
fprintf(stderr, "out of memory");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cachedir || !strcmp(cachedir, "default")) {
|
||||
if (xdg_cache)
|
||||
sprintf(buf, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5);
|
||||
else
|
||||
sprintf(buf, "%s/.thumbnails/%s/%s.png", home, dsize, md5);
|
||||
} else {
|
||||
sprintf(buf, "%s/%s/%s.png", cachedir, dsize, md5);
|
||||
}
|
||||
|
||||
loadimage(buf, width, height);
|
||||
|
||||
|
|
|
@ -46,6 +46,7 @@ static int imagegaps = 0; /* Image gaps */
|
|||
static int imageposition = 0; /* Image position (0: Top, 1: Bottom, 2: Center, 3: Top center) */
|
||||
static int generatecache = 1; /* Generate image cache by default */
|
||||
static int maxcache = 512; /* Max image size to cache */
|
||||
static char *cachedir = "default"; /* Cache directory. Default means spmenu will determine automatically */
|
||||
|
||||
/* Mode options */
|
||||
static int mode = 0; /* Mode to start speedwm in (0: Normal mode, 1: Insert mode) */
|
||||
|
|
3
spmenu.1
3
spmenu.1
|
@ -68,6 +68,9 @@ Don\[cq]t generate image cache
|
|||
\f[V]-mc, --max-cache size\f[R]
|
||||
Set max image cache size to size
|
||||
.TP
|
||||
\f[V]-cd, --cache-dir dir\f[R]
|
||||
Set cache directory to dir
|
||||
.TP
|
||||
\f[V]-rw, --relative-width\f[R]
|
||||
Enable relative input width
|
||||
.TP
|
||||
|
|
|
@ -215,6 +215,10 @@ Don’t generate image cache
|
|||
<dd>
|
||||
Set max image cache size to size
|
||||
</dd>
|
||||
<dt><code>-cd, --cache-dir dir</code></dt>
|
||||
<dd>
|
||||
Set cache directory to dir
|
||||
</dd>
|
||||
<dt><code>-rw, --relative-width</code></dt>
|
||||
<dd>
|
||||
Enable relative input width
|
||||
|
|
Loading…
Reference in a new issue