From 1a3a7f25140d6751906789582c11edffc3c14090 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 19 Nov 2015 08:20:07 -0500 Subject: [PATCH] Basic image rendering for swaybg --- swaybg/main.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/swaybg/main.c b/swaybg/main.c index 56fdc06d..fd5e34c6 100644 --- a/swaybg/main.c +++ b/swaybg/main.c @@ -28,6 +28,10 @@ int main(int argc, char **argv) { surfaces = create_list(); registry = registry_poll(); + if (argc < 2) { + sway_abort("Usage: swaybg path/to/file.png"); + } + if (!registry->desktop_shell) { sway_abort("swaybg requires the compositor to support the desktop-shell extension."); } @@ -45,19 +49,18 @@ int main(int argc, char **argv) { list_add(surfaces, window); } - uint8_t r = 0, g = 0, b = 0; + cairo_surface_t *image = cairo_image_surface_create_from_png(argv[1]); do { for (i = 0; i < surfaces->length; ++i) { struct window *window = surfaces->items[i]; if (window_prerender(window) && window->cairo) { - cairo_set_source_rgb(window->cairo, r / 256.0, g / 256.0, b / 256.0); + cairo_set_source_surface(window->cairo, image, 0, 0); cairo_rectangle(window->cairo, 0, 0, window->width, window->height); cairo_fill(window->cairo); window_render(window); } - r++; g += 2; b += 4; } } while (wl_display_dispatch(registry->display) != -1);