From 329671771ce1a24ccd31de12ab5010b86dd5b871 Mon Sep 17 00:00:00 2001 From: Artem Senichev Date: Fri, 24 Jan 2025 17:49:25 +0300 Subject: [PATCH] Add action to toggle zoom keeping Default key is Alt+z. Relates to #240. Signed-off-by: Artem Senichev --- extra/swayimgrc | 1 + extra/swayimgrc.5 | 1 + src/action.c | 1 + src/action.h | 1 + src/config.c | 1 + src/viewer.c | 13 +++++++++++++ 6 files changed, 18 insertions(+) diff --git a/extra/swayimgrc b/extra/swayimgrc index aa88105c..0b42dd09 100644 --- a/extra/swayimgrc +++ b/extra/swayimgrc @@ -170,6 +170,7 @@ Shift+z = zoom fill 0 = zoom real BackSpace = zoom optimal Alt+s = scale +Alt+z = keep_zoom bracketleft = rotate_left bracketright = rotate_right m = flip_vertical diff --git a/extra/swayimgrc.5 b/extra/swayimgrc.5 index 0450bb12..c83c058c 100644 --- a/extra/swayimgrc.5 +++ b/extra/swayimgrc.5 @@ -326,6 +326,7 @@ Predefined names for mouse scroll: .IP "\fBstep_down\fR \fI[PERCENT]\fR: move viewport down, default is 10%;" .IP "\fBzoom\fR \fI[SCALE]\fR: zoom in/out/fix, \fISCALE\fR is one of \fIviewer.scale\fR modes, or percent, e.g. \fI+10\fR;" .IP "\fBscale\fR \fI[SCALE]\fR: set default/global scale, \fISCALE\fR is one of \fIviewer.scale\fR modes, cycles through available modes by default;" +.IP "\fBkeep_zoom\fR: toggle zoom keeping mode;" .IP "\fBrotate_left\fR: rotate image anticlockwise;" .IP "\fBrotate_right\fR: rotate image clockwise;" .IP "\fBflip_vertical\fR: flip image vertically;" diff --git a/src/action.c b/src/action.c index 7aec07fd..ad9e6e89 100644 --- a/src/action.c +++ b/src/action.c @@ -39,6 +39,7 @@ static const char* action_names[] = { [action_page_down] = "page_down", [action_zoom] = "zoom", [action_scale] = "scale", + [action_keep_zoom] = "keep_zoom", [action_rotate_left] = "rotate_left", [action_rotate_right] = "rotate_right", [action_flip_vertical] = "flip_vertical", diff --git a/src/action.h b/src/action.h index c76de9c0..836b716a 100644 --- a/src/action.h +++ b/src/action.h @@ -33,6 +33,7 @@ enum action_type { action_page_down, action_zoom, action_scale, + action_keep_zoom, action_rotate_left, action_rotate_right, action_flip_vertical, diff --git a/src/config.c b/src/config.c index bd686541..302386bf 100644 --- a/src/config.c +++ b/src/config.c @@ -107,6 +107,7 @@ static const struct config_default defaults[] = { { CFG_KEYS_VIEWER, "Shift+z", "zoom fill" }, { CFG_KEYS_VIEWER, "0", "zoom real" }, { CFG_KEYS_VIEWER, "BackSpace", "zoom optimal" }, + { CFG_KEYS_VIEWER, "Alt+z", "keep_zoom" }, { CFG_KEYS_VIEWER, "bracketleft", "rotate_left" }, { CFG_KEYS_VIEWER, "bracketright", "rotate_right" }, { CFG_KEYS_VIEWER, "m", "flip_vertical" }, diff --git a/src/viewer.c b/src/viewer.c index 2611aef5..70ba3c75 100644 --- a/src/viewer.c +++ b/src/viewer.c @@ -386,6 +386,16 @@ static void scale_global(const char* params) app_redraw(); } +/** + * Toggle zoom keeping mode. + */ +static void toggle_keep_zoom(void) +{ + ctx.keep_zoom = !ctx.keep_zoom; + info_update(info_status, "Keep zoom %s", ctx.keep_zoom ? "ON" : "OFF"); + app_redraw(); +} + /** * Start/stop animation if image supports it. * @param enable state to set @@ -708,6 +718,9 @@ static void apply_action(const struct action* action) case action_scale: scale_global(action->params); break; + case action_keep_zoom: + toggle_keep_zoom(); + break; case action_rotate_left: rotate_image(false); break;