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:
committed by
Daniel Stone
parent
1c1e4fdaf4
commit
20b241691b
+18
-2
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user