diff --git a/commands.c b/commands.c index ab1e805..6a9b742 100644 --- a/commands.c +++ b/commands.c @@ -57,9 +57,9 @@ bool cg_quit(arg_t _) { unsigned int i; - if (options->to_stdout && markcnt > 0) { + if (options->to_stdout && (markcnt > 0 || options->automarkall)) { for (i = 0; i < filecnt; i++) { - if (files[i].flags & FF_MARK) + if ((files[i].flags & FF_MARK) || options->automarkall) printf("%s\n", files[i].name); } } @@ -443,6 +443,11 @@ bool ct_move_sel(arg_t dir) return tns_move_selection(&tns, dir, prefix); } +bool ct_move_image(arg_t dir) +{ + return tns_move_image(&tns, dir, prefix); +} + bool ct_reload_all(arg_t _) { tns_free(&tns); diff --git a/commands.lst b/commands.lst index a658dd4..003f69f 100644 --- a/commands.lst +++ b/commands.lst @@ -31,5 +31,6 @@ I_CMD(toggle_alpha) I_CMD(slideshow) T_CMD(move_sel) +T_CMD(move_image) T_CMD(reload_all) diff --git a/config.def.h b/config.def.h index f3cc71e..aaa33ac 100644 --- a/config.def.h +++ b/config.def.h @@ -104,6 +104,8 @@ static const keymap_t keys[] = { { 0, XK_l, t_move_sel, DIR_RIGHT }, { 0, XK_Right, t_move_sel, DIR_RIGHT }, { 0, XK_R, t_reload_all, None }, + { 0, XK_x, t_move_image, DIR_LEFT }, + { 0, XK_c, t_move_image, DIR_RIGHT }, { 0, XK_n, i_navigate, +1 }, { 0, XK_n, i_scroll_to_edge, DIR_LEFT | DIR_UP }, diff --git a/options.c b/options.c index f7aac23..080dfc6 100644 --- a/options.c +++ b/options.c @@ -32,7 +32,7 @@ const options_t *options = (const options_t*) &_options; void print_usage(void) { - printf("usage: sxiv [-abcfhioqrtvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] " + printf("usage: sxiv [-abcfhiMoqrtvZ] [-G GAMMA] [-g GEOMETRY] [-n NUM] " "[-N NAME] [-S DELAY] [-s MODE] [-z ZOOM] FILES...\n"); } @@ -70,7 +70,9 @@ void parse_options(int argc, char **argv) _options.thumb_mode = false; _options.clean_cache = false; - while ((opt = getopt(argc, argv, "abcfG:g:hin:N:oqrS:s:tvZz:")) != -1) { + _options.automarkall = false; + + while ((opt = getopt(argc, argv, "abcfG:g:hin:N:MoqrS:s:tvZz:")) != -1) { switch (opt) { case '?': print_usage(); @@ -111,6 +113,9 @@ void parse_options(int argc, char **argv) case 'N': _options.res_name = optarg; break; + case 'M': + _options.automarkall = true; + break; case 'o': _options.to_stdout = true; break; diff --git a/options.h b/options.h index 25abf16..b8e8970 100644 --- a/options.h +++ b/options.h @@ -48,6 +48,7 @@ typedef struct { bool quiet; bool thumb_mode; bool clean_cache; + bool automarkall; } options_t; extern const options_t *options; diff --git a/sxiv.1 b/sxiv.1 index 4756150..950f255 100644 --- a/sxiv.1 +++ b/sxiv.1 @@ -3,7 +3,7 @@ sxiv \- Simple X Image Viewer .SH SYNOPSIS .B sxiv -.RB [ \-abcfhioqrtvZ ] +.RB [ \-abcfhiMoqrtvZ ] .RB [ \-G .IR GAMMA ] .RB [ \-g @@ -62,6 +62,12 @@ Print brief usage information to standard output and exit. .B \-i Read names of files to open from standard input. .TP +.B \-M +Automatically mark all files in view. (Useful in combination with +.BR \-o +and +.BR D .) +.TP .B \-o Write list of all marked files to standard output when quitting. In combination with diff --git a/thumbs.c b/thumbs.c index bfce2ff..451cd12 100644 --- a/thumbs.c +++ b/thumbs.c @@ -550,6 +550,50 @@ bool tns_move_selection(tns_t *tns, direction_t dir, int cnt) return *tns->sel != old; } + +bool tns_move_image(tns_t *tns, direction_t dir, int cnt) +{ + int old, max; + fileinfo_t fi_tmp = {0}; + thumb_t th_tmp = {0}; + + old = *tns->sel; + cnt = cnt > 1 ? cnt : 1; + + switch (dir) { + case DIR_UP: + *tns->sel = MAX(*tns->sel - cnt * tns->cols, *tns->sel % tns->cols); + break; + case DIR_DOWN: + max = tns->cols * ((*tns->cnt - 1) / tns->cols) + + MIN((*tns->cnt - 1) % tns->cols, *tns->sel % tns->cols); + *tns->sel = MIN(*tns->sel + cnt * tns->cols, max); + break; + case DIR_LEFT: + *tns->sel = MAX(*tns->sel - cnt, 0); + break; + case DIR_RIGHT: + *tns->sel = MIN(*tns->sel + cnt, *tns->cnt - 1); + break; + } + + if (*tns->sel != old) { + th_tmp = tns->thumbs[old]; + tns->thumbs[old] = tns->thumbs[*tns->sel]; + tns->thumbs[*tns->sel] = th_tmp; + fi_tmp = tns->files[old]; + tns->files[old] = tns->files[*tns->sel]; + tns->files[*tns->sel] = fi_tmp; + tns->dirty = true; + + tns_highlight(tns, old, false); + tns_check_view(tns, false); + if (!tns->dirty) + tns_highlight(tns, *tns->sel, true); + } + return *tns->sel != old; +} + bool tns_scroll(tns_t *tns, direction_t dir, bool screen) { int d, max, old; diff --git a/thumbs.h b/thumbs.h index 7b9987e..2898dee 100644 --- a/thumbs.h +++ b/thumbs.h @@ -68,6 +68,7 @@ void tns_mark(tns_t*, int, bool); void tns_highlight(tns_t*, int, bool); bool tns_move_selection(tns_t*, direction_t, int); +bool tns_move_image(tns_t*, direction_t, int); bool tns_scroll(tns_t*, direction_t, bool); bool tns_zoom(tns_t*, int);