aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Gysin <christoph.gysin@gmail.com>2015-11-25 20:52:34 +0200
committerChristoph Gysin <christoph.gysin@gmail.com>2015-11-25 22:29:49 +0200
commit81a87ec7a721b2f14c129f86b8403cce8c434435 (patch)
treee94a68c9de78c0474081a75fa79c341e98e371e8
parent904983c3753f3b1f275dedc1c7841542f77c9f89 (diff)
swaybg: implement scaling mode "fill"
-rw-r--r--swaybg/main.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/swaybg/main.c b/swaybg/main.c
index 5510f2ef..a85c56bd 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -14,6 +14,7 @@ struct registry *registry;
enum scaling_mode_t {
SCALING_MODE_STRETCH,
+ SCALING_MODE_FILL,
};
void sway_terminate(void) {
@@ -61,6 +62,8 @@ int main(int argc, const char **argv) {
enum scaling_mode_t scaling_mode;
if (strcmp(scaling_mode_str, "stretch") == 0) {
scaling_mode = SCALING_MODE_STRETCH;
+ } else if (strcmp(scaling_mode_str, "fill") == 0) {
+ scaling_mode = SCALING_MODE_FILL;
} else {
sway_abort("Unsupported scaling mode: %s", scaling_mode_str);
}
@@ -76,6 +79,26 @@ int main(int argc, const char **argv) {
(double) window->height / height);
cairo_set_source_surface(window->cairo, image, 0, 0);
break;
+ case SCALING_MODE_FILL:
+ {
+ double window_ratio = (double) window->width / window->height;
+ double bg_ratio = width / height;
+
+ if (window_ratio > bg_ratio) {
+ double scale = (double) window->width / width;
+ cairo_scale(window->cairo, scale, scale);
+ cairo_set_source_surface(window->cairo, image,
+ 0,
+ (double) window->height/2 / scale - height/2);
+ } else {
+ double scale = (double) window->height / height;
+ cairo_scale(window->cairo, scale, scale);
+ cairo_set_source_surface(window->cairo, image,
+ (double) window->width/2 / scale - width/2,
+ 0);
+ }
+ }
+ break;
default:
sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
}