summaryrefslogtreecommitdiffstats
path: root/swaylock/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaylock/main.c')
-rw-r--r--swaylock/main.c284
1 files changed, 261 insertions, 23 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 68d67a10..faebc757 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -89,7 +89,7 @@ static bool surface_is_opaque(struct swaylock_surface *surface) {
89 if (surface->image) { 89 if (surface->image) {
90 return cairo_surface_get_content(surface->image) == CAIRO_CONTENT_COLOR; 90 return cairo_surface_get_content(surface->image) == CAIRO_CONTENT_COLOR;
91 } 91 }
92 return (surface->state->args.color & 0xff) == 0xff; 92 return (surface->state->args.colors.background & 0xff) == 0xff;
93} 93}
94 94
95static void create_layer_surface(struct swaylock_surface *surface) { 95static void create_layer_surface(struct swaylock_surface *surface) {
@@ -381,59 +381,225 @@ static void load_image(char *arg, struct swaylock_state *state) {
381 image->path, image->output_name ? image->output_name : "*"); 381 image->path, image->output_name ? image->output_name : "*");
382} 382}
383 383
384static void set_default_colors(struct swaylock_colors *colors) {
385 colors->background = 0xFFFFFFFF;
386 colors->bs_highlight = 0xDB3300FF;
387 colors->key_highlight = 0x33DB00FF;
388 colors->separator = 0x000000FF;
389 colors->inside = (struct swaylock_colorset){
390 .input = 0x000000C0,
391 .cleared = 0xE5A445C0,
392 .verifying = 0x0072FFC0,
393 .wrong = 0xFA0000C0,
394 };
395 colors->line = (struct swaylock_colorset){
396 .input = 0x000000FF,
397 .cleared = 0x000000FF,
398 .verifying = 0x000000FF,
399 .wrong = 0x000000FF,
400 };
401 colors->ring = (struct swaylock_colorset){
402 .input = 0x337D00FF,
403 .cleared = 0xE5A445FF,
404 .verifying = 0x3300FFFF,
405 .wrong = 0x7D3300FF,
406 };
407 colors->text = (struct swaylock_colorset){
408 .input = 0xE5A445FF,
409 .cleared = 0x000000FF,
410 .verifying = 0x000000FF,
411 .wrong = 0x000000FF,
412 };
413}
414
384static struct swaylock_state state; 415static struct swaylock_state state;
385 416
386int main(int argc, char **argv) { 417int main(int argc, char **argv) {
418 enum line_mode {
419 LM_LINE,
420 LM_INSIDE,
421 LM_RING,
422 };
423
424 enum long_option_codes {
425 LO_BS_HL_COLOR = 256,
426 LO_FONT,
427 LO_IND_RADIUS,
428 LO_IND_THICKNESS,
429 LO_INSIDE_COLOR,
430 LO_INSIDE_CLEAR_COLOR,
431 LO_INSIDE_VER_COLOR,
432 LO_INSIDE_WRONG_COLOR,
433 LO_KEY_HL_COLOR,
434 LO_LINE_COLOR,
435 LO_LINE_CLEAR_COLOR,
436 LO_LINE_VER_COLOR,
437 LO_LINE_WRONG_COLOR,
438 LO_RING_COLOR,
439 LO_RING_CLEAR_COLOR,
440 LO_RING_VER_COLOR,
441 LO_RING_WRONG_COLOR,
442 LO_SEP_COLOR,
443 LO_TEXT_COLOR,
444 LO_TEXT_CLEAR_COLOR,
445 LO_TEXT_VER_COLOR,
446 LO_TEXT_WRONG_COLOR,
447 };
448
387 static struct option long_options[] = { 449 static struct option long_options[] = {
388 {"help", no_argument, NULL, 'h'},
389 {"color", required_argument, NULL, 'c'}, 450 {"color", required_argument, NULL, 'c'},
451 {"ignore-empty-password", no_argument, NULL, 'e'},
452 {"daemonize", no_argument, NULL, 'f'},
453 {"help", no_argument, NULL, 'h'},
390 {"image", required_argument, NULL, 'i'}, 454 {"image", required_argument, NULL, 'i'},
455 {"line-uses-inside", no_argument, NULL, 'n'},
456 {"socket", required_argument, NULL, 'p'},
457 {"line-uses-ring", no_argument, NULL, 'r'},
391 {"scaling", required_argument, NULL, 's'}, 458 {"scaling", required_argument, NULL, 's'},
392 {"tiling", no_argument, NULL, 't'}, 459 {"tiling", no_argument, NULL, 't'},
393 {"version", no_argument, NULL, 'v'},
394 {"socket", required_argument, NULL, 'p'},
395 {"no-unlock-indicator", no_argument, NULL, 'u'}, 460 {"no-unlock-indicator", no_argument, NULL, 'u'},
396 {"daemonize", no_argument, NULL, 'f'}, 461 {"version", no_argument, NULL, 'v'},
462 {"bs-hl-color", required_argument, NULL, LO_BS_HL_COLOR},
463 {"font", required_argument, NULL, LO_FONT},
464 {"indicator-radius", required_argument, NULL, LO_IND_RADIUS},
465 {"indicator-thickness", required_argument, NULL, LO_IND_THICKNESS},
466 {"inside-color", required_argument, NULL, LO_INSIDE_COLOR},
467 {"inside-clear-color", required_argument, NULL, LO_INSIDE_CLEAR_COLOR},
468 {"inside-ver-color", required_argument, NULL, LO_INSIDE_VER_COLOR},
469 {"inside-wrong-color", required_argument, NULL, LO_INSIDE_WRONG_COLOR},
470 {"key-hl-color", required_argument, NULL, LO_KEY_HL_COLOR},
471 {"line-color", required_argument, NULL, LO_LINE_COLOR},
472 {"line-clear-color", required_argument, NULL, LO_LINE_CLEAR_COLOR},
473 {"line-ver-color", required_argument, NULL, LO_LINE_VER_COLOR},
474 {"line-wrong-color", required_argument, NULL, LO_LINE_WRONG_COLOR},
475 {"ring-color", required_argument, NULL, LO_RING_COLOR},
476 {"ring-clear-color", required_argument, NULL, LO_RING_CLEAR_COLOR},
477 {"ring-ver-color", required_argument, NULL, LO_RING_VER_COLOR},
478 {"ring-wrong-color", required_argument, NULL, LO_RING_WRONG_COLOR},
479 {"separator-color", required_argument, NULL, LO_SEP_COLOR},
480 {"text-color", required_argument, NULL, LO_TEXT_COLOR},
481 {"text-clear-color", required_argument, NULL, LO_TEXT_CLEAR_COLOR},
482 {"text-ver-color", required_argument, NULL, LO_TEXT_VER_COLOR},
483 {"text-wrong-color", required_argument, NULL, LO_TEXT_WRONG_COLOR},
397 {0, 0, 0, 0} 484 {0, 0, 0, 0}
398 }; 485 };
399 486
400 const char usage[] = 487 const char usage[] =
401 "Usage: swaylock [options...]\n" 488 "Usage: swaylock [options...]\n"
402 "\n" 489 "\n"
403 " -h, --help Show help message and quit.\n" 490 " -c, --color <color> "
404 " -c, --color <rrggbb[aa]> Turn the screen into the given color instead of white.\n" 491 "Turn the screen into the given color instead of white.\n"
405 " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n" 492 " -e, --ignore-empty-password "
406 " -t, --tiling Same as --scaling=tile.\n" 493 "When an empty password is provided, do not validate it.\n"
407 " -v, --version Show the version number and quit.\n" 494 " -f, --daemonize "
408 " -i, --image [<output>:]<path> Display the given image.\n" 495 "Detach from the controlling terminal after locking.\n"
409 " -u, --no-unlock-indicator Disable the unlock indicator.\n" 496 " -h, --help "
410 " -f, --daemonize Detach from the controlling terminal after locking.\n"; 497 "Show help message and quit.\n"
498 " -i, --image [<output>:]<path> "
499 "Display the given image.\n"
500 " -s, --scaling <mode> "
501 "Scaling mode: stretch, fill, fit, center, tile.\n"
502 " -t, --tiling "
503 "Same as --scaling=tile.\n"
504 " -u, --no-unlock-indicator "
505 "Disable the unlock indicator.\n"
506 " -v, --version "
507 "Show the version number and quit.\n"
508 " --bs-hl-color <color> "
509 "Sets the color of backspace highlight segments.\n"
510 " --font <font> "
511 "Sets the font of the text.\n"
512 " --indicator-radius <radius> "
513 "Sets the indicator radius.\n"
514 " --indicator-thickness <thick> "
515 "Sets the indicator thickness.\n"
516 " --inside-color <color> "
517 "Sets the color of the inside of the indicator.\n"
518 " --inside-clear-color <color> "
519 "Sets the color of the inside of the indicator when cleared.\n"
520 " --inside-ver-color <color> "
521 "Sets the color of the inside of the indicator when verifying.\n"
522 " --inside-wrong-color <color> "
523 "Sets the color of the inside of the indicator when invalid.\n"
524 " --key-hl-color <color> "
525 "Sets the color of the key press highlight segments.\n"
526 " --line-color <color> "
527 "Sets the color of the line between the inside and ring.\n"
528 " --line-clear-color <color> "
529 "Sets the color of the line between the inside and ring when "
530 "cleared.\n"
531 " --line-ver-color <color> "
532 "Sets the color of the line between the inside and ring when "
533 "verifying.\n"
534 " --line-wrong-color <color> "
535 "Sets the color of the line between the inside and ring when "
536 "invalid.\n"
537 " -n, --line-uses-inside "
538 "Use the inside color for the line between the inside and ring.\n"
539 " -r, --line-uses-ring "
540 "Use the ring color for the line between the inside and ring.\n"
541 " --ring-color <color> "
542 "Sets the color of the ring of the indicator.\n"
543 " --ring-clear-color <color> "
544 "Sets the color of the ring of the indicator when cleared.\n"
545 " --ring-ver-color <color> "
546 "Sets the color of the ring of the indicator when verifying.\n"
547 " --ring-wrong-color <color> "
548 "Sets the color of the ring of the indicator when invalid.\n"
549 " --separator-color <color> "
550 "Sets the color of the lines that separate highlight segments.\n"
551 " --text-color <color> "
552 "Sets the color of the text.\n"
553 " --text-clear-color <color> "
554 "Sets the color of the text when cleared.\n"
555 " --text-ver-color <color> "
556 "Sets the color of the text when verifying.\n"
557 " --text-wrong-color <color> "
558 "Sets the color of the text when invalid.\n"
559 "\n"
560 "All <color> options are of the form <rrggbb[aa]>.\n";
411 561
562 enum line_mode line_mode = LM_LINE;
412 state.args = (struct swaylock_args){ 563 state.args = (struct swaylock_args){
413 .mode = BACKGROUND_MODE_SOLID_COLOR, 564 .mode = BACKGROUND_MODE_SOLID_COLOR,
414 .color = 0xFFFFFFFF, 565 .font = strdup("sans-serif"),
566 .radius = 50,
567 .thickness = 10,
568 .ignore_empty = false,
415 .show_indicator = true, 569 .show_indicator = true,
416 }; 570 };
417 wl_list_init(&state.images); 571 wl_list_init(&state.images);
572 set_default_colors(&state.args.colors);
418 573
419 wlr_log_init(WLR_DEBUG, NULL); 574 wlr_log_init(WLR_DEBUG, NULL);
420 575
421 int c; 576 int c;
422 while (1) { 577 while (1) {
423 int option_index = 0; 578 int opt_idx = 0;
424 c = getopt_long(argc, argv, "hc:i:s:tvuf", long_options, &option_index); 579 c = getopt_long(argc, argv, "c:efhi:nrs:tuv", long_options, &opt_idx);
425 if (c == -1) { 580 if (c == -1) {
426 break; 581 break;
427 } 582 }
428 switch (c) { 583 switch (c) {
429 case 'c': { 584 case 'c':
430 state.args.color = parse_color(optarg); 585 state.args.colors.background = parse_color(optarg);
431 state.args.mode = BACKGROUND_MODE_SOLID_COLOR; 586 state.args.mode = BACKGROUND_MODE_SOLID_COLOR;
432 break; 587 break;
433 } 588 case 'e':
589 state.args.ignore_empty = true;
590 break;
591 case 'f':
592 state.args.daemonize = true;
593 break;
434 case 'i': 594 case 'i':
435 load_image(optarg, &state); 595 load_image(optarg, &state);
436 break; 596 break;
597 case 'n':
598 line_mode = LM_INSIDE;
599 break;
600 case 'r':
601 line_mode = LM_RING;
602 break;
437 case 's': 603 case 's':
438 state.args.mode = parse_background_mode(optarg); 604 state.args.mode = parse_background_mode(optarg);
439 if (state.args.mode == BACKGROUND_MODE_INVALID) { 605 if (state.args.mode == BACKGROUND_MODE_INVALID) {
@@ -443,6 +609,9 @@ int main(int argc, char **argv) {
443 case 't': 609 case 't':
444 state.args.mode = BACKGROUND_MODE_TILE; 610 state.args.mode = BACKGROUND_MODE_TILE;
445 break; 611 break;
612 case 'u':
613 state.args.show_indicator = false;
614 break;
446 case 'v': 615 case 'v':
447#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE 616#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
448 fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", 617 fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n",
@@ -451,11 +620,72 @@ int main(int argc, char **argv) {
451 fprintf(stdout, "version unknown\n"); 620 fprintf(stdout, "version unknown\n");
452#endif 621#endif
453 return 0; 622 return 0;
454 case 'u': 623 case LO_BS_HL_COLOR:
455 state.args.show_indicator = false; 624 state.args.colors.bs_highlight = parse_color(optarg);
456 break; 625 break;
457 case 'f': 626 case LO_FONT:
458 state.args.daemonize = true; 627 free(state.args.font);
628 state.args.font = strdup(optarg);
629 break;
630 case LO_IND_RADIUS:
631 state.args.radius = strtol(optarg, NULL, 0);
632 break;
633 case LO_IND_THICKNESS:
634 state.args.thickness = strtol(optarg, NULL, 0);
635 break;
636 case LO_INSIDE_COLOR:
637 state.args.colors.inside.input = parse_color(optarg);
638 break;
639 case LO_INSIDE_CLEAR_COLOR:
640 state.args.colors.inside.cleared = parse_color(optarg);
641 break;
642 case LO_INSIDE_VER_COLOR:
643 state.args.colors.inside.verifying = parse_color(optarg);
644 break;
645 case LO_INSIDE_WRONG_COLOR:
646 state.args.colors.inside.wrong = parse_color(optarg);
647 break;
648 case LO_KEY_HL_COLOR:
649 state.args.colors.key_highlight = parse_color(optarg);
650 break;
651 case LO_LINE_COLOR:
652 state.args.colors.line.input = parse_color(optarg);
653 break;
654 case LO_LINE_CLEAR_COLOR:
655 state.args.colors.line.cleared = parse_color(optarg);
656 break;
657 case LO_LINE_VER_COLOR:
658 state.args.colors.line.verifying = parse_color(optarg);
659 break;
660 case LO_LINE_WRONG_COLOR:
661 state.args.colors.line.wrong = parse_color(optarg);
662 break;
663 case LO_RING_COLOR:
664 state.args.colors.ring.input = parse_color(optarg);
665 break;
666 case LO_RING_CLEAR_COLOR:
667 state.args.colors.ring.cleared = parse_color(optarg);
668 break;
669 case LO_RING_VER_COLOR:
670 state.args.colors.ring.verifying = parse_color(optarg);
671 break;
672 case LO_RING_WRONG_COLOR:
673 state.args.colors.ring.wrong = parse_color(optarg);
674 break;
675 case LO_SEP_COLOR:
676 state.args.colors.separator = parse_color(optarg);
677 break;
678 case LO_TEXT_COLOR:
679 state.args.colors.text.input = parse_color(optarg);
680 break;
681 case LO_TEXT_CLEAR_COLOR:
682 state.args.colors.text.cleared = parse_color(optarg);
683 break;
684 case LO_TEXT_VER_COLOR:
685 state.args.colors.text.verifying = parse_color(optarg);
686 break;
687 case LO_TEXT_WRONG_COLOR:
688 state.args.colors.text.wrong = parse_color(optarg);
459 break; 689 break;
460 default: 690 default:
461 fprintf(stderr, "%s", usage); 691 fprintf(stderr, "%s", usage);
@@ -463,6 +693,12 @@ int main(int argc, char **argv) {
463 } 693 }
464 } 694 }
465 695
696 if (line_mode == LM_INSIDE) {
697 state.args.colors.line = state.args.colors.inside;
698 } else if (line_mode == LM_RING) {
699 state.args.colors.line = state.args.colors.ring;
700 }
701
466#ifdef __linux__ 702#ifdef __linux__
467 // Most non-linux platforms require root to mlock() 703 // Most non-linux platforms require root to mlock()
468 if (mlock(state.password.buffer, sizeof(state.password.buffer)) != 0) { 704 if (mlock(state.password.buffer, sizeof(state.password.buffer)) != 0) {
@@ -520,5 +756,7 @@ int main(int argc, char **argv) {
520 while (wl_display_dispatch(state.display) != -1 && state.run_display) { 756 while (wl_display_dispatch(state.display) != -1 && state.run_display) {
521 // This space intentionally left blank 757 // This space intentionally left blank
522 } 758 }
759
760 free(state.args.font);
523 return 0; 761 return 0;
524} 762}