Merge pull request #2294 from RedSoxFan/fix-swaylock-args

Fix swaylock arguments
This commit is contained in:
Drew DeVault 2018-07-17 19:52:12 -07:00 committed by GitHub
commit 81e4bbf8b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -345,20 +345,23 @@ static void load_image(char *arg, struct swaylock_state *state) {
image->path = strdup(arg); image->path = strdup(arg);
} }
bool exists = false; struct swaylock_image *iter_image, *temp;
struct swaylock_image *iter_image; wl_list_for_each_safe(iter_image, temp, &state->images, link) {
wl_list_for_each(iter_image, &state->images, link) {
if (lenient_strcmp(iter_image->output_name, image->output_name) == 0) { if (lenient_strcmp(iter_image->output_name, image->output_name) == 0) {
exists = true;
break;
}
}
if (exists) {
if (image->output_name) { if (image->output_name) {
wlr_log(WLR_ERROR, "Multiple images defined for output %s", wlr_log(WLR_DEBUG,
image->output_name); "Replacing image defined for output %s with %s",
image->output_name, image->path);
} else { } else {
wlr_log(WLR_ERROR, "Multiple default images defined"); wlr_log(WLR_DEBUG, "Replacing default image with %s",
image->path);
}
wl_list_remove(&iter_image->link);
free(iter_image->cairo_surface);
free(iter_image->output_name);
free(iter_image->path);
free(iter_image);
break;
} }
} }
@ -420,7 +423,7 @@ enum line_mode {
}; };
static int parse_options(int argc, char **argv, struct swaylock_state *state, static int parse_options(int argc, char **argv, struct swaylock_state *state,
enum line_mode *line_mode) { enum line_mode *line_mode, char **config_path) {
enum long_option_codes { enum long_option_codes {
LO_BS_HL_COLOR = 256, LO_BS_HL_COLOR = 256,
LO_FONT, LO_FONT,
@ -572,38 +575,58 @@ static int parse_options(int argc, char **argv, struct swaylock_state *state,
} }
switch (c) { switch (c) {
case 'C': case 'C':
// Config file. This will have already been handled so just ignore. if (config_path) {
*config_path = strdup(optarg);
}
break; break;
case 'c': case 'c':
if (state) {
state->args.colors.background = parse_color(optarg); state->args.colors.background = parse_color(optarg);
state->args.mode = BACKGROUND_MODE_SOLID_COLOR; state->args.mode = BACKGROUND_MODE_SOLID_COLOR;
}
break; break;
case 'e': case 'e':
if (state) {
state->args.ignore_empty = true; state->args.ignore_empty = true;
}
break; break;
case 'f': case 'f':
if (state) {
state->args.daemonize = true; state->args.daemonize = true;
}
break; break;
case 'i': case 'i':
if (state) {
load_image(optarg, state); load_image(optarg, state);
}
break; break;
case 'n': case 'n':
if (line_mode) {
*line_mode = LM_INSIDE; *line_mode = LM_INSIDE;
}
break; break;
case 'r': case 'r':
if (line_mode) {
*line_mode = LM_RING; *line_mode = LM_RING;
}
break; break;
case 's': case 's':
if (state) {
state->args.mode = parse_background_mode(optarg); state->args.mode = parse_background_mode(optarg);
if (state->args.mode == BACKGROUND_MODE_INVALID) { if (state->args.mode == BACKGROUND_MODE_INVALID) {
return 1; return 1;
} }
}
break; break;
case 't': case 't':
if (state) {
state->args.mode = BACKGROUND_MODE_TILE; state->args.mode = BACKGROUND_MODE_TILE;
}
break; break;
case 'u': case 'u':
if (state) {
state->args.show_indicator = false; state->args.show_indicator = false;
}
break; break;
case 'v': case 'v':
#if defined SWAY_GIT_VERSION && defined SWAY_GIT_BRANCH && defined SWAY_VERSION_DATE #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,
#else #else
fprintf(stdout, "version unknown\n"); fprintf(stdout, "version unknown\n");
#endif #endif
return 0; return 1;
case LO_BS_HL_COLOR: case LO_BS_HL_COLOR:
if (state) {
state->args.colors.bs_highlight = parse_color(optarg); state->args.colors.bs_highlight = parse_color(optarg);
}
break; break;
case LO_FONT: case LO_FONT:
if (state) {
free(state->args.font); free(state->args.font);
state->args.font = strdup(optarg); state->args.font = strdup(optarg);
}
break; break;
case LO_IND_RADIUS: case LO_IND_RADIUS:
if (state) {
state->args.radius = strtol(optarg, NULL, 0); state->args.radius = strtol(optarg, NULL, 0);
}
break; break;
case LO_IND_THICKNESS: case LO_IND_THICKNESS:
if (state) {
state->args.thickness = strtol(optarg, NULL, 0); state->args.thickness = strtol(optarg, NULL, 0);
}
break; break;
case LO_INSIDE_COLOR: case LO_INSIDE_COLOR:
if (state) {
state->args.colors.inside.input = parse_color(optarg); state->args.colors.inside.input = parse_color(optarg);
}
break; break;
case LO_INSIDE_CLEAR_COLOR: case LO_INSIDE_CLEAR_COLOR:
if (state) {
state->args.colors.inside.cleared = parse_color(optarg); state->args.colors.inside.cleared = parse_color(optarg);
}
break; break;
case LO_INSIDE_VER_COLOR: case LO_INSIDE_VER_COLOR:
if (state) {
state->args.colors.inside.verifying = parse_color(optarg); state->args.colors.inside.verifying = parse_color(optarg);
}
break; break;
case LO_INSIDE_WRONG_COLOR: case LO_INSIDE_WRONG_COLOR:
if (state) {
state->args.colors.inside.wrong = parse_color(optarg); state->args.colors.inside.wrong = parse_color(optarg);
}
break; break;
case LO_KEY_HL_COLOR: case LO_KEY_HL_COLOR:
if (state) {
state->args.colors.key_highlight = parse_color(optarg); state->args.colors.key_highlight = parse_color(optarg);
}
break; break;
case LO_LINE_COLOR: case LO_LINE_COLOR:
if (state) {
state->args.colors.line.input = parse_color(optarg); state->args.colors.line.input = parse_color(optarg);
}
break; break;
case LO_LINE_CLEAR_COLOR: case LO_LINE_CLEAR_COLOR:
if (state) {
state->args.colors.line.cleared = parse_color(optarg); state->args.colors.line.cleared = parse_color(optarg);
}
break; break;
case LO_LINE_VER_COLOR: case LO_LINE_VER_COLOR:
if (state) {
state->args.colors.line.verifying = parse_color(optarg); state->args.colors.line.verifying = parse_color(optarg);
}
break; break;
case LO_LINE_WRONG_COLOR: case LO_LINE_WRONG_COLOR:
if (state) {
state->args.colors.line.wrong = parse_color(optarg); state->args.colors.line.wrong = parse_color(optarg);
}
break; break;
case LO_RING_COLOR: case LO_RING_COLOR:
if (state) {
state->args.colors.ring.input = parse_color(optarg); state->args.colors.ring.input = parse_color(optarg);
}
break; break;
case LO_RING_CLEAR_COLOR: case LO_RING_CLEAR_COLOR:
if (state) {
state->args.colors.ring.cleared = parse_color(optarg); state->args.colors.ring.cleared = parse_color(optarg);
}
break; break;
case LO_RING_VER_COLOR: case LO_RING_VER_COLOR:
if (state) {
state->args.colors.ring.verifying = parse_color(optarg); state->args.colors.ring.verifying = parse_color(optarg);
}
break; break;
case LO_RING_WRONG_COLOR: case LO_RING_WRONG_COLOR:
if (state) {
state->args.colors.ring.wrong = parse_color(optarg); state->args.colors.ring.wrong = parse_color(optarg);
}
break; break;
case LO_SEP_COLOR: case LO_SEP_COLOR:
if (state) {
state->args.colors.separator = parse_color(optarg); state->args.colors.separator = parse_color(optarg);
}
break; break;
case LO_TEXT_COLOR: case LO_TEXT_COLOR:
if (state) {
state->args.colors.text.input = parse_color(optarg); state->args.colors.text.input = parse_color(optarg);
}
break; break;
case LO_TEXT_CLEAR_COLOR: case LO_TEXT_CLEAR_COLOR:
if (state) {
state->args.colors.text.cleared = parse_color(optarg); state->args.colors.text.cleared = parse_color(optarg);
}
break; break;
case LO_TEXT_VER_COLOR: case LO_TEXT_VER_COLOR:
if (state) {
state->args.colors.text.verifying = parse_color(optarg); state->args.colors.text.verifying = parse_color(optarg);
}
break; break;
case LO_TEXT_WRONG_COLOR: case LO_TEXT_WRONG_COLOR:
if (state) {
state->args.colors.text.wrong = parse_color(optarg); state->args.colors.text.wrong = parse_color(optarg);
}
break; break;
default: default:
fprintf(stderr, "%s", usage); fprintf(stderr, "%s", usage);
@ -759,7 +826,7 @@ static int load_config(char *path, struct swaylock_state *state,
char flag[strlen(line) + 3]; char flag[strlen(line) + 3];
sprintf(flag, "--%s", line); sprintf(flag, "--%s", line);
char *argv[] = {"swaylock", flag}; char *argv[] = {"swaylock", flag};
int result = parse_options(2, argv, state, line_mode); int result = parse_options(2, argv, state, line_mode, NULL);
if (result != 0) { if (result != 0) {
free(line); free(line);
fclose(config); fclose(config);
@ -789,18 +856,10 @@ int main(int argc, char **argv) {
wlr_log_init(WLR_DEBUG, NULL); wlr_log_init(WLR_DEBUG, NULL);
char *config_path = NULL; char *config_path = NULL;
static struct option long_options[] = { int result = parse_options(argc, argv, NULL, NULL, &config_path);
{"config", required_argument, NULL, 'C'}, if (result != 0) {
{0, 0, 0, 0}, free(config_path);
}; return result;
while (1) {
int c = getopt_long(argc, argv, "C:", long_options, NULL);
if (c == -1) {
break;
} else if (c == 'C') {
config_path = strdup(optarg);
break;
}
} }
if (!config_path) { if (!config_path) {
config_path = get_config_path(); config_path = get_config_path();
@ -817,7 +876,7 @@ int main(int argc, char **argv) {
if (argc > 1) { if (argc > 1) {
wlr_log(WLR_DEBUG, "Parsing CLI Args"); wlr_log(WLR_DEBUG, "Parsing CLI Args");
int result = parse_options(argc, argv, &state, &line_mode); int result = parse_options(argc, argv, &state, &line_mode, NULL);
if (result != 0) { if (result != 0) {
return result; return result;
} }