Skip to content

Commit

Permalink
Add action to toggle zoom keeping
Browse files Browse the repository at this point in the history
Default key is Alt+z.

Relates to #240.

Signed-off-by: Artem Senichev <artemsen@gmail.com>
  • Loading branch information
artemsen committed Jan 24, 2025
1 parent b9d0c3a commit 3296717
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions extra/swayimgrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions extra/swayimgrc.5
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand Down
1 change: 1 addition & 0 deletions src/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
13 changes: 13 additions & 0 deletions src/viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3296717

Please sign in to comment.