[PATCH weston 07/18] desktop-shell: new wallpaper mode scale-crop
ppaalanen at gmail.com
ppaalanen at gmail.com
Wed May 22 08:03:10 PDT 2013
From: Pekka Paalanen <ppaalanen at gmail.com>
Scale-crop mode scales the wallpaper to tightly fill the whole output,
but preserving wallpaper aspect ratio. If aspect ratio differs from the
output's, the wallpaper is centered cutting it from top/bottom or
left/right.
Add this to the weston.ini man page, and explain all three modes.
Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
---
clients/desktop-shell.c | 27 ++++++++++++++++++++++-----
man/weston.ini.man | 9 +++++++--
2 files changed, 29 insertions(+), 7 deletions(-)
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 4a39653..1fc8753 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -664,6 +664,7 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
enum {
BACKGROUND_SCALE,
+ BACKGROUND_SCALE_CROP,
BACKGROUND_TILE
};
@@ -675,7 +676,9 @@ background_draw(struct widget *widget, void *data)
cairo_pattern_t *pattern;
cairo_matrix_t matrix;
cairo_t *cr;
- double sx, sy;
+ double im_w, im_h;
+ double sx, sy, s;
+ double tx, ty;
struct rectangle allocation;
int type = -1;
struct display *display;
@@ -695,6 +698,8 @@ background_draw(struct widget *widget, void *data)
if (strcmp(key_background_type, "scale") == 0)
type = BACKGROUND_SCALE;
+ else if (strcmp(key_background_type, "scale-crop") == 0)
+ type = BACKGROUND_SCALE_CROP;
else if (strcmp(key_background_type, "tile") == 0)
type = BACKGROUND_TILE;
else
@@ -702,20 +707,32 @@ background_draw(struct widget *widget, void *data)
key_background_type);
if (image && type != -1) {
+ im_w = cairo_image_surface_get_width(image);
+ im_h = cairo_image_surface_get_height(image);
+ sx = im_w / allocation.width;
+ sy = im_h / allocation.height;
+
pattern = cairo_pattern_create_for_surface(image);
+
switch (type) {
case BACKGROUND_SCALE:
- sx = (double) cairo_image_surface_get_width(image) /
- allocation.width;
- sy = (double) cairo_image_surface_get_height(image) /
- allocation.height;
cairo_matrix_init_scale(&matrix, sx, sy);
cairo_pattern_set_matrix(pattern, &matrix);
break;
+ case BACKGROUND_SCALE_CROP:
+ s = (sx < sy) ? sx : sy;
+ /* align center */
+ tx = (im_w - s * allocation.width) * 0.5;
+ ty = (im_h - s * allocation.height) * 0.5;
+ cairo_matrix_init_translate(&matrix, tx, ty);
+ cairo_matrix_scale(&matrix, s, s);
+ cairo_pattern_set_matrix(pattern, &matrix);
+ break;
case BACKGROUND_TILE:
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
break;
}
+
cairo_set_source(cr, pattern);
cairo_pattern_destroy (pattern);
cairo_surface_destroy(image);
diff --git a/man/weston.ini.man b/man/weston.ini.man
index d37654a..c3e5747 100644
--- a/man/weston.ini.man
+++ b/man/weston.ini.man
@@ -118,8 +118,13 @@ The entries that can appear in this section are:
sets the path for the background image file (string).
.TP 7
.BI "background-type=" tile
-determines how the background image is drawn (string). Can be scale or
-tile (default).
+determines how the background image is drawn (string). Can be
+.BR scale ", " scale-crop " or " tile " (default)."
+Scale means scaled to fit the output precisely, not preserving aspect ratio.
+Scale-crop preserves aspect ratio, scales the background image just big
+enough to cover the output, and centers it. The image ends up cropped from
+left and right, or top and bottom, if the aspect ratio does not match the
+output. Tile repeats the background image to fill the output.
.TP 7
.BI "background-color=" 0xAARRGGBB
sets the color of the background (unsigned integer). The hexadecimal
--
1.8.1.5
More information about the wayland-devel
mailing list