summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Calvin Lee <cyrus296@gmail.com>2017-12-13 16:25:35 -0700
committerLibravatar Calvin Lee <cyrus296@gmail.com>2017-12-13 16:47:53 -0700
commit609430053bcd0416003713a4dec725f908c4bc0e (patch)
treed8822aae58a69636610215a2abb5f76d59b026d5
parentMerge pull request #1446 from kon14/patch-1 (diff)
downloadsway-609430053bcd0416003713a4dec725f908c4bc0e.tar.gz
sway-609430053bcd0416003713a4dec725f908c4bc0e.tar.zst
sway-609430053bcd0416003713a4dec725f908c4bc0e.zip
Fix `swaylock -f`
This commit makes swaylock poll the registry the first time in its fork in order for sway to recognize it and grant it lock privileges
-rw-r--r--swaylock/main.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index c2615951..1ed28c2b 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -343,6 +343,7 @@ cairo_surface_t *load_image(char *image_path) {
343 343
344int main(int argc, char **argv) { 344int main(int argc, char **argv) {
345 const char *scaling_mode_str = "fit", *socket_path = NULL; 345 const char *scaling_mode_str = "fit", *socket_path = NULL;
346 char *image_path = NULL;
346 int i; 347 int i;
347 void *images = NULL; 348 void *images = NULL;
348 config = init_config(); 349 config = init_config();
@@ -400,8 +401,6 @@ int main(int argc, char **argv) {
400 " For more information see `man swaylock`\n"; 401 " For more information see `man swaylock`\n";
401 402
402 403
403 registry = registry_poll();
404
405 int c; 404 int c;
406 while (1) { 405 while (1) {
407 int option_index = 0; 406 int option_index = 0;
@@ -418,29 +417,7 @@ int main(int argc, char **argv) {
418 } 417 }
419 case 'i': 418 case 'i':
420 { 419 {
421 char *image_path = strchr(optarg, ':'); 420 image_path = 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 }
444 break; 421 break;
445 } 422 }
446 case 't': 423 case 't':
@@ -519,6 +496,33 @@ int main(int argc, char **argv) {
519 exit(EXIT_FAILURE); 496 exit(EXIT_FAILURE);
520 } 497 }
521 } 498 }
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 }
522 526
523 render_data.scaling_mode = SCALING_MODE_STRETCH; 527 render_data.scaling_mode = SCALING_MODE_STRETCH;
524 if (strcmp(scaling_mode_str, "stretch") == 0) { 528 if (strcmp(scaling_mode_str, "stretch") == 0) {