1
0
mirror of https://github.com/emersion/kanshi synced 2024-11-23 00:02:16 +01:00

Require profiles with a name to have a profile directive

Also make the syntax without a "profile" directive legacy by removing
docs for it.

Closes: https://github.com/emersion/kanshi/issues/75
This commit is contained in:
Simon Ser 2020-03-30 15:43:03 +02:00
parent dc9f4c8fc3
commit ef4c7f083d
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 40 additions and 20 deletions

@ -6,18 +6,18 @@ kanshi - configuration file
# DESCRIPTION # DESCRIPTION
A kanshi configuration file is a list of profiles. Each profile starts with an A kanshi configuration file is a list of profiles. Each profile has an
optional name and contains directives delimited by brackets (*{* and *}*). optional name and contains directives delimited by brackets (*{* and *}*).
Example: Example:
``` ```
{ profile {
output LVDS-1 disable output LVDS-1 disable
output "Some Company ASDF 4242" mode 1600x900 position 0,0 output "Some Company ASDF 4242" mode 1600x900 position 0,0
} }
nomad { profile nomad {
output LVDS-1 enable scale 2 output LVDS-1 enable scale 2
} }
``` ```
@ -65,7 +65,6 @@ Directives are followed by space-separated arguments. Arguments can be quoted
} }
``` ```
# OUTPUT DIRECTIVES # OUTPUT DIRECTIVES
*enable*|*disable* *enable*|*disable*
@ -96,7 +95,6 @@ Directives are followed by space-separated arguments. Arguments can be quoted
or "flipped", "flipped-90", "flipped-180", "flipped-270" for a rotation and or "flipped", "flipped-90", "flipped-180", "flipped-270" for a rotation and
a flip; or "normal" for no transform. a flip; or "normal" for no transform.
# AUTHORS # AUTHORS
Maintained by Simon Ser <contact@emersion.fr>, who is assisted by other Maintained by Simon Ser <contact@emersion.fr>, who is assisted by other

@ -400,18 +400,23 @@ static struct kanshi_profile *parse_profile(struct kanshi_parser *parser) {
wl_list_init(&profile->outputs); wl_list_init(&profile->outputs);
wl_list_init(&profile->commands); wl_list_init(&profile->commands);
// First parse an optional profile name if (!parser_next_token(parser)) {
parser->tok_str_len = 0;
if (!parser_read_str(parser)) {
fprintf(stderr, "expected new profile, got %s\n",
token_type_str(parser->tok_type));
return NULL; return NULL;
} }
profile->name = (parser->tok_str_len == 0) ? NULL : strdup(parser->tok_str);
// Then parse the opening bracket switch (parser->tok_type) {
if (!parser_expect_token(parser, KANSHI_TOKEN_LBRACKET)) { case KANSHI_TOKEN_LBRACKET:
return NULL; break;
case KANSHI_TOKEN_STR:
// Parse an optional profile name
profile->name = strdup(parser->tok_str);
if (!parser_expect_token(parser, KANSHI_TOKEN_LBRACKET)) {
return NULL;
}
break;
default:
fprintf(stderr, "unexpected %s, expected '{' or a profile name\n",
token_type_str(parser->tok_type));
} }
// Use the bracket position to generate a default profile name // Use the bracket position to generate a default profile name
@ -491,13 +496,30 @@ static struct kanshi_config *_parse_config(struct kanshi_parser *parser) {
continue; continue;
} }
struct kanshi_profile *profile = parse_profile(parser); if (ch == '{') {
if (!profile) { // Legacy profile syntax without a profile directive
return NULL; struct kanshi_profile *profile = parse_profile(parser);
} if (!profile) {
return NULL;
}
wl_list_insert(config->profiles.prev, &profile->link);
} else {
if (!parser_expect_token(parser, KANSHI_TOKEN_STR)) {
return NULL;
}
// Inset at the end to preserve ordering const char *directive = parser->tok_str;
wl_list_insert(config->profiles.prev, &profile->link); if (strcmp(parser->tok_str, "profile") == 0) {
struct kanshi_profile *profile = parse_profile(parser);
if (!profile) {
return NULL;
}
wl_list_insert(config->profiles.prev, &profile->link);
} else {
fprintf(stderr, "unknown directive '%s'\n", directive);
return NULL;
}
}
} }
} }