Skip to content

Commit

Permalink
Add fit-width and fit-height options.
Browse files Browse the repository at this point in the history
Signed-off-by: Spaceship Operations <spaceshipoperations@gmail.com>
  • Loading branch information
SpaceshipOperations authored and artemsen committed Dec 30, 2023
1 parent e4a1836 commit 310e7a0
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 7 deletions.
2 changes: 2 additions & 0 deletions extra/swayimgrc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ j = step_down 10
equal = zoom_in 10
plus = zoom_in 10
minus = zoom_out 10
w = fit_width
W = fit_height
x = zoom_optimal
z = zoom_fit
Z = zoom_fill
Expand Down
6 changes: 6 additions & 0 deletions src/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,12 @@ void canvas_set_scale(enum canvas_scale sc)
case cs_fit_window:
ctx.scale = min(scale_w, scale_h);
break;
case cs_fit_width:
ctx.scale = scale_w;
break;
case cs_fit_height:
ctx.scale = scale_h;
break;
case cs_fill_window:
ctx.scale = max(scale_w, scale_h);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
enum canvas_scale {
cs_fit_or100, ///< Fit to window, but not more than 100%
cs_fit_window, ///< Fit to window size
cs_fit_width, ///< Fit width to window width
cs_fit_height, ///< Fit height to window height
cs_fill_window, ///< Fill the window
cs_real_size, ///< Real image size (100%)
};
Expand Down
4 changes: 4 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ static enum config_status load_general(const char* key, const char* value)
config.scale = cfgsc_optimal;
} else if (strcmp(value, "fit") == 0) {
config.scale = cfgsc_fit;
} else if (strcmp(value, "fit-width") == 0) {
config.scale = cfgsc_fit_width;
} else if (strcmp(value, "fit-height") == 0) {
config.scale = cfgsc_fit_height;
} else if (strcmp(value, "fill") == 0) {
config.scale = cfgsc_fill;
} else if (strcmp(value, "real") == 0) {
Expand Down
10 changes: 6 additions & 4 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

/** Initial scaling of images. */
enum config_scale {
cfgsc_optimal, ///< Fit to window, but not more than 100%
cfgsc_fit, ///< Fit to window size
cfgsc_fill, ///< Fill the window
cfgsc_real ///< Real image size (100%)
cfgsc_optimal, ///< Fit to window, but not more than 100%
cfgsc_fit, ///< Fit to window size
cfgsc_fit_width, ///< Fit to window size
cfgsc_fit_height, ///< Fit to window size
cfgsc_fill, ///< Fill the window
cfgsc_real ///< Real image size (100%)
};

/** Load status. */
Expand Down
4 changes: 4 additions & 0 deletions src/keybind.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ static const char* action_names[] = {
[kb_zoom_in] = "zoom_in",
[kb_zoom_out] = "zoom_out",
[kb_zoom_optimal] = "zoom_optimal",
[kb_zoom_fit_width] = "zoom_fit_width",
[kb_zoom_fit_height] = "zoom_fit_height",
[kb_zoom_fit] = "zoom_fit",
[kb_zoom_fill] = "zoom_fill",
[kb_zoom_real] = "zoom_real",
Expand Down Expand Up @@ -84,6 +86,8 @@ static struct key_binding default_bindings[] = {
{ XKB_KEY_plus, kb_zoom_in, NULL },
{ XKB_KEY_minus, kb_zoom_out, NULL },
{ XKB_KEY_x, kb_zoom_optimal, NULL },
{ XKB_KEY_w, kb_zoom_fit_width, NULL },
{ XKB_KEY_W, kb_zoom_fit_height, NULL },
{ XKB_KEY_z, kb_zoom_fit, NULL },
{ XKB_KEY_Z, kb_zoom_fill, NULL },
{ XKB_KEY_0, kb_zoom_real, NULL },
Expand Down
6 changes: 4 additions & 2 deletions src/keybind.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ enum kb_action {
kb_zoom_in,
kb_zoom_out,
kb_zoom_optimal,
kb_zoom_fit,
kb_zoom_fill,
kb_zoom_fit_width,
kb_zoom_fit_height,
kb_zoom_fit, // Fit largest dimension
kb_zoom_fill, // Fit smallest dimension
kb_zoom_real,
kb_zoom_reset,
kb_rotate_left,
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static const struct cmdarg arguments[] = {
{ 'a', "all", NULL, "open all files from the same directory", "list", "all", "yes" },
{ 'l', "slideshow", NULL, "activate slideshow mode on startup", NULL, NULL, NULL },
{ 'f', "fullscreen", NULL, "show image in full screen mode", NULL, NULL, NULL },
{ 's', "scale", "SCALE", "set initial image scale: [optimal]/fit/fill/real", "general", "scale", NULL },
{ 's', "scale", "SCALE", "set initial image scale: [optimal]/fit/fit-width/fit-height/fill/real", "general", "scale", NULL },
{ 'b', "background", "COLOR", "set image background color: none/[grid]/RGB", "general", "background", NULL },
{ 'w', "wndbkg", "COLOR", "set window background color: [none]/RGB", "general", "wndbkg", NULL },
{ 'p', "wndpos", "POS", "set window position [parent]/X,Y", "general", "wndpos", NULL },
Expand Down
6 changes: 6 additions & 0 deletions src/viewer.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,12 @@ bool viewer_on_keyboard(xkb_keysym_t key)
case kb_zoom_fit:
canvas_set_scale(cs_fit_window);
return true;
case kb_zoom_fit_width:
canvas_set_scale(cs_fit_width);
return true;
case kb_zoom_fit_height:
canvas_set_scale(cs_fit_height);
return true;
case kb_zoom_fill:
canvas_set_scale(cs_fill_window);
return true;
Expand Down

0 comments on commit 310e7a0

Please sign in to comment.