Krolyxon
Commit 304fd38

Branches

Refs →

nsxiv304fd38

Adhere to XDG Base Directory Specification; fixes issue #124

Author
Bert Münnich
Date
2014-01-11 22:47 +0100
Parent
48954a1
Commit
304fd382db98a6a134e0e281cc6f4cf27fb0789a

+41 −41

7 files changed

  1. M Makefile +1 −1
  2. M README.md +1 −1
  3. M exec/image-info +1 −1
  4. M exec/key-handler +1 −1
  5. M main.c +26 −28
  6. M sxiv.1 +3 −4
  7. M thumbs.c +8 −5
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20140109
1+VERSION = git-20140111
22
33 PREFIX = /usr/local
44 MANPREFIX = $(PREFIX)/share/man
M README.md View
@@ -212,7 +212,7 @@ on GitHub or get a copy using git with the following command:
212212 **[v0.8](https://github.com/muennich/sxiv/archive/v0.8.tar.gz)**
213213 *(April 18, 2011)*
214214
215− * Support for thumbnail caching, only enabled if directory `~/.sxiv/` exists
215+ * Support for thumbnail caching
216216 * Ability to run external commands (e.g. jpegtran, convert) on current image
217217
218218 **[v0.7](https://github.com/muennich/sxiv/archive/v0.7.tar.gz)**
M exec/image-info View
@@ -1,6 +1,6 @@
11 #!/bin/sh
22
3−# Example for ~/.sxiv/exec/image-info
3+# Example for $XDG_CONFIG_HOME/sxiv/exec/image-info
44 # Called by sxiv(1) whenever an image gets loaded,
55 # with the name of the image file as its first argument.
66 # The output is displayed in sxiv's status bar.
M exec/key-handler View
@@ -1,6 +1,6 @@
11 #!/bin/sh
22
3−# Example for ~/.sxiv/exec/key-handler
3+# Example for $XDG_CONFIG_HOME/sxiv/exec/key-handler
44 # Called by sxiv(1) whenever an unbound key combo is used,
55 # with the key combo as its first argument and the path of the current image
66 # as its second argument.
M main.c View
@@ -47,13 +47,6 @@ enum {
4747 TITLE_LEN = 256
4848 };
4949
50−#define EXEC_REL_DIR ".sxiv/exec"
51−
52−enum {
53− EXEC_INFO,
54− EXEC_KEY
55−};
56−
5750 typedef struct {
5851 const char *name;
5952 char *cmd;
@@ -85,11 +78,6 @@ int prefix;
8578
8679 bool resized = false;
8780
88−exec_t exec[] = {
89− { "image-info", NULL },
90− { "key-handler", NULL }
91−};
92−
9381 struct {
9482 char *cmd;
9583 int fd;
@@ -97,6 +85,8 @@ struct {
9785 bool open;
9886 } info;
9987
88+char * keyhandler;
89+
10090 timeout_t timeouts[] = {
10191 { { 0, 0 }, false, redraw },
10292 { { 0, 0 }, false, reset_cursor },
@@ -455,14 +445,14 @@ void clear_resize(void)
455445 resized = false;
456446 }
457447
458−void key_handler(const char *key, unsigned int mask)
448+void run_key_handler(const char *key, unsigned int mask)
459449 {
460450 pid_t pid;
461451 int retval, status, n = mode == MODE_IMAGE ? fileidx : tns.sel;
462− char *cmd = exec[EXEC_KEY].cmd, kstr[32];
452+ char kstr[32];
463453 struct stat oldst, newst;
464454
465− if (cmd == NULL || key == NULL)
455+ if (keyhandler == NULL || key == NULL)
466456 return;
467457
468458 snprintf(kstr, sizeof(kstr), "%s%s%s%s",
@@ -473,7 +463,7 @@ void key_handler(const char *key, unsigned int mask)
473463 stat(files[n].path, &oldst);
474464
475465 if ((pid = fork()) == 0) {
476− execl(cmd, cmd, kstr, files[n].path, NULL);
466+ execl(keyhandler, keyhandler, kstr, files[n].path, NULL);
477467 warn("could not exec key handler");
478468 exit(EXIT_FAILURE);
479469 } else if (pid < 0) {
@@ -556,7 +546,7 @@ void on_keypress(XKeyEvent *kev)
556546 }
557547 }
558548 if (i == ARRLEN(keys))
559− key_handler(XKeysymToString(ksym), kev->state & ~sh);
549+ run_key_handler(XKeysymToString(ksym), kev->state & ~sh);
560550 prefix = 0;
561551 }
562552
@@ -736,7 +726,7 @@ int main(int argc, char **argv)
736726 size_t n;
737727 ssize_t len;
738728 char *filename;
739− const char *homedir;
729+ const char *homedir, *dsuffix = "";
740730 struct stat fstats;
741731 r_dir_t dir;
742732
@@ -812,19 +802,27 @@ int main(int argc, char **argv)
812802 win_init(&win);
813803 img_init(&img, &win);
814804
815− if ((homedir = getenv("HOME")) == NULL) {
816− warn("could not locate home directory");
817− } else for (i = 0; i < ARRLEN(exec); i++) {
818− len = strlen(homedir) + strlen(EXEC_REL_DIR) + strlen(exec[i].name) + 3;
819− exec[i].cmd = (char*) s_malloc(len);
820− snprintf(exec[i].cmd, len, "%s/%s/%s", homedir, EXEC_REL_DIR, exec[i].name);
821− if (access(exec[i].cmd, X_OK) != 0) {
822− free(exec[i].cmd);
823− exec[i].cmd = NULL;
805+ if ((homedir = getenv("XDG_CONFIG_HOME")) == NULL || homedir[0] == '\0') {
806+ homedir = getenv("HOME");
807+ dsuffix = "/.config";
808+ }
809+ if (homedir != NULL) {
810+ char **cmd[] = { &info.cmd, &keyhandler };
811+ const char *name[] = { "image-info", "key-handler" };
812+
813+ for (i = 0; i < ARRLEN(cmd); i++) {
814+ len = strlen(homedir) + strlen(dsuffix) + strlen(name[i]) + 12;
815+ *cmd[i] = (char*) s_malloc(len);
816+ snprintf(*cmd[i], len, "%s%s/sxiv/exec/%s", homedir, dsuffix, name[i]);
817+ if (access(*cmd[i], X_OK) != 0) {
818+ free(*cmd[i]);
819+ *cmd[i] = NULL;
820+ }
824821 }
822+ } else {
823+ warn("could not locate exec directory");
825824 }
826825 info.fd = -1;
827− info.cmd = exec[EXEC_INFO].cmd;
828826
829827 if (options->thumb_mode) {
830828 mode = MODE_THUMB;
M sxiv.1 View
@@ -353,14 +353,14 @@ Pan image right.
353353 The information displayed on the left side of the status bar can be replaced
354354 with the output of a user-provided script, which is called by sxiv whenever an
355355 image gets loaded. The path of this script is
356−.I ~/.sxiv/exec/image-info
356+.I $XDG_CONFIG_HOME/sxiv/exec/image-info
357357 and the first argument to this script is the path of the loaded image.
358358 .P
359359 There is also an example script installed together with sxiv as
360360 .IR PREFIX/share/sxiv/exec/image-info .
361361 .SH THUMBNAIL CACHING
362362 To enable thumbnail caching, please make sure to create the directory
363−.I ~/.sxiv/cache/
363+.I $XDG_CACHE_HOME/sxiv/
364364 with write permissions. sxiv will then store all thumbnails inside this
365365 directory, but it will not create this directory by itself. It rather uses the
366366 existance of this directory as an affirmation, that the user wants thumbnails
@@ -377,7 +377,7 @@ find . \-depth \-type d \-empty ! \-name '.' \-exec rmdir {} \\;
377377 .RE
378378 .SH AUTHOR
379379 .EX
380−Bert Muennich <be.muennich @ gmail.com>
380+Bert Muennich <ber.t at posteo.de>
381381 .EE
382382 .SH CONTRIBUTORS
383383 .EX
@@ -387,7 +387,6 @@ Fung SzeTat <sthorde at gmail.com>
387387 .EE
388388 .SH HOMEPAGE
389389 .EX
390−http://muennich.github.com/sxiv
391390 https://github.com/muennich/sxiv
392391 .EE
393392 .SH SEE ALSO
M thumbs.c View
@@ -34,7 +34,6 @@
3434
3535 static const int thumb_dim = THUMB_SIZE + 10;
3636
37−static const char * const CACHE_DIR = ".sxiv/cache";
3837 static char *cache_dir = NULL;
3938
4039 bool tns_cache_enabled(void)
@@ -163,7 +162,7 @@ void tns_clean_cache(tns_t *tns)
163162 void tns_init(tns_t *tns, int cnt, win_t *win)
164163 {
165164 int len;
166− char *homedir;
165+ const char *homedir, *dsuffix = "";
167166
168167 if (tns == NULL)
169168 return;
@@ -181,12 +180,16 @@ void tns_init(tns_t *tns, int cnt, win_t *win)
181180 tns->alpha = !RENDER_WHITE_ALPHA;
182181 tns->dirty = false;
183182
184− if ((homedir = getenv("HOME")) != NULL) {
183+ if ((homedir = getenv("XDG_CACHE_HOME")) == NULL || homedir[0] == '\0') {
184+ homedir = getenv("HOME");
185+ dsuffix = "/.cache";
186+ }
187+ if (homedir != NULL) {
185188 if (cache_dir != NULL)
186189 free(cache_dir);
187− len = strlen(homedir) + strlen(CACHE_DIR) + 2;
190+ len = strlen(homedir) + strlen(dsuffix) + 6;
188191 cache_dir = (char*) s_malloc(len);
189− snprintf(cache_dir, len, "%s/%s", homedir, CACHE_DIR);
192+ snprintf(cache_dir, len, "%s%s/sxiv", homedir, dsuffix);
190193 } else {
191194 warn("could not locate thumbnail cache directory");
192195 }