aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--swaybg/main.c27
1 files changed, 24 insertions, 3 deletions
diff --git a/swaybg/main.c b/swaybg/main.c
index cb9cc42b..5510f2ef 100644
--- a/swaybg/main.c
+++ b/swaybg/main.c
@@ -12,6 +12,10 @@ list_t *surfaces;
struct registry *registry;
+enum scaling_mode_t {
+ SCALING_MODE_STRETCH,
+};
+
void sway_terminate(void) {
int 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);
list_add(surfaces, window);
- const char *scaling_mode = argv[3];
cairo_surface_t *image = cairo_image_surface_create_from_png(argv[2]);
double width = cairo_image_surface_get_width(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) {
struct window *window = surfaces->items[i];
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);
window_render(window);