summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Hanley <nicholasjhanley@gmail.com>2022-01-15 23:51:31 +0100
committerGitHub <noreply@github.com>2022-01-15 23:51:31 +0100
commit2ac44709bd9a9ec8d3ab60a40a81ac7ca3ad1b57 (patch)
tree73221bb787569c4089930436ddc644490ccb2c18
parent7a75c42b37b08f44c72f9a7c98eb6076967470fb (diff)
downloadnsxiv-2ac44709bd9a9ec8d3ab60a40a81ac7ca3ad1b57.tar.zst
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.c5
-rw-r--r--commands.h2
-rw-r--r--config.def.h1
-rw-r--r--image.c8
-rw-r--r--nsxiv.13
-rw-r--r--nsxiv.h1
6 files changed, 20 insertions, 0 deletions
diff --git a/commands.c b/commands.c
index aafc510..7b7be62 100644
--- a/commands.c
+++ b/commands.c
@@ -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);
diff --git a/commands.h b/commands.h
index 70af13a..b78157d 100644
--- a/commands.h
+++ b/commands.h
@@ -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 },
diff --git a/image.c b/image.c
index 2c4eec1..6b30731 100644
--- a/image.c
+++ b/image.c
@@ -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;
diff --git a/nsxiv.1 b/nsxiv.1
index f032327..6c8d8e6 100644
--- a/nsxiv.1
+++ b/nsxiv.1
@@ -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 =
diff --git a/nsxiv.h b/nsxiv.h
index eb5b398..a9a9b8a 100644
--- a/nsxiv.h
+++ b/nsxiv.h
@@ -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);