summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBert Münnich <ber.t@gmx.com>2011-10-27 16:21:01 +0200
committerBert Münnich <ber.t@gmx.com>2011-10-27 16:21:01 +0200
commit1cdbeb972a64e1fb12db5dc05fbaa1428e72bb12 (patch)
tree9e0d12081ff6f8b9708422f10e0f3e1047ccf6ae
parent3e2523818b2420a86d71ac7c908ddcbb800abd38 (diff)
downloadnsxiv-1cdbeb972a64e1fb12db5dc05fbaa1428e72bb12.tar.zst
Added screen-wise scrolling for thumbnail mode
-rw-r--r--Makefile2
-rw-r--r--README.md1
-rw-r--r--commands.c8
-rw-r--r--commands.h6
-rw-r--r--config.def.h52
-rw-r--r--main.c3
-rw-r--r--sxiv.16
-rw-r--r--thumbs.c21
-rw-r--r--thumbs.h2
9 files changed, 57 insertions, 44 deletions
diff --git a/Makefile b/Makefile
index 25a40fc..d6360b8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-VERSION = git-20111017
+VERSION = git-20111027
CC = gcc
CFLAGS = -ansi -Wall -pedantic -O2
diff --git a/README.md b/README.md
index 854343f..5783635 100644
--- a/README.md
+++ b/README.md
@@ -102,6 +102,7 @@ The following general key commands are available:
The following additional key commands are available in *thumbnail mode*:
h,j,k,l Move selection left/down/up/right
+ Ctrl-j,k Scroll thumbnail grid one window height down/up
The following additional key commands are available in *image mode*:
diff --git a/commands.c b/commands.c
index b869175..a8b9e77 100644
--- a/commands.c
+++ b/commands.c
@@ -188,7 +188,7 @@ bool i_toggle_animation(arg_t a) {
return true;
}
-bool it_move(arg_t a) {
+bool it_scroll_move(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
@@ -197,16 +197,16 @@ bool it_move(arg_t a) {
return tns_move_selection(&tns, dir);
}
-bool i_pan_screen(arg_t a) {
+bool it_scroll_screen(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
return img_pan(&img, dir, -1);
else
- return false;
+ return tns_scroll(&tns, dir, true);
}
-bool i_pan_edge(arg_t a) {
+bool i_scroll_to_edge(arg_t a) {
direction_t dir = (direction_t) a;
if (mode == MODE_IMAGE)
diff --git a/commands.h b/commands.h
index 061ebc3..065982b 100644
--- a/commands.h
+++ b/commands.h
@@ -51,9 +51,9 @@ bool it_first(arg_t);
bool it_n_or_last(arg_t);
bool i_navigate_frame(arg_t);
bool i_toggle_animation(arg_t);
-bool it_move(arg_t);
-bool i_pan_screen(arg_t);
-bool i_pan_edge(arg_t);
+bool it_scroll_move(arg_t);
+bool it_scroll_screen(arg_t);
+bool i_scroll_to_edge(arg_t);
bool i_drag(arg_t);
bool i_zoom(arg_t);
bool i_set_zoom(arg_t);
diff --git a/config.def.h b/config.def.h
index d8bb47f..777cb80 100644
--- a/config.def.h
+++ b/config.def.h
@@ -85,28 +85,28 @@ static const keymap_t keys[] = {
{ true, XK_p, i_navigate_frame, (arg_t) -1 },
{ true, XK_space, i_toggle_animation, (arg_t) None },
- { false, XK_h, it_move, (arg_t) DIR_LEFT },
- { false, XK_Left, it_move, (arg_t) DIR_LEFT },
- { false, XK_j, it_move, (arg_t) DIR_DOWN },
- { false, XK_Down, it_move, (arg_t) DIR_DOWN },
- { false, XK_k, it_move, (arg_t) DIR_UP },
- { false, XK_Up, it_move, (arg_t) DIR_UP },
- { false, XK_l, it_move, (arg_t) DIR_RIGHT },
- { false, XK_Right, it_move, (arg_t) DIR_RIGHT },
-
- { true, XK_h, i_pan_screen, (arg_t) DIR_LEFT },
- { true, XK_Left, i_pan_screen, (arg_t) DIR_LEFT },
- { true, XK_j, i_pan_screen, (arg_t) DIR_DOWN },
- { true, XK_Down, i_pan_screen, (arg_t) DIR_DOWN },
- { true, XK_k, i_pan_screen, (arg_t) DIR_UP },
- { true, XK_Up, i_pan_screen, (arg_t) DIR_UP },
- { true, XK_l, i_pan_screen, (arg_t) DIR_RIGHT },
- { true, XK_Right, i_pan_screen, (arg_t) DIR_RIGHT },
-
- { false, XK_H, i_pan_edge, (arg_t) DIR_LEFT },
- { false, XK_J, i_pan_edge, (arg_t) DIR_DOWN },
- { false, XK_K, i_pan_edge, (arg_t) DIR_UP },
- { false, XK_L, i_pan_edge, (arg_t) DIR_RIGHT },
+ { false, XK_h, it_scroll_move, (arg_t) DIR_LEFT },
+ { false, XK_Left, it_scroll_move, (arg_t) DIR_LEFT },
+ { false, XK_j, it_scroll_move, (arg_t) DIR_DOWN },
+ { false, XK_Down, it_scroll_move, (arg_t) DIR_DOWN },
+ { false, XK_k, it_scroll_move, (arg_t) DIR_UP },
+ { false, XK_Up, it_scroll_move, (arg_t) DIR_UP },
+ { false, XK_l, it_scroll_move, (arg_t) DIR_RIGHT },
+ { false, XK_Right, it_scroll_move, (arg_t) DIR_RIGHT },
+
+ { true, XK_h, it_scroll_screen, (arg_t) DIR_LEFT },
+ { true, XK_Left, it_scroll_screen, (arg_t) DIR_LEFT },
+ { true, XK_j, it_scroll_screen, (arg_t) DIR_DOWN },
+ { true, XK_Down, it_scroll_screen, (arg_t) DIR_DOWN },
+ { true, XK_k, it_scroll_screen, (arg_t) DIR_UP },
+ { true, XK_Up, it_scroll_screen, (arg_t) DIR_UP },
+ { true, XK_l, it_scroll_screen, (arg_t) DIR_RIGHT },
+ { true, XK_Right, it_scroll_screen, (arg_t) DIR_RIGHT },
+
+ { false, XK_H, i_scroll_to_edge, (arg_t) DIR_LEFT },
+ { false, XK_J, i_scroll_to_edge, (arg_t) DIR_DOWN },
+ { false, XK_K, i_scroll_to_edge, (arg_t) DIR_UP },
+ { false, XK_L, i_scroll_to_edge, (arg_t) DIR_RIGHT },
{ false, XK_plus, i_zoom, (arg_t) +1 },
{ false, XK_KP_Add, i_zoom, (arg_t) +1 },
@@ -147,10 +147,10 @@ static const button_t buttons[] = {
{ false, false, Button1, i_navigate, (arg_t) +1 },
{ false, false, Button3, i_navigate, (arg_t) -1 },
{ false, false, Button2, i_drag, (arg_t) None },
- { false, false, Button4, it_move, (arg_t) DIR_UP },
- { false, false, Button5, it_move, (arg_t) DIR_DOWN },
- { false, true, Button4, it_move, (arg_t) DIR_LEFT },
- { false, true, Button5, it_move, (arg_t) DIR_RIGHT },
+ { false, false, Button4, it_scroll_move, (arg_t) DIR_UP },
+ { false, false, Button5, it_scroll_move, (arg_t) DIR_DOWN },
+ { false, true, Button4, it_scroll_move, (arg_t) DIR_LEFT },
+ { false, true, Button5, it_scroll_move, (arg_t) DIR_RIGHT },
{ true, false, Button4, i_zoom, (arg_t) +1 },
{ true, false, Button5, i_zoom, (arg_t) -1 },
};
diff --git a/main.c b/main.c
index 97dd2db..22729e9 100644
--- a/main.c
+++ b/main.c
@@ -394,7 +394,8 @@ void on_buttonpress(XButtonEvent *bev) {
break;
case Button4:
case Button5:
- if (tns_scroll(&tns, bev->button == Button4 ? DIR_UP : DIR_DOWN))
+ if (tns_scroll(&tns, bev->button == Button4 ? DIR_UP : DIR_DOWN,
+ (bev->state & ControlMask) != 0))
redraw();
break;
}
diff --git a/sxiv.1 b/sxiv.1
index 69ee9c4..c2d20db 100644
--- a/sxiv.1
+++ b/sxiv.1
@@ -127,6 +127,12 @@ Move selection up.
.TP
.BR l ", " Right
Move selection right.
+.TP
+.BR Ctrl-j ", " Ctrl-Down
+Scroll thumbnail grid one window height down.
+.TP
+.BR Ctrl-k ", " Ctrl-Up
+Scroll thumbnail grid one window height up.
.SH IMAGE KEYBOARD COMMANDS
The following keyboard commands are only available in image mode:
.SS Navigate image list
diff --git a/thumbs.c b/thumbs.c
index 8f20336..69b2645 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -430,20 +430,25 @@ bool tns_move_selection(tns_t *tns, direction_t dir) {
return tns->sel != old;
}
-bool tns_scroll(tns_t *tns, direction_t dir) {
- int old;
+bool tns_scroll(tns_t *tns, direction_t dir, bool screen) {
+ int d, max, old;
if (tns == NULL)
return false;
old = tns->first;
+ d = tns->cols * (screen ? tns->rows : 1);
+
+ if (dir == DIR_DOWN) {
+ max = tns->cnt - tns->cols * tns->rows;
+ if (tns->cnt % tns->cols != 0)
+ max += tns->cols - tns->cnt % tns->cols;
+ tns->first = MIN(tns->first + d, max);
+ } else if (dir == DIR_UP) {
+ tns->first = MAX(tns->first - d, 0);
+ }
- if (dir == DIR_DOWN && tns->first + tns->cols * tns->rows < tns->cnt) {
- tns->first += tns->cols;
- tns_check_view(tns, true);
- tns->dirty = true;
- } else if (dir == DIR_UP && tns->first >= tns->cols) {
- tns->first -= tns->cols;
+ if (tns->first != old) {
tns_check_view(tns, true);
tns->dirty = true;
}
diff --git a/thumbs.h b/thumbs.h
index df83535..4a32347 100644
--- a/thumbs.h
+++ b/thumbs.h
@@ -62,7 +62,7 @@ void tns_render(tns_t*);
void tns_highlight(tns_t*, int, bool);
bool tns_move_selection(tns_t*, direction_t);
-bool tns_scroll(tns_t*, direction_t);
+bool tns_scroll(tns_t*, direction_t, bool);
int tns_translate(tns_t*, int, int);