diff options
| author | Nick Hanley <nicholasjhanley@gmail.com> | 2022-01-15 17:51:31 -0500 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-01-15 18:51:31 -0400 | 
| commit | 2ac44709bd9a9ec8d3ab60a40a81ac7ca3ad1b57 (patch) | |
| tree | 73221bb787569c4089930436ddc644490ccb2c18 | |
| parent | 7a75c42b37b08f44c72f9a7c98eb6076967470fb (diff) | |
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.
| -rw-r--r-- | commands.c | 5 | ||||
| -rw-r--r-- | commands.h | 2 | ||||
| -rw-r--r-- | config.def.h | 1 | ||||
| -rw-r--r-- | image.c | 8 | ||||
| -rw-r--r-- | nsxiv.1 | 3 | ||||
| -rw-r--r-- | nsxiv.h | 1 | 
6 files changed, 20 insertions, 0 deletions
| @@ -325,6 +325,11 @@ bool ci_scroll(arg_t dir)  	return img_pan(&img, dir, prefix);  } +bool ci_scroll_to_center(arg_t _) +{ +	return img_pan_center(&img); +} +  bool ci_scroll_to_edge(arg_t dir)  {  	return img_pan_edge(&img, dir); @@ -30,6 +30,7 @@ bool ci_navigate(arg_t);  bool ci_navigate_frame(arg_t);  bool ci_rotate(arg_t);  bool ci_scroll(arg_t); +bool ci_scroll_to_center(arg_t);  bool ci_scroll_to_edge(arg_t);  bool ci_set_zoom(arg_t);  bool ci_slideshow(arg_t); @@ -72,6 +73,7 @@ bool ct_select(arg_t);  #define i_navigate_frame { ci_navigate_frame, MODE_IMAGE }  #define i_rotate { ci_rotate, MODE_IMAGE }  #define i_scroll { ci_scroll, MODE_IMAGE } +#define i_scroll_to_center { ci_scroll_to_center, MODE_IMAGE }  #define i_scroll_to_edge { ci_scroll_to_edge, MODE_IMAGE }  #define i_set_zoom { ci_set_zoom, MODE_IMAGE }  #define i_slideshow { ci_slideshow, MODE_IMAGE } diff --git a/config.def.h b/config.def.h index b328305..0973ff4 100644 --- a/config.def.h +++ b/config.def.h @@ -158,6 +158,7 @@ static const keymap_t keys[] = {  	{ 0,            XK_J,             i_scroll_to_edge,     DIR_DOWN },  	{ 0,            XK_K,             i_scroll_to_edge,     DIR_UP },  	{ 0,            XK_L,             i_scroll_to_edge,     DIR_RIGHT }, +	{ 0,            XK_z,             i_scroll_to_center,   None },  	{ 0,            XK_equal,         i_set_zoom,           100 },  	{ 0,            XK_w,             i_fit_to_win,         SCALE_DOWN },  	{ 0,            XK_W,             i_fit_to_win,         SCALE_FIT }, @@ -744,6 +744,14 @@ bool img_pan(img_t *img, direction_t dir, int d)  	return false;  } +bool img_pan_center(img_t *img) +{ +	float x, y; +	x = (img->win->w - img->w * img->zoom) / 2.0; +	y = (img->win->h - img->h * img->zoom) / 2.0; +	return img_pos(img, x, y); +} +  bool img_pan_edge(img_t *img, direction_t dir)  {  	float ox, oy; @@ -318,6 +318,9 @@ Scroll to top image edge.  .B L  Scroll to right image edge.  .TP +.B z +Scroll to image center. +.TP  Zooming:  .TP  .B = @@ -229,6 +229,7 @@ bool img_zoom(img_t*, int);  bool img_zoom_to(img_t*, float);  bool img_pos(img_t*, float, float);  bool img_pan(img_t*, direction_t, int); +bool img_pan_center(img_t*);  bool img_pan_edge(img_t*, direction_t);  void img_rotate(img_t*, degree_t);  void img_flip(img_t*, flipdir_t); | 
