Krolyxon
Commit 2ac4470

Branches

Refs →

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.
Author
Nick Hanley
Date
2022-01-15 17:51 -0500
Committer
GitHub · 2022-01-15 18:51 -0400
Parent
7a75c42
Commit
2ac44709bd9a9ec8d3ab60a40a81ac7ca3ad1b57

+20 −0

6 files changed

  1. M commands.c +5 −0
  2. M commands.h +2 −0
  3. M config.def.h +1 −0
  4. M image.c +8 −0
  5. M nsxiv.1 +3 −0
  6. M nsxiv.h +1 −0
M commands.c View
@@ -325,6 +325,11 @@ bool ci_scroll(arg_t dir)
325325 return img_pan(&img, dir, prefix);
326326 }
327327
328+bool ci_scroll_to_center(arg_t _)
329+{
330+ return img_pan_center(&img);
331+}
332+
328333 bool ci_scroll_to_edge(arg_t dir)
329334 {
330335 return img_pan_edge(&img, dir);
M commands.h View
@@ -30,6 +30,7 @@ bool ci_navigate(arg_t);
3030 bool ci_navigate_frame(arg_t);
3131 bool ci_rotate(arg_t);
3232 bool ci_scroll(arg_t);
33+bool ci_scroll_to_center(arg_t);
3334 bool ci_scroll_to_edge(arg_t);
3435 bool ci_set_zoom(arg_t);
3536 bool ci_slideshow(arg_t);
@@ -72,6 +73,7 @@ bool ct_select(arg_t);
7273 #define i_navigate_frame { ci_navigate_frame, MODE_IMAGE }
7374 #define i_rotate { ci_rotate, MODE_IMAGE }
7475 #define i_scroll { ci_scroll, MODE_IMAGE }
76+#define i_scroll_to_center { ci_scroll_to_center, MODE_IMAGE }
7577 #define i_scroll_to_edge { ci_scroll_to_edge, MODE_IMAGE }
7678 #define i_set_zoom { ci_set_zoom, MODE_IMAGE }
7779 #define i_slideshow { ci_slideshow, MODE_IMAGE }
M config.def.h View
@@ -158,6 +158,7 @@ static const keymap_t keys[] = {
158158 { 0, XK_J, i_scroll_to_edge, DIR_DOWN },
159159 { 0, XK_K, i_scroll_to_edge, DIR_UP },
160160 { 0, XK_L, i_scroll_to_edge, DIR_RIGHT },
161+ { 0, XK_z, i_scroll_to_center, None },
161162 { 0, XK_equal, i_set_zoom, 100 },
162163 { 0, XK_w, i_fit_to_win, SCALE_DOWN },
163164 { 0, XK_W, i_fit_to_win, SCALE_FIT },
M image.c View
@@ -744,6 +744,14 @@ bool img_pan(img_t *img, direction_t dir, int d)
744744 return false;
745745 }
746746
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+
747755 bool img_pan_edge(img_t *img, direction_t dir)
748756 {
749757 float ox, oy;
M nsxiv.1 View
@@ -318,6 +318,9 @@ Scroll to top image edge.
318318 .B L
319319 Scroll to right image edge.
320320 .TP
321+.B z
322+Scroll to image center.
323+.TP
321324 Zooming:
322325 .TP
323326 .B =
M nsxiv.h View
@@ -229,6 +229,7 @@ bool img_zoom(img_t*, int);
229229 bool img_zoom_to(img_t*, float);
230230 bool img_pos(img_t*, float, float);
231231 bool img_pan(img_t*, direction_t, int);
232+bool img_pan_center(img_t*);
232233 bool img_pan_edge(img_t*, direction_t);
233234 void img_rotate(img_t*, degree_t);
234235 void img_flip(img_t*, flipdir_t);