Krolyxon
Commit 7d878bd

Branches

Refs →

nsxiv7d878bd

Added file marks; fixes issue #94

- Command it_toggle_image_mark (bound to 'm') toggles mark of current
  image
- Command it_navigate_marked (bound to 'N'/'P') can be used to go to
  the next/previous marked image
- When option -o is given, all marked files get printed
Author
Bert Münnich
Date
2013-08-10 21:18 +0200
Parent
84d77b1
Commit
7d878bd16df1abffde780e195144b845dc133166

+77 −6

7 files changed

  1. M README.md +5 −1
  2. M commands.c +45 −2
  3. M commands.h +2 −0
  4. M config.def.h +4 −0
  5. M main.c +5 −2
  6. M sxiv.1 +15 −1
  7. M types.h +1 −0
M README.md View
@@ -79,7 +79,7 @@ of small previews is displayed, making it easy to choose an image to open.
7979 -i Read file list from stdin
8080 -n NUM Start at picture NUM
8181 -N NAME Set X window resource name to NAME
82− -o Write file list to stdout when quitting
82+ -o Write list of marked/all files to stdout when quitting
8383 -p Pixelize, i.e. turn off image anti-aliasing
8484 -q Be quiet, disable warnings
8585 -r Search given directories recursively for images
@@ -108,6 +108,10 @@ of small previews is displayed, making it easy to choose an image to open.
108108 R Reload all thumbnails
109109 D Remove image from file list and go to next image
110110
111+ m Mark/unmark current image
112+ N Go [count] marked images forward
113+ P Go [count] marked images backward
114+
111115 *Thumbnail mode:*
112116
113117 h,j,k,l Move selection left/down/up/right [count] times
M commands.c View
@@ -48,6 +48,7 @@ extern win_t win;
4848
4949 extern fileinfo_t *files;
5050 extern int filecnt, fileidx;
51+extern int markcnt;
5152 extern int alternate;
5253
5354 extern int prefix;
@@ -61,8 +62,10 @@ bool it_quit(arg_t a)
6162 unsigned int i;
6263
6364 if (options->to_stdout) {
64− for (i = 0; i < filecnt; i++)
65− printf("%s\n", files[i].name);
65+ for (i = 0; i < filecnt; i++) {
66+ if (!markcnt || files[i].marked)
67+ printf("%s\n", files[i].name);
68+ }
6669 }
6770 cleanup();
6871 exit(EXIT_SUCCESS);
@@ -237,6 +240,46 @@ bool i_toggle_animation(arg_t a)
237240 return true;
238241 }
239242
243+bool it_toggle_image_mark(arg_t a)
244+{
245+ int sel = mode == MODE_IMAGE ? fileidx : tns.sel;
246+
247+ files[sel].marked = !files[sel].marked;
248+ markcnt += files[sel].marked ? 1 : -1;
249+ return true;
250+}
251+
252+bool it_navigate_marked(arg_t a)
253+{
254+ long n = (long) a;
255+ int d, i, cnt, sel, new;
256+
257+ if (mode == MODE_IMAGE)
258+ cnt = filecnt, sel = new = fileidx;
259+ else
260+ cnt = tns.cnt, sel = new = tns.sel;
261+ if (prefix > 0)
262+ n *= prefix;
263+ d = n > 0 ? 1 : -1;
264+ for (i = sel + d; n != 0 && i >= 0 && i < cnt; i += d) {
265+ if (files[i].marked) {
266+ n -= d;
267+ new = i;
268+ }
269+ }
270+ if (new != sel) {
271+ if (mode == MODE_IMAGE) {
272+ load_image(new);
273+ } else {
274+ tns.sel = new;
275+ tns.dirty = true;
276+ }
277+ return true;
278+ } else {
279+ return false;
280+ }
281+}
282+
240283 bool it_scroll_move(arg_t a)
241284 {
242285 direction_t dir = (direction_t) a;
M commands.h View
@@ -54,6 +54,8 @@ bool it_first(arg_t);
5454 bool it_n_or_last(arg_t);
5555 bool i_navigate_frame(arg_t);
5656 bool i_toggle_animation(arg_t);
57+bool it_toggle_image_mark(arg_t);
58+bool it_navigate_marked(arg_t);
5759 bool it_scroll_move(arg_t);
5860 bool it_scroll_screen(arg_t);
5961 bool i_scroll_to_edge(arg_t);
M config.def.h View
@@ -81,6 +81,10 @@ static const keymap_t keys[] = {
8181 { true, XK_p, i_navigate_frame, (arg_t) -1 },
8282 { true, XK_space, i_toggle_animation, (arg_t) None },
8383
84+ { false, XK_m, it_toggle_image_mark, (arg_t) None },
85+ { false, XK_N, it_navigate_marked, (arg_t) +1 },
86+ { false, XK_P, it_navigate_marked, (arg_t) -1 },
87+
8488 { false, XK_h, it_scroll_move, (arg_t) DIR_LEFT },
8589 { false, XK_Left, it_scroll_move, (arg_t) DIR_LEFT },
8690 { false, XK_j, it_scroll_move, (arg_t) DIR_DOWN },
M main.c View
@@ -65,6 +65,7 @@ win_t win;
6565
6666 fileinfo_t *files;
6767 int filecnt, fileidx;
68+int markcnt;
6869 int alternate;
6970
7071 int prefix;
@@ -312,6 +313,7 @@ void update_info(void)
312313 unsigned int i, fn, fw, n;
313314 unsigned int llen = sizeof(win.bar.l), rlen = sizeof(win.bar.r);
314315 char *lt = win.bar.l, *rt = win.bar.r, title[TITLE_LEN];
316+ const char * mark;
315317 bool ow_info;
316318
317319 for (fw = 0, i = filecnt; i > 0; fw++, i /= 10);
@@ -328,9 +330,10 @@ void update_info(void)
328330 /* update bar contents */
329331 if (win.bar.h == 0)
330332 return;
333+ mark = files[sel].marked ? "* " : "";
331334 if (mode == MODE_THUMB) {
332335 if (tns.cnt == filecnt) {
333− n = snprintf(rt, rlen, "%0*d/%d", fw, sel + 1, filecnt);
336+ n = snprintf(rt, rlen, "%s%0*d/%d", mark, fw, sel + 1, filecnt);
334337 ow_info = true;
335338 } else {
336339 snprintf(lt, llen, "Loading... %0*d/%d", fw, tns.cnt, filecnt);
@@ -338,7 +341,7 @@ void update_info(void)
338341 ow_info = false;
339342 }
340343 } else {
341− n = snprintf(rt, rlen, "%3d%% | ", (int) (img.zoom * 100.0));
344+ n = snprintf(rt, rlen, "%s%3d%% | ", mark, (int) (img.zoom * 100.0));
342345 if (img.multi.cnt > 0) {
343346 for (fn = 0, i = img.multi.cnt; i > 0; fn++, i /= 10);
344347 n += snprintf(rt + n, rlen - n, "%0*d/%d | ",
M sxiv.1 View
@@ -62,7 +62,8 @@ Print brief usage information to standard output and exit.
6262 Read names of files to open from standard input.
6363 .TP
6464 .B \-o
65−Write list of opened files to standard output when quitting. If combined with
65+Write list of all marked files, or all opened files if no files are marked, to
66+standard output when quitting. If combined with
6667 .IR \-i ,
6768 then sxiv acts as a visual filter/pipe.
6869 .TP
@@ -128,6 +129,19 @@ Reload all thumbnails.
128129 .TP
129130 .B D
130131 Remove current image from file list and go to next image.
132+.TP
133+.B m
134+Mark/unmark the current image.
135+.TP
136+.B N
137+Go
138+.I count
139+marked images forward.
140+.TP
141+.B P
142+Go
143+.I count
144+marked images backward.
131145 .SH THUMBNAIL KEYBOARD COMMANDS
132146 The following keyboard commands are only available in thumbnail mode:
133147 .TP
M types.h View
@@ -69,6 +69,7 @@ typedef struct {
6969 const char *path; /* always absolute */
7070 const char *base;
7171 bool loaded;
72+ bool marked;
7273 } fileinfo_t;
7374
7475 /* timeouts in milliseconds: */