swaybg: implement scaling mode "stretch"

This commit is contained in:
Christoph Gysin 2015-11-25 16:57:35 +02:00
parent 504ac84cbc
commit 904983c375

View file

@ -12,6 +12,10 @@ list_t *surfaces;
struct registry *registry; struct registry *registry;
enum scaling_mode_t {
SCALING_MODE_STRETCH,
};
void sway_terminate(void) { void sway_terminate(void) {
int i; int i;
for (i = 0; i < surfaces->length; ++i) { for (i = 0; i < surfaces->length; ++i) {
@ -49,16 +53,33 @@ int main(int argc, const char **argv) {
desktop_shell_set_background(registry->desktop_shell, output->output, window->surface); desktop_shell_set_background(registry->desktop_shell, output->output, window->surface);
list_add(surfaces, window); list_add(surfaces, window);
const char *scaling_mode = argv[3];
cairo_surface_t *image = cairo_image_surface_create_from_png(argv[2]); cairo_surface_t *image = cairo_image_surface_create_from_png(argv[2]);
double width = cairo_image_surface_get_width(image); double width = cairo_image_surface_get_width(image);
double height = cairo_image_surface_get_height(image); double height = cairo_image_surface_get_height(image);
const char *scaling_mode_str = argv[3];
enum scaling_mode_t scaling_mode;
if (strcmp(scaling_mode_str, "stretch") == 0) {
scaling_mode = SCALING_MODE_STRETCH;
} else {
sway_abort("Unsupported scaling mode: %s", scaling_mode_str);
}
for (i = 0; i < surfaces->length; ++i) { for (i = 0; i < surfaces->length; ++i) {
struct window *window = surfaces->items[i]; struct window *window = surfaces->items[i];
if (window_prerender(window) && window->cairo) { if (window_prerender(window) && window->cairo) {
cairo_scale(window->cairo, window->width / width, window->height / height);
cairo_set_source_surface(window->cairo, image, 0, 0); switch (scaling_mode) {
case SCALING_MODE_STRETCH:
cairo_scale(window->cairo,
(double) window->width / width,
(double) window->height / height);
cairo_set_source_surface(window->cairo, image, 0, 0);
break;
default:
sway_abort("Scaling mode '%s' not implemented yet!", scaling_mode_str);
}
cairo_paint(window->cairo); cairo_paint(window->cairo);
window_render(window); window_render(window);