desktop-shell: Support tiling of background images

dev
Kristian Høgsberg 13 years ago
parent d654876510
commit 07f729441e
  1. 38
      clients/desktop-shell.c

@ -96,6 +96,7 @@ struct unlock_dialog {
}; };
static char *key_background_image; static char *key_background_image;
static char *key_background_type;
static uint32_t key_panel_color; static uint32_t key_panel_color;
static uint32_t key_background_color; static uint32_t key_background_color;
static char *key_launcher_icon; static char *key_launcher_icon;
@ -105,6 +106,7 @@ static int key_locking = 1;
static const struct config_key shell_config_keys[] = { static const struct config_key shell_config_keys[] = {
{ "background-image", CONFIG_KEY_STRING, &key_background_image }, { "background-image", CONFIG_KEY_STRING, &key_background_image },
{ "background-type", CONFIG_KEY_STRING, &key_background_type },
{ "panel-color", CONFIG_KEY_INTEGER, &key_panel_color }, { "panel-color", CONFIG_KEY_INTEGER, &key_panel_color },
{ "background-color", CONFIG_KEY_INTEGER, &key_background_color }, { "background-color", CONFIG_KEY_INTEGER, &key_background_color },
{ "locking", CONFIG_KEY_BOOLEAN, &key_locking }, { "locking", CONFIG_KEY_BOOLEAN, &key_locking },
@ -355,6 +357,11 @@ panel_add_launcher(struct panel *panel, const char *icon, const char *path)
panel_launcher_redraw_handler); panel_launcher_redraw_handler);
} }
enum {
BACKGROUND_SCALE,
BACKGROUND_TILE
};
static void static void
background_draw(struct widget *widget, void *data) background_draw(struct widget *widget, void *data)
{ {
@ -365,6 +372,7 @@ background_draw(struct widget *widget, void *data)
cairo_t *cr; cairo_t *cr;
double sx, sy; double sx, sy;
struct rectangle allocation; struct rectangle allocation;
int type = -1;
surface = window_get_surface(background->window); surface = window_get_surface(background->window);
@ -377,14 +385,30 @@ background_draw(struct widget *widget, void *data)
image = NULL; image = NULL;
if (key_background_image) if (key_background_image)
image = load_image(key_background_image); image = load_image(key_background_image);
if (image) {
if (strcmp(key_background_type, "scale") == 0)
type = BACKGROUND_SCALE;
else if (strcmp(key_background_type, "tile") == 0)
type = BACKGROUND_TILE;
else
fprintf(stderr, "invalid background-type: %s\n",
key_background_type);
if (image && type != -1) {
pattern = cairo_pattern_create_for_surface(image); pattern = cairo_pattern_create_for_surface(image);
sx = (double) cairo_image_surface_get_width(image) / switch (type) {
allocation.width; case BACKGROUND_SCALE:
sy = (double) cairo_image_surface_get_height(image) / sx = (double) cairo_image_surface_get_width(image) /
allocation.height; allocation.width;
cairo_matrix_init_scale(&matrix, sx, sy); sy = (double) cairo_image_surface_get_height(image) /
cairo_pattern_set_matrix(pattern, &matrix); allocation.height;
cairo_matrix_init_scale(&matrix, sx, sy);
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_set_source(cr, pattern);
cairo_pattern_destroy (pattern); cairo_pattern_destroy (pattern);
cairo_surface_destroy(image); cairo_surface_destroy(image);

Loading…
Cancel
Save