nsxivaabc2bd
Provide image width and height to image-info script; fixes issue #159
+12 −5
3 files changed
- M exec/image-info +6 −3
- M main.c +4 −1
- M sxiv.1 +2 −1
| @@ -1,16 +1,19 @@ | |||
| 1 | 1 | #!/bin/sh | |
| 2 | 2 | ||
| 3 | 3 | # Example for $XDG_CONFIG_HOME/sxiv/exec/image-info | |
| 4 | − | # Called by sxiv(1) whenever an image gets loaded, | |
| 5 | − | # with the name of the image file as its first argument. | |
| 4 | + | # Called by sxiv(1) whenever an image gets loaded. | |
| 6 | 5 | # The output is displayed in sxiv's status bar. | |
| 6 | + | # Arguments: | |
| 7 | + | # $1: path to image file | |
| 8 | + | # $2: image width | |
| 9 | + | # $3: image height | |
| 7 | 10 | ||
| 8 | 11 | s=" | " # field separator | |
| 9 | 12 | ||
| 10 | 13 | filename=$(basename -- "$1") | |
| 11 | 14 | filesize=$(du -Hh -- "$1" | cut -f 1) | |
| 12 | 15 | ||
| 13 | − | geometry=$(identify -format '%wx%h' ":$1[0]") | |
| 16 | + | geometry="${2}x${3}" | |
| 14 | 17 | tags=$(identify -format '%[IPTC:2:25]' ":$1" | tr ';' ',') | |
| 15 | 18 | ||
| 16 | 19 | echo "${filesize}${s}${geometry}${tags:+$s}${tags}${s}${filename}" | |
| @@ -224,6 +224,7 @@ void open_info(void) | |||
| 224 | 224 | { | |
| 225 | 225 | static pid_t pid; | |
| 226 | 226 | int pfd[2]; | |
| 227 | + | char w[12], h[12]; | |
| 227 | 228 | ||
| 228 | 229 | if (info.f.err != 0 || info.open || win.bar.h == 0) | |
| 229 | 230 | return; | |
| @@ -239,7 +240,9 @@ void open_info(void) | |||
| 239 | 240 | if ((pid = fork()) == 0) { | |
| 240 | 241 | close(pfd[0]); | |
| 241 | 242 | dup2(pfd[1], 1); | |
| 242 | − | execl(info.f.cmd, info.f.cmd, files[fileidx].name, NULL); | |
| 243 | + | snprintf(w, sizeof(w), "%d", img.w); | |
| 244 | + | snprintf(h, sizeof(h), "%d", img.h); | |
| 245 | + | execl(info.f.cmd, info.f.cmd, files[fileidx].name, w, h, NULL); | |
| 243 | 246 | error(EXIT_FAILURE, errno, "exec: %s", info.f.cmd); | |
| 244 | 247 | } | |
| 245 | 248 | close(pfd[1]); | |
| @@ -366,7 +366,8 @@ The information displayed on the left side of the status bar can be replaced | |||
| 366 | 366 | with the output of a user-provided script, which is called by sxiv whenever an | |
| 367 | 367 | image gets loaded. The path of this script is | |
| 368 | 368 | .I $XDG_CONFIG_HOME/sxiv/exec/image-info | |
| 369 | − | and the first argument to this script is the path of the loaded image. | |
| 369 | + | and the arguments given to it are: 1) path to image file, 2) image width, | |
| 370 | + | 3) image height. | |
| 370 | 371 | .P | |
| 371 | 372 | There is also an example script installed together with sxiv as | |
| 372 | 373 | .IR PREFIX/share/sxiv/exec/image-info . | |