diff options
author | 2018-07-17 19:52:12 -0700 | |
---|---|---|
committer | 2018-07-17 19:52:12 -0700 | |
commit | 81e4bbf8b26a836b5f0fe83687658e854ca6a11e (patch) | |
tree | c46630987b3ad73b03f214d5ea751a0337186be4 /swaylock/main.c | |
parent | Merge pull request #2229 from vilhalmer/destroy-output-destroy-empty-workspaces (diff) | |
parent | Fix swaylock arguments (diff) | |
download | sway-81e4bbf8b26a836b5f0fe83687658e854ca6a11e.tar.gz sway-81e4bbf8b26a836b5f0fe83687658e854ca6a11e.tar.zst sway-81e4bbf8b26a836b5f0fe83687658e854ca6a11e.zip |
Merge pull request #2294 from RedSoxFan/fix-swaylock-args
Fix swaylock arguments
Diffstat (limited to 'swaylock/main.c')
-rw-r--r-- | swaylock/main.c | 187 |
1 files changed, 123 insertions, 64 deletions
diff --git a/swaylock/main.c b/swaylock/main.c index ae5b86b9..668a8742 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -345,22 +345,25 @@ static void load_image(char *arg, struct swaylock_state *state) { | |||
345 | image->path = strdup(arg); | 345 | image->path = strdup(arg); |
346 | } | 346 | } |
347 | 347 | ||
348 | bool exists = false; | 348 | struct swaylock_image *iter_image, *temp; |
349 | struct swaylock_image *iter_image; | 349 | wl_list_for_each_safe(iter_image, temp, &state->images, link) { |
350 | wl_list_for_each(iter_image, &state->images, link) { | ||
351 | if (lenient_strcmp(iter_image->output_name, image->output_name) == 0) { | 350 | if (lenient_strcmp(iter_image->output_name, image->output_name) == 0) { |
352 | exists = true; | 351 | if (image->output_name) { |
352 | wlr_log(WLR_DEBUG, | ||
353 | "Replacing image defined for output %s with %s", | ||
354 | image->output_name, image->path); | ||
355 | } else { | ||
356 | wlr_log(WLR_DEBUG, "Replacing default image with %s", | ||
357 | image->path); | ||
358 | } | ||
359 | wl_list_remove(&iter_image->link); | ||
360 | free(iter_image->cairo_surface); | ||
361 | free(iter_image->output_name); | ||
362 | free(iter_image->path); | ||
363 | free(iter_image); | ||
353 | break; | 364 | break; |
354 | } | 365 | } |
355 | } | 366 | } |
356 | if (exists) { | ||
357 | if (image->output_name) { | ||
358 | wlr_log(WLR_ERROR, "Multiple images defined for output %s", | ||
359 | image->output_name); | ||
360 | } else { | ||
361 | wlr_log(WLR_ERROR, "Multiple default images defined"); | ||
362 | } | ||
363 | } | ||
364 | 367 | ||
365 | // Bash doesn't replace the ~ with $HOME if the output name is supplied | 368 | // Bash doesn't replace the ~ with $HOME if the output name is supplied |
366 | wordexp_t p; | 369 | wordexp_t p; |
@@ -420,7 +423,7 @@ enum line_mode { | |||
420 | }; | 423 | }; |
421 | 424 | ||
422 | static int parse_options(int argc, char **argv, struct swaylock_state *state, | 425 | static int parse_options(int argc, char **argv, struct swaylock_state *state, |
423 | enum line_mode *line_mode) { | 426 | enum line_mode *line_mode, char **config_path) { |
424 | enum long_option_codes { | 427 | enum long_option_codes { |
425 | LO_BS_HL_COLOR = 256, | 428 | LO_BS_HL_COLOR = 256, |
426 | LO_FONT, | 429 | LO_FONT, |
@@ -572,38 +575,58 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, | |||
572 | } | 575 | } |
573 | switch (c) { | 576 | switch (c) { |
574 | case 'C': | 577 | case 'C': |
575 | // Config file. This will have already been handled so just ignore. | 578 | if (config_path) { |
579 | *config_path = strdup(optarg); | ||
580 | } | ||
576 | break; | 581 | break; |
577 | case 'c': | 582 | case 'c': |
578 | state->args.colors.background = parse_color(optarg); | 583 | if (state) { |
579 | state->args.mode = BACKGROUND_MODE_SOLID_COLOR; | 584 | state->args.colors.background = parse_color(optarg); |
585 | state->args.mode = BACKGROUND_MODE_SOLID_COLOR; | ||
586 | } | ||
580 | break; | 587 | break; |
581 | case 'e': | 588 | case 'e': |
582 | state->args.ignore_empty = true; | 589 | if (state) { |
590 | state->args.ignore_empty = true; | ||
591 | } | ||
583 | break; | 592 | break; |
584 | case 'f': | 593 | case 'f': |
585 | state->args.daemonize = true; | 594 | if (state) { |
595 | state->args.daemonize = true; | ||
596 | } | ||
586 | break; | 597 | break; |
587 | case 'i': | 598 | case 'i': |
588 | load_image(optarg, state); | 599 | if (state) { |
600 | load_image(optarg, state); | ||
601 | } | ||
589 | break; | 602 | break; |
590 | case 'n': | 603 | case 'n': |
591 | *line_mode = LM_INSIDE; | 604 | if (line_mode) { |
605 | *line_mode = LM_INSIDE; | ||
606 | } | ||
592 | break; | 607 | break; |
593 | case 'r': | 608 | case 'r': |
594 | *line_mode = LM_RING; | 609 | if (line_mode) { |
610 | *line_mode = LM_RING; | ||
611 | } | ||
595 | break; | 612 | break; |
596 | case 's': | 613 | case 's': |
597 | state->args.mode = parse_background_mode(optarg); | 614 | if (state) { |
598 | if (state->args.mode == BACKGROUND_MODE_INVALID) { | 615 | state->args.mode = parse_background_mode(optarg); |
599 | return 1; | 616 | if (state->args.mode == BACKGROUND_MODE_INVALID) { |
617 | return 1; | ||
618 | } | ||
600 | } | 619 | } |
601 | break; | 620 | break; |
602 | case 't': | 621 | case 't': |
603 | state->args.mode = BACKGROUND_MODE_TILE; | 622 | if (state) { |
623 | state->args.mode = BACKGROUND_MODE_TILE; | ||
624 | } | ||
604 | break; | 625 | break; |
605 | case 'u': | 626 | case 'u': |
606 | state->args.show_indicator = false; | 627 | if (state) { |
628 | state->args.show_indicator = false; | ||
629 | } | ||
607 | break; | 630 | break; |
608 | case 'v': | 631 | case 'v': |
609 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE | 632 | #if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE |
@@ -612,73 +635,117 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state, | |||
612 | #else | 635 | #else |
613 | fprintf(stdout, "version unknown\n"); | 636 | fprintf(stdout, "version unknown\n"); |
614 | #endif | 637 | #endif |
615 | return 0; | 638 | return 1; |
616 | case LO_BS_HL_COLOR: | 639 | case LO_BS_HL_COLOR: |
617 | state->args.colors.bs_highlight = parse_color(optarg); | 640 | if (state) { |
641 | state->args.colors.bs_highlight = parse_color(optarg); | ||
642 | } | ||
618 | break; | 643 | break; |
619 | case LO_FONT: | 644 | case LO_FONT: |
620 | free(state->args.font); | 645 | if (state) { |
621 | state->args.font = strdup(optarg); | 646 | free(state->args.font); |
647 | state->args.font = strdup(optarg); | ||
648 | } | ||
622 | break; | 649 | break; |
623 | case LO_IND_RADIUS: | 650 | case LO_IND_RADIUS: |
624 | state->args.radius = strtol(optarg, NULL, 0); | 651 | if (state) { |
652 | state->args.radius = strtol(optarg, NULL, 0); | ||
653 | } | ||
625 | break; | 654 | break; |
626 | case LO_IND_THICKNESS: | 655 | case LO_IND_THICKNESS: |
627 | state->args.thickness = strtol(optarg, NULL, 0); | 656 | if (state) { |
657 | state->args.thickness = strtol(optarg, NULL, 0); | ||
658 | } | ||
628 | break; | 659 | break; |
629 | case LO_INSIDE_COLOR: | 660 | case LO_INSIDE_COLOR: |
630 | state->args.colors.inside.input = parse_color(optarg); | 661 | if (state) { |
662 | state->args.colors.inside.input = parse_color(optarg); | ||
663 | } | ||
631 | break; | 664 | break; |
632 | case LO_INSIDE_CLEAR_COLOR: | 665 | case LO_INSIDE_CLEAR_COLOR: |
633 | state->args.colors.inside.cleared = parse_color(optarg); | 666 | if (state) { |
667 | state->args.colors.inside.cleared = parse_color(optarg); | ||
668 | } | ||
634 | break; | 669 | break; |
635 | case LO_INSIDE_VER_COLOR: | 670 | case LO_INSIDE_VER_COLOR: |
636 | state->args.colors.inside.verifying = parse_color(optarg); | 671 | if (state) { |
672 | state->args.colors.inside.verifying = parse_color(optarg); | ||
673 | } | ||
637 | break; | 674 | break; |
638 | case LO_INSIDE_WRONG_COLOR: | 675 | case LO_INSIDE_WRONG_COLOR: |
639 | state->args.colors.inside.wrong = parse_color(optarg); | 676 | if (state) { |
677 | state->args.colors.inside.wrong = parse_color(optarg); | ||
678 | } | ||
640 | break; | 679 | break; |
641 | case LO_KEY_HL_COLOR: | 680 | case LO_KEY_HL_COLOR: |
642 | state->args.colors.key_highlight = parse_color(optarg); | 681 | if (state) { |
682 | state->args.colors.key_highlight = parse_color(optarg); | ||
683 | } | ||
643 | break; | 684 | break; |
644 | case LO_LINE_COLOR: | 685 | case LO_LINE_COLOR: |
645 | state->args.colors.line.input = parse_color(optarg); | 686 | if (state) { |
687 | state->args.colors.line.input = parse_color(optarg); | ||
688 | } | ||
646 | break; | 689 | break; |
647 | case LO_LINE_CLEAR_COLOR: | 690 | case LO_LINE_CLEAR_COLOR: |
648 | state->args.colors.line.cleared = parse_color(optarg); | 691 | if (state) { |
692 | state->args.colors.line.cleared = parse_color(optarg); | ||
693 | } | ||
649 | break; | 694 | break; |
650 | case LO_LINE_VER_COLOR: | 695 | case LO_LINE_VER_COLOR: |
651 | state->args.colors.line.verifying = parse_color(optarg); | 696 | if (state) { |
697 | state->args.colors.line.verifying = parse_color(optarg); | ||
698 | } | ||
652 | break; | 699 | break; |
653 | case LO_LINE_WRONG_COLOR: | 700 | case LO_LINE_WRONG_COLOR: |
654 | state->args.colors.line.wrong = parse_color(optarg); | 701 | if (state) { |
702 | state->args.colors.line.wrong = parse_color(optarg); | ||
703 | } | ||
655 | break; | 704 | break; |
656 | case LO_RING_COLOR: | 705 | case LO_RING_COLOR: |
657 | state->args.colors.ring.input = parse_color(optarg); | 706 | if (state) { |
707 | state->args.colors.ring.input = parse_color(optarg); | ||
708 | } | ||
658 | break; | 709 | break; |
659 | case LO_RING_CLEAR_COLOR: | 710 | case LO_RING_CLEAR_COLOR: |
660 | state->args.colors.ring.cleared = parse_color(optarg); | 711 | if (state) { |
712 | state->args.colors.ring.cleared = parse_color(optarg); | ||
713 | } | ||
661 | break; | 714 | break; |
662 | case LO_RING_VER_COLOR: | 715 | case LO_RING_VER_COLOR: |
663 | state->args.colors.ring.verifying = parse_color(optarg); | 716 | if (state) { |
717 | state->args.colors.ring.verifying = parse_color(optarg); | ||
718 | } | ||
664 | break; | 719 | break; |
665 | case LO_RING_WRONG_COLOR: | 720 | case LO_RING_WRONG_COLOR: |
666 | state->args.colors.ring.wrong = parse_color(optarg); | 721 | if (state) { |
722 | state->args.colors.ring.wrong = parse_color(optarg); | ||
723 | } | ||
667 | break; | 724 | break; |
668 | case LO_SEP_COLOR: | 725 | case LO_SEP_COLOR: |
669 | state->args.colors.separator = parse_color(optarg); | 726 | if (state) { |
727 | state->args.colors.separator = parse_color(optarg); | ||
728 | } | ||
670 | break; | 729 | break; |
671 | case LO_TEXT_COLOR: | 730 | case LO_TEXT_COLOR: |
672 | state->args.colors.text.input = parse_color(optarg); | 731 | if (state) { |
732 | state->args.colors.text.input = parse_color(optarg); | ||
733 | } | ||
673 | break; | 734 | break; |
674 | case LO_TEXT_CLEAR_COLOR: | 735 | case LO_TEXT_CLEAR_COLOR: |
675 | state->args.colors.text.cleared = parse_color(optarg); | 736 | if (state) { |
737 | state->args.colors.text.cleared = parse_color(optarg); | ||
738 | } | ||
676 | break; | 739 | break; |
677 | case LO_TEXT_VER_COLOR: | 740 | case LO_TEXT_VER_COLOR: |
678 | state->args.colors.text.verifying = parse_color(optarg); | 741 | if (state) { |
742 | state->args.colors.text.verifying = parse_color(optarg); | ||
743 | } | ||
679 | break; | 744 | break; |
680 | case LO_TEXT_WRONG_COLOR: | 745 | case LO_TEXT_WRONG_COLOR: |
681 | state->args.colors.text.wrong = parse_color(optarg); | 746 | if (state) { |
747 | state->args.colors.text.wrong = parse_color(optarg); | ||
748 | } | ||
682 | break; | 749 | break; |
683 | default: | 750 | default: |
684 | fprintf(stderr, "%s", usage); | 751 | fprintf(stderr, "%s", usage); |
@@ -759,7 +826,7 @@ static int load_config(char *path, struct swaylock_state *state, | |||
759 | char flag[strlen(line) + 3]; | 826 | char flag[strlen(line) + 3]; |
760 | sprintf(flag, "--%s", line); | 827 | sprintf(flag, "--%s", line); |
761 | char *argv[] = {"swaylock", flag}; | 828 | char *argv[] = {"swaylock", flag}; |
762 | int result = parse_options(2, argv, state, line_mode); | 829 | int result = parse_options(2, argv, state, line_mode, NULL); |
763 | if (result != 0) { | 830 | if (result != 0) { |
764 | free(line); | 831 | free(line); |
765 | fclose(config); | 832 | fclose(config); |
@@ -789,18 +856,10 @@ int main(int argc, char **argv) { | |||
789 | wlr_log_init(WLR_DEBUG, NULL); | 856 | wlr_log_init(WLR_DEBUG, NULL); |
790 | 857 | ||
791 | char *config_path = NULL; | 858 | char *config_path = NULL; |
792 | static struct option long_options[] = { | 859 | int result = parse_options(argc, argv, NULL, NULL, &config_path); |
793 | {"config", required_argument, NULL, 'C'}, | 860 | if (result != 0) { |
794 | {0, 0, 0, 0}, | 861 | free(config_path); |
795 | }; | 862 | return result; |
796 | while (1) { | ||
797 | int c = getopt_long(argc, argv, "C:", long_options, NULL); | ||
798 | if (c == -1) { | ||
799 | break; | ||
800 | } else if (c == 'C') { | ||
801 | config_path = strdup(optarg); | ||
802 | break; | ||
803 | } | ||
804 | } | 863 | } |
805 | if (!config_path) { | 864 | if (!config_path) { |
806 | config_path = get_config_path(); | 865 | config_path = get_config_path(); |
@@ -817,7 +876,7 @@ int main(int argc, char **argv) { | |||
817 | 876 | ||
818 | if (argc > 1) { | 877 | if (argc > 1) { |
819 | wlr_log(WLR_DEBUG, "Parsing CLI Args"); | 878 | wlr_log(WLR_DEBUG, "Parsing CLI Args"); |
820 | int result = parse_options(argc, argv, &state, &line_mode); | 879 | int result = parse_options(argc, argv, &state, &line_mode, NULL); |
821 | if (result != 0) { | 880 | if (result != 0) { |
822 | return result; | 881 | return result; |
823 | } | 882 | } |