Added screen-wise scrolling for thumbnail mode

This commit is contained in:
Bert Münnich 2011-10-27 16:21:01 +02:00
parent 3e2523818b
commit 1cdbeb972a
9 changed files with 55 additions and 42 deletions

View File

@ -1,4 +1,4 @@
VERSION = git-20111017
VERSION = git-20111027
CC = gcc
CFLAGS = -ansi -Wall -pedantic -O2

View File

@ -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*:

View File

@ -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)

View File

@ -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);

View File

@ -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 },
{ 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, 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 },
{ 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_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, 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 },
};

3
main.c
View File

@ -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;
}

6
sxiv.1
View File

@ -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

View File

@ -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 && 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 (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 (tns->first != old) {
tns_check_view(tns, true);
tns->dirty = true;
}

View File

@ -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);