mirror of
https://gitlab.freedesktop.org/wayland/weston.git
synced 2026-05-05 15:48:05 +02:00
desktop-shell: allow to center background image
Add the centered option as background-type. This draws the image once in the center of the screen. If the image is larger, it will be cropped like scale-crop. Signed-off-by: Stefan Agner <stefan@agner.ch>
This commit is contained in:
parent
1c1e4fdaf4
commit
20b241691b
2 changed files with 22 additions and 3 deletions
|
|
@ -736,7 +736,8 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
|
|||
enum {
|
||||
BACKGROUND_SCALE,
|
||||
BACKGROUND_SCALE_CROP,
|
||||
BACKGROUND_TILE
|
||||
BACKGROUND_TILE,
|
||||
BACKGROUND_CENTERED
|
||||
};
|
||||
|
||||
static void
|
||||
|
|
@ -800,14 +801,27 @@ background_draw(struct widget *widget, void *data)
|
|||
case BACKGROUND_TILE:
|
||||
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
||||
break;
|
||||
case BACKGROUND_CENTERED:
|
||||
s = (sx < sy) ? sx : sy;
|
||||
if (s < 1.0)
|
||||
s = 1.0;
|
||||
|
||||
/* 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;
|
||||
}
|
||||
|
||||
cairo_set_source(cr, pattern);
|
||||
cairo_pattern_destroy (pattern);
|
||||
cairo_surface_destroy(image);
|
||||
cairo_mask(cr, pattern);
|
||||
}
|
||||
|
||||
cairo_paint(cr);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_destroy(surface);
|
||||
|
||||
|
|
@ -1143,6 +1157,8 @@ background_create(struct desktop *desktop, struct output *output)
|
|||
background->type = BACKGROUND_SCALE_CROP;
|
||||
} else if (strcmp(type, "tile") == 0) {
|
||||
background->type = BACKGROUND_TILE;
|
||||
} else if (strcmp(type, "centered") == 0) {
|
||||
background->type = BACKGROUND_CENTERED;
|
||||
} else {
|
||||
background->type = -1;
|
||||
fprintf(stderr, "invalid background-type: %s\n",
|
||||
|
|
|
|||
|
|
@ -260,7 +260,10 @@ 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
|
||||
.BR scale ", " scale-crop " or " tile " (default)."
|
||||
.BR centered ", " scale ", " scale-crop " or " tile " (default)."
|
||||
Centered shows the image once centered. If the image is smaller than the
|
||||
output, the rest of the surface will be in background color. If the image
|
||||
size does fit the output it will be cropped left and right, or top and bottom.
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue