Adhere to XDG Base Directory Specification; fixes issue #124

This commit is contained in:
Bert Münnich 2014-01-11 22:47:41 +01:00
parent 48954a163a
commit 304fd382db
7 changed files with 41 additions and 41 deletions

View File

@ -1,4 +1,4 @@
VERSION = git-20140109
VERSION = git-20140111
PREFIX = /usr/local
MANPREFIX = $(PREFIX)/share/man

View File

@ -212,7 +212,7 @@ on GitHub or get a copy using git with the following command:
**[v0.8](https://github.com/muennich/sxiv/archive/v0.8.tar.gz)**
*(April 18, 2011)*
* Support for thumbnail caching, only enabled if directory `~/.sxiv/` exists
* Support for thumbnail caching
* Ability to run external commands (e.g. jpegtran, convert) on current image
**[v0.7](https://github.com/muennich/sxiv/archive/v0.7.tar.gz)**

View File

@ -1,6 +1,6 @@
#!/bin/sh
# Example for ~/.sxiv/exec/image-info
# Example for $XDG_CONFIG_HOME/sxiv/exec/image-info
# Called by sxiv(1) whenever an image gets loaded,
# with the name of the image file as its first argument.
# The output is displayed in sxiv's status bar.

View File

@ -1,6 +1,6 @@
#!/bin/sh
# Example for ~/.sxiv/exec/key-handler
# Example for $XDG_CONFIG_HOME/sxiv/exec/key-handler
# Called by sxiv(1) whenever an unbound key combo is used,
# with the key combo as its first argument and the path of the current image
# as its second argument.

54
main.c
View File

@ -47,13 +47,6 @@ enum {
TITLE_LEN = 256
};
#define EXEC_REL_DIR ".sxiv/exec"
enum {
EXEC_INFO,
EXEC_KEY
};
typedef struct {
const char *name;
char *cmd;
@ -85,11 +78,6 @@ int prefix;
bool resized = false;
exec_t exec[] = {
{ "image-info", NULL },
{ "key-handler", NULL }
};
struct {
char *cmd;
int fd;
@ -97,6 +85,8 @@ struct {
bool open;
} info;
char * keyhandler;
timeout_t timeouts[] = {
{ { 0, 0 }, false, redraw },
{ { 0, 0 }, false, reset_cursor },
@ -455,14 +445,14 @@ void clear_resize(void)
resized = false;
}
void key_handler(const char *key, unsigned int mask)
void run_key_handler(const char *key, unsigned int mask)
{
pid_t pid;
int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel;
char *cmd = exec[EXEC_KEY].cmd, kstr[32];
char kstr[32];
struct stat oldst, newst;
if (cmd == NULL || key == NULL)
if (keyhandler == NULL || key == NULL)
return;
snprintf(kstr, sizeof(kstr), "%s%s%s%s",
@ -473,7 +463,7 @@ void key_handler(const char *key, unsigned int mask)
stat(files[n].path, &oldst);
if ((pid = fork()) == 0) {
execl(cmd, cmd, kstr, files[n].path, NULL);
execl(keyhandler, keyhandler, kstr, files[n].path, NULL);
warn("could not exec key handler");
exit(EXIT_FAILURE);
} else if (pid < 0) {
@ -556,7 +546,7 @@ void on_keypress(XKeyEvent *kev)
}
}
if (i == ARRLEN(keys))
key_handler(XKeysymToString(ksym), kev->state & ~sh);
run_key_handler(XKeysymToString(ksym), kev->state & ~sh);
prefix = 0;
}
@ -736,7 +726,7 @@ int main(int argc, char **argv)
size_t n;
ssize_t len;
char *filename;
const char *homedir;
const char *homedir, *dsuffix = "";
struct stat fstats;
r_dir_t dir;
@ -812,19 +802,27 @@ int main(int argc, char **argv)
win_init(&win);
img_init(&img, &win);
if ((homedir = getenv("HOME")) == NULL) {
warn("could not locate home directory");
} else for (i = 0; i < ARRLEN(exec); i++) {
len = strlen(homedir) + strlen(EXEC_REL_DIR) + strlen(exec[i].name) + 3;
exec[i].cmd = (char*) s_malloc(len);
snprintf(exec[i].cmd, len, "%s/%s/%s", homedir, EXEC_REL_DIR, exec[i].name);
if (access(exec[i].cmd, X_OK) != 0) {
free(exec[i].cmd);
exec[i].cmd = NULL;
if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || homedir[0] == '\0') {
homedir = getenv("HOME");
dsuffix = "/.config";
}
if (homedir != NULL) {
char **cmd[] = { &info.cmd, &keyhandler };
const char *name[] = { "image-info", "key-handler" };
for (i = 0; i < ARRLEN(cmd); i++) {
len = strlen(homedir) + strlen(dsuffix) + strlen(name[i]) + 12;
*cmd[i] = (char*) s_malloc(len);
snprintf(*cmd[i], len, "%s%s/sxiv/exec/%s", homedir, dsuffix, name[i]);
if (access(*cmd[i], X_OK) != 0) {
free(*cmd[i]);
*cmd[i] = NULL;
}
}
} else {
warn("could not locate exec directory");
}
info.fd = -1;
info.cmd = exec[EXEC_INFO].cmd;
if (options->thumb_mode) {
mode = MODE_THUMB;

7
sxiv.1
View File

@ -353,14 +353,14 @@ Pan image right.
The information displayed on the left side of the status bar can be replaced
with the output of a user-provided script, which is called by sxiv whenever an
image gets loaded. The path of this script is
.I ~/.sxiv/exec/image-info
.I $XDG_CONFIG_HOME/sxiv/exec/image-info
and the first argument to this script is the path of the loaded image.
.P
There is also an example script installed together with sxiv as
.IR PREFIX/share/sxiv/exec/image-info .
.SH THUMBNAIL CACHING
To enable thumbnail caching, please make sure to create the directory
.I ~/.sxiv/cache/
.I $XDG_CACHE_HOME/sxiv/
with write permissions. sxiv will then store all thumbnails inside this
directory, but it will not create this directory by itself. It rather uses the
existance of this directory as an affirmation, that the user wants thumbnails
@ -377,7 +377,7 @@ find . \-depth \-type d \-empty ! \-name '.' \-exec rmdir {} \\;
.RE
.SH AUTHOR
.EX
Bert Muennich <be.muennich @ gmail.com>
Bert Muennich <ber.t at posteo.de>
.EE
.SH CONTRIBUTORS
.EX
@ -387,7 +387,6 @@ Fung SzeTat <sthorde at gmail.com>
.EE
.SH HOMEPAGE
.EX
http://muennich.github.com/sxiv
https://github.com/muennich/sxiv
.EE
.SH SEE ALSO

View File

@ -34,7 +34,6 @@
static const int thumb_dim = THUMB_SIZE + 10;
static const char * const CACHE_DIR = ".sxiv/cache";
static char *cache_dir = NULL;
bool tns_cache_enabled(void)
@ -163,7 +162,7 @@ void tns_clean_cache(tns_t *tns)
void tns_init(tns_t *tns, int cnt, win_t *win)
{
int len;
char *homedir;
const char *homedir, *dsuffix = "";
if (tns == NULL)
return;
@ -181,12 +180,16 @@ void tns_init(tns_t *tns, int cnt, win_t *win)
tns->alpha = !RENDER_WHITE_ALPHA;
tns->dirty = false;
if ((homedir = getenv("HOME")) != NULL) {
if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') {
homedir = getenv("HOME");
dsuffix = "/.cache";
}
if (homedir != NULL) {
if (cache_dir != NULL)
free(cache_dir);
len = strlen(homedir) + strlen(CACHE_DIR) + 2;
len = strlen(homedir) + strlen(dsuffix) + 6;
cache_dir = (char*) s_malloc(len);
snprintf(cache_dir, len, "%s/%s", homedir, CACHE_DIR);
snprintf(cache_dir, len, "%s%s/sxiv", homedir, dsuffix);
} else {
warn("could not locate thumbnail cache directory");
}