nsxiv2ac4470
Add keybind to scroll to image center (#203)
There are keybinds for scrolling to the edges of an image but there's no way back to the center. This is particularly annoying while zooming.
+20 −0
6 files changed
- M commands.c +5 −0
- M commands.h +2 −0
- M config.def.h +1 −0
- M image.c +8 −0
- M nsxiv.1 +3 −0
- M nsxiv.h +1 −0
| @@ -325,6 +325,11 @@ bool ci_scroll(arg_t dir) | |||
| 325 | 325 | return img_pan(&img, dir, prefix); | |
| 326 | 326 | } | |
| 327 | 327 | ||
| 328 | + | bool ci_scroll_to_center(arg_t _) | |
| 329 | + | { | |
| 330 | + | return img_pan_center(&img); | |
| 331 | + | } | |
| 332 | + | ||
| 328 | 333 | bool ci_scroll_to_edge(arg_t dir) | |
| 329 | 334 | { | |
| 330 | 335 | return img_pan_edge(&img, dir); | |
| @@ -30,6 +30,7 @@ bool ci_navigate(arg_t); | |||
| 30 | 30 | bool ci_navigate_frame(arg_t); | |
| 31 | 31 | bool ci_rotate(arg_t); | |
| 32 | 32 | bool ci_scroll(arg_t); | |
| 33 | + | bool ci_scroll_to_center(arg_t); | |
| 33 | 34 | bool ci_scroll_to_edge(arg_t); | |
| 34 | 35 | bool ci_set_zoom(arg_t); | |
| 35 | 36 | bool ci_slideshow(arg_t); | |
| @@ -72,6 +73,7 @@ bool ct_select(arg_t); | |||
| 72 | 73 | #define i_navigate_frame { ci_navigate_frame, MODE_IMAGE } | |
| 73 | 74 | #define i_rotate { ci_rotate, MODE_IMAGE } | |
| 74 | 75 | #define i_scroll { ci_scroll, MODE_IMAGE } | |
| 76 | + | #define i_scroll_to_center { ci_scroll_to_center, MODE_IMAGE } | |
| 75 | 77 | #define i_scroll_to_edge { ci_scroll_to_edge, MODE_IMAGE } | |
| 76 | 78 | #define i_set_zoom { ci_set_zoom, MODE_IMAGE } | |
| 77 | 79 | #define i_slideshow { ci_slideshow, MODE_IMAGE } | |
| @@ -158,6 +158,7 @@ static const keymap_t keys[] = { | |||
| 158 | 158 | { 0, XK_J, i_scroll_to_edge, DIR_DOWN }, | |
| 159 | 159 | { 0, XK_K, i_scroll_to_edge, DIR_UP }, | |
| 160 | 160 | { 0, XK_L, i_scroll_to_edge, DIR_RIGHT }, | |
| 161 | + | { 0, XK_z, i_scroll_to_center, None }, | |
| 161 | 162 | { 0, XK_equal, i_set_zoom, 100 }, | |
| 162 | 163 | { 0, XK_w, i_fit_to_win, SCALE_DOWN }, | |
| 163 | 164 | { 0, XK_W, i_fit_to_win, SCALE_FIT }, | |
| @@ -744,6 +744,14 @@ bool img_pan(img_t *img, direction_t dir, int d) | |||
| 744 | 744 | return false; | |
| 745 | 745 | } | |
| 746 | 746 | ||
| 747 | + | bool img_pan_center(img_t *img) | |
| 748 | + | { | |
| 749 | + | float x, y; | |
| 750 | + | x = (img->win->w - img->w * img->zoom) / 2.0; | |
| 751 | + | y = (img->win->h - img->h * img->zoom) / 2.0; | |
| 752 | + | return img_pos(img, x, y); | |
| 753 | + | } | |
| 754 | + | ||
| 747 | 755 | bool img_pan_edge(img_t *img, direction_t dir) | |
| 748 | 756 | { | |
| 749 | 757 | float ox, oy; | |
| @@ -318,6 +318,9 @@ Scroll to top image edge. | |||
| 318 | 318 | .B L | |
| 319 | 319 | Scroll to right image edge. | |
| 320 | 320 | .TP | |
| 321 | + | .B z | |
| 322 | + | Scroll to image center. | |
| 323 | + | .TP | |
| 321 | 324 | Zooming: | |
| 322 | 325 | .TP | |
| 323 | 326 | .B = | |
| @@ -229,6 +229,7 @@ bool img_zoom(img_t*, int); | |||
| 229 | 229 | bool img_zoom_to(img_t*, float); | |
| 230 | 230 | bool img_pos(img_t*, float, float); | |
| 231 | 231 | bool img_pan(img_t*, direction_t, int); | |
| 232 | + | bool img_pan_center(img_t*); | |
| 232 | 233 | bool img_pan_edge(img_t*, direction_t); | |
| 233 | 234 | void img_rotate(img_t*, degree_t); | |
| 234 | 235 | void img_flip(img_t*, flipdir_t); | |