nsxiv591be8c
Add thumb-info (#265)
+69 −19
5 files changed
- M commands.c +8 −1
- M examples/image-info +2 −1
- A examples/thumb-info +20 −0
- M main.c +17 −12
- M nsxiv.1 +22 −5
| @@ -84,6 +84,8 @@ bool cg_switch_mode(arg_t _) | |||
| 84 | 84 | load_image(fileidx); | |
| 85 | 85 | mode = MODE_IMAGE; | |
| 86 | 86 | } | |
| 87 | + | close_info(); | |
| 88 | + | open_info(); | |
| 87 | 89 | return true; | |
| 88 | 90 | } | |
| 89 | 91 | ||
| @@ -429,7 +431,12 @@ bool ci_slideshow(arg_t _) | |||
| 429 | 431 | ||
| 430 | 432 | bool ct_move_sel(arg_t dir) | |
| 431 | 433 | { | |
| 432 | − | return tns_move_selection(&tns, dir, prefix); | |
| 434 | + | bool dirty = tns_move_selection(&tns, dir, prefix); | |
| 435 | + | if (dirty) { | |
| 436 | + | close_info(); | |
| 437 | + | open_info(); | |
| 438 | + | } | |
| 439 | + | return dirty; | |
| 433 | 440 | } | |
| 434 | 441 | ||
| 435 | 442 | bool ct_reload_all(arg_t _) | |
| @@ -4,9 +4,10 @@ | |||
| 4 | 4 | # Called by nsxiv(1) whenever an image gets loaded. | |
| 5 | 5 | # The output is displayed in nsxiv's status bar. | |
| 6 | 6 | # Arguments: | |
| 7 | − | # $1: path to image file | |
| 7 | + | # $1: path to image file (as provided by the user) | |
| 8 | 8 | # $2: image width | |
| 9 | 9 | # $3: image height | |
| 10 | + | # $4: fully resolved path to the image file | |
| 10 | 11 | ||
| 11 | 12 | s=" " # field separator | |
| 12 | 13 | ||
| @@ -0,0 +1,20 @@ | |||
| 1 | + | #!/bin/sh | |
| 2 | + | ||
| 3 | + | # Example for $XDG_CONFIG_HOME/nsxiv/exec/thumb-info | |
| 4 | + | # Called by nsxiv(1) whenever the selected thumbnail changes. | |
| 5 | + | # The output is displayed in nsxiv's status bar. | |
| 6 | + | # Arguments: | |
| 7 | + | # $1: path to image file (as provided by the user) | |
| 8 | + | # $2: empty | |
| 9 | + | # $3: empty | |
| 10 | + | # $4: fully resolved path to the image file | |
| 11 | + | ||
| 12 | + | s=" " # field separator | |
| 13 | + | ||
| 14 | + | exec 2>/dev/null | |
| 15 | + | ||
| 16 | + | filename=$(basename -- "$4") | |
| 17 | + | filesize=$(du -Hh -- "$4" | cut -f 1) | |
| 18 | + | ||
| 19 | + | echo "${filesize}${s}${filename}" | |
| 20 | + | ||
| @@ -76,7 +76,7 @@ typedef struct { | |||
| 76 | 76 | } extcmd_t; | |
| 77 | 77 | ||
| 78 | 78 | static struct { | |
| 79 | − | extcmd_t f; | |
| 79 | + | extcmd_t f, ft; | |
| 80 | 80 | int fd; | |
| 81 | 81 | unsigned int i, lastsep; | |
| 82 | 82 | pid_t pid; | |
| @@ -283,16 +283,21 @@ void close_info(void) | |||
| 283 | 283 | void open_info(void) | |
| 284 | 284 | { | |
| 285 | 285 | spawn_t pfd; | |
| 286 | − | char w[12], h[12]; | |
| 287 | − | char *argv[5]; | |
| 286 | + | char w[12] = "", h[12] = ""; | |
| 287 | + | char *argv[6]; | |
| 288 | + | char *cmd = mode == MODE_IMAGE ? info.f.cmd : info.ft.cmd; | |
| 289 | + | bool ferr = mode == MODE_IMAGE ? info.f.err : info.ft.err; | |
| 288 | 290 | ||
| 289 | − | if (info.f.err || info.fd >= 0 || win.bar.h == 0) | |
| 291 | + | if (ferr || info.fd >= 0 || win.bar.h == 0) | |
| 290 | 292 | return; | |
| 291 | 293 | win.bar.l.buf[0] = '\0'; | |
| 292 | − | snprintf(w, sizeof(w), "%d", img.w); | |
| 293 | − | snprintf(h, sizeof(h), "%d", img.h); | |
| 294 | − | construct_argv(argv, ARRLEN(argv), info.f.cmd, files[fileidx].name, w, h, NULL); | |
| 295 | − | pfd = spawn(info.f.cmd, argv, X_READ); | |
| 294 | + | if (mode == MODE_IMAGE) { | |
| 295 | + | snprintf(w, sizeof(w), "%d", img.w); | |
| 296 | + | snprintf(h, sizeof(h), "%d", img.h); | |
| 297 | + | } | |
| 298 | + | construct_argv(argv, ARRLEN(argv), cmd, files[fileidx].name, w, h, | |
| 299 | + | files[fileidx].path, NULL); | |
| 300 | + | pfd = spawn(cmd, argv, X_READ); | |
| 296 | 301 | if (pfd.readfd >= 0) { | |
| 297 | 302 | fcntl(pfd.readfd, F_SETFL, O_NONBLOCK); | |
| 298 | 303 | info.fd = pfd.readfd; | |
| @@ -396,7 +401,7 @@ static void bar_put(win_bar_t *bar, const char *fmt, ...) | |||
| 396 | 401 | static void update_info(void) | |
| 397 | 402 | { | |
| 398 | 403 | unsigned int i, fn, fw; | |
| 399 | − | const char * mark; | |
| 404 | + | const char *mark; | |
| 400 | 405 | win_bar_t *l = &win.bar.l, *r = &win.bar.r; | |
| 401 | 406 | ||
| 402 | 407 | /* update bar contents */ | |
| @@ -411,7 +416,7 @@ static void update_info(void) | |||
| 411 | 416 | bar_put(l, "Loading... %0*d", fw, tns.loadnext + 1); | |
| 412 | 417 | else if (tns.initnext < filecnt) | |
| 413 | 418 | bar_put(l, "Caching... %0*d", fw, tns.initnext + 1); | |
| 414 | − | else | |
| 419 | + | else if (info.ft.err) | |
| 415 | 420 | strncpy(l->buf, files[fileidx].name, l->size); | |
| 416 | 421 | bar_put(r, "%s%0*d/%d", mark, fw, fileidx + 1, filecnt); | |
| 417 | 422 | } else { | |
| @@ -916,8 +921,8 @@ int main(int argc, char *argv[]) | |||
| 916 | 921 | dsuffix = "/.config"; | |
| 917 | 922 | } | |
| 918 | 923 | if (homedir != NULL) { | |
| 919 | − | extcmd_t *cmd[] = { &info.f, &keyhandler.f, &wintitle.f }; | |
| 920 | − | const char *name[] = { "image-info", "key-handler", "win-title" }; | |
| 924 | + | extcmd_t *cmd[] = { &info.f, &info.ft, &keyhandler.f, &wintitle.f }; | |
| 925 | + | const char *name[] = { "image-info", "thumb-info", "key-handler", "win-title" }; | |
| 921 | 926 | const char *s = "/nsxiv/exec/"; | |
| 922 | 927 | ||
| 923 | 928 | for (i = 0; i < ARRLEN(cmd); i++) { | |
| @@ -450,19 +450,36 @@ There is also an example script installed together with nsxiv as | |||
| 450 | 450 | .IR EGPREFIX/win-title . | |
| 451 | 451 | .SH STATUS BAR | |
| 452 | 452 | The information displayed on the left side of the status bar can be replaced | |
| 453 | − | with the output of a user-provided script, which is called by nsxiv whenever an | |
| 454 | − | image gets loaded. The path of this script is | |
| 453 | + | with the output of user-provided script. | |
| 454 | + | .P | |
| 455 | + | The script that is called by nsxiv whenever an image gets loaded is located at | |
| 455 | 456 | .I $XDG_CONFIG_HOME/nsxiv/exec/image-info | |
| 456 | 457 | and the arguments given to it are: | |
| 457 | 458 | .IP $1 4 | |
| 458 | − | path to image file | |
| 459 | + | path to image file (as provided by the user) | |
| 459 | 460 | .IP $2 4 | |
| 460 | 461 | image width | |
| 461 | 462 | .IP $3 4 | |
| 462 | 463 | image height | |
| 464 | + | .IP $4 4 | |
| 465 | + | fully resolved path to the image file | |
| 463 | 466 | .P | |
| 464 | − | There is also an example script installed together with nsxiv as | |
| 465 | − | .IR EGPREFIX/image-info . | |
| 467 | + | In thumbnail mode, the script that is called is located at | |
| 468 | + | .I $XDG_CONFIG_HOME/nsxiv/exec/thumb-info | |
| 469 | + | and the arguments given to it are: | |
| 470 | + | .IP $1 4 | |
| 471 | + | path to image file (as provided by the user) | |
| 472 | + | .IP $2 4 | |
| 473 | + | empty | |
| 474 | + | .IP $3 4 | |
| 475 | + | empty | |
| 476 | + | .IP $4 4 | |
| 477 | + | fully resolved path to the image file | |
| 478 | + | .P | |
| 479 | + | There are also example scripts installed together with nsxiv as | |
| 480 | + | .IR EGPREFIX/image-info | |
| 481 | + | and | |
| 482 | + | .IR EGPREFIX/thumb-info . | |
| 466 | 483 | .SH EXTERNAL KEY HANDLER | |
| 467 | 484 | Additional external keyboard commands can be defined using a handler program | |
| 468 | 485 | located in | |