@@ -343,6 +343,7 @@ cairo_surface_t *load_image(char *image_path) {
343343
344344int main (int argc , char * * argv ) {
345345 const char * scaling_mode_str = "fit" , * socket_path = NULL ;
346+ char * image_path = NULL ;
346347 int i ;
347348 void * images = NULL ;
348349 config = init_config ();
@@ -400,8 +401,6 @@ int main(int argc, char **argv) {
400401 " For more information see `man swaylock`\n" ;
401402
402403
403- registry = registry_poll ();
404-
405404 int c ;
406405 while (1 ) {
407406 int option_index = 0 ;
@@ -418,29 +417,7 @@ int main(int argc, char **argv) {
418417 }
419418 case 'i' :
420419 {
421- char * image_path = strchr (optarg , ':' );
422- if (image_path == NULL ) {
423- if (render_data .num_images == 0 ) {
424- // Provided image without output
425- render_data .image = load_image (optarg );
426- render_data .num_images = -1 ;
427- } else {
428- sway_log (L_ERROR , "output must be defined for all --images or no --images" );
429- exit (EXIT_FAILURE );
430- }
431- } else {
432- // Provided image for all outputs
433- if (render_data .num_images == 0 ) {
434- images = calloc (registry -> outputs -> length , sizeof (char * ) * 2 );
435- } else if (render_data .num_images == -1 ) {
436- sway_log (L_ERROR , "output must be defined for all --images or no --images" );
437- exit (EXIT_FAILURE );
438- }
439-
440- image_path [0 ] = '\0' ;
441- ((char * * ) images )[render_data .num_images * 2 ] = optarg ;
442- ((char * * ) images )[render_data .num_images ++ * 2 + 1 ] = ++ image_path ;
443- }
420+ image_path = optarg ;
444421 break ;
445422 }
446423 case 't' :
@@ -519,6 +496,33 @@ int main(int argc, char **argv) {
519496 exit (EXIT_FAILURE );
520497 }
521498 }
499+ registry = registry_poll ();
500+
501+ if (image_path ) {
502+ char * path = strchr (image_path , ':' );
503+ if (path == NULL ) {
504+ if (render_data .num_images == 0 ) {
505+ // Provided image without output
506+ render_data .image = load_image (image_path );
507+ render_data .num_images = -1 ;
508+ } else {
509+ sway_log (L_ERROR , "output must be defined for all --images or no --images" );
510+ exit (EXIT_FAILURE );
511+ }
512+ } else {
513+ // Provided image for all outputs
514+ if (render_data .num_images == 0 ) {
515+ images = calloc (registry -> outputs -> length , sizeof (char * ) * 2 );
516+ } else if (render_data .num_images == -1 ) {
517+ sway_log (L_ERROR , "output must be defined for all --images or no --images" );
518+ exit (EXIT_FAILURE );
519+ }
520+
521+ path [0 ] = '\0' ;
522+ ((char * * ) images )[render_data .num_images * 2 ] = image_path ;
523+ ((char * * ) images )[render_data .num_images ++ * 2 + 1 ] = ++ path ;
524+ }
525+ }
522526
523527 render_data .scaling_mode = SCALING_MODE_STRETCH ;
524528 if (strcmp (scaling_mode_str , "stretch" ) == 0 ) {
0 commit comments