New commands: fit to the window's height/width
This commit is contained in:
parent
5b6467913c
commit
b56989f8fb
|
@ -115,6 +115,8 @@ The following additional key commands are available in *image mode*:
|
||||||
- Zoom out
|
- Zoom out
|
||||||
= Set zoom level to 100%, or [count]%
|
= Set zoom level to 100%, or [count]%
|
||||||
w Fit image into window
|
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
|
h,j,k,l Pan image 1/5 of window width/height or [count] pixels
|
||||||
left/down/up/right (also with arrow keys)
|
left/down/up/right (also with arrow keys)
|
||||||
|
|
|
@ -310,9 +310,10 @@ bool i_set_zoom(arg_t a) {
|
||||||
|
|
||||||
bool i_fit_to_win(arg_t a) {
|
bool i_fit_to_win(arg_t a) {
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
scalemode_t sm = (scalemode_t) a;
|
||||||
|
|
||||||
if (mode == MODE_IMAGE) {
|
if (mode == MODE_IMAGE) {
|
||||||
if ((ret = img_fit_win(&img)))
|
if ((ret = img_fit_win(&img, sm)))
|
||||||
img_center(&img);
|
img_center(&img);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -108,7 +108,9 @@ static const keymap_t keys[] = {
|
||||||
{ false, XK_minus, i_zoom, (arg_t) -1 },
|
{ false, XK_minus, i_zoom, (arg_t) -1 },
|
||||||
{ false, XK_KP_Subtract, 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_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_W, i_fit_to_img, (arg_t) None },
|
||||||
|
|
||||||
{ false, XK_less, i_rotate, (arg_t) DIR_LEFT },
|
{ false, XK_less, i_rotate, (arg_t) DIR_LEFT },
|
||||||
|
|
15
image.c
15
image.c
|
@ -365,7 +365,18 @@ bool img_fit(img_t *img) {
|
||||||
zw = (float) img->win->w / (float) img->w;
|
zw = (float) img->win->w / (float) img->w;
|
||||||
zh = (float) img->win->h / (float) img->h;
|
zh = (float) img->win->h / (float) img->h;
|
||||||
|
|
||||||
|
switch (img->scalemode) {
|
||||||
|
case SCALE_WIDTH:
|
||||||
|
z = zw;
|
||||||
|
break;
|
||||||
|
case SCALE_HEIGHT:
|
||||||
|
z = zh;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
z = MIN(zw, zh);
|
z = MIN(zw, zh);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
z = MAX(z, zoom_min);
|
z = MAX(z, zoom_min);
|
||||||
z = MIN(z, zmax);
|
z = MIN(z, zmax);
|
||||||
|
|
||||||
|
@ -448,11 +459,11 @@ void img_render(img_t *img) {
|
||||||
img->dirty = false;
|
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)
|
if (img == NULL || img->im == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
img->scalemode = SCALE_FIT;
|
img->scalemode = sm;
|
||||||
return img_fit(img);
|
return img_fit(img);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
image.h
2
image.h
|
@ -65,7 +65,7 @@ void img_close(img_t*, bool);
|
||||||
|
|
||||||
void img_render(img_t*);
|
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_center(img_t*);
|
||||||
|
|
||||||
bool img_zoom(img_t*, float);
|
bool img_zoom(img_t*, float);
|
||||||
|
|
6
sxiv.1
6
sxiv.1
|
@ -197,6 +197,12 @@ Set zoom level to 100%, or
|
||||||
.TP
|
.TP
|
||||||
.B w
|
.B w
|
||||||
Set zoom level to fit image into window.
|
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
|
.SS Panning
|
||||||
.TP
|
.TP
|
||||||
.BR h ", " Left
|
.BR h ", " Left
|
||||||
|
|
Loading…
Reference in a new issue