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 {
|
enum {
|
||||||
BACKGROUND_SCALE,
|
BACKGROUND_SCALE,
|
||||||
BACKGROUND_SCALE_CROP,
|
BACKGROUND_SCALE_CROP,
|
||||||
BACKGROUND_TILE
|
BACKGROUND_TILE,
|
||||||
|
BACKGROUND_CENTERED
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -800,14 +801,27 @@ background_draw(struct widget *widget, void *data)
|
|||||||
case BACKGROUND_TILE:
|
case BACKGROUND_TILE:
|
||||||
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT);
|
||||||
break;
|
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_set_source(cr, pattern);
|
||||||
cairo_pattern_destroy (pattern);
|
cairo_pattern_destroy (pattern);
|
||||||
cairo_surface_destroy(image);
|
cairo_surface_destroy(image);
|
||||||
|
cairo_mask(cr, pattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
cairo_paint(cr);
|
|
||||||
cairo_destroy(cr);
|
cairo_destroy(cr);
|
||||||
cairo_surface_destroy(surface);
|
cairo_surface_destroy(surface);
|
||||||
|
|
||||||
@@ -1143,6 +1157,8 @@ background_create(struct desktop *desktop, struct output *output)
|
|||||||
background->type = BACKGROUND_SCALE_CROP;
|
background->type = BACKGROUND_SCALE_CROP;
|
||||||
} else if (strcmp(type, "tile") == 0) {
|
} else if (strcmp(type, "tile") == 0) {
|
||||||
background->type = BACKGROUND_TILE;
|
background->type = BACKGROUND_TILE;
|
||||||
|
} else if (strcmp(type, "centered") == 0) {
|
||||||
|
background->type = BACKGROUND_CENTERED;
|
||||||
} else {
|
} else {
|
||||||
background->type = -1;
|
background->type = -1;
|
||||||
fprintf(stderr, "invalid background-type: %s\n",
|
fprintf(stderr, "invalid background-type: %s\n",
|
||||||
|
|||||||
+4
-1
@@ -260,7 +260,10 @@ sets the path for the background image file (string).
|
|||||||
.TP 7
|
.TP 7
|
||||||
.BI "background-type=" tile
|
.BI "background-type=" tile
|
||||||
determines how the background image is drawn (string). Can be
|
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 means scaled to fit the output precisely, not preserving aspect ratio.
|
||||||
Scale-crop preserves aspect ratio, scales the background image just big
|
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
|
enough to cover the output, and centers it. The image ends up cropped from
|
||||||
|
|||||||
Reference in New Issue
Block a user