summaryrefslogtreecommitdiffstats
path: root/swaylock/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/main.c')
-rw-r--r--swaylock/main.c137
1 files changed, 55 insertions, 82 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index a8d61d88..49b24a3a 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -57,7 +57,7 @@ void sway_terminate(int exit_code) {
57 57
58char *password; 58char *password;
59int password_size; 59int password_size;
60int line_source = 0; 60enum line_source line_source = LINE_SOURCE_DEFAULT;
61 61
62struct lock_config *init_config() { 62struct lock_config *init_config() {
63 struct lock_config *config = calloc(1, sizeof(struct lock_config)); 63 struct lock_config *config = calloc(1, sizeof(struct lock_config));
@@ -362,15 +362,15 @@ int main(int argc, char **argv) {
362 {"help", no_argument, NULL, 'h'}, 362 {"help", no_argument, NULL, 'h'},
363 {"color", required_argument, NULL, 'c'}, 363 {"color", required_argument, NULL, 'c'},
364 {"image", required_argument, NULL, 'i'}, 364 {"image", required_argument, NULL, 'i'},
365 {"scaling", required_argument, NULL, 's'}, 365 {"scaling", required_argument, NULL, 0},
366 {"tiling", no_argument, NULL, 't'}, 366 {"tiling", no_argument, NULL, 't'},
367 {"version", no_argument, NULL, 'v'}, 367 {"version", no_argument, NULL, 'v'},
368 {"socket", required_argument, NULL, 'p'}, 368 {"socket", required_argument, NULL, 'p'},
369 {"no-unlock-indicator", no_argument, NULL, 'u'}, 369 {"no-unlock-indicator", no_argument, NULL, 'u'},
370 {"daemonize", no_argument, NULL, 'f'}, 370 {"daemonize", no_argument, NULL, 'f'},
371 {"font", required_argument, NULL, 0}, 371 {"font", required_argument, NULL, 0},
372 {"line-uses-ring", no_argument, NULL, 0}, 372 {"line-uses-ring", no_argument, NULL, 'r'},
373 {"line-uses-inside", no_argument, NULL, 0}, 373 {"line-uses-inside", no_argument, NULL, 's'},
374 {"textcolor", required_argument, NULL, 0}, 374 {"textcolor", required_argument, NULL, 0},
375 {"insidevercolor", required_argument, NULL, 0}, 375 {"insidevercolor", required_argument, NULL, 0},
376 {"insidewrongcolor", required_argument, NULL, 0}, 376 {"insidewrongcolor", required_argument, NULL, 0},
@@ -388,27 +388,16 @@ int main(int argc, char **argv) {
388 const char *usage = 388 const char *usage =
389 "Usage: swaylock [options...]\n" 389 "Usage: swaylock [options...]\n"
390 "\n" 390 "\n"
391 " -h, --help Show help message and quit.\n" 391 " -h, --help Show help message and quit.\n"
392 " -c, --color <rrggbb[aa]> Turn the screen into the given color instead of white.\n" 392 " -c, --color <rrggbb[aa]> Turn the screen into the given color instead of white.\n"
393 " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n" 393 " --scaling Scaling mode: stretch, fill, fit, center, tile.\n"
394 " -t, --tiling Same as --scaling=tile.\n" 394 " -t, --tiling Same as --scaling=tile.\n"
395 " -v, --version Show the version number and quit.\n" 395 " -v, --version Show the version number and quit.\n"
396 " -i, --image [<output>:]<path> Display the given image.\n" 396 " -i, --image [<output>:]<path> Display the given image.\n"
397 " -u, --no-unlock-indicator Disable the unlock indicator.\n" 397 " -u, --no-unlock-indicator Disable the unlock indicator.\n"
398 " -f, --daemonize Detach from the controlling terminal.\n" 398 " -f, --daemonize Detach from the controlling terminal.\n"
399 " --socket <socket> Use the specified socket.\n" 399 " --socket <socket> Use the specified socket.\n"
400 " --font <font> Use the specified font instead of sans-serif.\n" 400 " For more information see `man swaylock`\n";
401 " --textcolor <rrggbb[aa]> Sets the color of the text.\n"
402 " --insidevercolor <rrggbb[aa]> Sets the color of the verifying indicator circle.\n"
403 " --insidewrongcolor <rrggbb[aa]> Sets the color of the invalid indicator circle.\n"
404 " --insidecolor <rrggbb[aa]> Sets the color of the typing or idle indicator circle.\n"
405 " --ringvercolor <rrggbb[aa]> Sets the color of the verifying indicator ring.\n"
406 " --ringwrongcolor <rrggbb[aa]> Sets the color of the invalid indicator ring.\n"
407 " --ringcolor <rrggbb[aa]> Sets the color of the typing or idle indicator ring.\n"
408 " --linecolor <rrggbb[aa]> Sets the color of the line that separates the indicator.\n"
409 " --separatorcolor <rrggbb[aa]> Sets the color of the line that separates highlight segments.\n"
410 " --keyhlcolor <rrggbb[aa]> Sets the color of keypress highlight segments.\n"
411 " --bshlcolor <rrggbb[aa]> Sets the color of keypress highlight segments.\n";
412 401
413 402
414 registry = registry_poll(); 403 registry = registry_poll();
@@ -416,7 +405,7 @@ int main(int argc, char **argv) {
416 int c; 405 int c;
417 while (1) { 406 while (1) {
418 int option_index = 0; 407 int option_index = 0;
419 c = getopt_long(argc, argv, "hc:i:s:tvuf", long_options, &option_index); 408 c = getopt_long(argc, argv, "hc:i:srtvuf", long_options, &option_index);
420 if (c == -1) { 409 if (c == -1) {
421 break; 410 break;
422 } 411 }
@@ -454,9 +443,6 @@ int main(int argc, char **argv) {
454 } 443 }
455 break; 444 break;
456 } 445 }
457 case 's':
458 scaling_mode_str = optarg;
459 break;
460 case 't': 446 case 't':
461 scaling_mode_str = "tile"; 447 scaling_mode_str = "tile";
462 break; 448 break;
@@ -480,56 +466,47 @@ int main(int argc, char **argv) {
480 exit(EXIT_FAILURE); 466 exit(EXIT_FAILURE);
481 } 467 }
482 break; 468 break;
469 case 'r':
470 if (line_source != LINE_SOURCE_DEFAULT) {
471 sway_log(L_ERROR, "line source options conflict");
472 exit(EXIT_FAILURE);
473 }
474 line_source = LINE_SOURCE_RING;
475 break;
476 case 's':
477 if (line_source != LINE_SOURCE_DEFAULT) {
478 sway_log(L_ERROR, "line source options conflict");
479 exit(EXIT_FAILURE);
480 }
481 line_source = LINE_SOURCE_INSIDE;
482 break;
483 case 0: 483 case 0:
484 if (strcmp(long_options[option_index].name, "font") == 0) { 484 if (strcmp(long_options[option_index].name, "font") == 0) {
485 free(config->font); 485 free(config->font);
486 config->font = strdup(optarg); 486 config->font = strdup(optarg);
487 } 487 } else if (strcmp(long_options[option_index].name, "scaling") == 0) {
488 else if (strcmp(long_options[option_index].name, "line-uses-ring") == 0) { 488 scaling_mode_str = optarg;
489 if (line_source != 0) { 489 } else if (strcmp(long_options[option_index].name, "textcolor") == 0) {
490 sway_log(L_ERROR, "Line source options conflict");
491 exit(EXIT_FAILURE);
492 }
493 line_source = 1;
494 }
495 else if (strcmp(long_options[option_index].name, "line-uses-inside") == 0) {
496 if (line_source != 0) {
497 sway_log(L_ERROR, "Line source options conflict");
498 exit(EXIT_FAILURE);
499 }
500 line_source = 2;
501 }
502 else if (strcmp(long_options[option_index].name, "textcolor") == 0) {
503 config->colors.text = parse_color(optarg); 490 config->colors.text = parse_color(optarg);
504 } 491 } else if (strcmp(long_options[option_index].name, "insidevercolor") == 0) {
505 else if (strcmp(long_options[option_index].name, "insidevercolor") == 0) {
506 config->colors.validating.inner_ring = parse_color(optarg); 492 config->colors.validating.inner_ring = parse_color(optarg);
507 } 493 } else if (strcmp(long_options[option_index].name, "insidewrongcolor") == 0) {
508 else if (strcmp(long_options[option_index].name, "insidewrongcolor") == 0) {
509 config->colors.invalid.inner_ring = parse_color(optarg); 494 config->colors.invalid.inner_ring = parse_color(optarg);
510 } 495 } else if (strcmp(long_options[option_index].name, "insidecolor") == 0) {
511 else if (strcmp(long_options[option_index].name, "insidecolor") == 0) {
512 config->colors.normal.inner_ring = parse_color(optarg); 496 config->colors.normal.inner_ring = parse_color(optarg);
513 } 497 } else if (strcmp(long_options[option_index].name, "ringvercolor") == 0) {
514 else if (strcmp(long_options[option_index].name, "ringvercolor") == 0) {
515 config->colors.validating.outer_ring = parse_color(optarg); 498 config->colors.validating.outer_ring = parse_color(optarg);
516 } 499 } else if (strcmp(long_options[option_index].name, "ringwrongcolor") == 0) {
517 else if (strcmp(long_options[option_index].name, "ringwrongcolor") == 0) {
518 config->colors.invalid.outer_ring = parse_color(optarg); 500 config->colors.invalid.outer_ring = parse_color(optarg);
519 } 501 } else if (strcmp(long_options[option_index].name, "ringcolor") == 0) {
520 else if (strcmp(long_options[option_index].name, "ringcolor") == 0) {
521 config->colors.normal.outer_ring = parse_color(optarg); 502 config->colors.normal.outer_ring = parse_color(optarg);
522 } 503 } else if (strcmp(long_options[option_index].name, "linecolor") == 0) {
523 else if (strcmp(long_options[option_index].name, "linecolor") == 0) {
524 config->colors.line = parse_color(optarg); 504 config->colors.line = parse_color(optarg);
525 } 505 } else if (strcmp(long_options[option_index].name, "separatorcolor") == 0) {
526 else if (strcmp(long_options[option_index].name, "separatorcolor") == 0) {
527 config->colors.separator = parse_color(optarg); 506 config->colors.separator = parse_color(optarg);
528 } 507 } else if (strcmp(long_options[option_index].name, "keyhlcolor") == 0) {
529 else if (strcmp(long_options[option_index].name, "keyhlcolor") == 0) {
530 config->colors.input_cursor = parse_color(optarg); 508 config->colors.input_cursor = parse_color(optarg);
531 } 509 } else if (strcmp(long_options[option_index].name, "bshlcolor") == 0) {
532 else if (strcmp(long_options[option_index].name, "bshlcolor") == 0) {
533 config->colors.backspace_cursor = parse_color(optarg); 510 config->colors.backspace_cursor = parse_color(optarg);
534 } 511 }
535 break; 512 break;
@@ -783,39 +760,35 @@ void render(struct render_data *render_data, struct lock_config *config) {
783 cairo_stroke(window->cairo); 760 cairo_stroke(window->cairo);
784 } 761 }
785 762
786 if (line_source == 1) { 763 switch(line_source) {
764 case LINE_SOURCE_RING:
787 switch(render_data->auth_state) { 765 switch(render_data->auth_state) {
788 case AUTH_STATE_VALIDATING: { 766 case AUTH_STATE_VALIDATING:
789 cairo_set_source_u32(window->cairo, config->colors.validating.outer_ring); 767 cairo_set_source_u32(window->cairo, config->colors.validating.outer_ring);
790 break; 768 break;
791 } 769 case AUTH_STATE_INVALID:
792 case AUTH_STATE_INVALID: {
793 cairo_set_source_u32(window->cairo, config->colors.invalid.outer_ring); 770 cairo_set_source_u32(window->cairo, config->colors.invalid.outer_ring);
794 break; 771 break;
795 } 772 default:
796 default: {
797 cairo_set_source_u32(window->cairo, config->colors.normal.outer_ring); 773 cairo_set_source_u32(window->cairo, config->colors.normal.outer_ring);
798 } 774 }
799 } 775 break;
800 } 776 case LINE_SOURCE_INSIDE:
801 else if (line_source == 2) {
802 switch(render_data->auth_state) { 777 switch(render_data->auth_state) {
803 case AUTH_STATE_VALIDATING: { 778 case AUTH_STATE_VALIDATING:
804 cairo_set_source_u32(window->cairo, config->colors.validating.inner_ring); 779 cairo_set_source_u32(window->cairo, config->colors.validating.inner_ring);
805 break; 780 break;
806 } 781 case AUTH_STATE_INVALID:
807 case AUTH_STATE_INVALID: {
808 cairo_set_source_u32(window->cairo, config->colors.invalid.inner_ring); 782 cairo_set_source_u32(window->cairo, config->colors.invalid.inner_ring);
809 break; 783 break;
810 } 784 default:
811 default: {
812 cairo_set_source_u32(window->cairo, config->colors.normal.inner_ring); 785 cairo_set_source_u32(window->cairo, config->colors.normal.inner_ring);
813 break; 786 break;
814 } 787 }
815 } 788 break;
816 } 789 default:
817 else {
818 cairo_set_source_u32(window->cairo, config->colors.line); 790 cairo_set_source_u32(window->cairo, config->colors.line);
791 break;
819 } 792 }
820 // Draw inner + outer border of the circle 793 // Draw inner + outer border of the circle
821 cairo_set_line_width(window->cairo, 2.0); 794 cairo_set_line_width(window->cairo, 2.0);