diff options
-rw-r--r-- | swaylock/main.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index f1c75e22..4b486461 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -334,6 +334,7 @@ cairo_surface_t *load_image(char *image_path) { | |||
334 | 334 | ||
335 | int main(int argc, char **argv) { | 335 | int main(int argc, char **argv) { |
336 | const char *scaling_mode_str = "fit", *socket_path = NULL; | 336 | const char *scaling_mode_str = "fit", *socket_path = NULL; |
337 | char *image_path = NULL; | ||
337 | int i; | 338 | int i; |
338 | void *images = NULL; | 339 | void *images = NULL; |
339 | config = init_config(); | 340 | config = init_config(); |
@@ -391,8 +392,6 @@ int main(int argc, char **argv) { | |||
391 | " For more information see `man swaylock`\n"; | 392 | " For more information see `man swaylock`\n"; |
392 | 393 | ||
393 | 394 | ||
394 | registry = registry_poll(); | ||
395 | |||
396 | int c; | 395 | int c; |
397 | while (1) { | 396 | while (1) { |
398 | int option_index = 0; | 397 | int option_index = 0; |
@@ -409,29 +408,7 @@ int main(int argc, char **argv) { | |||
409 | } | 408 | } |
410 | case 'i': | 409 | case 'i': |
411 | { | 410 | { |
412 | char *image_path = strchr(optarg, ':'); | 411 | image_path = optarg; |
413 | if (image_path == NULL) { | ||
414 | if (render_data.num_images == 0) { | ||
415 | // Provided image without output | ||
416 | render_data.image = load_image(optarg); | ||
417 | render_data.num_images = -1; | ||
418 | } else { | ||
419 | sway_log(L_ERROR, "output must be defined for all --images or no --images"); | ||
420 | exit(EXIT_FAILURE); | ||
421 | } | ||
422 | } else { | ||
423 | // Provided image for all outputs | ||
424 | if (render_data.num_images == 0) { | ||
425 | images = calloc(registry->outputs->length, sizeof(char*) * 2); | ||
426 | } else if (render_data.num_images == -1) { | ||
427 | sway_log(L_ERROR, "output must be defined for all --images or no --images"); | ||
428 | exit(EXIT_FAILURE); | ||
429 | } | ||
430 | |||
431 | image_path[0] = '\0'; | ||
432 | ((char**) images)[render_data.num_images * 2] = optarg; | ||
433 | ((char**) images)[render_data.num_images++ * 2 + 1] = ++image_path; | ||
434 | } | ||
435 | break; | 412 | break; |
436 | } | 413 | } |
437 | case 't': | 414 | case 't': |
@@ -510,6 +487,33 @@ int main(int argc, char **argv) { | |||
510 | exit(EXIT_FAILURE); | 487 | exit(EXIT_FAILURE); |
511 | } | 488 | } |
512 | } | 489 | } |
490 | registry = registry_poll(); | ||
491 | |||
492 | if (image_path) { | ||
493 | char *path = strchr(image_path, ':'); | ||
494 | if (path == NULL) { | ||
495 | if (render_data.num_images == 0) { | ||
496 | // Provided image without output | ||
497 | render_data.image = load_image(image_path); | ||
498 | render_data.num_images = -1; | ||
499 | } else { | ||
500 | sway_log(L_ERROR, "output must be defined for all --images or no --images"); | ||
501 | exit(EXIT_FAILURE); | ||
502 | } | ||
503 | } else { | ||
504 | // Provided image for all outputs | ||
505 | if (render_data.num_images == 0) { | ||
506 | images = calloc(registry->outputs->length, sizeof(char*) * 2); | ||
507 | } else if (render_data.num_images == -1) { | ||
508 | sway_log(L_ERROR, "output must be defined for all --images or no --images"); | ||
509 | exit(EXIT_FAILURE); | ||
510 | } | ||
511 | |||
512 | path[0] = '\0'; | ||
513 | ((char**) images)[render_data.num_images * 2] = image_path; | ||
514 | ((char**) images)[render_data.num_images++ * 2 + 1] = ++path; | ||
515 | } | ||
516 | } | ||
513 | 517 | ||
514 | render_data.scaling_mode = SCALING_MODE_STRETCH; | 518 | render_data.scaling_mode = SCALING_MODE_STRETCH; |
515 | if (strcmp(scaling_mode_str, "stretch") == 0) { | 519 | if (strcmp(scaling_mode_str, "stretch") == 0) { |