Krolyxon
Commit 591be8c

Branches

Refs →

nsxiv591be8c

Add thumb-info (#265)

Author
N-R-K
Date
2022-05-03 15:34 +0000
Committer
GitHub · 2022-05-03 15:34 +0000
Parent
6922d5d
Commit
591be8cecfaef143824e76c73f7c586261297c9c

+69 −19

5 files changed

  1. M commands.c +8 −1
  2. M examples/image-info +2 −1
  3. A examples/thumb-info +20 −0
  4. M main.c +17 −12
  5. M nsxiv.1 +22 −5
M commands.c View
@@ -84,6 +84,8 @@ bool cg_switch_mode(arg_t _)
8484 load_image(fileidx);
8585 mode = MODE_IMAGE;
8686 }
87+ close_info();
88+ open_info();
8789 return true;
8890 }
8991
@@ -429,7 +431,12 @@ bool ci_slideshow(arg_t _)
429431
430432 bool ct_move_sel(arg_t dir)
431433 {
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;
433440 }
434441
435442 bool ct_reload_all(arg_t _)
M examples/image-info View
@@ -4,9 +4,10 @@
44 # Called by nsxiv(1) whenever an image gets loaded.
55 # The output is displayed in nsxiv's status bar.
66 # Arguments:
7−# $1: path to image file
7+# $1: path to image file (as provided by the user)
88 # $2: image width
99 # $3: image height
10+# $4: fully resolved path to the image file
1011
1112 s=" " # field separator
1213
A examples/thumb-info View
@@ -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+
M main.c View
@@ -76,7 +76,7 @@ typedef struct {
7676 } extcmd_t;
7777
7878 static struct {
79− extcmd_t f;
79+ extcmd_t f, ft;
8080 int fd;
8181 unsigned int i, lastsep;
8282 pid_t pid;
@@ -283,16 +283,21 @@ void close_info(void)
283283 void open_info(void)
284284 {
285285 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;
288290
289− if (info.f.err || info.fd >= 0 || win.bar.h == 0)
291+ if (ferr || info.fd >= 0 || win.bar.h == 0)
290292 return;
291293 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);
296301 if (pfd.readfd >= 0) {
297302 fcntl(pfd.readfd, F_SETFL, O_NONBLOCK);
298303 info.fd = pfd.readfd;
@@ -396,7 +401,7 @@ static void bar_put(win_bar_t *bar, const char *fmt, ...)
396401 static void update_info(void)
397402 {
398403 unsigned int i, fn, fw;
399− const char * mark;
404+ const char *mark;
400405 win_bar_t *l = &win.bar.l, *r = &win.bar.r;
401406
402407 /* update bar contents */
@@ -411,7 +416,7 @@ static void update_info(void)
411416 bar_put(l, "Loading... %0*d", fw, tns.loadnext + 1);
412417 else if (tns.initnext < filecnt)
413418 bar_put(l, "Caching... %0*d", fw, tns.initnext + 1);
414− else
419+ else if (info.ft.err)
415420 strncpy(l->buf, files[fileidx].name, l->size);
416421 bar_put(r, "%s%0*d/%d", mark, fw, fileidx + 1, filecnt);
417422 } else {
@@ -916,8 +921,8 @@ int main(int argc, char *argv[])
916921 dsuffix = "/.config";
917922 }
918923 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" };
921926 const char *s = "/nsxiv/exec/";
922927
923928 for (i = 0; i < ARRLEN(cmd); i++) {
M nsxiv.1 View
@@ -450,19 +450,36 @@ There is also an example script installed together with nsxiv as
450450 .IR EGPREFIX/win-title .
451451 .SH STATUS BAR
452452 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
455456 .I $XDG_CONFIG_HOME/nsxiv/exec/image-info
456457 and the arguments given to it are:
457458 .IP $1 4
458−path to image file
459+path to image file (as provided by the user)
459460 .IP $2 4
460461 image width
461462 .IP $3 4
462463 image height
464+.IP $4 4
465+fully resolved path to the image file
463466 .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 .
466483 .SH EXTERNAL KEY HANDLER
467484 Additional external keyboard commands can be defined using a handler program
468485 located in