Adhere to XDG Base Directory Specification; fixes issue #124
This commit is contained in:
parent
48954a163a
commit
304fd382db
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
VERSION = git-20140109
|
VERSION = git-20140111
|
||||||
|
|
||||||
PREFIX = /usr/local
|
PREFIX = /usr/local
|
||||||
MANPREFIX = $(PREFIX)/share/man
|
MANPREFIX = $(PREFIX)/share/man
|
||||||
|
|
|
@ -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)**
|
**[v0.8](https://github.com/muennich/sxiv/archive/v0.8.tar.gz)**
|
||||||
*(April 18, 2011)*
|
*(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
|
* Ability to run external commands (e.g. jpegtran, convert) on current image
|
||||||
|
|
||||||
**[v0.7](https://github.com/muennich/sxiv/archive/v0.7.tar.gz)**
|
**[v0.7](https://github.com/muennich/sxiv/archive/v0.7.tar.gz)**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/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,
|
# Called by sxiv(1) whenever an image gets loaded,
|
||||||
# with the name of the image file as its first argument.
|
# with the name of the image file as its first argument.
|
||||||
# The output is displayed in sxiv's status bar.
|
# The output is displayed in sxiv's status bar.
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/sh
|
#!/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,
|
# 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
|
# with the key combo as its first argument and the path of the current image
|
||||||
# as its second argument.
|
# as its second argument.
|
||||||
|
|
54
main.c
54
main.c
|
@ -47,13 +47,6 @@ enum {
|
||||||
TITLE_LEN = 256
|
TITLE_LEN = 256
|
||||||
};
|
};
|
||||||
|
|
||||||
#define EXEC_REL_DIR ".sxiv/exec"
|
|
||||||
|
|
||||||
enum {
|
|
||||||
EXEC_INFO,
|
|
||||||
EXEC_KEY
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
const char *name;
|
const char *name;
|
||||||
char *cmd;
|
char *cmd;
|
||||||
|
@ -85,11 +78,6 @@ int prefix;
|
||||||
|
|
||||||
bool resized = false;
|
bool resized = false;
|
||||||
|
|
||||||
exec_t exec[] = {
|
|
||||||
{ "image-info", NULL },
|
|
||||||
{ "key-handler", NULL }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
char *cmd;
|
char *cmd;
|
||||||
int fd;
|
int fd;
|
||||||
|
@ -97,6 +85,8 @@ struct {
|
||||||
bool open;
|
bool open;
|
||||||
} info;
|
} info;
|
||||||
|
|
||||||
|
char * keyhandler;
|
||||||
|
|
||||||
timeout_t timeouts[] = {
|
timeout_t timeouts[] = {
|
||||||
{ { 0, 0 }, false, redraw },
|
{ { 0, 0 }, false, redraw },
|
||||||
{ { 0, 0 }, false, reset_cursor },
|
{ { 0, 0 }, false, reset_cursor },
|
||||||
|
@ -455,14 +445,14 @@ void clear_resize(void)
|
||||||
resized = false;
|
resized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_handler(const char *key, unsigned int mask)
|
void run_key_handler(const char *key, unsigned int mask)
|
||||||
{
|
{
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel;
|
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;
|
struct stat oldst, newst;
|
||||||
|
|
||||||
if (cmd == NULL || key == NULL)
|
if (keyhandler == NULL || key == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
snprintf(kstr, sizeof(kstr), "%s%s%s%s",
|
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);
|
stat(files[n].path, &oldst);
|
||||||
|
|
||||||
if ((pid = fork()) == 0) {
|
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");
|
warn("could not exec key handler");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
} else if (pid < 0) {
|
} else if (pid < 0) {
|
||||||
|
@ -556,7 +546,7 @@ void on_keypress(XKeyEvent *kev)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == ARRLEN(keys))
|
if (i == ARRLEN(keys))
|
||||||
key_handler(XKeysymToString(ksym), kev->state & ~sh);
|
run_key_handler(XKeysymToString(ksym), kev->state & ~sh);
|
||||||
prefix = 0;
|
prefix = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -736,7 +726,7 @@ int main(int argc, char **argv)
|
||||||
size_t n;
|
size_t n;
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
char *filename;
|
char *filename;
|
||||||
const char *homedir;
|
const char *homedir, *dsuffix = "";
|
||||||
struct stat fstats;
|
struct stat fstats;
|
||||||
r_dir_t dir;
|
r_dir_t dir;
|
||||||
|
|
||||||
|
@ -812,19 +802,27 @@ int main(int argc, char **argv)
|
||||||
win_init(&win);
|
win_init(&win);
|
||||||
img_init(&img, &win);
|
img_init(&img, &win);
|
||||||
|
|
||||||
if ((homedir = getenv("HOME")) == NULL) {
|
if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || homedir[0] == '\0') {
|
||||||
warn("could not locate home directory");
|
homedir = getenv("HOME");
|
||||||
} else for (i = 0; i < ARRLEN(exec); i++) {
|
dsuffix = "/.config";
|
||||||
len = strlen(homedir) + strlen(EXEC_REL_DIR) + strlen(exec[i].name) + 3;
|
}
|
||||||
exec[i].cmd = (char*) s_malloc(len);
|
if (homedir != NULL) {
|
||||||
snprintf(exec[i].cmd, len, "%s/%s/%s", homedir, EXEC_REL_DIR, exec[i].name);
|
char **cmd[] = { &info.cmd, &keyhandler };
|
||||||
if (access(exec[i].cmd, X_OK) != 0) {
|
const char *name[] = { "image-info", "key-handler" };
|
||||||
free(exec[i].cmd);
|
|
||||||
exec[i].cmd = NULL;
|
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.fd = -1;
|
||||||
info.cmd = exec[EXEC_INFO].cmd;
|
|
||||||
|
|
||||||
if (options->thumb_mode) {
|
if (options->thumb_mode) {
|
||||||
mode = MODE_THUMB;
|
mode = MODE_THUMB;
|
||||||
|
|
7
sxiv.1
7
sxiv.1
|
@ -353,14 +353,14 @@ Pan image right.
|
||||||
The information displayed on the left side of the status bar can be replaced
|
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
|
with the output of a user-provided script, which is called by sxiv whenever an
|
||||||
image gets loaded. The path of this script is
|
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.
|
and the first argument to this script is the path of the loaded image.
|
||||||
.P
|
.P
|
||||||
There is also an example script installed together with sxiv as
|
There is also an example script installed together with sxiv as
|
||||||
.IR PREFIX/share/sxiv/exec/image-info .
|
.IR PREFIX/share/sxiv/exec/image-info .
|
||||||
.SH THUMBNAIL CACHING
|
.SH THUMBNAIL CACHING
|
||||||
To enable thumbnail caching, please make sure to create the directory
|
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
|
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
|
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
|
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
|
.RE
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
.EX
|
.EX
|
||||||
Bert Muennich <be.muennich @ gmail.com>
|
Bert Muennich <ber.t at posteo.de>
|
||||||
.EE
|
.EE
|
||||||
.SH CONTRIBUTORS
|
.SH CONTRIBUTORS
|
||||||
.EX
|
.EX
|
||||||
|
@ -387,7 +387,6 @@ Fung SzeTat <sthorde at gmail.com>
|
||||||
.EE
|
.EE
|
||||||
.SH HOMEPAGE
|
.SH HOMEPAGE
|
||||||
.EX
|
.EX
|
||||||
http://muennich.github.com/sxiv
|
|
||||||
https://github.com/muennich/sxiv
|
https://github.com/muennich/sxiv
|
||||||
.EE
|
.EE
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
|
|
13
thumbs.c
13
thumbs.c
|
@ -34,7 +34,6 @@
|
||||||
|
|
||||||
static const int thumb_dim = THUMB_SIZE + 10;
|
static const int thumb_dim = THUMB_SIZE + 10;
|
||||||
|
|
||||||
static const char * const CACHE_DIR = ".sxiv/cache";
|
|
||||||
static char *cache_dir = NULL;
|
static char *cache_dir = NULL;
|
||||||
|
|
||||||
bool tns_cache_enabled(void)
|
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)
|
void tns_init(tns_t *tns, int cnt, win_t *win)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
char *homedir;
|
const char *homedir, *dsuffix = "";
|
||||||
|
|
||||||
if (tns == NULL)
|
if (tns == NULL)
|
||||||
return;
|
return;
|
||||||
|
@ -181,12 +180,16 @@ void tns_init(tns_t *tns, int cnt, win_t *win)
|
||||||
tns->alpha = !RENDER_WHITE_ALPHA;
|
tns->alpha = !RENDER_WHITE_ALPHA;
|
||||||
tns->dirty = false;
|
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)
|
if (cache_dir != NULL)
|
||||||
free(cache_dir);
|
free(cache_dir);
|
||||||
len = strlen(homedir) + strlen(CACHE_DIR) + 2;
|
len = strlen(homedir) + strlen(dsuffix) + 6;
|
||||||
cache_dir = (char*) s_malloc(len);
|
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 {
|
} else {
|
||||||
warn("could not locate thumbnail cache directory");
|
warn("could not locate thumbnail cache directory");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue