From 621062f18d3511a2b0fae0a18f168e07f1ff1b0d Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Wed, 25 Nov 2015 20:53:13 +0200 Subject: [PATCH] swaybg: implement scaling mode "center" --- swaybg/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/swaybg/main.c b/swaybg/main.c index a85c56bd..481fdf9a 100644 --- a/swaybg/main.c +++ b/swaybg/main.c @@ -15,6 +15,7 @@ struct registry *registry; enum scaling_mode_t { SCALING_MODE_STRETCH, SCALING_MODE_FILL, + SCALING_MODE_CENTER, }; void sway_terminate(void) { @@ -64,6 +65,8 @@ int main(int argc, const char **argv) { scaling_mode = SCALING_MODE_STRETCH; } else if (strcmp(scaling_mode_str, "fill") == 0) { scaling_mode = SCALING_MODE_FILL; + } else if (strcmp(scaling_mode_str, "center") == 0) { + scaling_mode = SCALING_MODE_CENTER; } else { sway_abort("Unsupported scaling mode: %s", scaling_mode_str); } @@ -99,6 +102,11 @@ int main(int argc, const char **argv) { } } break; + case SCALING_MODE_CENTER: + cairo_set_source_surface(window->cairo, image, + (double) window->width/2 - width/2, + (double) window->height/2 - height/2); + break; default: sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str); }