From 7e69000556ab2b542d5ab51c1e60a1d71563dd59 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Thu, 8 Sep 2011 18:18:02 -0400 Subject: [PATCH] desktop-shell: Scale background image to output size --- clients/desktop-shell.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index 4ed1c35..3f773e9 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -284,7 +284,10 @@ static void background_draw(struct window *window, int width, int height, const char *path) { cairo_surface_t *surface, *image; + cairo_pattern_t *pattern; + cairo_matrix_t matrix; cairo_t *cr; + double sx, sy; window_set_child_size(window, width, height); window_draw(window); @@ -297,7 +300,13 @@ background_draw(struct window *window, int width, int height, const char *path) if (path) { image = cairo_image_surface_create_from_png(path); - cairo_set_source_surface(cr, image, 0, 0); + pattern = cairo_pattern_create_for_surface(image); + sx = (double) cairo_image_surface_get_width(image) / width; + sy = (double) cairo_image_surface_get_height(image) / height; + cairo_matrix_init_scale(&matrix, sx, sy); + cairo_pattern_set_matrix(pattern, &matrix); + cairo_set_source(cr, pattern); + cairo_pattern_destroy (pattern); cairo_paint(cr); } -- 2.7.4