summaryrefslogtreecommitdiffstats
path: root/swaylock/main.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-10 21:29:15 -0400
committerLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-07-10 21:29:15 -0400
commit936a920a8e95c001c86b9186d36fa652f874287d (patch)
treec56b4475f38f6ad5b783434dc609f0cfabeeec8a /swaylock/main.c
parentMerge pull request #2233 from emersion/remove-clipboard (diff)
downloadsway-936a920a8e95c001c86b9186d36fa652f874287d.tar.gz
sway-936a920a8e95c001c86b9186d36fa652f874287d.tar.zst
sway-936a920a8e95c001c86b9186d36fa652f874287d.zip
Implement swaylock customization flags
Diffstat (limited to 'swaylock/main.c')
-rw-r--r--swaylock/main.c266
1 files changed, 246 insertions, 20 deletions
diff --git a/swaylock/main.c b/swaylock/main.c
index 68d67a10..abdb00f5 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,213 @@ 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"
490 " -c, --color <color> Turn the screen into the given color"
491 " instead of white.\n"
492 " -e, --ignore-empty-password When an empty password is provided"
493 " by the user, do not validate it.\n"
494 " -f, --daemonize Detach from the controlling terminal"
495 " after locking.\n"
403 " -h, --help Show help message and quit.\n" 496 " -h, --help Show help message and quit.\n"
404 " -c, --color <rrggbb[aa]> Turn the screen into the given color instead of white.\n"
405 " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n"
406 " -t, --tiling Same as --scaling=tile.\n"
407 " -v, --version Show the version number and quit.\n"
408 " -i, --image [<output>:]<path> Display the given image.\n" 497 " -i, --image [<output>:]<path> Display the given image.\n"
498 " -s, --scaling <mode> Scaling mode: stretch, fill, fit,"
499 " center, tile.\n"
500 " -t, --tiling Same as --scaling=tile.\n"
409 " -u, --no-unlock-indicator Disable the unlock indicator.\n" 501 " -u, --no-unlock-indicator Disable the unlock indicator.\n"
410 " -f, --daemonize Detach from the controlling terminal after locking.\n"; 502 " -v, --version Show the version number and quit.\n"
503 " --bs-hl-color <color> Sets the color of backspace"
504 " highlight segments.\n"
505 " --font <font> Sets the font of the text.\n"
506 " --indicator-radius <radius> Sets the indicator radius.\n"
507 " --indicator-thickness <thick> Sets the indicator thickness.\n"
508 " --inside-color <color> Sets the color of the inside of the"
509 " indicator.\n"
510 " --inside-clear-color <color> Sets the color of the inside of the"
511 " indicator when cleared.\n"
512 " --inside-ver-color <color> Sets the color of the inside of the"
513 " indicator when verifying.\n"
514 " --inside-wrong-color <color> Sets the color of the inside of the"
515 " indicator when invalid.\n"
516 " --key-hl-color <color> Sets the color of the key press"
517 " highlight segments.\n"
518 " --line-color <color> Sets the color of the line between"
519 " the inside and ring.\n"
520 " --line-clear-color <color> Sets the color of the line between"
521 " the inside and ring when cleared.\n"
522 " --line-ver-color <color> Sets the color of the line between"
523 " the inside and ring when verifying.\n"
524 " --line-wrong-color <color> Sets the color of the line between"
525 " the inside and ring when invalid.\n"
526 " -n, --line-uses-inside Use the inside color for the line"
527 " between the inside and ring.\n"
528 " -r, --line-uses-ring Use the ring color for the line"
529 " between the inside and ring.\n"
530 " --ring-color <color> Sets the color of the ring of the"
531 " indicator.\n"
532 " --ring-clear-color <color> Sets the color of the ring of the"
533 " indicator when cleared.\n"
534 " --ring-ver-color <color> Sets the color of the ring of the"
535 " indicator when verifying.\n"
536 " --ring-wrong-color <color> Sets the color of the ring of the"
537 " indicator when invalid.\n"
538 " --separator-color <color> Sets the color of the lines that"
539 " separate highlight segments.\n"
540 " --text-color <color> Sets the color of the text.\n"
541 " --text-clear-color <color> Sets the color of the text when"
542 " cleared.\n"
543 " --text-ver-color <color> Sets the color of the text when"
544 " verifying.\n"
545 " --text-wrong-color <color> Sets the color of the text when"
546 " invalid.\n"
547 "\n"
548 "All <color> options are of the form <rrggbb[aa]>.\n";
411 549
550 enum line_mode line_mode = LM_LINE;
412 state.args = (struct swaylock_args){ 551 state.args = (struct swaylock_args){
413 .mode = BACKGROUND_MODE_SOLID_COLOR, 552 .mode = BACKGROUND_MODE_SOLID_COLOR,
414 .color = 0xFFFFFFFF, 553 .font = strdup("sans-serif"),
554 .radius = 50,
555 .thickness = 10,
556 .ignore_empty = false,
415 .show_indicator = true, 557 .show_indicator = true,
416 }; 558 };
417 wl_list_init(&state.images); 559 wl_list_init(&state.images);
560 set_default_colors(&state.args.colors);
418 561
419 wlr_log_init(WLR_DEBUG, NULL); 562 wlr_log_init(WLR_DEBUG, NULL);
420 563
421 int c; 564 int c;
422 while (1) { 565 while (1) {
423 int option_index = 0; 566 int opt_idx = 0;
424 c = getopt_long(argc, argv, "hc:i:s:tvuf", long_options, &option_index); 567 c = getopt_long(argc, argv, "c:efhi:nrs:tuv", long_options, &opt_idx);
425 if (c == -1) { 568 if (c == -1) {
426 break; 569 break;
427 } 570 }
428 switch (c) { 571 switch (c) {
429 case 'c': { 572 case 'c':
430 state.args.color = parse_color(optarg); 573 state.args.colors.background = parse_color(optarg);
431 state.args.mode = BACKGROUND_MODE_SOLID_COLOR; 574 state.args.mode = BACKGROUND_MODE_SOLID_COLOR;
432 break; 575 break;
433 } 576 case 'e':
577 state.args.ignore_empty = true;
578 break;
579 case 'f':
580 state.args.daemonize = true;
581 break;
434 case 'i': 582 case 'i':
435 load_image(optarg, &state); 583 load_image(optarg, &state);
436 break; 584 break;
585 case 'n':
586 line_mode = LM_INSIDE;
587 break;
588 case 'r':
589 line_mode = LM_RING;
590 break;
437 case 's': 591 case 's':
438 state.args.mode = parse_background_mode(optarg); 592 state.args.mode = parse_background_mode(optarg);
439 if (state.args.mode == BACKGROUND_MODE_INVALID) { 593 if (state.args.mode == BACKGROUND_MODE_INVALID) {
@@ -443,6 +597,9 @@ int main(int argc, char **argv) {
443 case 't': 597 case 't':
444 state.args.mode = BACKGROUND_MODE_TILE; 598 state.args.mode = BACKGROUND_MODE_TILE;
445 break; 599 break;
600 case 'u':
601 state.args.show_indicator = false;
602 break;
446 case 'v': 603 case 'v':
447#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE 604#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE
448 fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n", 605 fprintf(stdout, "swaylock version %s (%s, branch \"%s\")\n",
@@ -451,11 +608,72 @@ int main(int argc, char **argv) {
451 fprintf(stdout, "version unknown\n"); 608 fprintf(stdout, "version unknown\n");
452#endif 609#endif
453 return 0; 610 return 0;
454 case 'u': 611 case LO_BS_HL_COLOR:
455 state.args.show_indicator = false; 612 state.args.colors.bs_highlight = parse_color(optarg);
456 break; 613 break;
457 case 'f': 614 case LO_FONT:
458 state.args.daemonize = true; 615 free(state.args.font);
616 state.args.font = strdup(optarg);
617 break;
618 case LO_IND_RADIUS:
619 state.args.radius = strtol(optarg, NULL, 0);
620 break;
621 case LO_IND_THICKNESS:
622 state.args.thickness = strtol(optarg, NULL, 0);
623 break;
624 case LO_INSIDE_COLOR:
625 state.args.colors.inside.input = parse_color(optarg);
626 break;
627 case LO_INSIDE_CLEAR_COLOR:
628 state.args.colors.inside.cleared = parse_color(optarg);
629 break;
630 case LO_INSIDE_VER_COLOR:
631 state.args.colors.inside.verifying = parse_color(optarg);
632 break;
633 case LO_INSIDE_WRONG_COLOR:
634 state.args.colors.inside.wrong = parse_color(optarg);
635 break;
636 case LO_KEY_HL_COLOR:
637 state.args.colors.key_highlight = parse_color(optarg);
638 break;
639 case LO_LINE_COLOR:
640 state.args.colors.line.input = parse_color(optarg);
641 break;
642 case LO_LINE_CLEAR_COLOR:
643 state.args.colors.line.cleared = parse_color(optarg);
644 break;
645 case LO_LINE_VER_COLOR:
646 state.args.colors.line.verifying = parse_color(optarg);
647 break;
648 case LO_LINE_WRONG_COLOR:
649 state.args.colors.line.wrong = parse_color(optarg);
650 break;
651 case LO_RING_COLOR:
652 state.args.colors.ring.input = parse_color(optarg);
653 break;
654 case LO_RING_CLEAR_COLOR:
655 state.args.colors.ring.cleared = parse_color(optarg);
656 break;
657 case LO_RING_VER_COLOR:
658 state.args.colors.ring.verifying = parse_color(optarg);
659 break;
660 case LO_RING_WRONG_COLOR:
661 state.args.colors.ring.wrong = parse_color(optarg);
662 break;
663 case LO_SEP_COLOR:
664 state.args.colors.separator = parse_color(optarg);
665 break;
666 case LO_TEXT_COLOR:
667 state.args.colors.text.input = parse_color(optarg);
668 break;
669 case LO_TEXT_CLEAR_COLOR:
670 state.args.colors.text.cleared = parse_color(optarg);
671 break;
672 case LO_TEXT_VER_COLOR:
673 state.args.colors.text.verifying = parse_color(optarg);
674 break;
675 case LO_TEXT_WRONG_COLOR:
676 state.args.colors.text.wrong = parse_color(optarg);
459 break; 677 break;
460 default: 678 default:
461 fprintf(stderr, "%s", usage); 679 fprintf(stderr, "%s", usage);
@@ -463,6 +681,12 @@ int main(int argc, char **argv) {
463 } 681 }
464 } 682 }
465 683
684 if (line_mode == LM_INSIDE) {
685 state.args.colors.line = state.args.colors.inside;
686 } else if (line_mode == LM_RING) {
687 state.args.colors.line = state.args.colors.ring;
688 }
689
466#ifdef __linux__ 690#ifdef __linux__
467 // Most non-linux platforms require root to mlock() 691 // Most non-linux platforms require root to mlock()
468 if (mlock(state.password.buffer, sizeof(state.password.buffer)) != 0) { 692 if (mlock(state.password.buffer, sizeof(state.password.buffer)) != 0) {
@@ -520,5 +744,7 @@ int main(int argc, char **argv) {
520 while (wl_display_dispatch(state.display) != -1 && state.run_display) { 744 while (wl_display_dispatch(state.display) != -1 && state.run_display) {
521 // This space intentionally left blank 745 // This space intentionally left blank
522 } 746 }
747
748 free(state.args.font);
523 return 0; 749 return 0;
524} 750}