Krolyxon
Commit 1cdbeb9

Branches

Refs →

nsxiv1cdbeb9

Added screen-wise scrolling for thumbnail mode

Author
Bert Münnich
Date
2011-10-27 16:21 +0200
Parent
3e25238
Commit
1cdbeb972a64e1fb12db5dc05fbaa1428e72bb12

+57 −44

9 files changed

  1. M Makefile +1 −1
  2. M README.md +1 −0
  3. M commands.c +4 −4
  4. M commands.h +3 −3
  5. M config.def.h +26 −26
  6. M main.c +2 −1
  7. M sxiv.1 +6 −0
  8. M thumbs.c +13 −8
  9. M thumbs.h +1 −1
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION = git-20111017
1+VERSION = git-20111027
22
33 CC = gcc
44 CFLAGS = -ansi -Wall -pedantic -O2
M README.md View
@@ -102,6 +102,7 @@ The following general key commands are available:
102102 The following additional key commands are available in *thumbnail mode*:
103103
104104 h,j,k,l Move selection left/down/up/right
105+ Ctrl-j,k Scroll thumbnail grid one window height down/up
105106
106107 The following additional key commands are available in *image mode*:
107108
M commands.c View
@@ -188,7 +188,7 @@ bool i_toggle_animation(arg_t a) {
188188 return true;
189189 }
190190
191−bool it_move(arg_t a) {
191+bool it_scroll_move(arg_t a) {
192192 direction_t dir = (direction_t) a;
193193
194194 if (mode == MODE_IMAGE)
@@ -197,16 +197,16 @@ bool it_move(arg_t a) {
197197 return tns_move_selection(&tns, dir);
198198 }
199199
200−bool i_pan_screen(arg_t a) {
200+bool it_scroll_screen(arg_t a) {
201201 direction_t dir = (direction_t) a;
202202
203203 if (mode == MODE_IMAGE)
204204 return img_pan(&img, dir, -1);
205205 else
206− return false;
206+ return tns_scroll(&tns, dir, true);
207207 }
208208
209−bool i_pan_edge(arg_t a) {
209+bool i_scroll_to_edge(arg_t a) {
210210 direction_t dir = (direction_t) a;
211211
212212 if (mode == MODE_IMAGE)
M commands.h View
@@ -51,9 +51,9 @@ bool it_first(arg_t);
5151 bool it_n_or_last(arg_t);
5252 bool i_navigate_frame(arg_t);
5353 bool i_toggle_animation(arg_t);
54−bool it_move(arg_t);
55−bool i_pan_screen(arg_t);
56−bool i_pan_edge(arg_t);
54+bool it_scroll_move(arg_t);
55+bool it_scroll_screen(arg_t);
56+bool i_scroll_to_edge(arg_t);
5757 bool i_drag(arg_t);
5858 bool i_zoom(arg_t);
5959 bool i_set_zoom(arg_t);
M config.def.h View
@@ -85,28 +85,28 @@ static const keymap_t keys[] = {
8585 { true, XK_p, i_navigate_frame, (arg_t) -1 },
8686 { true, XK_space, i_toggle_animation, (arg_t) None },
8787
88− { false, XK_h, it_move, (arg_t) DIR_LEFT },
89− { false, XK_Left, it_move, (arg_t) DIR_LEFT },
90− { false, XK_j, it_move, (arg_t) DIR_DOWN },
91− { false, XK_Down, it_move, (arg_t) DIR_DOWN },
92− { false, XK_k, it_move, (arg_t) DIR_UP },
93− { false, XK_Up, it_move, (arg_t) DIR_UP },
94− { false, XK_l, it_move, (arg_t) DIR_RIGHT },
95− { false, XK_Right, it_move, (arg_t) DIR_RIGHT },
96−
97− { true, XK_h, i_pan_screen, (arg_t) DIR_LEFT },
98− { true, XK_Left, i_pan_screen, (arg_t) DIR_LEFT },
99− { true, XK_j, i_pan_screen, (arg_t) DIR_DOWN },
100− { true, XK_Down, i_pan_screen, (arg_t) DIR_DOWN },
101− { true, XK_k, i_pan_screen, (arg_t) DIR_UP },
102− { true, XK_Up, i_pan_screen, (arg_t) DIR_UP },
103− { true, XK_l, i_pan_screen, (arg_t) DIR_RIGHT },
104− { true, XK_Right, i_pan_screen, (arg_t) DIR_RIGHT },
105−
106− { false, XK_H, i_pan_edge, (arg_t) DIR_LEFT },
107− { false, XK_J, i_pan_edge, (arg_t) DIR_DOWN },
108− { false, XK_K, i_pan_edge, (arg_t) DIR_UP },
109− { false, XK_L, i_pan_edge, (arg_t) DIR_RIGHT },
88+ { false, XK_h, it_scroll_move, (arg_t) DIR_LEFT },
89+ { false, XK_Left, it_scroll_move, (arg_t) DIR_LEFT },
90+ { false, XK_j, it_scroll_move, (arg_t) DIR_DOWN },
91+ { false, XK_Down, it_scroll_move, (arg_t) DIR_DOWN },
92+ { false, XK_k, it_scroll_move, (arg_t) DIR_UP },
93+ { false, XK_Up, it_scroll_move, (arg_t) DIR_UP },
94+ { false, XK_l, it_scroll_move, (arg_t) DIR_RIGHT },
95+ { false, XK_Right, it_scroll_move, (arg_t) DIR_RIGHT },
96+
97+ { true, XK_h, it_scroll_screen, (arg_t) DIR_LEFT },
98+ { true, XK_Left, it_scroll_screen, (arg_t) DIR_LEFT },
99+ { true, XK_j, it_scroll_screen, (arg_t) DIR_DOWN },
100+ { true, XK_Down, it_scroll_screen, (arg_t) DIR_DOWN },
101+ { true, XK_k, it_scroll_screen, (arg_t) DIR_UP },
102+ { true, XK_Up, it_scroll_screen, (arg_t) DIR_UP },
103+ { true, XK_l, it_scroll_screen, (arg_t) DIR_RIGHT },
104+ { true, XK_Right, it_scroll_screen, (arg_t) DIR_RIGHT },
105+
106+ { false, XK_H, i_scroll_to_edge, (arg_t) DIR_LEFT },
107+ { false, XK_J, i_scroll_to_edge, (arg_t) DIR_DOWN },
108+ { false, XK_K, i_scroll_to_edge, (arg_t) DIR_UP },
109+ { false, XK_L, i_scroll_to_edge, (arg_t) DIR_RIGHT },
110110
111111 { false, XK_plus, i_zoom, (arg_t) +1 },
112112 { false, XK_KP_Add, i_zoom, (arg_t) +1 },
@@ -147,10 +147,10 @@ static const button_t buttons[] = {
147147 { false, false, Button1, i_navigate, (arg_t) +1 },
148148 { false, false, Button3, i_navigate, (arg_t) -1 },
149149 { false, false, Button2, i_drag, (arg_t) None },
150− { false, false, Button4, it_move, (arg_t) DIR_UP },
151− { false, false, Button5, it_move, (arg_t) DIR_DOWN },
152− { false, true, Button4, it_move, (arg_t) DIR_LEFT },
153− { false, true, Button5, it_move, (arg_t) DIR_RIGHT },
150+ { false, false, Button4, it_scroll_move, (arg_t) DIR_UP },
151+ { false, false, Button5, it_scroll_move, (arg_t) DIR_DOWN },
152+ { false, true, Button4, it_scroll_move, (arg_t) DIR_LEFT },
153+ { false, true, Button5, it_scroll_move, (arg_t) DIR_RIGHT },
154154 { true, false, Button4, i_zoom, (arg_t) +1 },
155155 { true, false, Button5, i_zoom, (arg_t) -1 },
156156 };
M main.c View
@@ -394,7 +394,8 @@ void on_buttonpress(XButtonEvent *bev) {
394394 break;
395395 case Button4:
396396 case Button5:
397− if (tns_scroll(&tns, bev->button == Button4 ? DIR_UP : DIR_DOWN))
397+ if (tns_scroll(&tns, bev->button == Button4 ? DIR_UP : DIR_DOWN,
398+ (bev->state & ControlMask) != 0))
398399 redraw();
399400 break;
400401 }
M sxiv.1 View
@@ -127,6 +127,12 @@ Move selection up.
127127 .TP
128128 .BR l ", " Right
129129 Move selection right.
130+.TP
131+.BR Ctrl-j ", " Ctrl-Down
132+Scroll thumbnail grid one window height down.
133+.TP
134+.BR Ctrl-k ", " Ctrl-Up
135+Scroll thumbnail grid one window height up.
130136 .SH IMAGE KEYBOARD COMMANDS
131137 The following keyboard commands are only available in image mode:
132138 .SS Navigate image list
M thumbs.c View
@@ -430,20 +430,25 @@ bool tns_move_selection(tns_t *tns, direction_t dir) {
430430 return tns->sel != old;
431431 }
432432
433−bool tns_scroll(tns_t *tns, direction_t dir) {
434− int old;
433+bool tns_scroll(tns_t *tns, direction_t dir, bool screen) {
434+ int d, max, old;
435435
436436 if (tns == NULL)
437437 return false;
438438
439439 old = tns->first;
440+ d = tns->cols * (screen ? tns->rows : 1);
441+
442+ if (dir == DIR_DOWN) {
443+ max = tns->cnt - tns->cols * tns->rows;
444+ if (tns->cnt % tns->cols != 0)
445+ max += tns->cols - tns->cnt % tns->cols;
446+ tns->first = MIN(tns->first + d, max);
447+ } else if (dir == DIR_UP) {
448+ tns->first = MAX(tns->first - d, 0);
449+ }
440450
441− if (dir == DIR_DOWN && tns->first + tns->cols * tns->rows < tns->cnt) {
442− tns->first += tns->cols;
443− tns_check_view(tns, true);
444− tns->dirty = true;
445− } else if (dir == DIR_UP && tns->first >= tns->cols) {
446− tns->first -= tns->cols;
451+ if (tns->first != old) {
447452 tns_check_view(tns, true);
448453 tns->dirty = true;
449454 }
M thumbs.h View
@@ -62,7 +62,7 @@ void tns_render(tns_t*);
6262 void tns_highlight(tns_t*, int, bool);
6363
6464 bool tns_move_selection(tns_t*, direction_t);
65−bool tns_scroll(tns_t*, direction_t);
65+bool tns_scroll(tns_t*, direction_t, bool);
6666
6767 int tns_translate(tns_t*, int, int);
6868