aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--commands.c3
-rw-r--r--config.def.h4
-rw-r--r--image.c17
-rw-r--r--image.h2
-rw-r--r--sxiv.16
-rw-r--r--types.h2
7 files changed, 30 insertions, 6 deletions
diff --git a/README.md b/README.md
index d81a907..22bf2a6 100644
--- a/README.md
+++ b/README.md
@@ -115,6 +115,8 @@ The following additional key commands are available in *image mode*:
- Zoom out
= Set zoom level to 100%, or [count]%
w Fit image into window
+ e Fit image to window's width
+ E Fit image to window's height
h,j,k,l Pan image 1/5 of window width/height or [count] pixels
left/down/up/right (also with arrow keys)
diff --git a/commands.c b/commands.c
index 2e877e3..8868091 100644
--- a/commands.c
+++ b/commands.c
@@ -310,9 +310,10 @@ bool i_set_zoom(arg_t a) {
bool i_fit_to_win(arg_t a) {
bool ret = false;
+ scalemode_t sm = (scalemode_t) a;
if (mode == MODE_IMAGE) {
- if ((ret = img_fit_win(&img)))
+ if ((ret = img_fit_win(&img, sm)))
img_center(&img);
}
return ret;
diff --git a/config.def.h b/config.def.h
index 1116602..49dac49 100644
--- a/config.def.h
+++ b/config.def.h
@@ -108,7 +108,9 @@ static const keymap_t keys[] = {
{ false, XK_minus, i_zoom, (arg_t) -1 },
{ false, XK_KP_Subtract, i_zoom, (arg_t) -1 },
{ false, XK_equal, i_set_zoom, (arg_t) 100 },
- { false, XK_w, i_fit_to_win, (arg_t) None },
+ { false, XK_w, i_fit_to_win, (arg_t) SCALE_FIT },
+ { false, XK_e, i_fit_to_win, (arg_t) SCALE_WIDTH },
+ { false, XK_E, i_fit_to_win, (arg_t) SCALE_HEIGHT },
{ false, XK_W, i_fit_to_img, (arg_t) None },
{ false, XK_less, i_rotate, (arg_t) DIR_LEFT },
diff --git a/image.c b/image.c
index cb71efa..cb71fe3 100644
--- a/image.c
+++ b/image.c
@@ -365,7 +365,18 @@ bool img_fit(img_t *img) {
zw = (float) img->win->w / (float) img->w;
zh = (float) img->win->h / (float) img->h;
- z = MIN(zw, zh);
+ switch (img->scalemode) {
+ case SCALE_WIDTH:
+ z = zw;
+ break;
+ case SCALE_HEIGHT:
+ z = zh;
+ break;
+ default:
+ z = MIN(zw, zh);
+ break;
+ }
+
z = MAX(z, zoom_min);
z = MIN(z, zmax);
@@ -448,11 +459,11 @@ void img_render(img_t *img) {
img->dirty = false;
}
-bool img_fit_win(img_t *img) {
+bool img_fit_win(img_t *img, scalemode_t sm) {
if (img == NULL || img->im == NULL)
return false;
- img->scalemode = SCALE_FIT;
+ img->scalemode = sm;
return img_fit(img);
}
diff --git a/image.h b/image.h
index c662a24..034922a 100644
--- a/image.h
+++ b/image.h
@@ -65,7 +65,7 @@ void img_close(img_t*, bool);
void img_render(img_t*);
-bool img_fit_win(img_t*);
+bool img_fit_win(img_t*, scalemode_t);
bool img_center(img_t*);
bool img_zoom(img_t*, float);
diff --git a/sxiv.1 b/sxiv.1
index 869d621..f4b104a 100644
--- a/sxiv.1
+++ b/sxiv.1
@@ -197,6 +197,12 @@ Set zoom level to 100%, or
.TP
.B w
Set zoom level to fit image into window.
+.TP
+.B e
+Set zoom level to fit image into the window's width.
+.TP
+.B E
+Set zoom level to fit image into the window's height.
.SS Panning
.TP
.BR h ", " Left
diff --git a/types.h b/types.h
index 12719a7..70ae9c4 100644
--- a/types.h
+++ b/types.h
@@ -31,6 +31,8 @@ typedef enum {
typedef enum {
SCALE_DOWN,
SCALE_FIT,
+ SCALE_WIDTH,
+ SCALE_HEIGHT,
SCALE_ZOOM
} scalemode_t;