From 63690038243febd8f2307ee05f0edd5d554dc02e Mon Sep 17 00:00:00 2001 From: jonathan poelen Date: Sun, 7 May 2017 11:52:42 +0200 Subject: [PATCH] add scroll_up_*_or_prev_img and scroll_down_*_or_next_img actions --- man/feh.pre | 24 +++++++++++++++--- src/help.raw | 2 ++ src/keyevents.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ src/options.h | 4 +++ 4 files changed, 92 insertions(+), 4 deletions(-) diff --git a/man/feh.pre b/man/feh.pre index 6086f65a..ce985264 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -1402,22 +1402,38 @@ Scroll down. Note that the scroll keys work without anti-aliasing for performance reasons, hit the render key after scrolling to antialias the image. . -.It Aq Alt+Left Bq scroll_left_page +.It P Bq scroll_up_or_prev_img +. +Scroll up or show previous image. Selects the previous image in thumbnail mode. +. +.It N Bq scroll_down_or_next_img +. +Scroll down or show next image. Selects the next image in thumbnail mode. +. +.It Ao Alt+Left Ac Bq scroll_left_page . Scroll to the left by one page . -.It Aq Alt+Right Bq scroll_right_page +.It Ao Alt+Right Ac Bq scroll_right_page . Scroll to the right by one page . -.It Aq Alt+Up Bq scroll_up_page +.It Ao Alt+Up Ac Bq scroll_up_page . Scroll up by one page . -.It Aq Alt+Down Bq scroll_down_page +.It Ao Alt+Down Ac Bq scroll_down_page . Scroll down by one page . +.It Ao Ctrl+P Ac Bq scroll_up_page_or_prev_img +. +Scroll up by one page or show previous image +. +.It Ao Ctrl+N Ac Bq scroll_down_page_or_next_img +. +Scroll down by one page or show next image +. .It R, Ao keypad begin Ac Bq render . Antialias the image. diff --git a/src/help.raw b/src/help.raw index 067e35f9..31e2f06b 100644 --- a/src/help.raw +++ b/src/help.raw @@ -152,8 +152,10 @@ KEYS i Toggle --info display k Toggle zoom/viewport freeze when switching images m Show menu + N Move the image down or go to next image n, , Go to next image o Toggle pointer visibility + P Move the image up or go to previous image p, , Go to previous image q, Quit r Reload image diff --git a/src/keyevents.c b/src/keyevents.c index e4b7c7b7..f74da995 100644 --- a/src/keyevents.c +++ b/src/keyevents.c @@ -103,10 +103,14 @@ void init_keyevents(void) { feh_set_kb(&keys.scroll_right,0,XK_KP_Right , 4, XK_Right , 0, 0); feh_set_kb(&keys.scroll_down,0, XK_KP_Down , 4, XK_Down , 0, 0); feh_set_kb(&keys.scroll_up , 0, XK_KP_Up , 4, XK_Up , 0, 0); + feh_set_kb(&keys.scroll_down_or_next_img, 0, XK_N, 0, 0 , 0, 0); + feh_set_kb(&keys.scroll_up_or_prev_img , 0, XK_P, 0, 0 , 0, 0); feh_set_kb(&keys.scroll_left_page , 8, XK_Left , 0, 0 , 0, 0); feh_set_kb(&keys.scroll_right_page, 8, XK_Right, 0, 0 , 0, 0); feh_set_kb(&keys.scroll_down_page , 8, XK_Down , 0, 0 , 0, 0); feh_set_kb(&keys.scroll_up_page , 8, XK_Up , 0, 0 , 0, 0); + feh_set_kb(&keys.scroll_down_page_or_next_img, 4, XK_N, 0, 0 , 0, 0); + feh_set_kb(&keys.scroll_up_page_or_prev_img , 4, XK_P, 0, 0 , 0, 0); feh_set_kb(&keys.prev_img , 0, XK_Left , 0, XK_p , 0, XK_BackSpace); feh_set_kb(&keys.next_img , 0, XK_Right , 0, XK_n , 0, XK_space); feh_set_kb(&keys.jump_back , 0, XK_Page_Up , 0, XK_KP_Page_Up, 0, 0); @@ -378,6 +382,10 @@ fehkey *feh_str_to_kb(char *action) return &keys.scroll_up; else if (!strcmp(action, "scroll_down")) return &keys.scroll_down; + else if (!strcmp(action, "scroll_up_or_prev_img")) + return &keys.scroll_up_or_prev_img; + else if (!strcmp(action, "scroll_down_or_next_img")) + return &keys.scroll_down_or_next_img; else if (!strcmp(action, "scroll_right_page")) return &keys.scroll_right_page; else if (!strcmp(action, "scroll_left_page")) @@ -386,6 +394,10 @@ fehkey *feh_str_to_kb(char *action) return &keys.scroll_up_page; else if (!strcmp(action, "scroll_down_page")) return &keys.scroll_down_page; + else if (!strcmp(action, "scroll_up_page_or_prev_img")) + return &keys.scroll_up_page_or_prev_img; + else if (!strcmp(action, "scroll_down_page_or_next_img")) + return &keys.scroll_down_page_or_next_img; else if (!strcmp(action, "prev_img")) return &keys.prev_img; else if (!strcmp(action, "next_img")) @@ -492,6 +504,48 @@ fehkey *feh_str_to_kb(char *action) return NULL; } +static void feh_scroll_or_next(winwidget winwid, int next, int scroll_step) +{ + if (next == (scroll_step > 0)) { + /* if bottom of view */ + if (winwid->h < winwid->im_h && winwid->h - (winwid->im_h * winwid->zoom) != winwid->im_y) { + winwid->im_y -= scroll_step; + if (winwid->h - (winwid->im_h * winwid->zoom) > winwid->im_y) { + winwid->im_y = winwid->h - (winwid->im_h * winwid->zoom); + } + winwidget_render_image(winwid, 0, 1); + } + else if (opt.slideshow) { + slideshow_change_image(winwid, SLIDE_NEXT, 1); + if (winwid->h < winwid->im_h && winwid->im_y != 0) { + winwid->im_y = 0; + winwidget_render_image(winwid, 0, 1); + } + } + else if (winwid->type == WIN_TYPE_THUMBNAIL) + feh_thumbnail_select_next(winwid, 1); + } + else { + /* if top of view */ + if (winwid->h < winwid->im_h && winwid->im_y) { + winwid->im_y += scroll_step; + if (winwid->im_y > 0) { + winwid->im_y = 0; + } + winwidget_render_image(winwid, 0, 1); + } + else if (opt.slideshow) { + slideshow_change_image(winwid, SLIDE_PREV, 1); + if (winwid->h < winwid->im_h && winwid->im_y != winwid->h - (winwid->im_h * winwid->zoom)) { + winwid->im_y = winwid->h - (winwid->im_h * winwid->zoom); + winwidget_render_image(winwid, 0, 1); + } + } + else if (winwid->type == WIN_TYPE_THUMBNAIL) + feh_thumbnail_select_prev(winwid, 1); + } +} + void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysym, unsigned int button) { int curr_screen = 0; @@ -522,11 +576,17 @@ void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysy winwidget_sanitise_offsets(winwid); winwidget_render_image(winwid, 0, 1); } + else if (feh_is_kp(&keys.scroll_down_or_next_img, state, keysym, button)) { + feh_scroll_or_next(winwid, 1, opt.scroll_step); + } else if (feh_is_kp(&keys.scroll_up, state, keysym, button)) { winwid->im_y += opt.scroll_step; winwidget_sanitise_offsets(winwid); winwidget_render_image(winwid, 0, 1); } + else if (feh_is_kp(&keys.scroll_up_or_prev_img, state, keysym, button)) { + feh_scroll_or_next(winwid, 0, opt.scroll_step); + } else if (feh_is_kp(&keys.scroll_right_page, state, keysym, button)) { winwid->im_x -= winwid->w; winwidget_sanitise_offsets(winwid); @@ -542,11 +602,17 @@ void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysy winwidget_sanitise_offsets(winwid); winwidget_render_image(winwid, 0, 0); } + else if (feh_is_kp(&keys.scroll_down_page_or_next_img, state, keysym, button)) { + feh_scroll_or_next(winwid, 1, winwid->h); + } else if (feh_is_kp(&keys.scroll_up_page, state, keysym, button)) { winwid->im_y += winwid->h; winwidget_sanitise_offsets(winwid); winwidget_render_image(winwid, 0, 0); } + else if (feh_is_kp(&keys.scroll_up_page_or_prev_img, state, keysym, button)) { + feh_scroll_or_next(winwid, 0, winwid->h); + } else if (feh_is_kp(&keys.jump_back, state, keysym, button)) { if (opt.slideshow) slideshow_change_image(winwid, SLIDE_JUMP_BACK, 1); diff --git a/src/options.h b/src/options.h index 5a5ce846..30ba103b 100644 --- a/src/options.h +++ b/src/options.h @@ -149,10 +149,14 @@ struct __fehkb { struct __fehkey next_img; struct __fehkey scroll_up; struct __fehkey scroll_down; + struct __fehkey scroll_up_or_prev_img; + struct __fehkey scroll_down_or_next_img; struct __fehkey scroll_right_page; struct __fehkey scroll_left_page; struct __fehkey scroll_up_page; struct __fehkey scroll_down_page; + struct __fehkey scroll_up_page_or_prev_img; + struct __fehkey scroll_down_page_or_next_img; struct __fehkey jump_back; struct __fehkey quit; struct __fehkey jump_fwd;